rubocop 1.75.4 → 1.75.5

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: 4fc4cebf1565ee3ced4efc79eb1012c0750f797f0ba74f94620ff50ff1d7be8e
4
- data.tar.gz: b1e53688b07611ebec3ebc028022f71314960573cc421cfdd1b6c6b831008abf
3
+ metadata.gz: 9421b54201da724554271e44969dd9b78ea86635ba622fd5d3f1807d9e3e3530
4
+ data.tar.gz: 6f76b18333faee3119a32957b72a5906a9a99cde620b95dc88014b1ebdbfa4f7
5
5
  SHA512:
6
- metadata.gz: b124c47ddee3e947bbcda187086ae1a8bf45317702d6ab0bc43f7888b90c8d560c12f61ae6fc4890bf5fec29016d88678cbc08db84e9dad5ee3ec242c8e03884
7
- data.tar.gz: fcc14e85af8aac9186971fa21371743f29221c8e694c7cf17b44762d628c7246d720b3e241f006286a43f3523e6ab9e587e0c2f0aecb5d34fe849375ca7ad183
6
+ metadata.gz: bfbad1a5c263aa4de3704954e0835a71d4d6b56bbf564dfec23dc1cc7b75913ae064ddf70a01c942a1ebfb3502fe881d840826a306ce24ed450747058f59541e
7
+ data.tar.gz: 88be3812e81036e0e8dde18c38548052f447ae76cf3195fc1b16189eb4c5d7e5b460f8425ecee663d96bfcb4c543f592f8471b7306906262426894fa76301da1
@@ -250,7 +250,7 @@ module RuboCop
250
250
  reset!
251
251
 
252
252
  alignment_for(first_pair).each do |alignment|
253
- delta = alignment.deltas_for_first_pair(first_pair, node)
253
+ delta = alignment.deltas_for_first_pair(first_pair)
254
254
  check_delta delta, node: first_pair, alignment: alignment
255
255
  end
256
256
 
@@ -58,6 +58,12 @@ module RuboCop
58
58
  # attr_reader :name #: String
59
59
  # attr_reader :age #: Integer?
60
60
  #
61
+ # #: (
62
+ # #| Integer,
63
+ # #| String
64
+ # #| ) -> void
65
+ # def foo; end
66
+ #
61
67
  # @example AllowRBSInlineAnnotation: true
62
68
  #
63
69
  # # good
@@ -67,6 +73,12 @@ module RuboCop
67
73
  # attr_reader :name #: String
68
74
  # attr_reader :age #: Integer?
69
75
  #
76
+ # #: (
77
+ # #| Integer,
78
+ # #| String
79
+ # #| ) -> void
80
+ # def foo; end
81
+ #
70
82
  # @example AllowSteepAnnotation: false (default)
71
83
  #
72
84
  # # bad
@@ -175,7 +187,7 @@ module RuboCop
175
187
  end
176
188
 
177
189
  def rbs_inline_annotation?(comment)
178
- allow_rbs_inline_annotation? && comment.text.start_with?(/#:|#\[.+\]/)
190
+ allow_rbs_inline_annotation? && comment.text.start_with?(/#:|#\[.+\]|#\|/)
179
191
  end
180
192
 
181
193
  def allow_steep_annotation?
@@ -23,6 +23,16 @@ module RuboCop
23
23
  def kind(token)
24
24
  'semicolon' if token.semicolon?
25
25
  end
26
+
27
+ def space_missing?(token1, token2)
28
+ super && !semicolon_sequence?(token1, token2)
29
+ end
30
+
31
+ private
32
+
33
+ def semicolon_sequence?(token, next_token)
34
+ token.semicolon? && next_token.semicolon?
35
+ end
26
36
  end
27
37
  end
28
38
  end
@@ -6,6 +6,8 @@ module RuboCop
6
6
  # Checks that brackets used for array literals have or don't have
7
7
  # surrounding space depending on configuration.
8
8
  #
9
+ # Array pattern matching is handled in the same way.
10
+ #
9
11
  # @example EnforcedStyle: no_space (default)
10
12
  # # The `no_space` style enforces that array literals have
11
13
  # # no surrounding space.
@@ -82,7 +84,7 @@ module RuboCop
82
84
  EMPTY_MSG = '%<command>s space inside empty array brackets.'
83
85
 
84
86
  def on_array(node)
85
- return unless node.square_brackets?
87
+ return if node.array_type? && !node.square_brackets?
86
88
 
87
89
  tokens, left, right = array_brackets(node)
88
90
 
@@ -95,6 +97,7 @@ module RuboCop
95
97
 
96
98
  issue_offenses(node, left, right, start_ok, end_ok)
97
99
  end
100
+ alias on_array_pattern on_array
98
101
 
99
102
  private
100
103
 
@@ -6,6 +6,8 @@ module RuboCop
6
6
  # Checks that braces used for hash literals have or don't have
7
7
  # surrounding space depending on configuration.
8
8
  #
9
+ # Hash pattern matching is handled in the same way.
10
+ #
9
11
  # @example EnforcedStyle: space (default)
10
12
  # # The `space` style enforces that hash literals have
11
13
  # # surrounding space.
@@ -87,6 +89,7 @@ module RuboCop
87
89
  check(tokens[-2], tokens[-1]) if tokens.size > 2
88
90
  check_whitespace_only_hash(node) if enforce_no_space_style_for_empty_braces?
89
91
  end
92
+ alias on_hash_pattern on_hash
90
93
 
91
94
  private
92
95
 
@@ -51,10 +51,9 @@ module RuboCop
51
51
  'in a regexp.'
52
52
 
53
53
  def on_interpolation(begin_node)
54
- final_node = begin_node.children.last
55
-
56
- return unless begin_node.parent.regexp_type?
54
+ return unless (final_node = begin_node.children.last)
57
55
  return unless final_node.array_type?
56
+ return unless begin_node.parent.regexp_type?
58
57
 
59
58
  if array_of_literal_values?(final_node)
60
59
  register_array_of_literal_values(begin_node, final_node)
@@ -248,7 +248,7 @@ module RuboCop
248
248
  add_offense(cond) do |corrector|
249
249
  corrector.replace(node, "else\n #{node.else_branch.source}")
250
250
  end
251
- elsif result
251
+ elsif node.if_branch && result
252
252
  add_offense(cond) do |corrector|
253
253
  corrector.replace(node, node.if_branch.source)
254
254
  end
@@ -128,8 +128,8 @@ module RuboCop
128
128
 
129
129
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
130
130
  def check_void_op(node, &block)
131
- node = node.children.first while node.begin_type?
132
- return unless node.call_type? && OPERATORS.include?(node.method_name)
131
+ node = node.children.first while node&.begin_type?
132
+ return unless node&.call_type? && OPERATORS.include?(node.method_name)
133
133
  if !UNARY_OPERATORS.include?(node.method_name) && node.loc.dot && node.arguments.none?
134
134
  return
135
135
  end
@@ -10,7 +10,7 @@ module RuboCop
10
10
  true
11
11
  end
12
12
 
13
- def deltas_for_first_pair(first_pair, _node)
13
+ def deltas_for_first_pair(first_pair)
14
14
  {
15
15
  separator: separator_delta(first_pair),
16
16
  value: value_delta(first_pair)
@@ -81,13 +81,7 @@ module RuboCop
81
81
  class TableAlignment
82
82
  include ValueAlignment
83
83
 
84
- def initialize
85
- self.max_key_width = 0
86
- end
87
-
88
- def deltas_for_first_pair(first_pair, node)
89
- self.max_key_width = node.keys.map { |key| key.source.length }.max
90
-
84
+ def deltas_for_first_pair(first_pair)
91
85
  separator_delta = separator_delta(first_pair, first_pair, 0)
92
86
  {
93
87
  separator: separator_delta,
@@ -97,30 +91,37 @@ module RuboCop
97
91
 
98
92
  private
99
93
 
100
- attr_accessor :max_key_width
101
-
102
94
  def key_delta(first_pair, current_pair)
103
95
  first_pair.key_delta(current_pair)
104
96
  end
105
97
 
106
98
  def hash_rocket_delta(first_pair, current_pair)
107
- first_pair.loc.column + max_key_width + 1 - current_pair.loc.operator.column
99
+ first_pair.loc.column + max_key_width(first_pair.parent) + 1 -
100
+ current_pair.loc.operator.column
108
101
  end
109
102
 
110
103
  def value_delta(first_pair, current_pair)
111
104
  correct_value_column = first_pair.key.loc.column +
112
- current_pair.delimiter(true).length +
113
- max_key_width
105
+ max_key_width(first_pair.parent) +
106
+ max_delimiter_width(first_pair.parent)
114
107
 
115
108
  current_pair.value_omission? ? 0 : correct_value_column - current_pair.value.loc.column
116
109
  end
110
+
111
+ def max_key_width(hash_node)
112
+ hash_node.keys.map { |key| key.source.length }.max
113
+ end
114
+
115
+ def max_delimiter_width(hash_node)
116
+ hash_node.pairs.map { |pair| pair.delimiter(true).length }.max
117
+ end
117
118
  end
118
119
 
119
120
  # Handles calculation of deltas when the enforced style is 'separator'.
120
121
  class SeparatorAlignment
121
122
  include ValueAlignment
122
123
 
123
- def deltas_for_first_pair(*_nodes)
124
+ def deltas_for_first_pair(_first_pair)
124
125
  {}
125
126
  end
126
127
 
@@ -107,7 +107,7 @@ module RuboCop
107
107
  # of the argument is not considered multiline, even if the argument
108
108
  # itself might span multiple lines.
109
109
  def allowed_multiline_argument?(node)
110
- elements(node).one? && (!node.loc.end || !Util.begins_its_line?(node.loc.end))
110
+ elements(node).one? && !Util.begins_its_line?(node_end_location(node))
111
111
  end
112
112
 
113
113
  def elements(node)
@@ -127,10 +127,14 @@ module RuboCop
127
127
 
128
128
  def no_elements_on_same_line?(node)
129
129
  items = elements(node).map(&:source_range)
130
- items << node.loc.end
130
+ items << node_end_location(node)
131
131
  items.each_cons(2).none? { |a, b| on_same_line?(a, b) }
132
132
  end
133
133
 
134
+ def node_end_location(node)
135
+ node.loc.end || node.source_range.end.adjust(begin_pos: -1)
136
+ end
137
+
134
138
  def on_same_line?(range1, range2)
135
139
  range1.last_line == range2.line
136
140
  end
@@ -479,6 +479,9 @@ module RuboCop
479
479
  end
480
480
 
481
481
  def ruby_32_only_anonymous_forwarding?
482
+ # A block argument and an anonymous block argument are never passed together.
483
+ return false if @send_node.each_ancestor(:any_block).any?
484
+
482
485
  def_all_anonymous_args?(@def_node) && send_all_anonymous_args?(@send_node)
483
486
  end
484
487
 
@@ -189,7 +189,7 @@ module RuboCop
189
189
  end
190
190
  end
191
191
 
192
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
192
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
193
193
  def check_expressions(node, expressions, insert_position)
194
194
  return if expressions.any?(&:nil?)
195
195
 
@@ -197,7 +197,7 @@ module RuboCop
197
197
 
198
198
  expressions.each do |expression|
199
199
  add_offense(expression) do |corrector|
200
- next if node.if_type? && node.ternary?
200
+ next if node.if_type? && (node.ternary? || node.then?)
201
201
 
202
202
  range = range_by_whole_lines(expression.source_range, include_final_newline: true)
203
203
  corrector.remove(range)
@@ -213,7 +213,7 @@ module RuboCop
213
213
  end
214
214
  end
215
215
  end
216
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
216
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
217
217
 
218
218
  def correct_assignment(corrector, node, expression, insert_position)
219
219
  if insert_position == :after_condition
@@ -222,6 +222,9 @@ module RuboCop
222
222
  end
223
223
 
224
224
  def unary_literal?(node)
225
+ # NOTE: should be removed after releasing https://github.com/rubocop/rubocop-ast/pull/379
226
+ return node.source.match?(/\A[+-]/) if node.complex_type?
227
+
225
228
  (node.numeric_type? && node.sign?) ||
226
229
  (node.parent&.send_type? && node.parent.unary_operation?)
227
230
  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.75.4'
6
+ STRING = '1.75.5'
7
7
 
8
8
  MSG = '%<version>s (using %<parser_version>s, ' \
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
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.75.4
4
+ version: 1.75.5
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-04-28 00:00:00.000000000 Z
13
+ date: 2025-05-05 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: json
@@ -1080,11 +1081,12 @@ licenses:
1080
1081
  - MIT
1081
1082
  metadata:
1082
1083
  homepage_uri: https://rubocop.org/
1083
- changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.75.4
1084
+ changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.75.5
1084
1085
  source_code_uri: https://github.com/rubocop/rubocop/
1085
1086
  documentation_uri: https://docs.rubocop.org/rubocop/1.75/
1086
1087
  bug_tracker_uri: https://github.com/rubocop/rubocop/issues
1087
1088
  rubygems_mfa_required: 'true'
1089
+ post_install_message:
1088
1090
  rdoc_options: []
1089
1091
  require_paths:
1090
1092
  - lib
@@ -1099,7 +1101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1099
1101
  - !ruby/object:Gem::Version
1100
1102
  version: '0'
1101
1103
  requirements: []
1102
- rubygems_version: 3.6.2
1104
+ rubygems_version: 3.3.7
1105
+ signing_key:
1103
1106
  specification_version: 4
1104
1107
  summary: Automatic Ruby code style checking tool.
1105
1108
  test_files: []