rubocop 1.4.0 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/assets/logo.png +0 -0
  4. data/assets/output.html.erb +261 -0
  5. data/config/default.yml +49 -9
  6. data/lib/rubocop.rb +4 -0
  7. data/lib/rubocop/cli.rb +5 -1
  8. data/lib/rubocop/cli/command/suggest_extensions.rb +108 -0
  9. data/lib/rubocop/config_loader.rb +1 -1
  10. data/lib/rubocop/config_loader_resolver.rb +5 -1
  11. data/lib/rubocop/config_obsoletion.rb +21 -3
  12. data/lib/rubocop/config_validator.rb +8 -1
  13. data/lib/rubocop/cop/autocorrect_logic.rb +21 -6
  14. data/lib/rubocop/cop/generator.rb +1 -1
  15. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +3 -3
  16. data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +6 -1
  17. data/lib/rubocop/cop/layout/end_of_line.rb +5 -5
  18. data/lib/rubocop/cop/layout/first_argument_indentation.rb +7 -2
  19. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +12 -0
  20. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +7 -3
  21. data/lib/rubocop/cop/lint/interpolation_check.rb +7 -2
  22. data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +1 -1
  23. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +13 -0
  24. data/lib/rubocop/cop/lint/unexpected_block_arity.rb +85 -0
  25. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +7 -2
  26. data/lib/rubocop/cop/metrics/abc_size.rb +25 -1
  27. data/lib/rubocop/cop/metrics/block_length.rb +13 -7
  28. data/lib/rubocop/cop/metrics/method_length.rb +7 -2
  29. data/lib/rubocop/cop/metrics/parameter_lists.rb +64 -1
  30. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +20 -10
  31. data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +146 -0
  32. data/lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb +6 -1
  33. data/lib/rubocop/cop/mixin/configurable_numbering.rb +3 -2
  34. data/lib/rubocop/cop/mixin/enforce_superclass.rb +9 -1
  35. data/lib/rubocop/cop/mixin/ignored_methods.rb +36 -3
  36. data/lib/rubocop/cop/mixin/method_complexity.rb +6 -0
  37. data/lib/rubocop/cop/naming/variable_number.rb +3 -1
  38. data/lib/rubocop/cop/style/and_or.rb +10 -0
  39. data/lib/rubocop/cop/style/class_and_module_children.rb +8 -3
  40. data/lib/rubocop/cop/style/format_string.rb +8 -3
  41. data/lib/rubocop/cop/style/if_with_semicolon.rb +39 -4
  42. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +11 -2
  43. data/lib/rubocop/cop/style/numeric_literals.rb +14 -11
  44. data/lib/rubocop/cop/style/redundant_argument.rb +3 -1
  45. data/lib/rubocop/cop/style/redundant_condition.rb +2 -1
  46. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +24 -8
  47. data/lib/rubocop/cop/style/sole_nested_conditional.rb +59 -3
  48. data/lib/rubocop/cop/style/string_concatenation.rb +7 -1
  49. data/lib/rubocop/cop/style/symbol_proc.rb +5 -3
  50. data/lib/rubocop/core_ext/hash.rb +20 -0
  51. data/lib/rubocop/ext/regexp_node.rb +29 -12
  52. data/lib/rubocop/ext/regexp_parser.rb +20 -9
  53. data/lib/rubocop/version.rb +1 -1
  54. metadata +23 -5
@@ -106,7 +106,13 @@ module RuboCop
106
106
  end
107
107
  end
108
108
 
109
- "\"#{interpolated_parts.join}\""
109
+ "\"#{handle_quotes(interpolated_parts).join}\""
110
+ end
111
+
112
+ def handle_quotes(parts)
113
+ parts.map do |part|
114
+ part == '"' ? '\"' : part
115
+ end
110
116
  end
111
117
 
112
118
  def single_quoted?(str_node)
@@ -8,6 +8,7 @@ module RuboCop
8
8
  # @example
9
9
  # # bad
10
10
  # something.map { |s| s.upcase }
11
+ # something.map { _1.upcase }
11
12
  #
12
13
  # # good
13
14
  # something.map(&:upcase)
@@ -22,9 +23,9 @@ module RuboCop
22
23
 
23
24
  def_node_matcher :proc_node?, '(send (const {nil? cbase} :Proc) :new)'
24
25
  def_node_matcher :symbol_proc?, <<~PATTERN
25
- (block
26
+ ({block numblock}
26
27
  ${(send ...) (super ...) zsuper}
27
- $(args (arg _var))
28
+ ${(args (arg _)) %Integer}
28
29
  (send (lvar _var) $_))
29
30
  PATTERN
30
31
 
@@ -40,11 +41,12 @@ module RuboCop
40
41
  return if proc_node?(dispatch_node)
41
42
  return if %i[lambda proc].include?(dispatch_node.method_name)
42
43
  return if ignored_method?(dispatch_node.method_name)
43
- return if destructuring_block_argument?(arguments_node)
44
+ return if node.block_type? && destructuring_block_argument?(arguments_node)
44
45
 
45
46
  register_offense(node, method_name, dispatch_node.method_name)
46
47
  end
47
48
  end
49
+ alias on_numblock on_block
48
50
 
49
51
  def destructuring_block_argument?(argument_node)
50
52
  argument_node.one? && argument_node.source.include?(',')
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Extensions to the core Hash class
4
+ class Hash
5
+ unless method_defined?(:slice)
6
+ # Adds `Hash#slice` for Ruby 2.4.
7
+ # Returns a hash containing a subset of keys. If a given key is not
8
+ # in the hash, it will not be returned.
9
+ #
10
+ # @return [Hash] hash containing only the keys given.
11
+ #
12
+ # @example
13
+ # { one: 1, two: 2 }.slice(:two, :three) #=> { two: 2 }
14
+ def slice(*keys)
15
+ h = {}
16
+ keys.each { |k| h[k] = self[k] if key?(k) }
17
+ h
18
+ end
19
+ end
20
+ end
@@ -15,20 +15,37 @@ module RuboCop
15
15
  # see `ext/regexp_parser`.
16
16
  attr_reader :parsed_tree
17
17
 
18
- def assign_properties(*)
19
- super
18
+ if Gem::Version.new(Regexp::Parser::VERSION) >= Gem::Version.new('2.0')
19
+ def assign_properties(*)
20
+ super
20
21
 
21
- str = with_interpolations_blanked
22
- begin
23
- @parsed_tree = Regexp::Parser.parse(str, options: options)
24
- rescue StandardError
25
- @parsed_tree = nil
26
- else
22
+ str = with_interpolations_blanked
23
+ @parsed_tree = begin
24
+ Regexp::Parser.parse(str, options: options)
25
+ rescue StandardError
26
+ nil
27
+ end
27
28
  origin = loc.begin.end
28
- source = @parsed_tree.to_s
29
- @parsed_tree.each_expression(true) do |e|
30
- e.origin = origin
31
- e.source = source
29
+ @parsed_tree&.each_expression(true) { |e| e.origin = origin }
30
+ end
31
+ # Please remove this `else` branch when support for regexp_parser 1.8 will be dropped.
32
+ # It's for compatibility with regexp_arser 1.8 and will never be maintained.
33
+ else
34
+ def assign_properties(*)
35
+ super
36
+
37
+ str = with_interpolations_blanked
38
+ begin
39
+ @parsed_tree = Regexp::Parser.parse(str, options: options)
40
+ rescue StandardError
41
+ @parsed_tree = nil
42
+ else
43
+ origin = loc.begin.end
44
+ source = @parsed_tree.to_s
45
+ @parsed_tree.each_expression(true) do |e|
46
+ e.origin = origin
47
+ e.source = source
48
+ end
32
49
  end
33
50
  end
34
51
  end
@@ -20,17 +20,28 @@ module RuboCop
20
20
  module Expression
21
21
  # Add `expression` and `loc` to all `regexp_parser` nodes
22
22
  module Base
23
- attr_accessor :origin, :source
23
+ attr_accessor :origin
24
24
 
25
- def start_index
26
- # ts is a byte index; convert it to a character index
27
- @start_index ||= source.byteslice(0, ts).length
28
- end
25
+ if Gem::Version.new(Regexp::Parser::VERSION) >= Gem::Version.new('2.0')
26
+ # Shortcut to `loc.expression`
27
+ def expression
28
+ @expression ||= origin.adjust(begin_pos: ts, end_pos: ts + full_length)
29
+ end
30
+ # Please remove this `else` branch when support for regexp_parser 1.8 will be dropped.
31
+ # It's for compatibility with regexp_arser 1.8 and will never be maintained.
32
+ else
33
+ attr_accessor :source
34
+
35
+ def start_index
36
+ # ts is a byte index; convert it to a character index
37
+ @start_index ||= source.byteslice(0, ts).length
38
+ end
29
39
 
30
- # Shortcut to `loc.expression`
31
- def expression
32
- @expression ||= begin
33
- origin.adjust(begin_pos: start_index, end_pos: start_index + full_length)
40
+ # Shortcut to `loc.expression`
41
+ def expression
42
+ @expression ||= begin
43
+ origin.adjust(begin_pos: start_index, end_pos: start_index + full_length)
44
+ end
34
45
  end
35
46
  end
36
47
 
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.4.0'
6
+ STRING = '1.5.2'
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, '\
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
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: 1.4.0
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-11-23 00:00:00.000000000 Z
13
+ date: 2020-12-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: parallel
@@ -67,6 +67,9 @@ dependencies:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '1.8'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '3.0'
70
73
  type: :runtime
71
74
  prerelease: false
72
75
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,6 +77,9 @@ dependencies:
74
77
  - - ">="
75
78
  - !ruby/object:Gem::Version
76
79
  version: '1.8'
80
+ - - "<"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
77
83
  - !ruby/object:Gem::Dependency
78
84
  name: rexml
79
85
  requirement: !ruby/object:Gem::Requirement
@@ -94,14 +100,20 @@ dependencies:
94
100
  requirements:
95
101
  - - ">="
96
102
  - !ruby/object:Gem::Version
97
- version: 1.1.1
103
+ version: 1.2.0
104
+ - - "<"
105
+ - !ruby/object:Gem::Version
106
+ version: '2.0'
98
107
  type: :runtime
99
108
  prerelease: false
100
109
  version_requirements: !ruby/object:Gem::Requirement
101
110
  requirements:
102
111
  - - ">="
103
112
  - !ruby/object:Gem::Version
104
- version: 1.1.1
113
+ version: 1.2.0
114
+ - - "<"
115
+ - !ruby/object:Gem::Version
116
+ version: '2.0'
105
117
  - !ruby/object:Gem::Dependency
106
118
  name: ruby-progressbar
107
119
  requirement: !ruby/object:Gem::Requirement
@@ -169,6 +181,8 @@ extra_rdoc_files:
169
181
  files:
170
182
  - LICENSE.txt
171
183
  - README.md
184
+ - assets/logo.png
185
+ - assets/output.html.erb
172
186
  - config/default.yml
173
187
  - exe/rubocop
174
188
  - lib/rubocop.rb
@@ -181,6 +195,7 @@ files:
181
195
  - lib/rubocop/cli/command/execute_runner.rb
182
196
  - lib/rubocop/cli/command/init_dotfile.rb
183
197
  - lib/rubocop/cli/command/show_cops.rb
198
+ - lib/rubocop/cli/command/suggest_extensions.rb
184
199
  - lib/rubocop/cli/command/version.rb
185
200
  - lib/rubocop/cli/environment.rb
186
201
  - lib/rubocop/comment_config.rb
@@ -424,6 +439,7 @@ files:
424
439
  - lib/rubocop/cop/lint/top_level_return_with_argument.rb
425
440
  - lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb
426
441
  - lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb
442
+ - lib/rubocop/cop/lint/unexpected_block_arity.rb
427
443
  - lib/rubocop/cop/lint/unified_integer.rb
428
444
  - lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb
429
445
  - lib/rubocop/cop/lint/unreachable_code.rb
@@ -452,6 +468,7 @@ files:
452
468
  - lib/rubocop/cop/metrics/utils/abc_size_calculator.rb
453
469
  - lib/rubocop/cop/metrics/utils/code_length_calculator.rb
454
470
  - lib/rubocop/cop/metrics/utils/iterating_block.rb
471
+ - lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb
455
472
  - lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb
456
473
  - lib/rubocop/cop/migration/department_name.rb
457
474
  - lib/rubocop/cop/mixin/alignment.rb
@@ -762,6 +779,7 @@ files:
762
779
  - lib/rubocop/cop/variable_force/variable.rb
763
780
  - lib/rubocop/cop/variable_force/variable_table.rb
764
781
  - lib/rubocop/cops_documentation_generator.rb
782
+ - lib/rubocop/core_ext/hash.rb
765
783
  - lib/rubocop/core_ext/string.rb
766
784
  - lib/rubocop/directive_comment.rb
767
785
  - lib/rubocop/error.rb
@@ -817,7 +835,7 @@ metadata:
817
835
  homepage_uri: https://rubocop.org/
818
836
  changelog_uri: https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md
819
837
  source_code_uri: https://github.com/rubocop-hq/rubocop/
820
- documentation_uri: https://docs.rubocop.org/rubocop/1.4/
838
+ documentation_uri: https://docs.rubocop.org/rubocop/1.5/
821
839
  bug_tracker_uri: https://github.com/rubocop-hq/rubocop/issues
822
840
  post_install_message:
823
841
  rdoc_options: []