rubocop 1.81.6 → 1.81.7

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: d82a03998b60107aedc6589884c7edbafdab71312f8328edf17eed92ef26980b
4
- data.tar.gz: 2ac88da54e9ad3d1b1d51f72391447749b440a8c90602a48b50d35d7767727d8
3
+ metadata.gz: 8acfafa4ed4b94c367e6ef95c84d2d02f01222a1e8a813790948977476f34456
4
+ data.tar.gz: 0d2ad56c4a81da58046a098351606bfb8314f09f9e5f946ad1dd825aa70fe0f7
5
5
  SHA512:
6
- metadata.gz: cde998922977693d608c6a80a4afd9e87605e9f6b673babd8c70824b79602134116f9c090bc222e97ec6dc46254e0a85d7329ebad1aa50465ea8cc36d4636814
7
- data.tar.gz: ed82346ea82e517fb1381653cc9a2a49ca1a5235df71491996e7b68d3000d137cd1c8ba69819cbd5d40d98440702757008ff69157d1dc7c13c8c6cf9345b5ac3
6
+ metadata.gz: ae4edea22ca7511df39ec99591df3d537bfd3fa8974d5bb461d2b1c674b48f15296f22c81b1cd9329719a68b0d3f8d36442eaa5742cbf8e0974c6e3e2e56e29c
7
+ data.tar.gz: ffce467cec50d2ed0ef7b312a15dd17e9b7fd1622b70528d12f0cfe16056ae3b5111f2d360b4e855ea5811befd092a306ff56ad091b89a6050f3354f3db205a4
data/config/default.yml CHANGED
@@ -4555,7 +4555,7 @@ Style/LambdaCall:
4555
4555
  Enabled: true
4556
4556
  AutoCorrect: contextual
4557
4557
  VersionAdded: '0.13'
4558
- VersionChanged: '<<next>>'
4558
+ VersionChanged: '1.81'
4559
4559
  EnforcedStyle: call
4560
4560
  SupportedStyles:
4561
4561
  - call
@@ -295,10 +295,11 @@ module RuboCop
295
295
  begin
296
296
  gem = Bundler.load.specs[gem_name].first
297
297
  gem_path = gem.full_gem_path if gem
298
- rescue Bundler::GemfileNotFound
299
- # No Gemfile found. Bundler may be loaded manually
300
- rescue Bundler::GitError
301
- # The Gemfile exists but contains an uninstalled git source
298
+ rescue StandardError
299
+ # The Gemfile has a problem, which could be one of:
300
+ # - No Gemfile found. Bundler may be loaded manually
301
+ # - The Gemfile exists but contains an uninstalled git source
302
+ # - The Gemfile exists but cannot be loaded for some other reason
302
303
  end
303
304
  end
304
305
 
@@ -232,6 +232,8 @@ module RuboCop
232
232
  end
233
233
 
234
234
  def argument_before_hash(hash_node)
235
+ return hash_node.children.first.children.first if hash_node.children.first.kwsplat_type?
236
+
235
237
  hash_node.left_sibling.respond_to?(:loc) ? hash_node.left_sibling : nil
236
238
  end
237
239
 
@@ -102,8 +102,6 @@ module RuboCop
102
102
  end
103
103
 
104
104
  def debugger_method?(send_node)
105
- return false if send_node.parent&.send_type? && send_node.parent.receiver == send_node
106
-
107
105
  debugger_methods.include?(chained_method_name(send_node))
108
106
  end
109
107
 
@@ -9,9 +9,21 @@ module RuboCop
9
9
  # cop disables on wide ranges of code, that latter contributors to
10
10
  # a file wouldn't be aware of.
11
11
  #
