rubocop 1.82.0 → 1.82.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 395ade8767ec51e33acbc9c14c0b11300df6100806f9e2c9bd23241f22f7f206
4
- data.tar.gz: ed5bf8c5e1f3f7adc724fd900ec7d8b0cda4c91892276349177e7eb7c06d87a7
3
+ metadata.gz: 9dfdd0a2943006435a98725498ab85032b82d1cff547cd0bed007a250e56aca4
4
+ data.tar.gz: c6a9e601a1e7858282d835dc00cd0f065ab3bc43de633988877dae6422f85f71
5
5
  SHA512:
6
- metadata.gz: 53fd7c4276518804677378c9c958c96c5512d9b3cfa89c0a5a8597a676a54efb18077a45e30d47f15c15a08448c9ad8c6b5c931cc0e244bb34abef88b5d30238
7
- data.tar.gz: e7298eed68c7cb9d9d7c294bc7ca031b538ea1a3205bb34ab854ef76bf1230a4e664c178088f1489030f51dd1ad4f9e1bfd1dc4397a5a240904b27bc55965428
6
+ metadata.gz: e19cc58194cf953813d3e3bf0d3bfa7d976f30127008ba84473b08cdcba188a4f73ac102baea188dfa463723b15fc768a3b7152306d5fcb5a5b7b7265e031ad2
7
+ data.tar.gz: 26ed5927b0b375947c553a46434c6a58a63022c928b84b03ff1b44a8a74eee6c8cb29342262df28fcca223e194257d7e9fe7a06fb422d42e0805287380830743
@@ -90,6 +90,8 @@ module RuboCop
90
90
  end
91
91
 
92
92
  def line_with_eol_comment_too_long?(range)
93
+ return false unless max_line_length
94
+
93
95
  (range.source_line + eol_comment).length > max_line_length
94
96
  end
95
97
 
@@ -43,8 +43,7 @@ module RuboCop
43
43
  def on_new_investigation
44
44
  return if processed_source.blank?
45
45
 
46
- gem_declarations(processed_source.ast)
47
- .each_cons(2) do |previous, current|
46
+ gem_declarations(processed_source.ast).each_cons(2) do |previous, current|
48
47
  next unless consecutive_lines?(previous, current)
49
48
  next unless case_insensitive_out_of_order?(gem_name(current), gem_name(previous))
50
49
 
@@ -69,8 +69,7 @@ module RuboCop
69
69
  def on_new_investigation
70
70
  return if processed_source.blank?
71
71
 
72
- dependency_declarations(processed_source.ast)
73
- .each_cons(2) do |previous, current|
72
+ dependency_declarations(processed_source.ast).each_cons(2) do |previous, current|
74
73
  next unless consecutive_lines?(previous, current)
75
74
  next unless case_insensitive_out_of_order?(gem_name(current), gem_name(previous))
76
75
  next unless get_dependency_name(previous) == get_dependency_name(current)
@@ -89,6 +89,7 @@ module RuboCop
89
89
  end
90
90
 
91
91
  def line_too_long?(node)
92
+ return false unless max_line_length
92
93
  return false if unlimited_heredoc_length?
93
94
 
94
95
  body = heredoc_body(node)
@@ -83,7 +83,10 @@ module RuboCop
83
83
 
84
84
  return unless begins_its_line?(end_loc)
85
85
 
86
- check_indentation(end_loc, node.body)
86
+ # For blocks where the dot is on a new line, use the dot position as the base.
87
+ # Otherwise, use the end keyword position as the base.
88
+ base_loc = dot_on_new_line?(node) ? node.send_node.loc.dot : end_loc
89
+ check_indentation(base_loc, node.body)
87
90
 
88
91
  return unless indented_internal_methods_style?
89
92
 
@@ -383,6 +386,14 @@ module RuboCop
383
386
 
384
387
  leftmost_modifier_of(node.parent)
385
388
  end
389
+
390
+ def dot_on_new_line?(node)
391
+ send_node = node.send_node
392
+ return false unless send_node.loc?(:dot)
393
+
394
+ receiver = send_node.receiver
395
+ receiver && receiver.last_line < send_node.loc.dot.line
396
+ end
386
397
  end
387
398
  end
388
399
  end
@@ -311,6 +311,7 @@ module RuboCop
311
311
  def max
312
312
  cop_config['Max']
313
313
  end
314
+ alias max_line_length max
314
315
 
315
316
  def allow_heredoc?
316
317
  allowed_heredoc
@@ -78,6 +78,8 @@ module RuboCop
78
78
  end
79
79
 
80
80
  def line_break_necessary_in_args?(node)
81
+ return false unless max_line_length
82
+
81
83
  needed_length_for_args(node) > max_line_length
82
84
  end
83
85
 
@@ -84,19 +84,23 @@ module RuboCop
84
84
  end
85
85
  end
86
86
 
87
+ # rubocop:disable Metrics/AbcSize
87
88
  def offending_range(node, lhs, rhs, given_style)
88
89
  return false unless begins_its_line?(rhs)
89
90
  return false if not_for_this_cop?(node)
90
91
 
91
92
  @base = alignment_base(node, rhs, given_style)
92
93
  correct_column = if @base
93
- @base.column + extra_indentation(given_style, node.parent)
94
+ parent = node.parent
95
+ parent = parent.parent if parent&.any_block_type?
96
+ @base.column + extra_indentation(given_style, parent)
94
97
  else
95
98
  indentation(lhs) + correct_indentation(node)
96
99
  end
97
100
  @column_delta = correct_column - rhs.column
98
101
  rhs if @column_delta.nonzero?
99
102
  end
103
+ # rubocop:enable Metrics/AbcSize
100
104
 
101
105
  def extra_indentation(given_style, parent)
102
106
  if given_style == :indented_relative_to_receiver
@@ -23,16 +23,8 @@ module RuboCop
23
23
  cfg['EnforcedStyle'] || 'space'
24
24
  end
25
25
 
26
- def kind(token)
27
- 'comma' if token.comma? && !before_semicolon?(token)
28
- end
29
-
30
- private
31
-
32
- def before_semicolon?(token)
33
- tokens = processed_source.tokens
34
-
35
- tokens[tokens.index(token) + 1].semicolon?
26
+ def kind(token, next_token)
27
+ 'comma' if token.comma? && !next_token.semicolon?
36
28
  end
37
29
  end
38
30
  end
@@ -20,7 +20,7 @@ module RuboCop
20
20
  cfg['EnforcedStyle'] || 'space'
21
21
  end
22
22
 
23
- def kind(token)
23
+ def kind(token, _next_token)
24
24
  'semicolon' if token.semicolon?
25
25
  end
26
26
 
@@ -25,17 +25,17 @@ module RuboCop
25
25
  #
26
26
  # # bad - repeated alternate patterns with the same conditions don't depend on the order
27
27
  # case x
28
- # in foo | bar
28
+ # in 0 | 1
29
29
  # first_method
30
- # in bar | foo
30
+ # in 1 | 0
31
31
  # second_method
32
32
  # end
33
33
  #
34
34
  # # good
35
35
  # case x
36
- # in foo | bar
36
+ # in 0 | 1
37
37
  # first_method
38
- # in bar | baz
38
+ # in 2 | 3
39
39
  # second_method
40
40
  # end
41
41
  #
@@ -52,32 +52,39 @@ module RuboCop
52
52
  scope.variables.each_value { |variable| check_for_unused_assignments(variable) }
53
53
  end
54
54
 
55
- # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
56
55
  def check_for_unused_assignments(variable)
57
56
  return if variable.should_be_unused?
58
57
 
59
58
  variable.assignments.reverse_each do |assignment|
60
- assignment_node = assignment.node
61
- next if assignment.used? || part_of_ignored_node?(assignment_node)
59
+ check_for_unused_assignment(variable, assignment)
60
+ end
61
+ end
62
62
 
63
- message = message_for_useless_assignment(assignment)
64
- range = offense_range(assignment)
63
+ def check_for_unused_assignment(variable, assignment)
64
+ assignment_node = assignment.node
65
65
 
66
- add_offense(range, message: message) do |corrector|
67
- # In cases like `x = 1, y = 2`, where removing a variable would cause a syntax error,
68
- # and where changing `x ||= 1` to `x = 1` would cause `NameError`,
69
- # the autocorrect will be skipped, even if the variable is unused.
70
- if sequential_assignment?(assignment_node) || assignment_node.parent&.or_asgn_type?
71
- next
72
- end
66
+ return if ignored_assignment?(variable, assignment_node, assignment)
73
67
 
74
- autocorrect(corrector, assignment)
75
- end
68
+ message = message_for_useless_assignment(assignment)
69
+ range = offense_range(assignment)
76
70
 
77
- ignore_node(assignment_node) if chained_assignment?(assignment_node)
71
+ add_offense(range, message: message) do |corrector|
72
+ # In cases like `x = 1, y = 2`, where removing a variable would cause a syntax error,
73
+ # and where changing `x ||= 1` to `x = 1` would cause `NameError`,
74
+ # the autocorrect will be skipped, even if the variable is unused.
75
+ next if sequential_assignment?(assignment_node) ||
76
+ assignment_node.parent&.or_asgn_type?
77
+
78
+ autocorrect(corrector, assignment)
78
79
  end
80
+
81
+ ignore_node(assignment_node) if chained_assignment?(assignment_node)
82
+ end
83
+
84
+ def ignored_assignment?(variable, assignment_node, assignment)
85
+ assignment.used? || part_of_ignored_node?(assignment_node) ||
86
+ variable_in_loop_condition?(assignment_node, variable)
79
87
  end
80
- # rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
81
88
 
82
89
  def message_for_useless_assignment(assignment)
83
90
  variable = assignment.variable
@@ -208,6 +215,27 @@ module RuboCop
208
215
  def remove_local_variable_assignment_part(corrector, node)
209
216
  corrector.replace(node, node.expression.source)
210
217
  end
218
+
219
+ def variable_in_loop_condition?(assignment_node, variable)
220
+ return false if assignment_node.each_ancestor(:any_def).any?
221
+
222
+ loop_node = assignment_node.each_ancestor.find do |ancestor|
223
+ ancestor.type?(*VariableForce::LOOP_TYPES)
224
+ end
225
+
226
+ return false unless loop_node.respond_to?(:condition)
227
+
228
+ condition_node = loop_node.condition
229
+ variable_name = variable.name
230
+
231
+ return true if condition_node.lvar_type? && condition_node.children.first == variable_name
232
+
233
+ condition_node.each_descendant(:lvar) do |lvar_node|
234
+ return true if lvar_node.children.first == variable_name
235
+ end
236
+
237
+ false
238
+ end
211
239
  end
212
240
  end
213
241
  end
@@ -14,6 +14,8 @@ module RuboCop
14
14
  private
15
15
 
16
16
  def too_long?(node)
17
+ return false unless max_line_length
18
+
17
19
  lines = processed_source.lines[(node.first_line - 1)...node.last_line]
18
20
  to_single_line(lines.join("\n")).length > max_line_length
19
21
  end
@@ -8,8 +8,8 @@ module RuboCop
8
8
  MSG = 'Space missing after %<token>s.'
9
9
 
10
10
  def on_new_investigation
11
- each_missing_space(processed_source.tokens) do |token|
12
- add_offense(token.pos, message: format(MSG, token: kind(token))) do |corrector|
11
+ each_missing_space(processed_source.tokens) do |token, kind|
12
+ add_offense(token.pos, message: format(MSG, token: kind)) do |corrector|
13
13
  PunctuationCorrector.add_space(corrector, token)
14
14
  end
15
15
  end
@@ -19,11 +19,12 @@ module RuboCop
19
19
 
20
20
  def each_missing_space(tokens)
21
21
  tokens.each_cons(2) do |token1, token2|
22
- next unless kind(token1)
22
+ kind = kind(token1, token2)
23
+ next unless kind
23
24
  next unless space_missing?(token1, token2)
24
25
  next unless space_required_before?(token2)
25
26
 
26
- yield token1
27
+ yield token1, kind
27
28
  end
28
29
  end
29
30
 
@@ -95,12 +95,16 @@ module RuboCop
95
95
  node.multiline? && !allowed_multiline_argument?(node)
96
96
  end
97
97
 
98
+ # rubocop:disable Metrics/AbcSize
98
99
  def method_name_and_arguments_on_same_line?(node)
99
100
  return false if !node.call_type? || node.last_line != node.last_argument.last_line
100
101
  return true if node.last_argument.hash_type? && node.last_argument.braces?
101
102
 
102
- node.loc.selector.line == node.last_argument.last_line
103
+ line = node.loc.selector&.line || node.loc.line
104
+
105
+ line == node.last_argument.last_line
103
106
  end
107
+ # rubocop:enable Metrics/AbcSize
104
108
 
105
109
  # A single argument with the closing bracket on the same line as the end
106
110
  # of the argument is not considered multiline, even if the argument
@@ -75,6 +75,8 @@ module RuboCop
75
75
  end
76
76
 
77
77
  def correction_exceeds_max_line_length?(node)
78
+ return false unless max_line_length
79
+
78
80
  indentation_width(node) + definition_width(node) > max_line_length
79
81
  end
80
82
 
@@ -26,9 +26,10 @@ module RuboCop
26
26
  splat kwsplat forwarded_args forwarded_restarg forwarded_kwrestarg block_pass
27
27
  ].freeze
28
28
 
29
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
29
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
30
30
  def on_send(node)
31
31
  return unless (dot = node.loc.dot)
32
+ return if unary_method_no_operator?(node)
32
33
  return if node.receiver.const_type? || !node.arguments.one?
33
34
 
34
35
  return unless (rhs = node.first_argument)
@@ -43,10 +44,18 @@ module RuboCop
43
44
  corrector.insert_after(selector, ' ') if insert_space_after?(node)
44
45
  end
45
46
  end
46
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
47
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
47
48
 
48
49
  private
49
50
 
51
+ # `foo.~@` and `foo.!@` call the method `~` and `!` respectively. While those
52
+ # are operator methods, we don't want to actually consider them as such.
53
+ def unary_method_no_operator?(node)
54
+ return false unless node.nonmutating_unary_operator_method?
55
+
56
+ node.method_name.to_s != node.selector.source
57
+ end
58
+
50
59
  # Checks for an acceptable case of `foo.+(bar).baz`.
51
60
  def method_call_with_parenthesized_arg?(argument)
52
61
  return false unless argument.parent.parent&.send_type?
@@ -22,7 +22,7 @@ module RuboCop
22
22
  # Remove old files so that the cache doesn't grow too big. When the
23
23
  # threshold MaxFilesInCache has been exceeded, the oldest 50% of all the
24
24
  # files in the cache are removed. The reason for removing so much is that
25
- # cleaning should be done relatively seldom, since there is a slight risk
25
+ # removing should be done relatively seldom, since there is a slight risk
26
26
  # that some other RuboCop process was just about to read the file, when
27
27
  # there's parallel execution and the cache is shared.
28
28
  def self.cleanup(config_store, verbose, cache_root_override = nil)
@@ -31,10 +31,12 @@ module RuboCop
31
31
  rubocop_cache_dir = cache_root(config_store, cache_root_override)
32
32
  return unless File.exist?(rubocop_cache_dir)
33
33
 
34
- files, dirs = Find.find(rubocop_cache_dir).partition { |path| File.file?(path) }
34
+ # We know the cache entries are 3 level deep, so globing
35
+ # for `*/*/*` only returns files.
36
+ files = Dir[File.join(rubocop_cache_dir, '*/*/*')]
35
37
  return unless requires_file_removal?(files.length, config_store)
36
38
 
37
- remove_oldest_files(files, dirs, rubocop_cache_dir, verbose)
39
+ remove_oldest_files(files, rubocop_cache_dir, verbose)
38
40
  end
39
41
 
40
42
  class << self
@@ -49,26 +51,36 @@ module RuboCop
49
51
  file_count > 1 && file_count > config_store.for_pwd.for_all_cops['MaxFilesInCache']
50
52
  end
51
53
 
52
- def remove_oldest_files(files, dirs, rubocop_cache_dir, verbose)
54
+ def remove_oldest_files(files, rubocop_cache_dir, verbose)
53
55
  # Add 1 to half the number of files, so that we remove the file if
54
56
  # there's only 1 left.
55
57
  remove_count = (files.length / 2) + 1
56
58
  puts "Removing the #{remove_count} oldest files from #{rubocop_cache_dir}" if verbose
57
59
  sorted = files.sort_by { |path| File.mtime(path) }
58
- remove_files(sorted, dirs, remove_count)
60
+ remove_files(sorted, remove_count)
59
61
  rescue Errno::ENOENT
60
62
  # This can happen if parallel RuboCop invocations try to remove the
61
63
  # same files. No problem.
62
64
  puts $ERROR_INFO if verbose
63
65
  end
64
66
 
65
- def remove_files(files, dirs, remove_count)
67
+ def remove_files(files, remove_count)
66
68
  # Batch file deletions, deleting over 130,000+ files will crash
67
69
  # File.delete.
68
70
  files[0, remove_count].each_slice(10_000).each do |files_slice|
69
71
  File.delete(*files_slice)
70
72
  end
71
- dirs.each { |dir| Dir.rmdir(dir) if Dir["#{dir}/*"].empty? }
73
+
74
+ dirs = files.map { |f| File.dirname(f) }.uniq
75
+ until dirs.empty?
76
+ dirs.select! do |dir|
77
+ Dir.rmdir(dir)
78
+ true
79
+ rescue SystemCallError # ENOTEMPTY etc
80
+ false
81
+ end
82
+ dirs = dirs.map { |f| File.dirname(f) }.uniq
83
+ end
72
84
  end
73
85
  end
74
86
 
@@ -90,7 +102,7 @@ module RuboCop
90
102
  @allow_symlinks_in_cache_location =
91
103
  ResultCache.allow_symlinks_in_cache_location?(config_store)
92
104
  @path = File.join(rubocop_cache_dir,
93
- rubocop_checksum,
105
+ self.class.source_checksum,
94
106
  context_checksum(team, options),
95
107
  file_checksum(file, config_store))
96
108
  @cached_data = CachedData.new(file)
@@ -167,13 +179,11 @@ module RuboCop
167
179
  end
168
180
 
169
181
  class << self
170
- attr_accessor :source_checksum, :inhibit_cleanup
171
- end
182
+ attr_accessor :inhibit_cleanup
172
183
 
173
- # The checksum of the RuboCop program running the inspection.
174
- def rubocop_checksum
175
- ResultCache.source_checksum ||=
176
- begin
184
+ # The checksum of the RuboCop program running the inspection.
185
+ def source_checksum
186
+ @source_checksum ||= begin
177
187
  digest = Digest::SHA1.new
178
188
  rubocop_extra_features
179
189
  .select { |path| File.file?(path) }
@@ -184,21 +194,22 @@ module RuboCop
184
194
  digest << RuboCop::Version::STRING << RuboCop::AST::Version::STRING
185
195
  digest.hexdigest
186
196
  end
187
- end
197
+ end
188
198
 
189
- def digest(path)
190
- content = if path.end_with?(*DL_EXTENSIONS)
191
- # Shared libraries often contain timestamps of when
192
- # they were compiled and other non-stable data.
193
- File.basename(path)
194
- else
195
- File.binread(path) # mtime not reliable
196
- end
197
- Zlib.crc32(content).to_s
198
- end
199
+ private
200
+
201
+ def digest(path)
202
+ content = if path.end_with?(*DL_EXTENSIONS)
203
+ # Shared libraries often contain timestamps of when
204
+ # they were compiled and other non-stable data.
205
+ File.basename(path)
206
+ else
207
+ File.binread(path) # mtime not reliable
208
+ end
209
+ Zlib.crc32(content).to_s
210
+ end
199
211
 
200
- def rubocop_extra_features
201
- @rubocop_extra_features ||= begin
212
+ def rubocop_extra_features
202
213
  lib_root = File.join(File.dirname(__FILE__), '..')
203
214
  exe_root = File.join(lib_root, '..', 'exe')
204
215
 
@@ -65,6 +65,10 @@ module RuboCop
65
65
  end
66
66
 
67
67
  def run(paths)
68
+ # Compute the cache source checksum once to avoid potential
69
+ # inconsistencies between workers.
70
+ ResultCache.source_checksum
71
+
68
72
  target_files = find_target_files(paths)
69
73
  if @options[:list_target_files]
70
74
  list_files(target_files)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.82.0'
6
+ STRING = '1.82.1'
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.82.0
4
+ version: 1.82.1
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-12-17 00:00:00.000000000 Z
12
+ date: 1980-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -1092,7 +1092,7 @@ licenses:
1092
1092
  - MIT
1093
1093
  metadata:
1094
1094
  homepage_uri: https://rubocop.org/
1095
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.82.0
1095
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.82.1
1096
1096
  source_code_uri: https://github.com/rubocop/rubocop/
1097
1097
  documentation_uri: https://docs.rubocop.org/rubocop/1.82/
1098
1098
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
@@ -1111,7 +1111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1111
1111
  - !ruby/object:Gem::Version
1112
1112
  version: '0'
1113
1113
  requirements: []
1114
- rubygems_version: 3.6.2
1114
+ rubygems_version: 3.6.9
1115
1115
  specification_version: 4
1116
1116
  summary: Automatic Ruby code style checking tool.
1117
1117
  test_files: []