rubocop 1.75.5 → 1.77.0

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 (89) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -14
  3. data/config/default.yml +74 -7
  4. data/config/obsoletion.yml +6 -3
  5. data/lib/rubocop/cop/autocorrect_logic.rb +18 -10
  6. data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
  7. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +5 -2
  8. data/lib/rubocop/cop/gemspec/attribute_assignment.rb +91 -0
  9. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +37 -15
  10. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
  11. data/lib/rubocop/cop/gemspec/require_mfa.rb +15 -1
  12. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +4 -4
  13. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +1 -0
  14. data/lib/rubocop/cop/layout/class_structure.rb +35 -0
  15. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +1 -1
  16. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +7 -3
  17. data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
  18. data/lib/rubocop/cop/layout/line_length.rb +26 -5
  19. data/lib/rubocop/cop/layout/space_before_brackets.rb +5 -38
  20. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +8 -2
  21. data/lib/rubocop/cop/lint/ambiguous_range.rb +5 -0
  22. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
  23. data/lib/rubocop/cop/lint/duplicate_methods.rb +84 -2
  24. data/lib/rubocop/cop/lint/empty_interpolation.rb +3 -1
  25. data/lib/rubocop/cop/lint/float_comparison.rb +31 -4
  26. data/lib/rubocop/cop/lint/identity_comparison.rb +19 -15
  27. data/lib/rubocop/cop/lint/literal_as_condition.rb +19 -27
  28. data/lib/rubocop/cop/lint/redundant_regexp_quantifiers.rb +1 -1
  29. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +4 -4
  30. data/lib/rubocop/cop/lint/self_assignment.rb +25 -0
  31. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +5 -0
  32. data/lib/rubocop/cop/lint/useless_access_modifier.rb +29 -4
  33. data/lib/rubocop/cop/lint/useless_assignment.rb +2 -0
  34. data/lib/rubocop/cop/lint/useless_default_value_argument.rb +90 -0
  35. data/lib/rubocop/cop/lint/useless_or.rb +98 -0
  36. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +3 -3
  37. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  38. data/lib/rubocop/cop/mixin/alignment.rb +1 -1
  39. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -1
  40. data/lib/rubocop/cop/mixin/gemspec_help.rb +22 -0
  41. data/lib/rubocop/cop/mixin/line_length_help.rb +24 -8
  42. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
  43. data/lib/rubocop/cop/naming/file_name.rb +2 -2
  44. data/lib/rubocop/cop/naming/predicate_method.rb +281 -0
  45. data/lib/rubocop/cop/naming/{predicate_name.rb → predicate_prefix.rb} +4 -4
  46. data/lib/rubocop/cop/style/access_modifier_declarations.rb +32 -10
  47. data/lib/rubocop/cop/style/case_like_if.rb +1 -1
  48. data/lib/rubocop/cop/style/collection_querying.rb +167 -0
  49. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  50. data/lib/rubocop/cop/style/comparable_between.rb +3 -0
  51. data/lib/rubocop/cop/style/conditional_assignment.rb +3 -1
  52. data/lib/rubocop/cop/style/data_inheritance.rb +7 -0
  53. data/lib/rubocop/cop/style/def_with_parentheses.rb +18 -5
  54. data/lib/rubocop/cop/style/empty_string_inside_interpolation.rb +100 -0
  55. data/lib/rubocop/cop/style/exponential_notation.rb +2 -2
  56. data/lib/rubocop/cop/style/fetch_env_var.rb +32 -6
  57. data/lib/rubocop/cop/style/hash_conversion.rb +12 -3
  58. data/lib/rubocop/cop/style/if_unless_modifier.rb +33 -6
  59. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +4 -7
  60. data/lib/rubocop/cop/style/it_block_parameter.rb +33 -14
  61. data/lib/rubocop/cop/style/map_to_hash.rb +11 -0
  62. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -2
  63. data/lib/rubocop/cop/style/min_max_comparison.rb +13 -5
  64. data/lib/rubocop/cop/style/multiline_if_modifier.rb +2 -0
  65. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  66. data/lib/rubocop/cop/style/redundant_array_flatten.rb +50 -0
  67. data/lib/rubocop/cop/style/redundant_format.rb +6 -1
  68. data/lib/rubocop/cop/style/redundant_interpolation.rb +1 -1
  69. data/lib/rubocop/cop/style/redundant_parentheses.rb +26 -5
  70. data/lib/rubocop/cop/style/redundant_self.rb +8 -5
  71. data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
  72. data/lib/rubocop/cop/style/safe_navigation.rb +24 -11
  73. data/lib/rubocop/cop/style/sole_nested_conditional.rb +6 -3
  74. data/lib/rubocop/cop/style/string_concatenation.rb +1 -2
  75. data/lib/rubocop/cop/style/struct_inheritance.rb +8 -1
  76. data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
  77. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
  78. data/lib/rubocop/cop/team.rb +1 -1
  79. data/lib/rubocop/cop/variable_force/assignment.rb +7 -3
  80. data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -0
  81. data/lib/rubocop/formatter/fuubar_style_formatter.rb +1 -1
  82. data/lib/rubocop/formatter/html_formatter.rb +1 -1
  83. data/lib/rubocop/formatter/offense_count_formatter.rb +1 -1
  84. data/lib/rubocop/lsp/diagnostic.rb +4 -4
  85. data/lib/rubocop/rspec/expect_offense.rb +9 -3
  86. data/lib/rubocop/version.rb +1 -1
  87. data/lib/rubocop.rb +8 -1
  88. data/lib/ruby_lsp/rubocop/addon.rb +2 -2
  89. metadata +15 -11
@@ -49,6 +49,7 @@ module RuboCop
49
49
  empty_parentheses?(node) ||
50
50
  first_arg_begins_with_hash_literal?(node) ||
51
51
  rescue?(node) ||
52
+ in_pattern_matching_in_method_argument?(node) ||
52
53
  allowed_pin_operator?(node) ||
53
54
  allowed_expression?(node)
54
55
  end
@@ -122,6 +123,13 @@ module RuboCop
122
123
  hash_literal && first_argument?(node) && !parentheses?(hash_literal) && !parenthesized
123
124
  end
124
125
 
126
+ def in_pattern_matching_in_method_argument?(begin_node)
127
+ return false unless begin_node.parent&.call_type?
128
+ return false unless (node = begin_node.children.first)
129
+
130
+ target_ruby_version <= 2.7 ? node.match_pattern_type? : node.match_pattern_p_type?
131
+ end
132
+
125
133
  def method_chain_begins_with_hash_literal(node)
126
134
  return if node.nil?
127
135
  return node if node.hash_type?
@@ -134,7 +142,7 @@ module RuboCop
134
142
  node = begin_node.children.first
135
143
 
136
144
  if (message = find_offense_message(begin_node, node))
137
- if node.range_type? && !argument_of_parenthesized_method_call?(begin_node)
145
+ if node.range_type? && !argument_of_parenthesized_method_call?(begin_node, node)
138
146
  begin_node = begin_node.parent
139
147
  end
140
148
 
@@ -156,8 +164,11 @@ module RuboCop
156
164
  if node.lambda_or_proc? && (node.braces? || node.send_node.lambda_literal?)
157
165
  return 'an expression'
158
166
  end
167
+ if disallowed_one_line_pattern_matching?(begin_node, node)
168
+ return 'a one-line pattern matching'
169
+ end
159
170
  return 'an interpolated expression' if interpolation?(begin_node)
160
- return 'a method argument' if argument_of_parenthesized_method_call?(begin_node)
171
+ return 'a method argument' if argument_of_parenthesized_method_call?(begin_node, node)
161
172
 
162
173
  return if begin_node.chained?
163
174
 
@@ -180,9 +191,10 @@ module RuboCop
180
191
  # @!method interpolation?(node)
181
192
  def_node_matcher :interpolation?, '[^begin ^^dstr]'
182
193
 
183
- def argument_of_parenthesized_method_call?(begin_node)
184
- node = begin_node.children.first
185
- return false if node.basic_conditional? || method_call_parentheses_required?(node)
194
+ def argument_of_parenthesized_method_call?(begin_node, node)
195
+ if node.basic_conditional? || node.rescue_type? || method_call_parentheses_required?(node)
196
+ return false
197
+ end
186
198
  return false unless (parent = begin_node.parent)
187
199
 
188
200
  parent.call_type? && parent.parenthesized? && parent.receiver != begin_node
@@ -242,6 +254,15 @@ module RuboCop
242
254
  end
243
255
  end
244
256
 
257
+ def disallowed_one_line_pattern_matching?(begin_node, node)
258
+ if (parent = begin_node.parent)
259
+ return false if parent.any_def_type? && parent.endless?
260
+ return false if parent.assignment?
261
+ end
262
+
263
+ node.any_match_pattern_type? && node.each_ancestor.none?(&:operator_keyword?)
264
+ end
265
+
245
266
  def raised_to_power_negative_numeric?(begin_node, node)
246
267
  return false unless node.numeric_type?
247
268
 
@@ -67,6 +67,9 @@ module RuboCop
67
67
 
68
68
  def on_or_asgn(node)
69
69
  allow_self(node.lhs)
70
+
71
+ lhs_name = node.lhs.lvasgn_type? ? node.lhs.name : node.lhs
72
+ add_lhs_to_local_variables_scopes(node.rhs, lhs_name)
70
73
  end
71
74
  alias on_and_asgn on_or_asgn
72
75
 
@@ -123,11 +126,11 @@ module RuboCop
123
126
  def on_if(node)
124
127
  # Allow conditional nodes to use `self` in the condition if that variable
125
128
  # name is used in an `lvasgn` or `masgn` within the `if`.
126
- node.child_nodes.each do |child_node|
127
- if child_node.lvasgn_type?
128
- add_lhs_to_local_variables_scopes(node.condition, child_node.lhs)
129
- elsif child_node.masgn_type?
130
- add_masgn_lhs_variables(node.condition, child_node.lhs)
129
+ node.each_descendant(:lvasgn, :masgn) do |descendant_node|
130
+ if descendant_node.lvasgn_type?
131
+ add_lhs_to_local_variables_scopes(node.condition, descendant_node.lhs)
132
+ else
133
+ add_masgn_lhs_variables(node.condition, descendant_node.lhs)
131
134
  end
132
135
  end
133
136
  end
@@ -155,7 +155,7 @@ module RuboCop
155
155
  end
156
156
 
157
157
  def preferred_delimiters
158
- config.for_cop('Style/PercentLiteralDelimiters') ['PreferredDelimiters']['%r'].chars
158
+ config.for_cop('Style/PercentLiteralDelimiters')['PreferredDelimiters']['%r'].chars
159
159
  end
160
160
 
161
161
  def allowed_omit_parentheses_with_percent_r_literal?(node)
@@ -86,6 +86,10 @@ module RuboCop
86
86
  # foo.baz = bar if foo
87
87
  # foo.baz + bar if foo
88
88
  # foo.bar > 2 if foo
89
+ #
90
+ # foo ? foo[index] : nil # Ignored `foo&.[](index)` due to unclear readability benefit.
91
+ # foo ? foo[idx] = v : nil # Ignored `foo&.[]=(idx, v)` due to unclear readability benefit.
92
+ # foo ? foo * 42 : nil # Ignored `foo&.*(42)` due to unclear readability benefit.
89
93
  class SafeNavigation < Base # rubocop:disable Metrics/ClassLength
90
94
  include NilMethods
91
95
  include RangeHelp
@@ -146,6 +150,7 @@ module RuboCop
146
150
 
147
151
  body = extract_if_body(node)
148
152
  method_call = receiver.parent
153
+ return if dotless_operator_call?(method_call) || method_call.double_colon?
149
154
 
150
155
  removal_ranges = [begin_range(node, body), end_range(node, body)]
151
156
 
@@ -181,6 +186,8 @@ module RuboCop
181
186
  end
182
187
  end
183
188
 
189
+ private
190
+
184
191
  def report_offense(node, rhs, rhs_receiver, *removal_ranges, offense_range: node)
185
192
  add_offense(offense_range) do |corrector|
186
193
  next if ignored_node?(node)
@@ -198,8 +205,6 @@ module RuboCop
198
205
  end
199
206
  end
200
207
 
201
- private
202
-
203
208
  def find_method_chain(node)
204
209
  return node unless node&.parent&.call_type?
205
210
 
@@ -235,7 +240,7 @@ module RuboCop
235
240
  return false if !matching_nodes?(lhs_receiver, rhs_receiver) || rhs_receiver.nil?
236
241
  return false if use_var_only_in_unless_modifier?(node, lhs_receiver)
237
242
  return false if chain_length(rhs, rhs_receiver) > max_chain_length
238
- return false if unsafe_method_used?(rhs, rhs_receiver.parent)
243
+ return false if unsafe_method_used?(node, rhs, rhs_receiver.parent)
239
244
  return false if rhs.send_type? && rhs.method?(:empty?)
240
245
 
241
246
  true
@@ -253,6 +258,12 @@ module RuboCop
253
258
  end
254
259
  end
255
260
 
261
+ def dotless_operator_call?(method_call)
262
+ return false if method_call.loc.dot
263
+
264
+ method_call.method?(:[]) || method_call.method?(:[]=) || method_call.operator_method?
265
+ end
266
+
256
267
  def handle_comments(corrector, node, method_call)
257
268
  comments = comments(node)
258
269
  return if comments.empty?
@@ -334,21 +345,24 @@ module RuboCop
334
345
  end
335
346
  end
336
347
 
337
- def unsafe_method_used?(method_chain, method)
338
- return true if unsafe_method?(method)
348
+ def unsafe_method_used?(node, method_chain, method)
349
+ return true if unsafe_method?(node, method)
339
350
 
340
351
  method.each_ancestor(:send).any? do |ancestor|
341
352
  break true unless config.cop_enabled?('Lint/SafeNavigationChain')
342
353
 
343
- break true if unsafe_method?(ancestor)
354
+ break true if unsafe_method?(node, ancestor)
344
355
  break true if nil_methods.include?(ancestor.method_name)
345
356
  break false if ancestor == method_chain
346
357
  end
347
358
  end
348
359
 
349
- def unsafe_method?(send_node)
350
- negated?(send_node) ||
351
- send_node.assignment? ||
360
+ def unsafe_method?(node, send_node)
361
+ return true if negated?(send_node)
362
+
363
+ return false if node.respond_to?(:ternary?) && node.ternary?
364
+
365
+ send_node.assignment? ||
352
366
  (!send_node.dot? && !send_node.safe_navigation?)
353
367
  end
354
368
 
@@ -377,8 +391,7 @@ module RuboCop
377
391
  method_chain)
378
392
  start_method.each_ancestor do |ancestor|
379
393
  break unless %i[send block].include?(ancestor.type)
380
- next unless ancestor.send_type?
381
- next if ancestor.safe_navigation?
394
+ next if !ancestor.send_type? || ancestor.operator_method?
382
395
 
383
396
  corrector.insert_before(ancestor.loc.dot, '&')
384
397
 
@@ -115,8 +115,9 @@ module RuboCop
115
115
  end
116
116
 
117
117
  def correct_node(corrector, node)
118
- corrector.replace(node.loc.keyword, 'if') if node.unless?
118
+ corrector.replace(node.loc.keyword, 'if') if node.unless? && !part_of_ignored_node?(node)
119
119
  corrector.replace(node.condition, chainable_condition(node))
120
+ ignore_node(node)
120
121
  end
121
122
 
122
123
  def correct_for_guard_condition_style(corrector, node, if_branch)
@@ -185,8 +186,10 @@ module RuboCop
185
186
  end
186
187
 
187
188
  def add_parentheses?(node)
188
- node.assignment? || (node.operator_keyword? && !node.and_type?) ||
189
- (node.call_type? && node.arguments.any? && !node.parenthesized?)
189
+ return true if node.assignment? || (node.operator_keyword? && !node.and_type?)
190
+ return false unless node.call_type?
191
+
192
+ (node.arguments.any? && !node.parenthesized?) || node.prefix_not?
190
193
  end
191
194
 
192
195
  def parenthesized_method_arguments(node)
@@ -51,7 +51,6 @@ module RuboCop
51
51
  # Pathname.new('/') + 'test'
52
52
  #
53
53
  class StringConcatenation < Base
54
- include RangeHelp
55
54
  extend AutoCorrector
56
55
 
57
56
  MSG = 'Prefer string interpolation to string concatenation.'
@@ -147,7 +146,7 @@ module RuboCop
147
146
  when :str
148
147
  adjust_str(part)
149
148
  when :dstr
150
- part.children.all?(&:str_type?) ? adjust_str(part) : contents_range(part).source
149
+ part.children.all?(&:str_type?) ? adjust_str(part) : part.value
151
150
  else
152
151
  "\#{#{part.source}}"
153
152
  end
@@ -3,7 +3,8 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Style
6
- # Checks for inheritance from Struct.new.
6
+ # Checks for inheritance from `Struct.new`. Inheriting from `Struct.new`
7
+ # adds a superfluous level in inheritance tree.
7
8
  #
8
9
  # @safety
9
10
  # Autocorrection is unsafe because it will change the inheritance
@@ -17,12 +18,18 @@ module RuboCop
17
18
  # end
18
19
  # end
19
20
  #
21
+ # Person.ancestors
22
+ # # => [Person, #<Class:0x000000010b4e14a0>, Struct, (...)]
23
+ #
20
24
  # # good
21
25
  # Person = Struct.new(:first_name, :last_name) do
22
26
  # def age
23
27
  # 42
24
28
  # end
25
29
  # end
30
+ #
31
+ # Person.ancestors
32
+ # # => [Person, Struct, (...)]
26
33
  class StructInheritance < Base
27
34
  include RangeHelp
28
35
  extend AutoCorrector
@@ -270,7 +270,7 @@ module RuboCop
270
270
  end
271
271
 
272
272
  def allow_if_method_has_argument?(send_node)
273
- !!cop_config.fetch('AllowMethodsWithArguments', false) && !send_node.arguments.count.zero?
273
+ !!cop_config.fetch('AllowMethodsWithArguments', false) && send_node.arguments.any?
274
274
  end
275
275
 
276
276
  def allow_comments?
@@ -97,7 +97,7 @@ module RuboCop
97
97
  pipes = tokens.select { |token| token.type == :tPIPE }
98
98
  begin_pos, end_pos = pipes.map { |pipe| tokens.index(pipe) }
99
99
 
100
- tokens[begin_pos + 1..end_pos - 1]
100
+ tokens[(begin_pos + 1)..(end_pos - 1)]
101
101
  end
102
102
  end
103
103
  end
@@ -279,7 +279,7 @@ module RuboCop
279
279
  @errors << message
280
280
  warn message
281
281
  if debug?
282
- puts error.message, error.backtrace
282
+ puts error.full_message
283
283
  else
284
284
  warn 'To see the complete backtrace run rubocop -d.'
285
285
  end
@@ -110,8 +110,13 @@ module RuboCop
110
110
  end
111
111
 
112
112
  def multiple_assignment_node
113
- return nil unless node.parent&.mlhs_type?
114
- return nil unless (grandparent_node = node.parent&.parent)
113
+ return nil unless (candidate_mlhs_node = node.parent)
114
+
115
+ # In `(foo, bar), *baz`, the splat node must be traversed as well.
116
+ candidate_mlhs_node = candidate_mlhs_node.parent if candidate_mlhs_node.splat_type?
117
+
118
+ return nil unless candidate_mlhs_node.mlhs_type?
119
+ return nil unless (grandparent_node = node.parent.parent)
115
120
  if (node = find_multiple_assignment_node(grandparent_node))
116
121
  return node
117
122
  end
@@ -139,7 +144,6 @@ module RuboCop
139
144
 
140
145
  def find_multiple_assignment_node(grandparent_node)
141
146
  return unless grandparent_node.type == MULTIPLE_LEFT_HAND_SIDE_TYPE
142
- return if grandparent_node.children.any?(&:splat_type?)
143
147
 
144
148
  parent = grandparent_node.parent
145
149
  return parent if parent.type == MULTIPLE_ASSIGNMENT_TYPE
@@ -178,6 +178,7 @@ module RuboCop
178
178
  next unless value.is_a?(Array)
179
179
  next if value.empty?
180
180
 
181
+ value.map! { |v| v.nil? ? '~' : v } # Change nil back to ~ as in the YAML file.
181
182
  output_buffer.puts "# #{param}: #{value.uniq.join(', ')}"
182
183
  end
183
184
  end
@@ -22,7 +22,7 @@ module RuboCop
22
22
 
23
23
  @severest_offense = nil
24
24
 
25
- file_phrase = target_files.count == 1 ? 'file' : 'files'
25
+ file_phrase = target_files.one? ? 'file' : 'files'
26
26
 
27
27
  # 185/407 files |====== 45 ======> | ETA: 00:00:04
28
28
  # %c / %C | %w > %i | %e
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cgi'
3
+ require 'cgi/escape'
4
4
  require 'erb'
5
5
 
6
6
  module RuboCop
@@ -24,7 +24,7 @@ module RuboCop
24
24
 
25
25
  return unless output.tty?
26
26
 
27
- file_phrase = target_files.count == 1 ? 'file' : 'files'
27
+ file_phrase = target_files.one? ? 'file' : 'files'
28
28
 
29
29
  # 185/407 files |====== 45 ======> | ETA: 00:00:04
30
30
  # %c / %C | %w > %i | %e
@@ -79,7 +79,7 @@ module RuboCop
79
79
  LanguageServer::Protocol::Interface::CodeDescription.new(href: doc_url)
80
80
  end
81
81
 
82
- # rubocop:disable Layout/LineLength, Metrics/MethodLength
82
+ # rubocop:disable Metrics/MethodLength
83
83
  def autocorrect_action
84
84
  LanguageServer::Protocol::Interface::CodeAction.new(
85
85
  title: "Autocorrect #{@offense.cop_name}",
@@ -98,7 +98,7 @@ module RuboCop
98
98
  is_preferred: true
99
99
  )
100
100
  end
101
- # rubocop:enable Layout/LineLength, Metrics/MethodLength
101
+ # rubocop:enable Metrics/MethodLength
102
102
 
103
103
  # rubocop:disable Metrics/MethodLength
104
104
  def offense_replacements
@@ -120,7 +120,7 @@ module RuboCop
120
120
  end
121
121
  # rubocop:enable Metrics/MethodLength
122
122
 
123
- # rubocop:disable Layout/LineLength, Metrics/MethodLength
123
+ # rubocop:disable Metrics/MethodLength
124
124
  def disable_line_action
125
125
  LanguageServer::Protocol::Interface::CodeAction.new(
126
126
  title: "Disable #{@offense.cop_name} for this line",
@@ -138,7 +138,7 @@ module RuboCop
138
138
  )
139
139
  )
140
140
  end
141
- # rubocop:enable Layout/LineLength, Metrics/MethodLength
141
+ # rubocop:enable Metrics/MethodLength
142
142
 
143
143
  def line_disable_comment
144
144
  new_text = if @offense.source_line.include?(' # rubocop:disable ')
@@ -72,9 +72,15 @@ module RuboCop
72
72
  #
73
73
  # expect_no_corrections
74
74
  #
75
- # If your code has variables of different lengths, you can use `%{foo}`,
76
- # `^{foo}`, and `_{foo}` to format your template; you can also abbreviate
77
- # offense messages with `[...]`:
75
+ # If your code has variables of different lengths, you can use the
76
+ # following markers to format your template by passing the variables as a
77
+ # keyword arguments:
78
+ #
79
+ # - `%{foo}`: Interpolates `foo`
80
+ # - `^{foo}`: Inserts `'^' * foo.size` for dynamic offense range length
81
+ # - `_{foo}`: Inserts `' ' * foo.size` for dynamic offense range indentation
82
+ #
83
+ # You can also abbreviate offense messages with `[...]`.
78
84
  #
79
85
  # %w[raise fail].each do |keyword|
80
86
  # expect_offense(<<~RUBY, keyword: keyword)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.75.5'
6
+ STRING = '1.77.0'
7
7
 
8
8
  MSG = '%<version>s (using %<parser_version>s, ' \
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
data/lib/rubocop.rb CHANGED
@@ -180,6 +180,7 @@ require_relative 'rubocop/cop/bundler/insecure_protocol_source'
180
180
  require_relative 'rubocop/cop/bundler/ordered_gems'
181
181
 
182
182
  require_relative 'rubocop/cop/gemspec/add_runtime_dependency'
183
+ require_relative 'rubocop/cop/gemspec/attribute_assignment'
183
184
  require_relative 'rubocop/cop/gemspec/dependency_version'
184
185
  require_relative 'rubocop/cop/gemspec/deprecated_attribute_assignment'
185
186
  require_relative 'rubocop/cop/gemspec/development_dependencies'
@@ -430,10 +431,12 @@ require_relative 'rubocop/cop/lint/uri_regexp'
430
431
  require_relative 'rubocop/cop/lint/useless_access_modifier'
431
432
  require_relative 'rubocop/cop/lint/useless_assignment'
432
433
  require_relative 'rubocop/cop/lint/useless_constant_scoping'
434
+ require_relative 'rubocop/cop/lint/useless_default_value_argument'
433
435
  require_relative 'rubocop/cop/lint/useless_defined'
434
436
  require_relative 'rubocop/cop/lint/useless_else_without_rescue'
435
437
  require_relative 'rubocop/cop/lint/useless_method_definition'
436
438
  require_relative 'rubocop/cop/lint/useless_numeric_operation'
439
+ require_relative 'rubocop/cop/lint/useless_or'
437
440
  require_relative 'rubocop/cop/lint/useless_rescue'
438
441
  require_relative 'rubocop/cop/lint/useless_ruby2_keywords'
439
442
  require_relative 'rubocop/cop/lint/useless_setter_call'
@@ -469,7 +472,8 @@ require_relative 'rubocop/cop/naming/memoized_instance_variable_name'
469
472
  require_relative 'rubocop/cop/naming/method_name'
470
473
  require_relative 'rubocop/cop/naming/method_parameter_name'
471
474
  require_relative 'rubocop/cop/naming/binary_operator_parameter_name'
472
- require_relative 'rubocop/cop/naming/predicate_name'
475
+ require_relative 'rubocop/cop/naming/predicate_method'
476
+ require_relative 'rubocop/cop/naming/predicate_prefix'
473
477
  require_relative 'rubocop/cop/naming/rescued_exceptions_variable_name'
474
478
  require_relative 'rubocop/cop/naming/variable_name'
475
479
  require_relative 'rubocop/cop/naming/variable_number'
@@ -504,6 +508,7 @@ require_relative 'rubocop/cop/style/class_methods_definitions'
504
508
  require_relative 'rubocop/cop/style/class_vars'
505
509
  require_relative 'rubocop/cop/style/collection_compact'
506
510
  require_relative 'rubocop/cop/style/collection_methods'
511
+ require_relative 'rubocop/cop/style/collection_querying'
507
512
  require_relative 'rubocop/cop/style/colon_method_call'
508
513
  require_relative 'rubocop/cop/style/colon_method_definition'
509
514
  require_relative 'rubocop/cop/style/combinable_defined'
@@ -538,6 +543,7 @@ require_relative 'rubocop/cop/style/empty_heredoc'
538
543
  require_relative 'rubocop/cop/style/empty_lambda_parameter'
539
544
  require_relative 'rubocop/cop/style/empty_literal'
540
545
  require_relative 'rubocop/cop/style/empty_method'
546
+ require_relative 'rubocop/cop/style/empty_string_inside_interpolation'
541
547
  require_relative 'rubocop/cop/style/endless_method'
542
548
  require_relative 'rubocop/cop/style/encoding'
543
549
  require_relative 'rubocop/cop/style/end_block'
@@ -604,6 +610,7 @@ require_relative 'rubocop/cop/style/numbered_parameters'
604
610
  require_relative 'rubocop/cop/style/open_struct_use'
605
611
  require_relative 'rubocop/cop/style/operator_method_call'
606
612
  require_relative 'rubocop/cop/style/redundant_array_constructor'
613
+ require_relative 'rubocop/cop/style/redundant_array_flatten'
607
614
  require_relative 'rubocop/cop/style/redundant_assignment'
608
615
  require_relative 'rubocop/cop/style/redundant_constant_base'
609
616
  require_relative 'rubocop/cop/style/redundant_current_directory_in_path'
@@ -34,7 +34,7 @@ module RubyLsp
34
34
  @runtime_adapter = nil
35
35
  end
36
36
 
37
- # rubocop:disable Layout/LineLength, Metrics/MethodLength
37
+ # rubocop:disable Metrics/MethodLength
38
38
  def register_additional_file_watchers(global_state, message_queue)
39
39
  return unless global_state.supports_watching_files
40
40
 
@@ -59,7 +59,7 @@ module RubyLsp
59
59
  )
60
60
  )
61
61
  end
62
- # rubocop:enable Layout/LineLength, Metrics/MethodLength
62
+ # rubocop:enable Metrics/MethodLength
63
63
 
64
64
  def workspace_did_change_watched_files(changes)
65
65
  return unless changes.any? { |change| change[:uri].end_with?('.rubocop.yml') }
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.75.5
4
+ version: 1.77.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
8
8
  - Jonas Arvidsson
9
9
  - Yuji Nakayama
10
- autorequire:
11
10
  bindir: exe
12
11
  cert_chain: []
13
- date: 2025-05-05 00:00:00.000000000 Z
12
+ date: 2025-06-20 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: json
@@ -128,7 +127,7 @@ dependencies:
128
127
  requirements:
129
128
  - - ">="
130
129
  - !ruby/object:Gem::Version
131
- version: 1.44.0
130
+ version: 1.45.1
132
131
  - - "<"
133
132
  - !ruby/object:Gem::Version
134
133
  version: '2.0'
@@ -138,7 +137,7 @@ dependencies:
138
137
  requirements:
139
138
  - - ">="
140
139
  - !ruby/object:Gem::Version
141
- version: 1.44.0
140
+ version: 1.45.1
142
141
  - - "<"
143
142
  - !ruby/object:Gem::Version
144
143
  version: '2.0'
@@ -266,6 +265,7 @@ files:
266
265
  - lib/rubocop/cop/exclude_limit.rb
267
266
  - lib/rubocop/cop/force.rb
268
267
  - lib/rubocop/cop/gemspec/add_runtime_dependency.rb
268
+ - lib/rubocop/cop/gemspec/attribute_assignment.rb
269
269
  - lib/rubocop/cop/gemspec/dependency_version.rb
270
270
  - lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb
271
271
  - lib/rubocop/cop/gemspec/development_dependencies.rb
@@ -562,10 +562,12 @@ files:
562
562
  - lib/rubocop/cop/lint/useless_access_modifier.rb
563
563
  - lib/rubocop/cop/lint/useless_assignment.rb
564
564
  - lib/rubocop/cop/lint/useless_constant_scoping.rb
565
+ - lib/rubocop/cop/lint/useless_default_value_argument.rb
565
566
  - lib/rubocop/cop/lint/useless_defined.rb
566
567
  - lib/rubocop/cop/lint/useless_else_without_rescue.rb
567
568
  - lib/rubocop/cop/lint/useless_method_definition.rb
568
569
  - lib/rubocop/cop/lint/useless_numeric_operation.rb
570
+ - lib/rubocop/cop/lint/useless_or.rb
569
571
  - lib/rubocop/cop/lint/useless_rescue.rb
570
572
  - lib/rubocop/cop/lint/useless_ruby2_keywords.rb
571
573
  - lib/rubocop/cop/lint/useless_setter_call.rb
@@ -680,7 +682,8 @@ files:
680
682
  - lib/rubocop/cop/naming/memoized_instance_variable_name.rb
681
683
  - lib/rubocop/cop/naming/method_name.rb
682
684
  - lib/rubocop/cop/naming/method_parameter_name.rb
683
- - lib/rubocop/cop/naming/predicate_name.rb
685
+ - lib/rubocop/cop/naming/predicate_method.rb
686
+ - lib/rubocop/cop/naming/predicate_prefix.rb
684
687
  - lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb
685
688
  - lib/rubocop/cop/naming/variable_name.rb
686
689
  - lib/rubocop/cop/naming/variable_number.rb
@@ -725,6 +728,7 @@ files:
725
728
  - lib/rubocop/cop/style/class_vars.rb
726
729
  - lib/rubocop/cop/style/collection_compact.rb
727
730
  - lib/rubocop/cop/style/collection_methods.rb
731
+ - lib/rubocop/cop/style/collection_querying.rb
728
732
  - lib/rubocop/cop/style/colon_method_call.rb
729
733
  - lib/rubocop/cop/style/colon_method_definition.rb
730
734
  - lib/rubocop/cop/style/combinable_defined.rb
@@ -759,6 +763,7 @@ files:
759
763
  - lib/rubocop/cop/style/empty_lambda_parameter.rb
760
764
  - lib/rubocop/cop/style/empty_literal.rb
761
765
  - lib/rubocop/cop/style/empty_method.rb
766
+ - lib/rubocop/cop/style/empty_string_inside_interpolation.rb
762
767
  - lib/rubocop/cop/style/encoding.rb
763
768
  - lib/rubocop/cop/style/end_block.rb
764
769
  - lib/rubocop/cop/style/endless_method.rb
@@ -879,6 +884,7 @@ files:
879
884
  - lib/rubocop/cop/style/random_with_offset.rb
880
885
  - lib/rubocop/cop/style/redundant_argument.rb
881
886
  - lib/rubocop/cop/style/redundant_array_constructor.rb
887
+ - lib/rubocop/cop/style/redundant_array_flatten.rb
882
888
  - lib/rubocop/cop/style/redundant_assignment.rb
883
889
  - lib/rubocop/cop/style/redundant_begin.rb
884
890
  - lib/rubocop/cop/style/redundant_capital_w.rb
@@ -1081,12 +1087,11 @@ licenses:
1081
1087
  - MIT
1082
1088
  metadata:
1083
1089
  homepage_uri: https://rubocop.org/
1084
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.75.5
1090
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.77.0
1085
1091
  source_code_uri: https://github.com/rubocop/rubocop/
1086
- documentation_uri: https://docs.rubocop.org/rubocop/1.75/
1092
+ documentation_uri: https://docs.rubocop.org/rubocop/1.77/
1087
1093
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
1088
1094
  rubygems_mfa_required: 'true'
1089
- post_install_message:
1090
1095
  rdoc_options: []
1091
1096
  require_paths:
1092
1097
  - lib
@@ -1101,8 +1106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1101
1106
  - !ruby/object:Gem::Version
1102
1107
  version: '0'
1103
1108
  requirements: []
1104
- rubygems_version: 3.3.7
1105
- signing_key:
1109
+ rubygems_version: 3.6.2
1106
1110
  specification_version: 4
1107
1111
  summary: Automatic Ruby code style checking tool.
1108
1112
  test_files: []