12
- # @example
13
- # # Lint/MissingCopEnableDirective:
14
- # # MaximumRangeSize: .inf
12
+ # You can set `MaximumRangeSize` to define the maximum number of
13
+ # consecutive lines a cop can be disabled for.
14
+ #
15
+ # - `.inf` any size (default)
16
+ # - `0` allows only single-line disables
17
+ # - `1` means the maximum allowed is as follows:
18
+ #
19
+ # [source,ruby]
20
+ # ----
21
+ # # rubocop:disable SomeCop
22
+ # a = 1
23
+ # # rubocop:enable SomeCop
24
+ # ----
25
+ #
26
+ # @example MaximumRangeSize: .inf (default)
15
27
  #
16
28
  # # good
17
29
  # # rubocop:disable Layout/SpaceAroundOperators
@@ -25,9 +37,7 @@ module RuboCop
25
37
  # x= 0
26
38
  # # EOF
27
39
  #
28
- # @example
29
- # # Lint/MissingCopEnableDirective:
30
- # # MaximumRangeSize: 2
40
+ # @example MaximumRangeSize: 2
31
41
  #
32
42
  # # good
33
43
  # # rubocop:disable Layout/SpaceAroundOperators
@@ -147,7 +147,9 @@ module RuboCop
147
147
  alias on_defs on_def
148
148
 
149
149
  def on_alias(node)
150
- handle_method_name(node.new_identifier, node.new_identifier.value)
150
+ return unless (new_identifier = node.new_identifier).sym_type?
151
+
152
+ handle_method_name(new_identifier, new_identifier.value)
151
153
  end
152
154
 
153
155
  private
@@ -193,8 +193,7 @@ module RuboCop
193
193
  return_values << extract_return_value(return_node)
194
194
  end
195
195
 
196
- last_value = last_value(node)
197
- return_values << last_value if last_value
196
+ return_values << last_value(node)
198
197
 
199
198
  process_return_values(return_values)
200
199
  end
@@ -247,8 +246,9 @@ module RuboCop
247
246
  end
248
247
 
249
248
  def last_value(node)
250
- value = node.begin_type? ? node.children.last : node
251
- value&.return_type? ? extract_return_value(value) : value
249
+ value = node.begin_type? ? node.children.last || s(:nil) : node
250
+
251
+ value.return_type? ? extract_return_value(value) : value
252
252
  end
253
253
 
254
254
  def process_return_values(return_values)
@@ -48,6 +48,11 @@ module RuboCop
48
48
  MSG = 'Explicitly make `%<constant_name>s` public or private using ' \
49
49
  'either `#public_constant` or `#private_constant`.'
50
50
 
51
+ # @!method visibility_declaration_for(node)
52
+ def_node_matcher :visibility_declaration_for, <<~PATTERN
53
+ (send nil? {:public_constant :private_constant} $...)
54
+ PATTERN
55
+
51
56
  def on_casgn(node)
52
57
  return unless class_or_module_scope?(node)
53
58
  return if visibility_declaration?(node)
@@ -77,20 +82,20 @@ module RuboCop
77
82
  end
78
83
  end
79
84
 
85
+ # rubocop:disable Metrics/AbcSize
80
86
  def visibility_declaration?(node)
81
87
  node.parent.each_child_node(:send).any? do |child|
82
- visibility_declaration_for?(child, node.name)
83
- end
84
- end
88
+ next false unless (arguments = visibility_declaration_for(child))
85
89
 
86
- # @!method visibility_declaration_for?(node, const_name)
87
- def_node_matcher :visibility_declaration_for?, <<~PATTERN
88
- (send nil? {:public_constant :private_constant} ({sym str} #match_name?(%1)))
89
- PATTERN
90
+ arguments = arguments.first.children.first.to_a if arguments.first&.splat_type?
91
+ constant_values = arguments.map do |argument|
92
+ argument.value.to_sym if argument.respond_to?(:value)
93
+ end
90
94
 
91
- def match_name?(name, constant_name)
92
- name.to_sym == constant_name.to_sym
95
+ constant_values.include?(node.name)
96
+ end
93
97
  end
98
+ # rubocop:enable Metrics/AbcSize
94
99
  end
95
100
  end
96
101
  end
@@ -7,9 +7,12 @@ module RuboCop
7
7
  # It is recommended to either always use `fdiv` or coerce one side only.
8
8
  # This cop also provides other options for code consistency.
9
9
  #
10
+ # For `Regexp.last_match` and nth reference (e.g., `$1`), it assumes that the value
11
+ # is a string matched by a regular expression, and allows conversion with `#to_f`.
12
+ #
10
13
  # @safety
11
14
  # This cop is unsafe, because if the operand variable is a string object
12
- # then `.to_f` will be removed and an error will occur.
15
+ # then `#to_f` will be removed and an error will occur.
13
16
  #
14
17
  # [source,ruby]
15
18
  # ----
@@ -84,6 +87,14 @@ module RuboCop
84
87
  (send !nil? :to_f)
85
88
  PATTERN
86
89
 
90
+ # @!method regexp_last_match?(node)
91
+ def_node_matcher :regexp_last_match?, <<~PATTERN
92
+ {
93
+ (send (const {nil? cbase} :Regexp) :last_match int)
94
+ (:nth_ref _)
95
+ }
96
+ PATTERN
97
+
87
98
  def on_send(node)
88
99
  return unless offense_condition?(node)
89
100
 
@@ -104,6 +115,9 @@ module RuboCop
104
115
  private
105
116
 
106
117
  def offense_condition?(node)
118
+ return false if regexp_last_match?(node.receiver.receiver) ||
119
+ regexp_last_match?(node.first_argument.receiver)
120
+
107
121
  case style
108
122
  when :left_coerce
109
123
  right_coerce?(node)
@@ -69,10 +69,11 @@ module RuboCop
69
69
 
70
70
  def each_semicolon
71
71
  tokens_for_lines.each do |line, tokens|
72
- semicolon_pos = semicolon_position(tokens)
72
+ next unless (semicolon_pos = semicolon_position(tokens))
73
+
73
74
  after_expr_pos = semicolon_pos == -1 ? -2 : semicolon_pos
74
75
 
75
- yield line, tokens[semicolon_pos].column, tokens[after_expr_pos] if semicolon_pos
76
+ yield line, tokens[semicolon_pos].column, tokens[after_expr_pos]
76
77
  end
77
78
  end
78
79
 
@@ -129,6 +129,7 @@ module RuboCop
129
129
  corrector.remove(range_with_surrounding_space(range, newlines: false))
130
130
  end
131
131
 
132
+ # rubocop:disable Metrics/AbcSize
132
133
  def correct_for_basic_condition_style(corrector, node, if_branch)
133
134
  range = range_between(
134
135
  node.condition.source_range.end_pos, if_branch.condition.source_range.begin_pos
@@ -137,8 +138,14 @@ module RuboCop
137
138
 
138
139
  corrector.replace(if_branch.condition, chainable_condition(if_branch))
139
140
 
140
- corrector.remove(range_by_whole_lines(node.loc.end, include_final_newline: true))
141
+ end_range = if same_line?(node.loc.end, node.if_branch.loc.end)
142
+ node.loc.end
143
+ else
144
+ range_by_whole_lines(node.loc.end, include_final_newline: true)
145
+ end
146
+ corrector.remove(end_range)
141
147
  end
148
+ # rubocop:enable Metrics/AbcSize
142
149
 
143
150
  def autocorrect_outer_condition_modify_form(corrector, node, if_branch)
144
151
  correct_node(corrector, if_branch)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.81.6'
6
+ STRING = '1.81.7'
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.81.6
4
+ version: 1.81.7
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-10-21 00:00:00.000000000 Z
12
+ date: 2025-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -1091,7 +1091,7 @@ licenses:
1091
1091
  - MIT
1092
1092
  metadata:
1093
1093
  homepage_uri: https://rubocop.org/
1094
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.81.6
1094
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.81.7
1095
1095
  source_code_uri: https://github.com/rubocop/rubocop/
1096
1096
  documentation_uri: https://docs.rubocop.org/rubocop/1.81/
1097
1097
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues