rubocop 1.76.1 → 1.76.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 +4 -4
- data/README.md +1 -1
- data/config/default.yml +3 -0
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_range.rb +5 -0
- data/lib/rubocop/cop/lint/empty_interpolation.rb +1 -1
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +4 -4
- data/lib/rubocop/cop/lint/useless_access_modifier.rb +21 -4
- data/lib/rubocop/cop/lint/useless_default_value_argument.rb +4 -1
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -1
- data/lib/rubocop/cop/naming/predicate_method.rb +31 -2
- data/lib/rubocop/cop/style/conditional_assignment.rb +3 -1
- data/lib/rubocop/cop/style/it_block_parameter.rb +2 -2
- data/lib/rubocop/cop/style/min_max_comparison.rb +13 -5
- data/lib/rubocop/cop/style/redundant_parentheses.rb +7 -1
- data/lib/rubocop/cop/style/redundant_self.rb +5 -5
- data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c98c6b67493a9eeb135c1e86846e068746676cd7caba305df7343f6da5a9307
|
4
|
+
data.tar.gz: a5e75c620016505e918bc98e273a729f14388b6c3cf95358c4975d785ca7fa57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08701aa9d2fa3f7a1cf2b950b8bdf8640c47965345c3572645dd04f73507142ebf08aa16d5e7ab829a9e74330d45b4280ef700a7974eb02d7cf29e5890f67bb8'
|
7
|
+
data.tar.gz: 8d0f787edacfee68d6e6bc13db5c9f2247f137c3074fec0af47dae1b6b0b51403e9d071d1a40a81529271d35d1954a5848e16c489ebb175c9b2a24a4c1192a48
|
data/README.md
CHANGED
@@ -112,7 +112,7 @@ Here's a list of RuboCop's core developers:
|
|
112
112
|
* [Yuji Nakayama](https://github.com/yujinakayama) (retired)
|
113
113
|
* [Evgeni Dzhelyov](https://github.com/edzhelyov) (retired)
|
114
114
|
* [Ted Johansson](https://github.com/drenmi)
|
115
|
-
* [Masataka Kuwabara](https://github.com/pocke)
|
115
|
+
* [Masataka Kuwabara](https://github.com/pocke) (retired)
|
116
116
|
* [Koichi Ito](https://github.com/koic)
|
117
117
|
* [Maxim Krizhanovski](https://github.com/darhazer)
|
118
118
|
* [Benjamin Quorning](https://github.com/bquorning)
|
data/config/default.yml
CHANGED
@@ -3063,6 +3063,7 @@ Naming/PredicateMethod:
|
|
3063
3063
|
Description: 'Checks that predicate methods end with `?` and non-predicate methods do not.'
|
3064
3064
|
Enabled: pending
|
3065
3065
|
VersionAdded: '1.76'
|
3066
|
+
VersionChanged: '1.76'
|
3066
3067
|
# In `aggressive` mode, the cop will register an offense for predicate methods that
|
3067
3068
|
# may return a non-boolean value.
|
3068
3069
|
# In `conservative` mode, the cop will *not* register an offense for predicate methods
|
@@ -3070,6 +3071,8 @@ Naming/PredicateMethod:
|
|
3070
3071
|
Mode: conservative
|
3071
3072
|
AllowedMethods:
|
3072
3073
|
- call
|
3074
|
+
AllowedPatterns: []
|
3075
|
+
AllowBangMethods: false
|
3073
3076
|
|
3074
3077
|
Naming/PredicatePrefix:
|
3075
3078
|
Description: 'Predicate method names should not be prefixed and end with a `?`.'
|
@@ -138,7 +138,7 @@ module RuboCop
|
|
138
138
|
end
|
139
139
|
|
140
140
|
def previous_line_ignoring_comments(processed_source, send_line)
|
141
|
-
processed_source[0..send_line - 2].reverse.find { |line| !comment_line?(line) }
|
141
|
+
processed_source[0..(send_line - 2)].reverse.find { |line| !comment_line?(line) }
|
142
142
|
end
|
143
143
|
|
144
144
|
def previous_line_empty?(send_line)
|
@@ -27,7 +27,9 @@ module RuboCop
|
|
27
27
|
# @example
|
28
28
|
# # bad
|
29
29
|
# x || 1..2
|
30
|
+
# x - 1..2
|
30
31
|
# (x || 1..2)
|
32
|
+
# x || 1..y || 2
|
31
33
|
# 1..2.to_a
|
32
34
|
#
|
33
35
|
# # good, unambiguous
|
@@ -41,6 +43,7 @@ module RuboCop
|
|
41
43
|
#
|
42
44
|
# # good, ambiguity removed
|
43
45
|
# x || (1..2)
|
46
|
+
# (x - 1)..2
|
44
47
|
# (x || 1)..2
|
45
48
|
# (x || 1)..(y || 2)
|
46
49
|
# (1..2).to_a
|
@@ -96,6 +99,8 @@ module RuboCop
|
|
96
99
|
# to avoid the ambiguity of `1..2.to_a`.
|
97
100
|
return false if node.receiver&.basic_literal?
|
98
101
|
|
102
|
+
return false if node.operator_method? && !node.method?(:[])
|
103
|
+
|
99
104
|
require_parentheses_for_method_chain? || node.receiver.nil?
|
100
105
|
end
|
101
106
|
|
@@ -20,7 +20,7 @@ module RuboCop
|
|
20
20
|
|
21
21
|
def on_interpolation(begin_node)
|
22
22
|
node_children = begin_node.children.dup
|
23
|
-
node_children.delete_if { |e| e.nil_type? || (e.basic_literal? && e.
|
23
|
+
node_children.delete_if { |e| e.nil_type? || (e.basic_literal? && e.str_content&.empty?) }
|
24
24
|
return unless node_children.empty?
|
25
25
|
|
26
26
|
add_offense(begin_node) { |corrector| corrector.remove(begin_node) }
|
@@ -97,7 +97,7 @@ module RuboCop
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def require_parentheses?(send_node)
|
100
|
-
return true if
|
100
|
+
return true if operator_inside_collection_literal?(send_node)
|
101
101
|
return false unless send_node.comparison_method?
|
102
102
|
return false unless (node = send_node.parent)
|
103
103
|
|
@@ -105,10 +105,10 @@ module RuboCop
|
|
105
105
|
(node.respond_to?(:comparison_method?) && node.comparison_method?)
|
106
106
|
end
|
107
107
|
|
108
|
-
def
|
109
|
-
# If an operator call (without a dot) is inside a hash, it needs
|
108
|
+
def operator_inside_collection_literal?(send_node)
|
109
|
+
# If an operator call (without a dot) is inside an array or a hash, it needs
|
110
110
|
# to be parenthesized when converted to safe navigation.
|
111
|
-
send_node.parent&.
|
111
|
+
send_node.parent&.type?(:array, :pair) && !send_node.loc.dot
|
112
112
|
end
|
113
113
|
end
|
114
114
|
end
|
@@ -4,10 +4,10 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Lint
|
6
6
|
# Checks for redundant access modifiers, including those with no
|
7
|
-
# code, those which are repeated,
|
8
|
-
# class or module body.
|
9
|
-
#
|
10
|
-
# are not redundant.
|
7
|
+
# code, those which are repeated, those which are on top-level, and
|
8
|
+
# leading `public` modifiers in a class or module body.
|
9
|
+
# Conditionally-defined methods are considered as always being defined,
|
10
|
+
# and thus access modifiers guarding such methods are not redundant.
|
11
11
|
#
|
12
12
|
# This cop has `ContextCreatingMethods` option. The default setting value
|
13
13
|
# is an empty array that means no method is specified.
|
@@ -58,6 +58,12 @@ module RuboCop
|
|
58
58
|
# private # this is redundant (no following methods are defined)
|
59
59
|
# end
|
60
60
|
#
|
61
|
+
# # bad
|
62
|
+
# private # this is useless (access modifiers have no effect on top-level)
|
63
|
+
#
|
64
|
+
# def method
|
65
|
+
# end
|
66
|
+
#
|
61
67
|
# # good
|
62
68
|
# class Foo
|
63
69
|
# private # this is not redundant (a method is defined)
|
@@ -145,6 +151,17 @@ module RuboCop
|
|
145
151
|
alias on_numblock on_block
|
146
152
|
alias on_itblock on_block
|
147
153
|
|
154
|
+
def on_begin(node)
|
155
|
+
return if node.parent
|
156
|
+
|
157
|
+
node.child_nodes.each do |child|
|
158
|
+
next unless child.send_type? && access_modifier?(child)
|
159
|
+
|
160
|
+
# This call always registers an offense for access modifier `child.method_name`
|
161
|
+
check_send_node(child, child.method_name, true)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
148
165
|
private
|
149
166
|
|
150
167
|
def autocorrect(corrector, node)
|
@@ -10,6 +10,9 @@ module RuboCop
|
|
10
10
|
# applies to `Array.new`, `Array#fetch`, `Hash#fetch`, `ENV.fetch` and
|
11
11
|
# `Thread#fetch`.
|
12
12
|
#
|
13
|
+
# A `fetch` call without a receiver is considered a custom method and does not register
|
14
|
+
# an offense.
|
15
|
+
#
|
13
16
|
# @safety
|
14
17
|
# This cop is unsafe because the receiver could have nonstandard implementation
|
15
18
|
# of `fetch`, or be a class other than the one listed above.
|
@@ -56,7 +59,7 @@ module RuboCop
|
|
56
59
|
def_node_matcher :default_value_argument_and_block, <<~PATTERN
|
57
60
|
(any_block
|
58
61
|
{
|
59
|
-
(call
|
62
|
+
(call !nil? :fetch $_key $_default_value)
|
60
63
|
(send (const _ :Array) :new $_size $_default_value)
|
61
64
|
}
|
62
65
|
_args
|
@@ -89,7 +89,7 @@ module RuboCop
|
|
89
89
|
|
90
90
|
if first_non_comment_token
|
91
91
|
# `line` is 1-indexed so we need to subtract 1 to get the array index
|
92
|
-
processed_source.lines[0...first_non_comment_token.line - 1]
|
92
|
+
processed_source.lines[0...(first_non_comment_token.line - 1)]
|
93
93
|
else
|
94
94
|
processed_source.lines
|
95
95
|
end
|
@@ -6,7 +6,7 @@ module RuboCop
|
|
6
6
|
# Checks that predicate methods end with `?` and non-predicate methods do not.
|
7
7
|
#
|
8
8
|
# The names of predicate methods (methods that return a boolean value) should end
|
9
|
-
# in a question mark. Methods that don
|
9
|
+
# in a question mark. Methods that don't return a boolean, shouldn't
|
10
10
|
# end in a question mark.
|
11
11
|
#
|
12
12
|
# The cop assesses a predicate method as one that returns boolean values. Likewise,
|
@@ -22,7 +22,11 @@ module RuboCop
|
|
22
22
|
#
|
23
23
|
# The cop also has `AllowedMethods` configuration in order to prevent the cop from
|
24
24
|
# registering an offense from a method name that does not confirm to the naming
|
25
|
-
# guidelines. By default, `call` is allowed.
|
25
|
+
# guidelines. By default, `call` is allowed. The cop also has `AllowedPatterns`
|
26
|
+
# configuration to allow method names by regular expression.
|
27
|
+
#
|
28
|
+
# The cop can furthermore be configured to allow all bang methods (method names
|
29
|
+
# ending with `!`), with `AllowBangMethods: true` (default false).
|
26
30
|
#
|
27
31
|
# @example Mode: conservative (default)
|
28
32
|
# # bad
|
@@ -73,8 +77,21 @@ module RuboCop
|
|
73
77
|
# true
|
74
78
|
# end
|
75
79
|
#
|
80
|
+
# @example AllowBangMethods: false (default)
|
81
|
+
# # bad
|
82
|
+
# def save!
|
83
|
+
# true
|
84
|
+
# end
|
85
|
+
#
|
86
|
+
# @example AllowBangMethods: true
|
87
|
+
# # good
|
88
|
+
# def save!
|
89
|
+
# true
|
90
|
+
# end
|
91
|
+
#
|
76
92
|
class PredicateMethod < Base
|
77
93
|
include AllowedMethods
|
94
|
+
include AllowedPattern
|
78
95
|
|
79
96
|
MSG_PREDICATE = 'Predicate method names should end with `?`.'
|
80
97
|
MSG_NON_PREDICATE = 'Non-predicate method names should not end with `?`.'
|
@@ -97,6 +114,8 @@ module RuboCop
|
|
97
114
|
|
98
115
|
def allowed?(node)
|
99
116
|
allowed_method?(node.method_name) ||
|
117
|
+
matches_allowed_pattern?(node.method_name) ||
|
118
|
+
allowed_bang_method?(node) ||
|
100
119
|
node.operator_method? ||
|
101
120
|
node.body.nil?
|
102
121
|
end
|
@@ -210,6 +229,16 @@ module RuboCop
|
|
210
229
|
def conservative?
|
211
230
|
cop_config.fetch('Mode', :conservative).to_sym == :conservative
|
212
231
|
end
|
232
|
+
|
233
|
+
def allowed_bang_method?(node)
|
234
|
+
return false unless allow_bang_methods?
|
235
|
+
|
236
|
+
node.bang_method?
|
237
|
+
end
|
238
|
+
|
239
|
+
def allow_bang_methods?
|
240
|
+
cop_config.fetch('AllowBangMethods', false)
|
241
|
+
end
|
213
242
|
end
|
214
243
|
end
|
215
244
|
end
|
@@ -451,7 +451,9 @@ module RuboCop
|
|
451
451
|
corrector.remove_preceding(condition.loc.else, condition.loc.else.column - column)
|
452
452
|
end
|
453
453
|
|
454
|
-
return unless condition.loc.end && !same_line?(
|
454
|
+
return unless condition.loc.end && !same_line?(
|
455
|
+
condition.branches.last.parent.else_branch, condition.loc.end
|
456
|
+
)
|
455
457
|
|
456
458
|
corrector.remove_preceding(condition.loc.end, condition.loc.end.column - column)
|
457
459
|
end
|
@@ -57,7 +57,7 @@ module RuboCop
|
|
57
57
|
|
58
58
|
MSG_USE_IT_PARAMETER = 'Use `it` block parameter.'
|
59
59
|
MSG_AVOID_IT_PARAMETER = 'Avoid using `it` block parameter.'
|
60
|
-
|
60
|
+
MSG_AVOID_IT_PARAMETER_MULTILINE = 'Avoid using `it` block parameter for multi-line blocks.'
|
61
61
|
|
62
62
|
minimum_target_ruby_version 3.4
|
63
63
|
|
@@ -96,7 +96,7 @@ module RuboCop
|
|
96
96
|
when :allow_single_line
|
97
97
|
return if node.single_line?
|
98
98
|
|
99
|
-
add_offense(node, message:
|
99
|
+
add_offense(node, message: MSG_AVOID_IT_PARAMETER_MULTILINE)
|
100
100
|
when :disallow
|
101
101
|
variables = find_block_variables(node, 'it')
|
102
102
|
|
@@ -39,13 +39,21 @@ module RuboCop
|
|
39
39
|
include RangeHelp
|
40
40
|
|
41
41
|
MSG = 'Use `%<prefer>s` instead.'
|
42
|
-
|
42
|
+
GREATER_OPERATORS = %i[> >=].freeze
|
43
43
|
LESS_OPERATORS = %i[< <=].freeze
|
44
|
-
COMPARISON_OPERATORS =
|
44
|
+
COMPARISON_OPERATORS = (GREATER_OPERATORS + LESS_OPERATORS).to_set.freeze
|
45
|
+
|
46
|
+
# @!method comparison_condition(node, name)
|
47
|
+
def_node_matcher :comparison_condition, <<~PATTERN
|
48
|
+
{
|
49
|
+
(send $_lhs $COMPARISON_OPERATORS $_rhs)
|
50
|
+
(begin (send $_lhs $COMPARISON_OPERATORS $_rhs))
|
51
|
+
}
|
52
|
+
PATTERN
|
45
53
|
|
46
54
|
def on_if(node)
|
47
|
-
lhs, operator, rhs =
|
48
|
-
return unless
|
55
|
+
lhs, operator, rhs = comparison_condition(node.condition)
|
56
|
+
return unless operator
|
49
57
|
|
50
58
|
if_branch = node.if_branch
|
51
59
|
else_branch = node.else_branch
|
@@ -63,7 +71,7 @@ module RuboCop
|
|
63
71
|
|
64
72
|
def preferred_method(operator, lhs, rhs, if_branch, else_branch)
|
65
73
|
if lhs == if_branch && rhs == else_branch
|
66
|
-
|
74
|
+
GREATER_OPERATORS.include?(operator) ? 'max' : 'min'
|
67
75
|
elsif lhs == else_branch && rhs == if_branch
|
68
76
|
LESS_OPERATORS.include?(operator) ? 'max' : 'min'
|
69
77
|
end
|
@@ -164,7 +164,7 @@ module RuboCop
|
|
164
164
|
if node.lambda_or_proc? && (node.braces? || node.send_node.lambda_literal?)
|
165
165
|
return 'an expression'
|
166
166
|
end
|
167
|
-
if
|
167
|
+
if disallowed_one_line_pattern_matching?(begin_node, node)
|
168
168
|
return 'a one-line pattern matching'
|
169
169
|
end
|
170
170
|
return 'an interpolated expression' if interpolation?(begin_node)
|
@@ -254,6 +254,12 @@ module RuboCop
|
|
254
254
|
end
|
255
255
|
end
|
256
256
|
|
257
|
+
def disallowed_one_line_pattern_matching?(begin_node, node)
|
258
|
+
return false if begin_node.parent&.any_def_type? && begin_node.parent.endless?
|
259
|
+
|
260
|
+
node.any_match_pattern_type? && node.each_ancestor.none?(&:operator_keyword?)
|
261
|
+
end
|
262
|
+
|
257
263
|
def raised_to_power_negative_numeric?(begin_node, node)
|
258
264
|
return false unless node.numeric_type?
|
259
265
|
|
@@ -123,11 +123,11 @@ module RuboCop
|
|
123
123
|
def on_if(node)
|
124
124
|
# Allow conditional nodes to use `self` in the condition if that variable
|
125
125
|
# name is used in an `lvasgn` or `masgn` within the `if`.
|
126
|
-
node.
|
127
|
-
if
|
128
|
-
add_lhs_to_local_variables_scopes(node.condition,
|
129
|
-
|
130
|
-
add_masgn_lhs_variables(node.condition,
|
126
|
+
node.each_descendant(:lvasgn, :masgn) do |descendant_node|
|
127
|
+
if descendant_node.lvasgn_type?
|
128
|
+
add_lhs_to_local_variables_scopes(node.condition, descendant_node.lhs)
|
129
|
+
else
|
130
|
+
add_masgn_lhs_variables(node.condition, descendant_node.lhs)
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
data/lib/rubocop/version.rb
CHANGED
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.76.
|
4
|
+
version: 1.76.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-06-
|
12
|
+
date: 2025-06-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -127,7 +127,7 @@ dependencies:
|
|
127
127
|
requirements:
|
128
128
|
- - ">="
|
129
129
|
- !ruby/object:Gem::Version
|
130
|
-
version: 1.45.
|
130
|
+
version: 1.45.1
|
131
131
|
- - "<"
|
132
132
|
- !ruby/object:Gem::Version
|
133
133
|
version: '2.0'
|
@@ -137,7 +137,7 @@ dependencies:
|
|
137
137
|
requirements:
|
138
138
|
- - ">="
|
139
139
|
- !ruby/object:Gem::Version
|
140
|
-
version: 1.45.
|
140
|
+
version: 1.45.1
|
141
141
|
- - "<"
|
142
142
|
- !ruby/object:Gem::Version
|
143
143
|
version: '2.0'
|
@@ -1085,7 +1085,7 @@ licenses:
|
|
1085
1085
|
- MIT
|
1086
1086
|
metadata:
|
1087
1087
|
homepage_uri: https://rubocop.org/
|
1088
|
-
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.76.
|
1088
|
+
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.76.2
|
1089
1089
|
source_code_uri: https://github.com/rubocop/rubocop/
|
1090
1090
|
documentation_uri: https://docs.rubocop.org/rubocop/1.76/
|
1091
1091
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|