rubocop 0.45.0 → 0.46.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubocop might be problematic. Click here for more details.

Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +17 -0
  4. data/config/enabled.yml +29 -2
  5. data/lib/rubocop.rb +6 -1
  6. data/lib/rubocop/config.rb +0 -10
  7. data/lib/rubocop/config_loader.rb +21 -9
  8. data/lib/rubocop/cop/bundler/duplicated_gem.rb +69 -0
  9. data/lib/rubocop/cop/bundler/ordered_gems.rb +54 -0
  10. data/lib/rubocop/cop/cop.rb +1 -0
  11. data/lib/rubocop/cop/lint/debugger.rb +9 -1
  12. data/lib/rubocop/cop/lint/each_with_object_argument.rb +5 -6
  13. data/lib/rubocop/cop/lint/eval.rb +3 -7
  14. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +6 -4
  15. data/lib/rubocop/cop/lint/unneeded_splat_expansion.rb +13 -4
  16. data/lib/rubocop/cop/lint/useless_comparison.rb +5 -9
  17. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -0
  18. data/lib/rubocop/cop/metrics/line_length.rb +16 -3
  19. data/lib/rubocop/cop/mixin/access_modifier_node.rb +9 -9
  20. data/lib/rubocop/cop/mixin/configurable_numbering.rb +14 -7
  21. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +92 -20
  22. data/lib/rubocop/cop/performance/compare_with_block.rb +61 -0
  23. data/lib/rubocop/cop/performance/count.rb +21 -57
  24. data/lib/rubocop/cop/performance/detect.rb +15 -15
  25. data/lib/rubocop/cop/performance/flat_map.rb +23 -35
  26. data/lib/rubocop/cop/performance/sample.rb +84 -82
  27. data/lib/rubocop/cop/performance/string_replacement.rb +18 -43
  28. data/lib/rubocop/cop/rails/enum_uniqueness.rb +71 -0
  29. data/lib/rubocop/cop/rails/http_positional_arguments.rb +1 -1
  30. data/lib/rubocop/cop/rails/output.rb +8 -12
  31. data/lib/rubocop/cop/rails/read_write_attribute.rb +10 -6
  32. data/lib/rubocop/cop/rails/request_referer.rb +8 -9
  33. data/lib/rubocop/cop/rails/scope_args.rb +5 -11
  34. data/lib/rubocop/cop/style/access_modifier_indentation.rb +1 -1
  35. data/lib/rubocop/cop/style/and_or.rb +1 -1
  36. data/lib/rubocop/cop/style/array_join.rb +4 -8
  37. data/lib/rubocop/cop/style/block_comments.rb +1 -1
  38. data/lib/rubocop/cop/style/case_equality.rb +3 -3
  39. data/lib/rubocop/cop/style/character_literal.rb +2 -4
  40. data/lib/rubocop/cop/style/class_check.rb +6 -6
  41. data/lib/rubocop/cop/style/colon_method_call.rb +6 -6
  42. data/lib/rubocop/cop/style/each_with_object.rb +13 -17
  43. data/lib/rubocop/cop/style/empty_literal.rb +46 -36
  44. data/lib/rubocop/cop/style/empty_method.rb +96 -0
  45. data/lib/rubocop/cop/style/even_odd.rb +19 -50
  46. data/lib/rubocop/cop/style/hash_syntax.rb +4 -1
  47. data/lib/rubocop/cop/style/lambda.rb +8 -18
  48. data/lib/rubocop/cop/style/module_function.rb +14 -11
  49. data/lib/rubocop/cop/style/nil_comparison.rb +4 -7
  50. data/lib/rubocop/cop/style/non_nil_check.rb +18 -36
  51. data/lib/rubocop/cop/style/numeric_predicate.rb +9 -10
  52. data/lib/rubocop/cop/style/op_method.rb +7 -9
  53. data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
  54. data/lib/rubocop/cop/style/proc.rb +5 -9
  55. data/lib/rubocop/cop/style/redundant_freeze.rb +6 -7
  56. data/lib/rubocop/cop/style/send.rb +6 -3
  57. data/lib/rubocop/cop/style/space_inside_block_braces.rb +1 -1
  58. data/lib/rubocop/cop/style/special_global_vars.rb +3 -3
  59. data/lib/rubocop/cop/style/symbol_proc.rb +22 -43
  60. data/lib/rubocop/cop/style/ternary_parentheses.rb +67 -18
  61. data/lib/rubocop/cop/util.rb +1 -1
  62. data/lib/rubocop/cop/variable_force/assignment.rb +2 -0
  63. data/lib/rubocop/cop/variable_force/locatable.rb +8 -6
  64. data/lib/rubocop/cop/variable_force/reference.rb +2 -0
  65. data/lib/rubocop/formatter/base_formatter.rb +4 -8
  66. data/lib/rubocop/formatter/fuubar_style_formatter.rb +6 -0
  67. data/lib/rubocop/node_pattern.rb +7 -5
  68. data/lib/rubocop/processed_source.rb +1 -0
  69. data/lib/rubocop/rspec/cop_helper.rb +4 -0
  70. data/lib/rubocop/rspec/host_environment_simulation_helper.rb +1 -1
  71. data/lib/rubocop/version.rb +1 -1
  72. metadata +7 -3
  73. data/lib/rubocop/cop/performance/sort_with_block.rb +0 -53
@@ -11,6 +11,12 @@ module RuboCop
11
11
  class FuubarStyleFormatter < ClangStyleFormatter
12
12
  RESET_SEQUENCE = "\e[0m".freeze
13
13
 
14
+ def initialize(*)
15
+ @severest_offense = nil
16
+
17
+ super
18
+ end
19
+
14
20
  def started(target_files)
15
21
  super
16
22
 
@@ -97,7 +97,7 @@ module RuboCop
97
97
  # @private
98
98
  # Builds Ruby code which implements a pattern
99
99
  class Compiler
100
- RSYM = %r{:(?:[\w+@_*/?!<>=~|%^-]+|\[\]=?)}
100
+ RSYM = %r{:(?:[\w+@*/?!<>=~|%^-]+|\[\]=?)}
101
101
  ID_CHAR = /[a-zA-Z_]/
102
102
  META = /\(|\)|\{|\}|\[|\]|\$\.\.\.|\$|!|\^|\.\.\./
103
103
  NUMBER = /-?\d+(?:\.\d+)?/
@@ -178,7 +178,7 @@ module RuboCop
178
178
  end
179
179
 
180
180
  def compile_seq_terms(tokens, cur_node)
181
- terms, size =
181
+ ret, size =
182
182
  compile_seq_terms_with_size(tokens, cur_node) do |token, terms, index|
183
183
  case token
184
184
  when '...'.freeze
@@ -188,7 +188,7 @@ module RuboCop
188
188
  end
189
189
  end
190
190
 
191
- terms << "(#{cur_node}.children.size == #{size})"
191
+ ret << "(#{cur_node}.children.size == #{size})"
192
192
  end
193
193
 
194
194
  def compile_seq_terms_with_size(tokens, cur_node)
@@ -334,7 +334,8 @@ module RuboCop
334
334
  "(#{cur_node}#{'.type' if seq_head} == temp#{@unify[name]})"
335
335
  else
336
336
  n = @unify[name] = next_temp_value
337
- "(temp#{n} = #{cur_node}#{'.type' if seq_head}; true)"
337
+ # double assign to temp#{n} to avoid "assigned but unused variable"
338
+ "(temp#{n} = temp#{n} = #{cur_node}#{'.type' if seq_head}; true)"
338
339
  end
339
340
  end
340
341
 
@@ -444,7 +445,8 @@ module RuboCop
444
445
 
445
446
  def with_temp_node(cur_node)
446
447
  with_temp_variable do |temp_var|
447
- yield "#{temp_var} = #{cur_node}", temp_var
448
+ # double assign to temp#{n} to avoid "assigned but unused variable"
449
+ yield "#{temp_var} = #{temp_var} = #{cur_node}", temp_var
448
450
  end
449
451
  end
450
452
 
@@ -31,6 +31,7 @@ module RuboCop
31
31
  @path = path
32
32
  @diagnostics = []
33
33
  @ruby_version = ruby_version
34
+ @parser_error = nil
34
35
 
35
36
  parse(source, ruby_version)
36
37
  end
@@ -12,6 +12,10 @@ module CopHelper
12
12
  Tempfile.open('tmp') { |f| inspect_source(cop, source, f) }
13
13
  end
14
14
 
15
+ def inspect_gemfile(cop, source)
16
+ inspect_source(cop, source, 'Gemfile')
17
+ end
18
+
15
19
  def inspect_source(cop, source, file = nil)
16
20
  if source.is_a?(Array) && source.size == 1
17
21
  raise "Don't use an array for a single line of code: #{source}"
@@ -10,7 +10,7 @@ module HostEnvironmentSimulatorHelper
10
10
  pid = ::Process.fork do
11
11
  # Need to write coverage result under different name
12
12
  if defined?(SimpleCov)
13
- SimpleCov.command_name "rspec_#{Process.pid}"
13
+ SimpleCov.coverage_dir "coverage/ignored_results_#{Process.pid}"
14
14
  SimpleCov.pid = Process.pid
15
15
  end
16
16
 
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '0.45.0'.freeze
6
+ STRING = '0.46.0'.freeze
7
7
 
8
8
  MSG = '%s (using Parser %s, running on %s %s %s)'.freeze
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.45.0
4
+ version: 0.46.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-10-31 00:00:00.000000000 Z
13
+ date: 2016-11-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rainbow
@@ -146,6 +146,8 @@ files:
146
146
  - lib/rubocop/config_loader_resolver.rb
147
147
  - lib/rubocop/config_store.rb
148
148
  - lib/rubocop/cop/autocorrect_logic.rb
149
+ - lib/rubocop/cop/bundler/duplicated_gem.rb
150
+ - lib/rubocop/cop/bundler/ordered_gems.rb
149
151
  - lib/rubocop/cop/commissioner.rb
150
152
  - lib/rubocop/cop/cop.rb
151
153
  - lib/rubocop/cop/corrector.rb
@@ -268,6 +270,7 @@ files:
268
270
  - lib/rubocop/cop/offense.rb
269
271
  - lib/rubocop/cop/performance/case_when_splat.rb
270
272
  - lib/rubocop/cop/performance/casecmp.rb
273
+ - lib/rubocop/cop/performance/compare_with_block.rb
271
274
  - lib/rubocop/cop/performance/count.rb
272
275
  - lib/rubocop/cop/performance/detect.rb
273
276
  - lib/rubocop/cop/performance/double_start_end_with.rb
@@ -284,7 +287,6 @@ files:
284
287
  - lib/rubocop/cop/performance/reverse_each.rb
285
288
  - lib/rubocop/cop/performance/sample.rb
286
289
  - lib/rubocop/cop/performance/size.rb
287
- - lib/rubocop/cop/performance/sort_with_block.rb
288
290
  - lib/rubocop/cop/performance/start_with.rb
289
291
  - lib/rubocop/cop/performance/string_replacement.rb
290
292
  - lib/rubocop/cop/performance/times_map.rb
@@ -293,6 +295,7 @@ files:
293
295
  - lib/rubocop/cop/rails/delegate.rb
294
296
  - lib/rubocop/cop/rails/delegate_allow_blank.rb
295
297
  - lib/rubocop/cop/rails/dynamic_find_by.rb
298
+ - lib/rubocop/cop/rails/enum_uniqueness.rb
296
299
  - lib/rubocop/cop/rails/exit.rb
297
300
  - lib/rubocop/cop/rails/find_by.rb
298
301
  - lib/rubocop/cop/rails/find_each.rb
@@ -365,6 +368,7 @@ files:
365
368
  - lib/rubocop/cop/style/empty_lines_around_method_body.rb
366
369
  - lib/rubocop/cop/style/empty_lines_around_module_body.rb
367
370
  - lib/rubocop/cop/style/empty_literal.rb
371
+ - lib/rubocop/cop/style/empty_method.rb
368
372
  - lib/rubocop/cop/style/encoding.rb
369
373
  - lib/rubocop/cop/style/end_block.rb
370
374
  - lib/rubocop/cop/style/end_of_line.rb
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module Performance
6
- # This cop identifies places where `sort { |a, b| a.foo <=> b.foo }`
7
- # can be replaced by `sort_by(&:foo)`.
8
- #
9
- # @example
10
- # @bad
11
- # array.sort { |a, b| a.foo <=> b.foo }
12
- #
13
- # @good
14
- # array.sort_by(&:foo)
15
- # array.sort_by { |v| v.foo }
16
- # array.sort_by do |var|
17
- # var.foo
18
- # end
19
- class SortWithBlock < Cop
20
- MSG = 'Use `sort_by(&:%s)` instead of ' \
21
- '`sort { |%s, %s| %s.%s <=> %s.%s }`.'.freeze
22
-
23
- def_node_matcher :sort, <<-END
24
- (block $(send _ :sort) (args (arg $_a) (arg $_b)) (send (send (lvar _a) $_m) :<=> (send (lvar _b) $_m)))
25
- END
26
-
27
- def on_block(node)
28
- sort(node) do |send, var_a, var_b, method|
29
- range = sort_range(send, node)
30
- add_offense(node, range,
31
- format(MSG, method, var_a, var_b,
32
- var_a, method, var_b, method))
33
- end
34
- end
35
-
36
- def autocorrect(node)
37
- send, = *node
38
-
39
- lambda do |corrector|
40
- method = node.children.last.children.last.children.last
41
- corrector.replace(sort_range(send, node), "sort_by(&:#{method})")
42
- end
43
- end
44
-
45
- private
46
-
47
- def sort_range(send, node)
48
- range_between(send.loc.selector.begin_pos, node.loc.end.end_pos)
49
- end
50
- end
51
- end
52
- end
53
- end