rubocop 1.75.1 → 1.75.4

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 (81) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.yml +29 -18
  3. data/lib/rubocop/config_validator.rb +6 -6
  4. data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -1
  5. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +1 -0
  6. data/lib/rubocop/cop/internal_affairs/undefined_config.rb +6 -1
  7. data/lib/rubocop/cop/layout/block_alignment.rb +1 -2
  8. data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
  9. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -1
  10. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -2
  11. data/lib/rubocop/cop/layout/hash_alignment.rb +1 -1
  12. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +1 -1
  13. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -4
  14. data/lib/rubocop/cop/lint/boolean_symbol.rb +1 -1
  15. data/lib/rubocop/cop/lint/circular_argument_reference.rb +2 -5
  16. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -1
  17. data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -3
  18. data/lib/rubocop/cop/lint/literal_as_condition.rb +25 -11
  19. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +1 -1
  20. data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -1
  21. data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +2 -2
  22. data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +1 -1
  23. data/lib/rubocop/cop/lint/redundant_type_conversion.rb +7 -4
  24. data/lib/rubocop/cop/lint/return_in_void_context.rb +7 -2
  25. data/lib/rubocop/cop/lint/suppressed_exception.rb +1 -1
  26. data/lib/rubocop/cop/lint/to_enum_arguments.rb +1 -1
  27. data/lib/rubocop/cop/lint/top_level_return_with_argument.rb +1 -1
  28. data/lib/rubocop/cop/lint/useless_rescue.rb +1 -1
  29. data/lib/rubocop/cop/message_annotator.rb +7 -3
  30. data/lib/rubocop/cop/mixin/check_line_breakable.rb +2 -2
  31. data/lib/rubocop/cop/mixin/check_single_line_suitability.rb +1 -1
  32. data/lib/rubocop/cop/mixin/def_node.rb +1 -1
  33. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -1
  34. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +0 -1
  35. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -0
  36. data/lib/rubocop/cop/mixin/trailing_comma.rb +4 -4
  37. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +1 -1
  38. data/lib/rubocop/cop/naming/method_name.rb +1 -1
  39. data/lib/rubocop/cop/style/arguments_forwarding.rb +5 -5
  40. data/lib/rubocop/cop/style/class_and_module_children.rb +19 -3
  41. data/lib/rubocop/cop/style/class_equality_comparison.rb +1 -1
  42. data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
  43. data/lib/rubocop/cop/style/comparable_between.rb +2 -2
  44. data/lib/rubocop/cop/style/conditional_assignment.rb +16 -4
  45. data/lib/rubocop/cop/style/double_negation.rb +1 -1
  46. data/lib/rubocop/cop/style/empty_literal.rb +4 -0
  47. data/lib/rubocop/cop/style/eval_with_location.rb +3 -3
  48. data/lib/rubocop/cop/style/explicit_block_argument.rb +2 -2
  49. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +3 -2
  50. data/lib/rubocop/cop/style/global_std_stream.rb +3 -0
  51. data/lib/rubocop/cop/style/hash_fetch_chain.rb +0 -1
  52. data/lib/rubocop/cop/style/hash_syntax.rb +3 -0
  53. data/lib/rubocop/cop/style/hash_transform_keys.rb +2 -2
  54. data/lib/rubocop/cop/style/hash_transform_values.rb +2 -2
  55. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +1 -1
  56. data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -1
  57. data/lib/rubocop/cop/style/lambda_call.rb +7 -2
  58. data/lib/rubocop/cop/style/map_into_array.rb +3 -1
  59. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +1 -1
  60. data/lib/rubocop/cop/style/redundant_condition.rb +13 -1
  61. data/lib/rubocop/cop/style/redundant_current_directory_in_path.rb +1 -1
  62. data/lib/rubocop/cop/style/redundant_line_continuation.rb +0 -3
  63. data/lib/rubocop/cop/style/redundant_parentheses.rb +20 -3
  64. data/lib/rubocop/cop/style/return_nil.rb +2 -2
  65. data/lib/rubocop/cop/style/safe_navigation.rb +18 -3
  66. data/lib/rubocop/cop/style/super_arguments.rb +1 -2
  67. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +7 -1
  68. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +1 -1
  69. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +1 -1
  70. data/lib/rubocop/cop/util.rb +1 -1
  71. data/lib/rubocop/cop/variable_force/variable.rb +1 -1
  72. data/lib/rubocop/cops_documentation_generator.rb +6 -2
  73. data/lib/rubocop/formatter/disabled_config_formatter.rb +1 -1
  74. data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
  75. data/lib/rubocop/magic_comment.rb +8 -0
  76. data/lib/rubocop/rspec/cop_helper.rb +2 -2
  77. data/lib/rubocop/rspec/shared_contexts.rb +1 -2
  78. data/lib/rubocop/server/cache.rb +13 -10
  79. data/lib/rubocop/target_finder.rb +6 -2
  80. data/lib/rubocop/version.rb +1 -1
  81. metadata +5 -5
@@ -174,12 +174,17 @@ module RuboCop
174
174
  range_with_surrounding_space(range: lhs.source_range, side: :right),
175
175
  range_with_surrounding_space(range: lhs_operator_range, side: :right),
176
176
  offense_range: range_between(lhs.source_range.begin_pos, rhs.source_range.end_pos)
177
- )
177
+ ) do |corrector|
178
+ corrector.replace(rhs_receiver, lhs_receiver.source)
179
+ end
180
+ ignore_node(node)
178
181
  end
179
182
  end
180
183
 
181
184
  def report_offense(node, rhs, rhs_receiver, *removal_ranges, offense_range: node)
182
185
  add_offense(offense_range) do |corrector|
186
+ next if ignored_node?(node)
187
+
183
188
  # If the RHS is an `or` we cannot safely autocorrect because in order to remove
184
189
  # the non-nil check we need to add safe-navs to all clauses where the receiver is used
185
190
  next if and_with_rhs_or?(node)
@@ -227,7 +232,7 @@ module RuboCop
227
232
  end
228
233
 
229
234
  def offending_node?(node, lhs_receiver, rhs, rhs_receiver) # rubocop:disable Metrics/CyclomaticComplexity
230
- return false if lhs_receiver != rhs_receiver || rhs_receiver.nil?
235
+ return false if !matching_nodes?(lhs_receiver, rhs_receiver) || rhs_receiver.nil?
231
236
  return false if use_var_only_in_unless_modifier?(node, lhs_receiver)
232
237
  return false if chain_length(rhs, rhs_receiver) > max_chain_length
233
238
  return false if unsafe_method_used?(rhs, rhs_receiver.parent)
@@ -306,11 +311,21 @@ module RuboCop
306
311
 
307
312
  receiver = method_chain.receiver
308
313
 
309
- return receiver if receiver == checked_variable
314
+ return receiver if matching_nodes?(receiver, checked_variable)
310
315
 
311
316
  find_matching_receiver_invocation(receiver, checked_variable)
312
317
  end
313
318
 
319
+ def matching_nodes?(left, right)
320
+ left == right || matching_call_nodes?(left, right)
321
+ end
322
+
323
+ def matching_call_nodes?(left, right)
324
+ return false unless left && right.respond_to?(:call_type?)
325
+
326
+ left.call_type? && right.call_type? && left.children == right.children
327
+ end
328
+
314
329
  def chain_length(method_chain, method)
315
330
  method.each_ancestor(:call).inject(0) do |total, ancestor|
316
331
  break total + 1 if ancestor == method_chain
@@ -68,7 +68,6 @@ module RuboCop
68
68
  class SuperArguments < Base
69
69
  extend AutoCorrector
70
70
 
71
- DEF_TYPES = %i[def defs].freeze
72
71
  ASSIGN_TYPES = %i[or_asgn lvasgn].freeze
73
72
 
74
73
  MSG = 'Call `super` without arguments and parentheses when the signature is identical.'
@@ -100,7 +99,7 @@ module RuboCop
100
99
  # `super` used within the block is always allowed.
101
100
  break if node.any_block_type? && !block_sends_to_super?(super_node, node)
102
101
 
103
- break node if DEF_TYPES.include?(node.type)
102
+ break node if node.any_def_type?
104
103
  end
105
104
  end
106
105
 
@@ -79,10 +79,16 @@ module RuboCop
79
79
  # # bad
80
80
  # method(1, 2,)
81
81
  #
82
+ # # bad
83
+ # object[1, 2,]
84
+ #
82
85
  # # good
83
86
  # method(1, 2)
84
87
  #
85
88
  # # good
89
+ # object[1, 2]
90
+ #
91
+ # # good
86
92
  # method(
87
93
  # 1,
88
94
  # 2
@@ -96,7 +102,7 @@ module RuboCop
96
102
  end
97
103
 
98
104
  def on_send(node)
99
- return unless node.arguments? && node.parenthesized?
105
+ return unless node.arguments? && (node.parenthesized? || node.method?(:[]))
100
106
 
101
107
  check(node, node.arguments, 'parameter of %<article>s method call',
102
108
  node.last_argument.source_range.end_pos,
@@ -11,7 +11,7 @@ module RuboCop
11
11
  # * `comma`: Requires a comma after the last item in an array, but only when each item is on
12
12
  # its own line.
13
13
  # * `diff_comma`: Requires a comma after the last item in an array, but only when that item is
14
- # followed by an immediate newline.
14
+ # followed by an immediate newline, even if there is an inline comment on the same line.
15
15
  # * `no_comma`: Does not require a comma after the last item in an array
16
16
  #
17
17
  # @example EnforcedStyleForMultiline: consistent_comma
@@ -11,7 +11,7 @@ module RuboCop
11
11
  # * `comma`: Requires a comma after the last item in a hash, but only when each item is on its
12
12
  # own line.
13
13
  # * `diff_comma`: Requires a comma after the last item in a hash, but only when that item is
14
- # followed by an immediate newline.
14
+ # followed by an immediate newline, even if there is an inline comment on the same line.
15
15
  # * `no_comma`: Does not require a comma after the last item in a hash
16
16
  #
17
17
  # @example EnforcedStyleForMultiline: consistent_comma
@@ -76,7 +76,7 @@ module RuboCop
76
76
  loc = node.loc
77
77
  selector = if node.type?(:super, :yield)
78
78
  loc.keyword
79
- elsif node.type?(:def, :defs)
79
+ elsif node.any_def_type?
80
80
  loc.name
81
81
  else
82
82
  loc.selector
@@ -107,7 +107,7 @@ module RuboCop
107
107
  end
108
108
 
109
109
  def method_argument?
110
- argument? && %i[def defs].include?(@scope.node.type)
110
+ argument? && @scope.node.any_def_type?
111
111
  end
112
112
 
113
113
  def block_argument?
@@ -327,8 +327,12 @@ class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
327
327
  def print_cop_with_doc(cop) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
328
328
  cop_config = config.for_cop(cop)
329
329
  non_display_keys = %w[
330
- AutoCorrect Description Enabled StyleGuide Reference Safe SafeAutoCorrect VersionAdded
331
- VersionChanged
330
+ Enabled
331
+ Description
332
+ StyleGuide
333
+ Reference References
334
+ Safe SafeAutoCorrect AutoCorrect
335
+ VersionAdded VersionChanged
332
336
  ]
333
337
  parameters = cop_config.reject { |k| non_display_keys.include? k }
334
338
  description = 'No documentation'
@@ -164,7 +164,7 @@ module RuboCop
164
164
 
165
165
  def cop_config_params(default_cfg, cfg)
166
166
  default_cfg.keys -
167
- %w[Description StyleGuide Reference Enabled Exclude Safe
167
+ %w[Description StyleGuide Reference References Enabled Exclude Safe
168
168
  SafeAutoCorrect VersionAdded VersionChanged VersionRemoved] -
169
169
  cfg.keys
170
170
  end
@@ -58,7 +58,7 @@ module RuboCop
58
58
  return pacdots(@total_files) unless @total_files > cols
59
59
  return pacdots(cols) unless (@total_files / cols).eql?(@repetitions)
60
60
 
61
- pacdots((@total_files - (cols * @repetitions)))
61
+ pacdots(@total_files - (cols * @repetitions))
62
62
  end
63
63
 
64
64
  def pacdots(number)
@@ -193,6 +193,10 @@ module RuboCop
193
193
  SEPARATOR = ';'
194
194
  OPERATOR = ':'
195
195
 
196
+ def new_frozen_string_literal(value)
197
+ "# -*- frozen_string_literal: #{value} -*-"
198
+ end
199
+
196
200
  private
197
201
 
198
202
  def extract_frozen_string_literal
@@ -275,6 +279,10 @@ module RuboCop
275
279
  end
276
280
  end
277
281
 
282
+ def new_frozen_string_literal(value)
283
+ "# frozen_string_literal: #{value}"
284
+ end
285
+
278
286
  private
279
287
 
280
288
  # Extract `frozen_string_literal`.
@@ -11,8 +11,8 @@ module CopHelper
11
11
  ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.3 : RuboCop::TargetRuby::DEFAULT_VERSION
12
12
  end
13
13
  let(:parser_engine) do
14
- # The maximum version Parser can parse is 3.4.
15
- ruby_version >= 3.5 ? :parser_prism : ENV.fetch('PARSER_ENGINE', :parser_whitequark).to_sym
14
+ # The maximum version Parser can correctly parse is 3.3.
15
+ ruby_version >= 3.4 ? :parser_prism : ENV.fetch('PARSER_ENGINE', :parser_whitequark).to_sym
16
16
  end
17
17
  let(:rails_version) { false }
18
18
 
@@ -267,6 +267,5 @@ RSpec.shared_context 'ruby 3.4' do
267
267
  end
268
268
 
269
269
  RSpec.shared_context 'ruby 3.5' do
270
- # Parser supports parsing Ruby <= 3.4.
271
- let(:ruby_version) { ENV['PARSER_ENGINE'] == 'parser_prism' ? 3.5 : 3.4 }
270
+ let(:ruby_version) { 3.5 }
272
271
  end
@@ -52,7 +52,8 @@ module RuboCop
52
52
  end.find(&:exist?)
53
53
  version_data = lockfile_path&.read || RuboCop::Version::STRING
54
54
  config_data = Pathname(ConfigFinder.find_config_path(Dir.pwd)).read
55
- yaml = YAML.safe_load(config_data, permitted_classes: [Regexp, Symbol], aliases: true)
55
+ yaml = load_erb_templated_yaml(config_data)
56
+
56
57
  inherit_from_data = inherit_from_data(yaml)
57
58
  require_data = require_data(yaml)
58
59
 
@@ -76,7 +77,6 @@ module RuboCop
76
77
  File.expand_path(File.join(cache_root_dir, 'server'))
77
78
  end
78
79
 
79
- # rubocop:disable Metrics/MethodLength
80
80
  def cache_root_dir_from_config
81
81
  CacheConfig.root_dir do
82
82
  # `RuboCop::ConfigStore` has heavy dependencies, this is a lightweight implementation
@@ -87,13 +87,7 @@ module RuboCop
87
87
  # Returns early if `CacheRootDirectory` is not used before requiring `erb` or `yaml`.
88
88
  next unless file_contents.include?('CacheRootDirectory')
89
89
 
90
- require 'erb'
91
- yaml_code = ERB.new(file_contents).result
92
-
93
- require 'yaml'
94
- config_yaml = YAML.safe_load(
95
- yaml_code, permitted_classes: [Regexp, Symbol], aliases: true
96
- )
90
+ config_yaml = load_erb_templated_yaml(file_contents)
97
91
 
98
92
  # For compatibility with Ruby 3.0 or lower.
99
93
  if Gem::Version.new(Psych::VERSION) < Gem::Version.new('4.0.0')
@@ -103,7 +97,6 @@ module RuboCop
103
97
  config_yaml&.dig('AllCops', 'CacheRootDirectory')
104
98
  end
105
99
  end
106
- # rubocop:enable Metrics/MethodLength
107
100
 
108
101
  def port_path
109
102
  dir.join('port')
@@ -197,6 +190,16 @@ module RuboCop
197
190
  path.exist? ? path.read : ''
198
191
  end.join
199
192
  end
193
+
194
+ private
195
+
196
+ def load_erb_templated_yaml(content)
197
+ require 'erb'
198
+ yaml_code = ERB.new(content).result
199
+
200
+ require 'yaml'
201
+ YAML.safe_load(yaml_code, permitted_classes: [Regexp, Symbol], aliases: true)
202
+ end
200
203
  end
201
204
  end
202
205
  end
@@ -46,7 +46,11 @@ module RuboCop
46
46
  hidden_files = all_files.select { |file| file.include?(HIDDEN_PATH_SUBSTRING) }.sort
47
47
  base_dir_config = @config_store.for(base_dir)
48
48
 
49
- target_files = all_files.select { |file| to_inspect?(file, hidden_files, base_dir_config) }
49
+ target_files = if base_dir.include?(HIDDEN_PATH_SUBSTRING)
50
+ all_files.select { |file| ruby_file?(file) }
51
+ else
52
+ all_files.select { |file| to_inspect?(file, hidden_files, base_dir_config) }
53
+ end
50
54
 
51
55
  target_files.sort_by!(&order)
52
56
  end
@@ -175,7 +179,7 @@ module RuboCop
175
179
  end
176
180
 
177
181
  def ruby_executable?(file)
178
- return false unless File.extname(file).empty? && File.exist?(file)
182
+ return false if !File.extname(file).empty? || !File.exist?(file) || File.empty?(file)
179
183
 
180
184
  first_line = File.open(file, &:readline)
181
185
  /#!.*(#{ruby_interpreters(file).join('|')})/.match?(first_line)
@@ -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.1'
6
+ STRING = '1.75.4'
7
7
 
8
8
  MSG = '%<version>s (using %<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.75.1
4
+ version: 1.75.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
@@ -9,7 +9,7 @@ authors:
9
9
  - Yuji Nakayama
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2025-03-26 00:00:00.000000000 Z
12
+ date: 2025-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -127,7 +127,7 @@ dependencies:
127
127
  requirements:
128
128
  - - ">="
129
129
  - !ruby/object:Gem::Version
130
- version: 1.43.0
130
+ version: 1.44.0
131
131
  - - "<"
132
132
  - !ruby/object:Gem::Version
133
133
  version: '2.0'
@@ -137,7 +137,7 @@ dependencies:
137
137
  requirements:
138
138
  - - ">="
139
139
  - !ruby/object:Gem::Version
140
- version: 1.43.0
140
+ version: 1.44.0
141
141
  - - "<"
142
142
  - !ruby/object:Gem::Version
143
143
  version: '2.0'
@@ -1080,7 +1080,7 @@ licenses:
1080
1080
  - MIT
1081
1081
  metadata:
1082
1082
  homepage_uri: https://rubocop.org/
1083
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.75.1
1083
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.75.4
1084
1084
  source_code_uri: https://github.com/rubocop/rubocop/
1085
1085
  documentation_uri: https://docs.rubocop.org/rubocop/1.75/
1086
1086
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues