rubocop 1.72.0 → 1.72.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4660ddf63f92b10c83414d6a542725aacda2df1b9f47aec675b075fcdaa58817
4
- data.tar.gz: b7c045964213e406e20675c06ed8df3a7e19bff18cf48b0db9891b8e1ae6cd8a
3
+ metadata.gz: 4a6ff0f849d961da13d2131ff60e0ed49dce01a4c2d32caa8484a2344344609b
4
+ data.tar.gz: 9da9fc43212c62cd6542649c90423e9365f50cb00e82b6337be1a241c6a17283
5
5
  SHA512:
6
- metadata.gz: 0c4982b57b3c2cfbd48d2768eefeb839b6b91a5c9c90a55f4dfc1f1c37b655d73b64d99bbebc642d928ecfb9740c6992ed340ea38f2f1638626aa3d2e2c7a190
7
- data.tar.gz: f4d6cfcfb42615a5a4065c961aac1dd55eb7e6bd28812d0a31aef135be94b9248eab2b53f1a452847b49c206aab7b3eb19b45581203af63d10be9e7cb71e67da
6
+ metadata.gz: 7ff34957554167b3b1e30645e3754094968fae93d0284a3882460b3e24f44fd64bcf358b23fd0e8154489206fd9c95fc6555b551f1af5ac810805fac2b6d27be
7
+ data.tar.gz: 48e989049de37523554c740ba1368e32de38bc0f879c1fc717924a758a1ba465ef4413cba80a42be59ccaaf87616b52c0ad437256702bf5fd091c4a5818f428a
data/config/default.yml CHANGED
@@ -5171,7 +5171,9 @@ Style/RedundantFilterChain:
5171
5171
  Style/RedundantFormat:
5172
5172
  Description: 'Checks for usages of `Kernel#format` or `Kernel#sprintf` with only a single argument.'
5173
5173
  Enabled: pending
5174
+ SafeAutoCorrect: false
5174
5175
  VersionAdded: '1.72'
5176
+ VersionChanged: '1.72'
5175
5177
 
5176
5178
  Style/RedundantFreeze:
5177
5179
  Description: "Checks usages of Object#freeze on immutable objects."
@@ -163,6 +163,10 @@ module RuboCop
163
163
  end
164
164
  end
165
165
 
166
+ # This API is primarily intended for testing and documenting plugins.
167
+ # When testing a plugin using `rubocop/rspec/support`, the plugin is loaded automatically,
168
+ # so this API is usually not needed. It is intended to be used only when implementing tests
169
+ # that do not use `rubocop/rspec/support`.
166
170
  # rubocop:disable Metrics/MethodLength
167
171
  def inject_defaults!(config_yml_path)
168
172
  if Pathname(config_yml_path).directory?
@@ -90,8 +90,10 @@ module RuboCop
90
90
  description_text = string_contents(current_description)
91
91
  return unless (new_description = correct_description(description_text, description_map))
92
92
 
93
+ quote = current_description.dstr_type? ? '"' : "'"
94
+
93
95
  add_offense(current_description, message: message) do |corrector|
94
- corrector.replace(current_description, "'#{new_description}'")
96
+ corrector.replace(current_description, "#{quote}#{new_description}#{quote}")
95
97
  end
96
98
  end
97
99
 
@@ -106,7 +108,7 @@ module RuboCop
106
108
  end
107
109
 
108
110
  def string_contents(node)
109
- node.str_type? ? node.value : node.source
111
+ node.type?(:str, :dstr) ? node.value : node.source
110
112
  end
111
113
  end
112
114
  end
@@ -161,7 +161,10 @@ module RuboCop
161
161
  }
162
162
  PATTERN
163
163
 
164
+ # rubocop:disable Metrics/AbcSize
164
165
  def on_send(node)
166
+ return if hash_or_set_with_block?(node)
167
+
165
168
  receiver = find_receiver(node)
166
169
  return unless literal_receiver?(node, receiver) ||
167
170
  constructor?(node, receiver) ||
@@ -174,10 +177,17 @@ module RuboCop
174
177
  corrector.remove(node.loc.dot.join(node.loc.selector))
175
178
  end
176
179
  end
180
+ # rubocop:enable Metrics/AbcSize
177
181
  alias on_csend on_send
178
182
 
179
183
  private
180
184
 
185
+ def hash_or_set_with_block?(node)
186
+ return false if !node.method?(:to_h) && !node.method?(:to_set)
187
+
188
+ node.parent&.any_block_type? || node.last_argument&.block_pass_type?
189
+ end
190
+
181
191
  def find_receiver(node)
182
192
  receiver = node.receiver
183
193
  return unless receiver
@@ -56,7 +56,13 @@ module RuboCop
56
56
  private
57
57
 
58
58
  def after_private_modifier?(left_siblings)
59
- left_siblings.compact.select(&:send_type?).any? { |node| node.command?(:private) }
59
+ access_modifier_candidates = left_siblings.compact.select do |left_sibling|
60
+ left_sibling.respond_to?(:send_type?) && left_sibling.send_type?
61
+ end
62
+
63
+ access_modifier_candidates.any? do |candidate|
64
+ candidate.command?(:private) && candidate.arguments.none?
65
+ end
60
66
  end
61
67
 
62
68
  def private_constantize?(right_siblings, const_value)
@@ -18,12 +18,12 @@ module RuboCop
18
18
  end
19
19
 
20
20
  # @deprecated Use allowed_line? instead
21
- def ignored_line?
21
+ def ignored_line?(line)
22
22
  warn Rainbow(<<~WARNING).yellow, uplevel: 1
23
23
  `ignored_line?` is deprecated. Use `allowed_line?` instead.
24
24
  WARNING
25
25
 
26
- allowed_line?
26
+ allowed_line?(line)
27
27
  end
28
28
 
29
29
  def matches_allowed_pattern?(line)
@@ -31,12 +31,12 @@ module RuboCop
31
31
  end
32
32
 
33
33
  # @deprecated Use matches_allowed_pattern? instead
34
- def matches_ignored_pattern?
34
+ def matches_ignored_pattern?(line)
35
35
  warn Rainbow(<<~WARNING).yellow, uplevel: 1
36
36
  `matches_ignored_pattern?` is deprecated. Use `matches_allowed_pattern?` instead.
37
37
  WARNING
38
38
 
39
- matches_allowed_pattern?
39
+ matches_allowed_pattern?(line)
40
40
  end
41
41
 
42
42
  def allowed_patterns
@@ -14,10 +14,10 @@ module RuboCop
14
14
  # autocorrected.
15
15
  #
16
16
  # [NOTE]
17
- # --
17
+ # ====
18
18
  # Because of a bug in Ruby 3.3.0, when a block is referenced inside of another block,
19
19
  # no offense will be registered until Ruby 3.4:
20
-
20
+ #
21
21
  # [source,ruby]
22
22
  # ----
23
23
  # def foo(&block)
@@ -25,7 +25,7 @@ module RuboCop
25
25
  # block_method { bar(&block) }
26
26
  # end
27
27
  # ----
28
- # --
28
+ # ====
29
29
  #
30
30
  # @example EnforcedStyle: anonymous (default)
31
31
  #
@@ -32,10 +32,10 @@ module RuboCop
32
32
  # This cop handles not only method forwarding but also forwarding to `super`.
33
33
  #
34
34
  # [NOTE]
35
- # --
35
+ # ====
36
36
  # Because of a bug in Ruby 3.3.0, when a block is referenced inside of another block,
37
37
  # no offense will be registered until Ruby 3.4:
38
-
38
+ #
39
39
  # [source,ruby]
40
40
  # ----
41
41
  # def foo(&block)
@@ -43,7 +43,7 @@ module RuboCop
43
43
  # block_method { bar(&block) }
44
44
  # end
45
45
  # ----
46
- # --
46
+ # ====
47
47
  #
48
48
  # @example
49
49
  # # bad
@@ -12,6 +12,22 @@ module RuboCop
12
12
  # inlined into a string easily. This applies to the `%s`, `%d`, `%i`, `%u`, and
13
13
  # `%f` format specifiers.
14
14
  #
15
+ # @safety
16
+ # This cop's autocorrection is unsafe because string object returned by
17
+ # `format` and `sprintf` are never frozen. If `format('string')` is autocorrected to
18
+ # `'string'`, `FrozenError` may occur when calling a destructive method like `String#<<`.
19
+ # Consider using `'string'.dup` instead of `format('string')`.
20
+ # Additionally, since the necessity of `dup` cannot be determined automatically,
21
+ # this autocorrection is inherently unsafe.
22
+ #
23
+ # [source,ruby]
24
+ # ----
25
+ # # frozen_string_literal: true
26
+ #
27
+ # format('template').frozen? # => false
28
+ # 'template'.frozen? # => true
29
+ # ----
30
+ #
15
31
  # @example
16
32
  #
17
33
  # # bad
@@ -113,7 +129,7 @@ module RuboCop
113
129
  end
114
130
 
115
131
  def find_argument(sequence, arguments, hash)
116
- if sequence.annotated? || sequence.template?
132
+ if hash && (sequence.annotated? || sequence.template?)
117
133
  find_hash_value_node(hash, sequence.name.to_sym).first
118
134
  elsif sequence.arg_number
119
135
  arguments[sequence.arg_number.to_i - 1]
