rubocop 1.77.0 → 1.79.1

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 (59) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -3
  3. data/config/default.yml +36 -20
  4. data/lib/rubocop/cli.rb +12 -1
  5. data/lib/rubocop/config_loader.rb +1 -38
  6. data/lib/rubocop/cop/internal_affairs/example_description.rb +1 -1
  7. data/lib/rubocop/cop/internal_affairs/node_type_group.rb +3 -2
  8. data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +1 -1
  9. data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +99 -0
  10. data/lib/rubocop/cop/layout/space_around_keyword.rb +6 -1
  11. data/lib/rubocop/cop/layout/space_around_operators.rb +8 -0
  12. data/lib/rubocop/cop/lint/duplicate_methods.rb +25 -4
  13. data/lib/rubocop/cop/lint/literal_as_condition.rb +15 -1
  14. data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +1 -0
  15. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +101 -2
  16. data/lib/rubocop/cop/lint/redundant_type_conversion.rb +4 -4
  17. data/lib/rubocop/cop/lint/require_range_parentheses.rb +1 -1
  18. data/lib/rubocop/cop/lint/rescue_type.rb +1 -1
  19. data/lib/rubocop/cop/lint/useless_numeric_operation.rb +1 -0
  20. data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +121 -0
  21. data/lib/rubocop/cop/naming/method_name.rb +127 -13
  22. data/lib/rubocop/cop/naming/predicate_method.rb +27 -2
  23. data/lib/rubocop/cop/security/eval.rb +2 -1
  24. data/lib/rubocop/cop/security/open.rb +1 -0
  25. data/lib/rubocop/cop/style/access_modifier_declarations.rb +1 -1
  26. data/lib/rubocop/cop/style/accessor_grouping.rb +13 -1
  27. data/lib/rubocop/cop/style/arguments_forwarding.rb +11 -17
  28. data/lib/rubocop/cop/style/array_intersect.rb +53 -23
  29. data/lib/rubocop/cop/style/block_delimiters.rb +1 -1
  30. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -1
  31. data/lib/rubocop/cop/style/dig_chain.rb +1 -1
  32. data/lib/rubocop/cop/style/exponential_notation.rb +1 -0
  33. data/lib/rubocop/cop/style/hash_conversion.rb +8 -9
  34. data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
  35. data/lib/rubocop/cop/style/it_assignment.rb +69 -12
  36. data/lib/rubocop/cop/style/it_block_parameter.rb +3 -1
  37. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -4
  38. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +16 -0
  39. data/lib/rubocop/cop/style/parallel_assignment.rb +32 -20
  40. data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -9
  41. data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
  42. data/lib/rubocop/cop/style/redundant_line_continuation.rb +1 -1
  43. data/lib/rubocop/cop/style/redundant_parentheses.rb +9 -0
  44. data/lib/rubocop/cop/style/single_line_methods.rb +7 -4
  45. data/lib/rubocop/cop/style/sole_nested_conditional.rb +30 -1
  46. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -1
  47. data/lib/rubocop/cop/variable_force.rb +18 -7
  48. data/lib/rubocop/cops_documentation_generator.rb +1 -0
  49. data/lib/rubocop/formatter/markdown_formatter.rb +1 -0
  50. data/lib/rubocop/formatter/pacman_formatter.rb +1 -0
  51. data/lib/rubocop/lsp/routes.rb +4 -4
  52. data/lib/rubocop/pending_cops_reporter.rb +56 -0
  53. data/lib/rubocop/server/cache.rb +4 -2
  54. data/lib/rubocop/server/client_command/base.rb +10 -0
  55. data/lib/rubocop/server/client_command/exec.rb +2 -1
  56. data/lib/rubocop/server/client_command/start.rb +11 -1
  57. data/lib/rubocop/version.rb +1 -1
  58. data/lib/rubocop.rb +3 -0
  59. metadata +13 -7
@@ -175,6 +175,8 @@ module RuboCop
175
175
 
176
176
  if parenthesize_method?(condition)
177
177
  parenthesized_method_arguments(condition)
178
+ elsif condition.and_type?
179
+ parenthesized_and(condition)
178
180
  else
179
181
  "(#{condition.source})"
180
182
  end
@@ -186,12 +188,19 @@ module RuboCop
186
188
  end
187
189
 
188
190
  def add_parentheses?(node)
189
- return true if node.assignment? || (node.operator_keyword? && !node.and_type?)
191
+ return true if node.assignment? || node.or_type?
192
+ return true if assignment_in_and?(node)
190
193
  return false unless node.call_type?
191
194
 
192
195
  (node.arguments.any? && !node.parenthesized?) || node.prefix_not?
193
196
  end
194
197
 
198
+ def assignment_in_and?(node)
199
+ return false unless node.and_type?
200
+
201
+ node.each_descendant.any?(&:assignment?)
202
+ end
203
+
195
204
  def parenthesized_method_arguments(node)
196
205
  method_call = node.source_range.begin.join(node.loc.selector.end).source
197
206
  arguments = node.first_argument.source_range.begin.join(node.source_range.end).source
@@ -199,6 +208,26 @@ module RuboCop
199
208
  "#{method_call}(#{arguments})"
200
209
  end
201
210
 
211
+ def parenthesized_and(node)
212
+ # We only need to add parentheses around the last clause if it's an assignment,
213
+ # because other clauses will be unchanged by merging conditionals.
214
+ lhs = node.lhs.source
215
+ rhs = parenthesized_and_clause(node.rhs)
216
+ operator = range_with_surrounding_space(node.loc.operator, whitespace: true).source
217
+
218
+ "#{lhs}#{operator}#{rhs}"
219
+ end
220
+
221
+ def parenthesized_and_clause(node)
222
+ if node.and_type?
223
+ parenthesized_and(node)
224
+ elsif node.assignment?
225
+ "(#{node.source})"
226
+ else
227
+ node.source
228
+ end
229
+ end
230
+
202
231
  def allow_modifier?
203
232
  cop_config['AllowModifier']
204
233
  end
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Style
6
- # Check for parentheses around stabby lambda arguments.
6
+ # Checks for parentheses around stabby lambda arguments.
7
7
  # There are two different styles. Defaults to `require_parentheses`.
8
8
  #
9
9
  # @example EnforcedStyle: require_parentheses (default)
@@ -296,7 +296,7 @@ module RuboCop
296
296
  variable_table.accessible_variables.each { |variable| variable.reference!(node) }
297
297
  end
298
298
 
299
- # Mark all assignments which are referenced in the same loop
299
+ # Mark last assignments which are referenced in the same loop
300
300
  # as referenced by ignoring AST order since they would be referenced
301
301
  # in next iteration.
302
302
  def mark_assignments_as_referenced_in_loop(node)
@@ -308,13 +308,12 @@ module RuboCop
308
308
  # would be skipped here.
309
309
  next unless variable
310
310
 
311
- variable.assignments.each do |assignment|
312
- next if assignment_nodes_in_loop.none? do |assignment_node|
313
- assignment_node.equal?(assignment.node)
314
- end
315
-
316
- assignment.reference!(node)
311
+ loop_assignments = variable.assignments.select do |assignment|
312
+ assignment_nodes_in_loop.include?(assignment.node)
317
313
  end
314
+ next unless loop_assignments.any?
315
+
316
+ reference_assignments(loop_assignments, node)
318
317
  end
319
318
  end
320
319
 
@@ -354,6 +353,18 @@ module RuboCop
354
353
  end
355
354
  end
356
355
 
356
+ def reference_assignments(loop_assignments, node)
357
+ # If inside a branching statement, mark all as referenced.
358
+ # Otherwise, mark only the last assignment as referenced.
359
+ # Note that `rescue` must be considered as branching because of
360
+ # the `retry` keyword.
361
+ if loop_assignments.first.node.each_ancestor(:if, :rescue, :case, :case_match).any?
362
+ loop_assignments.each { |assignment| assignment.reference!(node) }
363
+ else
364
+ loop_assignments.last&.reference!(node)
365
+ end
366
+ end
367
+
357
368
  def scanned_node?(node)
358
369
  scanned_nodes.include?(node)
359
370
  end
@@ -7,6 +7,7 @@ require 'yard'
7
7
  # @api private
8
8
  class CopsDocumentationGenerator # rubocop:disable Metrics/ClassLength
9
9
  include ::RuboCop::Cop::Documentation
10
+
10
11
  CopData = Struct.new(
11
12
  :cop, :description, :example_objects, :safety_objects, :see_objects, :config, keyword_init: true
12
13
  )
@@ -6,6 +6,7 @@ module RuboCop
6
6
  class MarkdownFormatter < BaseFormatter
7
7
  include TextUtil
8
8
  include PathUtil
9
+
9
10
  attr_reader :files, :summary
10
11
 
11
12
  def initialize(output, options = {})
@@ -9,6 +9,7 @@ module RuboCop
9
9
  # https://github.com/go-labs/rspec_pacman_formatter
10
10
  class PacmanFormatter < ClangStyleFormatter
11
11
  include TextUtil
12
+
12
13
  attr_accessor :progress_line
13
14
 
14
15
  FALLBACK_TERMINAL_WIDTH = 80
@@ -194,7 +194,7 @@ module RuboCop
194
194
  return []
195
195
  end
196
196
 
197
- new_text = @server.format(remove_file_protocol_from(file_uri), text, command: command)
197
+ new_text = @server.format(convert_file_uri_to_path(file_uri), text, command: command)
198
198
 
199
199
  return [] if new_text == text
200
200
 
@@ -214,13 +214,13 @@ module RuboCop
214
214
  method: 'textDocument/publishDiagnostics',
215
215
  params: {
216
216
  uri: file_uri,
217
- diagnostics: @server.offenses(remove_file_protocol_from(file_uri), text)
217
+ diagnostics: @server.offenses(convert_file_uri_to_path(file_uri), text)
218
218
  }
219
219
  }
220
220
  end
221
221
 
222
- def remove_file_protocol_from(uri)
223
- uri.delete_prefix('file://')
222
+ def convert_file_uri_to_path(uri)
223
+ URI.decode_www_form_component(uri.delete_prefix('file://'))
224
224
  end
225
225
  end
226
226
  end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ # Reports information about pending cops that are not explicitly configured.
5
+ #
6
+ # This class is responsible for displaying warnings when new cops have been added to RuboCop
7
+ # but have not yet been enabled or disabled in the user's configuration.
8
+ # It provides a centralized way to determine whether such warnings should be shown,
9
+ # based on global flags or configuration settings.
10
+ class PendingCopsReporter
11
+ class << self
12
+ PENDING_BANNER = <<~BANNER
13
+ The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.
14
+
15
+ Please also note that you can opt-in to new cops by default by adding this to your config:
16
+ AllCops:
17
+ NewCops: enable
18
+ BANNER
19
+
20
+ attr_accessor :disable_pending_cops, :enable_pending_cops
21
+
22
+ def warn_if_needed(config)
23
+ return if possible_new_cops?(config)
24
+
25
+ pending_cops = pending_cops_only_qualified(config.pending_cops)
26
+ warn_on_pending_cops(pending_cops) unless pending_cops.empty?
27
+ end
28
+
29
+ private
30
+
31
+ def pending_cops_only_qualified(pending_cops)
32
+ pending_cops.select { |cop| Cop::Registry.qualified_cop?(cop.name) }
33
+ end
34
+
35
+ def possible_new_cops?(config)
36
+ disable_pending_cops || enable_pending_cops ||
37
+ config.disabled_new_cops? || config.enabled_new_cops?
38
+ end
39
+
40
+ def warn_on_pending_cops(pending_cops)
41
+ warn Rainbow(PENDING_BANNER).yellow
42
+
43
+ pending_cops.each { |cop| warn_pending_cop cop }
44
+
45
+ warn Rainbow('For more information: https://docs.rubocop.org/rubocop/versioning.html').yellow
46
+ end
47
+
48
+ def warn_pending_cop(cop)
49
+ version = cop.metadata['VersionAdded'] || 'N/A'
50
+
51
+ warn Rainbow("#{cop.name}: # new in #{version}").yellow
52
+ warn Rainbow(' Enabled: true').yellow
53
+ end
54
+ end
55
+ end
56
+ end
@@ -46,12 +46,14 @@ module RuboCop
46
46
  end
47
47
 
48
48
  # rubocop:disable Metrics/AbcSize
49
- def restart_key
49
+ def restart_key(args_config_file_path: nil)
50
50
  lockfile_path = LOCKFILE_NAMES.map do |lockfile_name|
51
51
  Pathname(project_dir).join(lockfile_name)
52
52
  end.find(&:exist?)
53
53
  version_data = lockfile_path&.read || RuboCop::Version::STRING
54
- config_data = Pathname(ConfigFinder.find_config_path(Dir.pwd)).read
54
+ config_data = Pathname(
55
+ args_config_file_path || ConfigFinder.find_config_path(Dir.pwd)
56
+ ).read
55
57
  yaml = load_erb_templated_yaml(config_data)
56
58
 
57
59
  inherit_from_data = inherit_from_data(yaml)
@@ -38,6 +38,16 @@ module RuboCop
38
38
  warn 'RuboCop server is not running.' unless running
39
39
  end
40
40
  end
41
+
42
+ class << self
43
+ def args_config_file_path
44
+ first_args_config_key_index = ARGV.index { |value| ['-c', '--config'].include?(value) }
45
+
46
+ return if first_args_config_key_index.nil?
47
+
48
+ ARGV[first_args_config_key_index + 1]
49
+ end
50
+ end
41
51
  end
42
52
  end
43
53
  end
@@ -41,7 +41,8 @@ module RuboCop
41
41
  end
42
42
 
43
43
  def incompatible_version?
44
- Cache.version_path.read != Cache.restart_key
44
+ Cache.version_path.read !=
45
+ Cache.restart_key(args_config_file_path: self.class.args_config_file_path)
45
46
  end
46
47
 
47
48
  def stderr
@@ -34,7 +34,7 @@ module RuboCop
34
34
  exit 0
35
35
  end
36
36
 
37
- Cache.write_version_file(Cache.restart_key)
37
+ write_version_file
38
38
 
39
39
  host = ENV.fetch('RUBOCOP_SERVER_HOST', '127.0.0.1')
40
40
  port = ENV.fetch('RUBOCOP_SERVER_PORT', 0)
@@ -42,6 +42,16 @@ module RuboCop
42
42
  Server::Core.new.start(host, port, detach: @detach)
43
43
  end
44
44
  end
45
+
46
+ private
47
+
48
+ def write_version_file
49
+ Cache.write_version_file(
50
+ Cache.restart_key(
51
+ args_config_file_path: self.class.args_config_file_path
52
+ )
53
+ )
54
+ end
45
55
  end
46
56
  end
47
57
  end
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.77.0'
6
+ STRING = '1.79.1'
7
7
 
8
8
  MSG = '%<version>s (using %<parser_version>s, ' \
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
data/lib/rubocop.rb CHANGED
@@ -211,6 +211,7 @@ require_relative 'rubocop/cop/layout/empty_line_after_guard_clause'
211
211
  require_relative 'rubocop/cop/layout/empty_line_after_magic_comment'
212
212
  require_relative 'rubocop/cop/layout/empty_line_after_multiline_condition'
213
213
  require_relative 'rubocop/cop/layout/empty_line_between_defs'
214
+ require_relative 'rubocop/cop/layout/empty_lines_after_module_inclusion'
214
215
  require_relative 'rubocop/cop/layout/empty_lines_around_access_modifier'
215
216
  require_relative 'rubocop/cop/layout/empty_lines_around_arguments'
216
217
  require_relative 'rubocop/cop/layout/empty_lines_around_attribute_accessor'
@@ -290,6 +291,7 @@ require_relative 'rubocop/cop/layout/space_inside_string_interpolation'
290
291
  require_relative 'rubocop/cop/layout/trailing_empty_lines'
291
292
  require_relative 'rubocop/cop/layout/trailing_whitespace'
292
293
 
294
+ require_relative 'rubocop/cop/lint/utils/nil_receiver_checker'
293
295
  require_relative 'rubocop/cop/lint/ambiguous_assignment'
294
296
  require_relative 'rubocop/cop/lint/ambiguous_block_association'
295
297
  require_relative 'rubocop/cop/lint/ambiguous_operator'
@@ -812,6 +814,7 @@ require_relative 'rubocop/options'
812
814
  require_relative 'rubocop/remote_config'
813
815
  require_relative 'rubocop/target_ruby'
814
816
  require_relative 'rubocop/yaml_duplication_checker'
817
+ require_relative 'rubocop/pending_cops_reporter'
815
818
 
816
819
  # rubocop:enable Style/RequireOrder
817
820
 
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.77.0
4
+ version: 1.79.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bozhidar Batsov
8
8
  - Jonas Arvidsson
9
9
  - Yuji Nakayama
10
+ autorequire:
10
11
  bindir: exe
11
12
  cert_chain: []
12
- date: 2025-06-20 00:00:00.000000000 Z
13
+ date: 2025-07-31 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: json
@@ -127,7 +128,7 @@ dependencies:
127
128
  requirements:
128
129
  - - ">="
129
130
  - !ruby/object:Gem::Version
130
- version: 1.45.1
131
+ version: 1.46.0
131
132
  - - "<"
132
133
  - !ruby/object:Gem::Version
133
134
  version: '2.0'
@@ -137,7 +138,7 @@ dependencies:
137
138
  requirements:
138
139
  - - ">="
139
140
  - !ruby/object:Gem::Version
140
- version: 1.45.1
141
+ version: 1.46.0
141
142
  - - "<"
142
143
  - !ruby/object:Gem::Version
143
144
  version: '2.0'
@@ -342,6 +343,7 @@ files:
342
343
  - lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb
343
344
  - lib/rubocop/cop/layout/empty_line_between_defs.rb
344
345
  - lib/rubocop/cop/layout/empty_lines.rb
346
+ - lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb
345
347
  - lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb
346
348
  - lib/rubocop/cop/layout/empty_lines_around_arguments.rb
347
349
  - lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb
@@ -572,6 +574,7 @@ files:
572
574
  - lib/rubocop/cop/lint/useless_ruby2_keywords.rb
573
575
  - lib/rubocop/cop/lint/useless_setter_call.rb
574
576
  - lib/rubocop/cop/lint/useless_times.rb
577
+ - lib/rubocop/cop/lint/utils/nil_receiver_checker.rb
575
578
  - lib/rubocop/cop/lint/void.rb
576
579
  - lib/rubocop/cop/message_annotator.rb
577
580
  - lib/rubocop/cop/metrics/abc_size.rb
@@ -1040,6 +1043,7 @@ files:
1040
1043
  - lib/rubocop/name_similarity.rb
1041
1044
  - lib/rubocop/options.rb
1042
1045
  - lib/rubocop/path_util.rb
1046
+ - lib/rubocop/pending_cops_reporter.rb
1043
1047
  - lib/rubocop/platform.rb
1044
1048
  - lib/rubocop/plugin.rb
1045
1049
  - lib/rubocop/plugin/configuration_integrator.rb
@@ -1087,11 +1091,12 @@ licenses:
1087
1091
  - MIT
1088
1092
  metadata:
1089
1093
  homepage_uri: https://rubocop.org/
1090
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.77.0
1094
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.79.1
1091
1095
  source_code_uri: https://github.com/rubocop/rubocop/
1092
- documentation_uri: https://docs.rubocop.org/rubocop/1.77/
1096
+ documentation_uri: https://docs.rubocop.org/rubocop/1.79/
1093
1097
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
1094
1098
  rubygems_mfa_required: 'true'
1099
+ post_install_message:
1095
1100
  rdoc_options: []
1096
1101
  require_paths:
1097
1102
  - lib
@@ -1106,7 +1111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1106
1111
  - !ruby/object:Gem::Version
1107
1112
  version: '0'
1108
1113
  requirements: []
1109
- rubygems_version: 3.6.2
1114
+ rubygems_version: 3.3.7
1115
+ signing_key:
1110
1116
  specification_version: 4
1111
1117
  summary: Automatic Ruby code style checking tool.
1112
1118
  test_files: []