rubocop 0.89.0 → 0.89.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/rubocop/cli/command/show_cops.rb +1 -1
  4. data/lib/rubocop/comment_config.rb +3 -5
  5. data/lib/rubocop/config.rb +1 -1
  6. data/lib/rubocop/config_loader.rb +1 -1
  7. data/lib/rubocop/config_validator.rb +1 -1
  8. data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
  9. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
  10. data/lib/rubocop/cop/layout/class_structure.rb +3 -7
  11. data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
  12. data/lib/rubocop/cop/layout/extra_spacing.rb +14 -21
  13. data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
  14. data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +2 -1
  15. data/lib/rubocop/cop/lint/missing_super.rb +9 -9
  16. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +33 -4
  17. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +14 -17
  18. data/lib/rubocop/cop/lint/uri_regexp.rb +9 -25
  19. data/lib/rubocop/cop/migration/department_name.rb +2 -2
  20. data/lib/rubocop/cop/mixin/alignment.rb +2 -1
  21. data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
  22. data/lib/rubocop/cop/mixin/enforce_superclass.rb +0 -2
  23. data/lib/rubocop/cop/mixin/hash_transform_method.rb +5 -11
  24. data/lib/rubocop/cop/mixin/line_length_help.rb +1 -3
  25. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +1 -2
  26. data/lib/rubocop/cop/mixin/percent_array.rb +2 -6
  27. data/lib/rubocop/cop/mixin/range_help.rb +18 -4
  28. data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -3
  29. data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
  30. data/lib/rubocop/cop/style/access_modifier_declarations.rb +5 -8
  31. data/lib/rubocop/cop/style/accessor_grouping.rb +20 -20
  32. data/lib/rubocop/cop/style/alias.rb +34 -33
  33. data/lib/rubocop/cop/style/and_or.rb +9 -11
  34. data/lib/rubocop/cop/style/array_join.rb +6 -8
  35. data/lib/rubocop/cop/style/ascii_comments.rb +4 -4
  36. data/lib/rubocop/cop/style/attr.rb +11 -9
  37. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +2 -5
  38. data/lib/rubocop/cop/style/bare_percent_literals.rb +10 -12
  39. data/lib/rubocop/cop/style/begin_block.rb +2 -2
  40. data/lib/rubocop/cop/style/bisected_attr_accessor.rb +9 -12
  41. data/lib/rubocop/cop/style/block_comments.rb +14 -18
  42. data/lib/rubocop/cop/style/block_delimiters.rb +23 -23
  43. data/lib/rubocop/cop/style/case_like_if.rb +17 -14
  44. data/lib/rubocop/cop/style/class_and_module_children.rb +14 -11
  45. data/lib/rubocop/cop/style/class_check.rb +7 -9
  46. data/lib/rubocop/cop/style/class_methods.rb +7 -11
  47. data/lib/rubocop/cop/style/class_vars.rb +6 -10
  48. data/lib/rubocop/cop/style/collection_methods.rb +11 -17
  49. data/lib/rubocop/cop/style/colon_method_call.rb +6 -7
  50. data/lib/rubocop/cop/style/colon_method_definition.rb +6 -6
  51. data/lib/rubocop/cop/style/command_literal.rb +23 -24
  52. data/lib/rubocop/cop/style/comment_annotation.rb +15 -15
  53. data/lib/rubocop/cop/style/commented_keyword.rb +1 -1
  54. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
  55. data/lib/rubocop/cop/style/constant_visibility.rb +3 -2
  56. data/lib/rubocop/cop/style/copyright.rb +12 -12
  57. data/lib/rubocop/cop/style/date_time.rb +1 -1
  58. data/lib/rubocop/cop/style/def_with_parentheses.rb +8 -10
  59. data/lib/rubocop/cop/style/dir.rb +7 -10
  60. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +7 -9
  61. data/lib/rubocop/cop/style/documentation.rb +2 -4
  62. data/lib/rubocop/cop/style/documentation_method.rb +1 -1
  63. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +12 -15
  64. data/lib/rubocop/cop/style/double_negation.rb +2 -2
  65. data/lib/rubocop/cop/style/each_for_simple_loop.rb +5 -8
  66. data/lib/rubocop/cop/style/each_with_object.rb +16 -17
  67. data/lib/rubocop/cop/style/empty_case_condition.rb +19 -20
  68. data/lib/rubocop/cop/style/empty_else.rb +17 -19
  69. data/lib/rubocop/cop/style/empty_literal.rb +15 -16
  70. data/lib/rubocop/cop/style/empty_method.rb +5 -8
  71. data/lib/rubocop/cop/style/encoding.rb +5 -9
  72. data/lib/rubocop/cop/style/end_block.rb +4 -6
  73. data/lib/rubocop/cop/style/eval_with_location.rb +5 -7
  74. data/lib/rubocop/cop/style/even_odd.rb +7 -11
  75. data/lib/rubocop/cop/style/expand_path_arguments.rb +21 -24
  76. data/lib/rubocop/cop/style/exponential_notation.rb +1 -1
  77. data/lib/rubocop/cop/style/float_division.rb +1 -1
  78. data/lib/rubocop/cop/style/for.rb +11 -15
  79. data/lib/rubocop/cop/style/format_string.rb +17 -19
  80. data/lib/rubocop/cop/style/format_string_token.rb +4 -7
  81. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +19 -41
  82. data/lib/rubocop/cop/style/global_vars.rb +2 -2
  83. data/lib/rubocop/cop/style/guard_clause.rb +3 -4
  84. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +1 -1
  85. data/lib/rubocop/cop/style/hash_each_methods.rb +5 -8
  86. data/lib/rubocop/cop/style/hash_syntax.rb +0 -2
  87. data/lib/rubocop/cop/style/hash_transform_keys.rb +3 -2
  88. data/lib/rubocop/cop/style/hash_transform_values.rb +2 -1
  89. data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
  90. data/lib/rubocop/cop/style/if_inside_else.rb +2 -2
  91. data/lib/rubocop/cop/style/if_unless_modifier.rb +10 -12
  92. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +3 -7
  93. data/lib/rubocop/cop/style/if_with_semicolon.rb +3 -6
  94. data/lib/rubocop/cop/style/implicit_runtime_error.rb +1 -1
  95. data/lib/rubocop/cop/style/infinite_loop.rb +23 -23
  96. data/lib/rubocop/cop/style/inline_comment.rb +3 -3
  97. data/lib/rubocop/cop/style/inverse_methods.rb +20 -29
  98. data/lib/rubocop/cop/style/lambda.rb +7 -12
  99. data/lib/rubocop/cop/style/lambda_call.rb +14 -13
  100. data/lib/rubocop/cop/style/line_end_concatenation.rb +19 -16
  101. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +2 -1
  102. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +11 -11
  103. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +4 -8
  104. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +7 -6
  105. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +2 -2
  106. data/lib/rubocop/cop/style/method_def_parentheses.rb +11 -16
  107. data/lib/rubocop/cop/style/min_max.rb +8 -12
  108. data/lib/rubocop/cop/style/missing_else.rb +13 -13
  109. data/lib/rubocop/cop/style/missing_respond_to_missing.rb +1 -1
  110. data/lib/rubocop/cop/style/mixin_grouping.rb +24 -27
  111. data/lib/rubocop/cop/style/mixin_usage.rb +1 -1
  112. data/lib/rubocop/cop/style/module_function.rb +10 -13
  113. data/lib/rubocop/cop/style/multiline_if_modifier.rb +3 -10
  114. data/lib/rubocop/cop/style/multiline_if_then.rb +4 -10
  115. data/lib/rubocop/cop/style/multiline_memoization.rb +12 -10
  116. data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
  117. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +4 -6
  118. data/lib/rubocop/cop/style/multiline_when_then.rb +7 -9
  119. data/lib/rubocop/cop/style/multiple_comparison.rb +1 -1
  120. data/lib/rubocop/cop/style/mutable_constant.rb +23 -20
  121. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +3 -1
  122. data/lib/rubocop/cop/style/redundant_sort.rb +0 -2
  123. data/lib/rubocop/cop/style/safe_navigation.rb +4 -4
  124. data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
  125. data/lib/rubocop/cop/util.rb +2 -0
  126. data/lib/rubocop/cops_documentation_generator.rb +1 -1
  127. data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
  128. data/lib/rubocop/formatter/junit_formatter.rb +1 -1
  129. data/lib/rubocop/options.rb +3 -3
  130. data/lib/rubocop/rspec/shared_contexts.rb +1 -5
  131. data/lib/rubocop/runner.rb +1 -1
  132. data/lib/rubocop/version.rb +1 -1
  133. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 220e683b0838a3b02076023d5a65ff57267b1eff2c250bb8fa65d03db9ff09ec
4
- data.tar.gz: 8fd50157ec4a8a007ab30cfb5ea34dd9b30bf4d6fa8c3d475268f73e2937bd99
3
+ metadata.gz: 3201b273ee3a04b13a9f41d768d230a5be311881c7fd0b39f24aa0d99a8a16ad
4
+ data.tar.gz: 794ba4bfcadcee6a8a9aae92f88c167dc1f75122e69f4bee08baa8f22976c1bf
5
5
  SHA512:
6
- metadata.gz: fb33582bad5b4b07308a11670c8fc173db0261e384160727057e8714f2dfb24d552663e0e14a5be1ad537bc269919e0182b2a1ca63f6ee13f471a422cae98fff
7
- data.tar.gz: 214a09139a2a0c85438e2724d289e3fb5e8e1b4d81e6a42231143803842423795867c9da4e0347df1b26e5dfaeaf108d347a1e4758a8604484e370a3e1343a74
6
+ metadata.gz: c2ea28c0fbfaa2f37ef651b91f38e3084fda1d8c829ebc1aaa839c793f0b759deb692bc70482d863797ab33799af9e083ab7f274f4faa905b956b4b53fbab96b
7
+ data.tar.gz: 2ac4b6b2e1852c4ca1df725c6de4f6d34442633cb7dea00f27499ebae6e24ad006110dd0b473c781961d6e44819039a5e5748ac0de6ec0a1b2cbceb950c3fcf2
data/README.md CHANGED
@@ -49,7 +49,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
49
49
  might want to use a conservative version lock in your `Gemfile`:
50
50
 
51
51
  ```rb
52
- gem 'rubocop', '~> 0.89.0', require: false
52
+ gem 'rubocop', '~> 0.89.1', require: false
53
53
  ```
54
54
 
55
55
  ## Quickstart
@@ -22,7 +22,7 @@ module RuboCop
22
22
  private
23
23
 
24
24
  def print_available_cops
25
- registry = Cop::Cop.registry
25
+ registry = Cop::Registry.global
26
26
  show_all = @options[:show_cops].empty?
27
27
 
28
28
  if show_all
@@ -128,9 +128,7 @@ module RuboCop
128
128
  end
129
129
 
130
130
  def each_directive
131
- return if processed_source.comments.nil?
132
-
133
- processed_source.each_comment do |comment|
131
+ processed_source.comments.each do |comment|
134
132
  directive = directive_parts(comment)
135
133
  next unless directive
136
134
 
@@ -153,11 +151,11 @@ module RuboCop
153
151
  end
154
152
 
155
153
  def qualified_cop_name(cop_name)
156
- Cop::Cop.qualified_cop_name(cop_name.strip, processed_source.file_path)
154
+ Cop::Registry.qualified_cop_name(cop_name.strip, processed_source.file_path)
157
155
  end
158
156
 
159
157
  def all_cop_names
160
- @all_cop_names ||= Cop::Cop.registry.names - [REDUNDANT_DISABLE]
158
+ @all_cop_names ||= Cop::Registry.global.names - [REDUNDANT_DISABLE]
161
159
  end
162
160
 
163
161
  def comment_only_line?(line_number)
@@ -24,7 +24,7 @@ module RuboCop
24
24
  def initialize(hash = {}, loaded_path = nil)
25
25
  @loaded_path = loaded_path
26
26
  @for_cop = Hash.new do |h, cop|
27
- qualified_cop_name = Cop::Cop.qualified_cop_name(cop, loaded_path)
27
+ qualified_cop_name = Cop::Registry.qualified_cop_name(cop, loaded_path)
28
28
  cop_options = self[qualified_cop_name] || {}
29
29
  cop_options['Enabled'] = enable_cop?(qualified_cop_name, cop_options)
30
30
  h[cop] = cop_options
@@ -73,7 +73,7 @@ module RuboCop
73
73
  # `can't add a new key into hash during iteration` error
74
74
  hash_keys = hash.keys
75
75
  hash_keys.each do |key|
76
- q = Cop::Cop.qualified_cop_name(key, path)
76
+ q = Cop::Registry.qualified_cop_name(key, path)
77
77
  next if q == key
78
78
 
79
79
  hash[q] = hash.delete(key)
@@ -84,7 +84,7 @@ module RuboCop
84
84
  unknown_cops = []
85
85
  invalid_cop_names.each do |name|
86
86
  # There could be a custom cop with this name. If so, don't warn
87
- next if Cop::Cop.registry.contains_cop_matching?([name])
87
+ next if Cop::Registry.global.contains_cop_matching?([name])
88
88
 
89
89
  # Special case for inherit_mode, which is a directive that we keep in
90
90
  # the configuration (even though it's not a cop), because it's easier
@@ -16,7 +16,7 @@ module RuboCop
16
16
  processed_source:)
17
17
  @processed_source = processed_source
18
18
  range = first_part_of(node.to_a.last)
19
- eol_comment = end_of_line_comment(node.source_range.line)
19
+ eol_comment = processed_source.comment_at_line(node.source_range.line)
20
20
 
21
21
  break_line_before(range: range, node: node, corrector: corrector,
22
22
  configured_width: configured_width)
@@ -71,7 +71,7 @@ module RuboCop
71
71
  prev_line_num,
72
72
  base_line_num,
73
73
  index)
74
- prev_line_num = word_node.first_line
74
+ prev_line_num = word_node.last_line
75
75
  content = fix_escaped_content(word_node, escape, delimiters)
76
76
  line_breaks + content
77
77
  end
@@ -269,15 +269,11 @@ module RuboCop
269
269
  end
270
270
 
271
271
  def begin_pos_with_comment(node)
272
- annotation_line = node.first_line - 1
273
272
  first_comment = nil
273
+ (node.first_line - 1).downto(1) do |annotation_line|
274
+ break unless (comment = processed_source.comment_at_line(annotation_line))
274
275
 
275
- processed_source.comments_before_line(annotation_line)
276
- .reverse_each do |comment|
277
- if comment.location.line == annotation_line
278
- first_comment = comment
279
- annotation_line -= 1
280
- end
276
+ first_comment = comment
281
277
  end
282
278
 
283
279
  start_line_position(first_comment || node)
@@ -39,7 +39,7 @@ module RuboCop
39
39
  'instead of %<correct_comment_indentation>d).'
40
40
 
41
41
  def investigate(processed_source)
42
- processed_source.each_comment { |comment| check(comment) }
42
+ processed_source.comments.each { |comment| check(comment) }
43
43
  end
44
44
 
45
45
  def autocorrect(comment)
@@ -40,6 +40,7 @@ module RuboCop
40
40
  def on_new_investigation
41
41
  return if processed_source.blank?
42
42
 
43
+ @aligned_comments = aligned_locations(processed_source.comments.map(&:loc))
43
44
  @corrected = Set.new if force_equal_sign_alignment?
44
45
 
45
46
  processed_source.tokens.each_cons(2) do |token1, token2|
@@ -49,6 +50,18 @@ module RuboCop
49
50
 
50
51
  private
51
52
 
53
+ def aligned_locations(locs)
54
+ return [] if locs.empty?
55
+
56
+ aligned = Set[locs.first.line, locs.last.line]
57
+ locs.each_cons(3) do |before, loc, after|
58
+ col = loc.column
59
+ aligned << loc.line if col == before.column || # rubocop:disable Style/MultipleComparison
60
+ col == after.column
61
+ end
62
+ aligned
63
+ end
64
+
52
65
  def check_tokens(ast, token1, token2)
53
66
  return if token2.type == :tNL
54
67
 
@@ -95,7 +108,7 @@ module RuboCop
95
108
 
96
109
  def aligned_tok?(token)
97
110
  if token.comment?
98
- aligned_comments?(token)
111
+ @aligned_comments.include?(token.line)
99
112
  else
100
113
  aligned_with_something?(token.pos)
101
114
  end
@@ -119,26 +132,6 @@ module RuboCop
119
132
  end.compact
120
133
  end
121
134
 
122
- def aligned_comments?(comment_token)
123
- ix = processed_source.comments.index do |comment|
124
- comment.loc.expression.begin_pos == comment_token.begin_pos
125
- end
126
- aligned_with_previous_comment?(ix) || aligned_with_next_comment?(ix)
127
- end
128
-
129
- def aligned_with_previous_comment?(index)
130
- index.positive? && comment_column(index - 1) == comment_column(index)
131
- end
132
-
133
- def aligned_with_next_comment?(index)
134
- index < processed_source.comments.length - 1 &&
135
- comment_column(index + 1) == comment_column(index)
136
- end
137
-
138
- def comment_column(index)
139
- processed_source.comments[index].loc.column
140
- end
141
-
142
135
  def force_equal_sign_alignment?
143
136
  cop_config['ForceEqualSignAlignment']
144
137
  end
@@ -55,7 +55,7 @@ module RuboCop
55
55
  MSG = 'Missing space after `#`.'
56
56
 
57
57
  def investigate(processed_source)
58
- processed_source.each_comment do |comment|
58
+ processed_source.comments.each do |comment|
59
59
  next unless /\A#+[^#\s=:+-]/.match?(comment.text)
60
60
  next if comment.loc.line == 1 && allowed_on_first_line?(comment)
61
61
  next if doxygen_comment_style?(comment)
@@ -29,12 +29,13 @@ module RuboCop
29
29
  #
30
30
  class BinaryOperatorWithIdenticalOperands < Base
31
31
  MSG = 'Binary operator `%<op>s` has identical operands.'
32
+ MATH_OPERATORS = %i[+ - * / % ** << >> | ^].to_set.freeze
32
33
 
33
34
  def on_send(node)
34
35
  return unless node.binary_operation?
35
36
 
36
37
  lhs, operation, rhs = *node
37
- return if node.arithmetic_operation? && lhs.basic_literal? && rhs.basic_literal?
38
+ return if MATH_OPERATORS.include?(node.method_name) && rhs.basic_literal?
38
39
 
39
40
  add_offense(node, message: format(MSG, op: operation)) if lhs == rhs
40
41
  end
@@ -45,7 +45,13 @@ module RuboCop
45
45
 
46
46
  OBJECT_LIFECYCLE_CALLBACKS = %i[method_missing respond_to_missing?].freeze
47
47
  CLASS_LIFECYCLE_CALLBACKS = %i[inherited].freeze
48
- MODULE_LIFECYCLE_CALLBACKS = %i[included extended prepended].freeze
48
+ METHOD_LIFECYCLE_CALLBACKS = %i[method_added method_removed method_undefined
49
+ singleton_method_added singleton_method_removed
50
+ singleton_method_undefined].freeze
51
+
52
+ CALLBACKS = (OBJECT_LIFECYCLE_CALLBACKS +
53
+ CLASS_LIFECYCLE_CALLBACKS +
54
+ METHOD_LIFECYCLE_CALLBACKS).to_set.freeze
49
55
 
50
56
  def on_def(node)
51
57
  return unless offender?(node)
@@ -70,15 +76,9 @@ module RuboCop
70
76
  end
71
77
 
72
78
  def callback_method_def?(node)
73
- method_name = node.method_name
74
-
75
- if OBJECT_LIFECYCLE_CALLBACKS.include?(method_name) ||
76
- CLASS_LIFECYCLE_CALLBACKS.include?(method_name)
79
+ return unless CALLBACKS.include?(node.method_name)
77
80
 
78
- node.each_ancestor(:class, :sclass, :module).first
79
- elsif MODULE_LIFECYCLE_CALLBACKS.include?(method_name)
80
- node.each_ancestor(:module).first
81
- end
81
+ node.each_ancestor(:class, :sclass, :module).first
82
82
  end
83
83
 
84
84
  def contains_super?(node)
@@ -21,16 +21,38 @@ module RuboCop
21
21
  class OutOfRangeRegexpRef < Base
22
22
  MSG = 'Do not use out of range reference for the Regexp.'
23
23
 
24
+ REGEXP_RECEIVER_METHODS = %i[=~ === match].to_set.freeze
25
+ REGEXP_ARGUMENT_METHODS = %i[=~ match grep gsub gsub! sub sub! [] slice slice! index rindex
26
+ scan partition rpartition start_with? end_with?].to_set.freeze
27
+ REGEXP_CAPTURE_METHODS = (REGEXP_RECEIVER_METHODS + REGEXP_ARGUMENT_METHODS).freeze
28
+
24
29
  def on_new_investigation
25
30
  @valid_ref = 0
26
31
  end
27
32
 
28
- def on_regexp(node)
33
+ def on_match_with_lvasgn(node)
34
+ check_regexp(node.children.first)
35
+ end
36
+
37
+ def on_send(node)
38
+ return unless REGEXP_CAPTURE_METHODS.include?(node.method_name)
39
+
29
40
  @valid_ref = nil
30
- return if contain_non_literal?(node)
31
41
 
32
- tree = Regexp::Parser.parse(node.content)
33
- @valid_ref = regexp_captures(tree)
42
+ if node.receiver&.regexp_type?
43
+ check_regexp(node.receiver)
44
+ elsif node.first_argument&.regexp_type? \
45
+ && REGEXP_ARGUMENT_METHODS.include?(node.method_name)
46
+ check_regexp(node.first_argument)
47
+ end
48
+ end
49
+
50
+ def on_when(node)
51
+ regexp_conditions = node.conditions.select(&:regexp_type?)
52
+
53
+ @valid_ref = regexp_conditions.map do |condition|
54
+ check_regexp(condition)
55
+ end.compact.max
34
56
  end
35
57
 
36
58
  def on_nth_ref(node)
@@ -42,6 +64,13 @@ module RuboCop
42
64
 
43
65
  private
44
66
 
67
+ def check_regexp(regexp)
68
+ return if contain_non_literal?(regexp)
69
+
70
+ tree = Regexp::Parser.parse(regexp.content)
71
+ @valid_ref = regexp_captures(tree)
72
+ end
73
+
45
74
  def contain_non_literal?(node)
46
75
  node.children.size != 2 || !node.children.first.str_type?
47
76
  end
@@ -41,13 +41,12 @@ module RuboCop
41
41
  def on_new_investigation
42
42
  return unless offenses_to_check
43
43
 
44
- comments = processed_source.comments
45
44
  cop_disabled_line_ranges = processed_source.disabled_line_ranges
46
45
 
47
46
  redundant_cops = Hash.new { |h, k| h[k] = Set.new }
48
47
 
49
48
  each_redundant_disable(cop_disabled_line_ranges,
50
- offenses_to_check, comments) do |comment, redundant_cop|
49
+ offenses_to_check) do |comment, redundant_cop|
51
50
  redundant_cops[comment].add(redundant_cop)
52
51
  end
53
52
 
@@ -88,25 +87,25 @@ module RuboCop
88
87
  newlines: false)
89
88
  end
90
89
 
91
- def each_redundant_disable(cop_disabled_line_ranges, offenses, comments,
90
+ def each_redundant_disable(cop_disabled_line_ranges, offenses,
92
91
  &block)
93
92
  disabled_ranges = cop_disabled_line_ranges[COP_NAME] || [0..0]
94
93
 
95
94
  cop_disabled_line_ranges.each do |cop, line_ranges|
96
95
  each_already_disabled(line_ranges,
97
- disabled_ranges, comments) do |comment|
96
+ disabled_ranges) do |comment|
98
97
  yield comment, cop
99
98
  end
100
99
 
101
- each_line_range(line_ranges, disabled_ranges, offenses, comments,
100
+ each_line_range(line_ranges, disabled_ranges, offenses,
102
101
  cop, &block)
103
102
  end
104
103
  end
105
104
 
106
- def each_line_range(line_ranges, disabled_ranges, offenses, comments,
105
+ def each_line_range(line_ranges, disabled_ranges, offenses,
107
106
  cop)
108
107
  line_ranges.each_with_index do |line_range, ix|
109
- comment = comments.find { |c| c.loc.line == line_range.begin }
108
+ comment = processed_source.comment_at_line(line_range.begin)
110
109
  next if ignore_offense?(disabled_ranges, line_range)
111
110
 
112
111
  redundant_cop = find_redundant(comment, offenses, cop, line_range,
@@ -115,7 +114,7 @@ module RuboCop
115
114
  end
116
115
  end
117
116
 
118
- def each_already_disabled(line_ranges, disabled_ranges, comments)
117
+ def each_already_disabled(line_ranges, disabled_ranges)
119
118
  line_ranges.each_cons(2) do |previous_range, range|
120
119
  next if ignore_offense?(disabled_ranges, range)
121
120
  next if previous_range.end != range.begin
@@ -124,14 +123,12 @@ module RuboCop
124
123
  # the end of the previous range, it means that the cop was
125
124
  # already disabled by an earlier comment. So it's redundant
126
125
  # whether there are offenses or not.
127
- redundant_comment = comments.find do |c|
128
- c.loc.line == range.begin &&
129
- # Comments disabling all cops don't count since it's reasonable
130
- # to disable a few select cops first and then all cops further
131
- # down in the code.
132
- !all_disabled?(c)
133
- end
134
- yield redundant_comment if redundant_comment
126
+ comment = processed_source.comment_at_line(range.begin)
127
+
128
+ # Comments disabling all cops don't count since it's reasonable
129
+ # to disable a few select cops first and then all cops further
130
+ # down in the code.
131
+ yield comment if comment && !all_disabled?(comment)
135
132
  end
136
133
  end
137
134
 
@@ -250,7 +247,7 @@ module RuboCop
250
247
  end
251
248
 
252
249
  def all_cop_names
253
- @all_cop_names ||= Cop.registry.names
250
+ @all_cop_names ||= Registry.global.names
254
251
  end
255
252
 
256
253
  def ends_its_line?(range)
@@ -16,35 +16,19 @@ module RuboCop
16
16
  class UriRegexp < Base
17
17
  extend AutoCorrector
18
18
 
19
- MSG = '`%<top_level>sURI.regexp%<arg>s` is obsolete and should not ' \
20
- 'be used. Instead, use `%<top_level>sURI::DEFAULT_PARSER.' \
21
- 'make_regexp%<arg>s`.'
22
-
23
- def_node_matcher :uri_regexp_with_argument?, <<~PATTERN
24
- (send
25
- (const ${nil? cbase} :URI) :regexp
26
- ${(str _) (array ...)})
27
- PATTERN
28
-
29
- def_node_matcher :uri_regexp_without_argument?, <<~PATTERN
30
- (send
31
- (const ${nil? cbase} :URI) :regexp)
32
- PATTERN
19
+ MSG = '`%<current>s` is obsolete and should not be used. Instead, use `%<preferred>s`.'
20
+ URI_CONSTANTS = ['URI', '::URI'].freeze
33
21
 
34
22
  def on_send(node)
35
- return unless node.method?(:regexp)
36
-
37
- captured_values = uri_regexp_with_argument?(node) || uri_regexp_without_argument?(node)
38
-
39
- double_colon, arg = captured_values
40
-
41
- top_level = double_colon ? '::' : ''
42
- argument = arg ? "(#{arg.source})" : ''
23
+ return unless node.method?(:regexp) && node.receiver
24
+ return unless URI_CONSTANTS.include?(node.receiver.source)
43
25
 
44
- format = format(MSG, top_level: top_level, arg: argument)
26
+ argument = node.first_argument ? "(#{node.first_argument.source})" : ''
27
+ preferred_method = "#{node.receiver.source}::DEFAULT_PARSER.make_regexp#{argument}"
28
+ message = format(MSG, current: node.source, preferred: preferred_method)
45
29
 
46
- add_offense(node.loc.selector, message: format) do |corrector|
47
- corrector.replace(node, "#{top_level}URI::DEFAULT_PARSER.make_regexp#{argument}")
30
+ add_offense(node.loc.selector, message: message) do |corrector|
31
+ corrector.replace(node, preferred_method)
48
32
  end
49
33
  end
50
34
  end
@@ -20,7 +20,7 @@ module RuboCop
20
20
  DISABLING_COPS_CONTENT_TOKEN = %r{[A-z]+/[A-z]+|all}.freeze
21
21
 
22
22
  def on_new_investigation
23
- processed_source.each_comment do |comment|
23
+ processed_source.comments.each do |comment|
24
24
  next if comment.text !~ DISABLE_COMMENT_FORMAT
25
25
 
26
26
  offset = Regexp.last_match(1).length
@@ -51,7 +51,7 @@ module RuboCop
51
51
 
52
52
  add_offense(range) do |corrector|
53
53
  cop_name = range.source
54
- qualified_cop_name = Cop.registry.qualified_cop_name(cop_name, nil, warn: false)
54
+ qualified_cop_name = Registry.global.qualified_cop_name(cop_name, nil, warn: false)
55
55
 
56
56
  unless qualified_cop_name.include?('/')
57
57
  qualified_cop_name = qualified_legacy_cop_name(cop_name)