@@ -144,7 +160,7 @@ module RuboCop
144
160
  end
145
161
 
146
162
  def numeric?(argument)
147
- argument.type?(:numeric, :str) ||
163
+ argument&.type?(:numeric, :str) ||
148
164
  rational_number?(argument) ||
149
165
  complex_number?(argument)
150
166
  end
@@ -13,8 +13,7 @@ module RuboCop
13
13
  # # good
14
14
  # x if y.z.nil?
15
15
  #
16
- # rubocop:disable Metrics/ClassLength
17
- class RedundantParentheses < Base
16
+ class RedundantParentheses < Base # rubocop:disable Metrics/ClassLength
18
17
  include Parentheses
19
18
  extend AutoCorrector
20
19
 
@@ -217,7 +216,9 @@ module RuboCop
217
216
 
218
217
  def disallowed_literal?(begin_node, node)
219
218
  if node.range_type?
220
- begin_node.parent&.begin_type?
219
+ return false unless (parent = begin_node.parent)
220
+
221
+ parent.begin_type? && parent.children.one?
221
222
  else
222
223
  !raised_to_power_negative_numeric?(begin_node, node)
223
224
  end
@@ -297,7 +298,6 @@ module RuboCop
297
298
  block.keywords? && begin_node.each_ancestor(:call).any?
298
299
  end
299
300
  end
300
- # rubocop:enable Metrics/ClassLength
301
301
  end
302
302
  end
303
303
  end
@@ -57,6 +57,8 @@ module RuboCop
57
57
  all_cop_keys_configured_by_plugins
58
58
  )
59
59
 
60
+ plugin_config.make_excludes_absolute
61
+
60
62
  ConfigLoader.merge_with_default(plugin_config, plugin_config_path)
61
63
  end
62
64
  end
@@ -13,21 +13,12 @@ module RuboCop
13
13
 
14
14
  def message
15
15
  <<~MESSAGE
16
- Failed loading plugin `#{@plugin_name}` because we couldn't determine the corresponding plugin class to instantiate.
17
- First, try upgrading it. If the issue persists, please check with the developer regarding the following points.
16
+ Failed to load plugin `#{@plugin_name}` because the corresponding plugin class could not be determined for instantiation.
17
+ Try upgrading it first (e.g., `bundle update #{@plugin_name}`).
18
+ If `#{@plugin_name}` is not yet a plugin, use `require: #{@plugin_name}` instead of `plugins: `#{@plugin_name}` in your configuration.
18
19
 
19
- RuboCop plugin class names must either be:
20
-
21
- - If the plugin is a gem, defined in the gemspec as `default_lint_roller_plugin'
22
-
23
- spec.metadata['default_lint_roller_plugin'] = 'MyModule::Plugin'
24
-
25
- - Set in YAML as `plugin_class_name'; example:
26
-
27
- plugins:
28
- - incomplete:
29
- require_path: my_module/plugin
30
- plugin_class_name: "MyModule::Plugin"
20
+ For further assistance, check with the developer regarding the following points:
21
+ https://docs.rubocop.org/rubocop/plugin_migration_guide.html
31
22
  MESSAGE
32
23
  end
33
24
  end
@@ -13,6 +13,15 @@ module CopHelper
13
13
  let(:parser_engine) { ENV.fetch('PARSER_ENGINE', :parser_whitequark).to_sym }
14
14
  let(:rails_version) { false }
15
15
 
16
+ before(:all) do
17
+ next if ENV['RUBOCOP_CORE_DEVELOPMENT']
18
+
19
+ plugins = Gem.loaded_specs.filter_map do |feature_name, feature_specification|
20
+ feature_name if feature_specification.metadata['default_lint_roller_plugin']
21
+ end
22
+ RuboCop::Plugin.integrate_plugins(RuboCop::Config.new, plugins)
23
+ end
24
+
16
25
  def inspect_source(source, file = nil)
17
26
  RuboCop::Formatter::DisabledConfigFormatter.config_to_allow_offenses = {}
18
27
  RuboCop::Formatter::DisabledConfigFormatter.detected_styles = {}
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.72.0'
6
+ STRING = '1.72.2'
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.72.0
4
+ version: 1.72.2
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-02-14 00:00:00.000000000 Z
12
+ date: 2025-02-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -1075,7 +1075,7 @@ licenses:
1075
1075
  - MIT
1076
1076
  metadata:
1077
1077
  homepage_uri: https://rubocop.org/
1078
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.72.0
1078
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.72.2
1079
1079
  source_code_uri: https://github.com/rubocop/rubocop/
1080
1080
  documentation_uri: https://docs.rubocop.org/rubocop/1.72/
1081
1081
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues