rubocop 1.73.0 → 1.73.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 +4 -4
- data/config/default.yml +3 -0
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +4 -4
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +10 -5
- data/lib/rubocop/cop/lint/literal_as_condition.rb +9 -16
- data/lib/rubocop/cop/lint/mixed_case_range.rb +1 -1
- data/lib/rubocop/cop/style/commented_keyword.rb +1 -1
- data/lib/rubocop/cop/style/redundant_condition.rb +12 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4215b7d095dfd177a36af3bdf5d5aecd786877a6feca3480078d9cb1a5917ad
|
4
|
+
data.tar.gz: fc20be6f63f1a0e3c06cd2fc13f8619f872e9a81642dfa833f90f88f70997857
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aee7de1fa54b8b7108f5ad7f29c3fbc1818547f28507010dca91adc0f648b02ce519c96846d2ad98407d8f8847047cd8f88547e7d5c81028d0f54cfafb44500b
|
7
|
+
data.tar.gz: afc90ab7e887e183ddfac0bf49e9f644c04564e7fd605423d29f2848f6cc509f2394fd642eccd8870d105b21055a5cb4d0dea051b92ba47ef3befbf5b7d3dad5
|
data/config/default.yml
CHANGED
@@ -5108,6 +5108,9 @@ Style/RedundantCondition:
|
|
5108
5108
|
Description: 'Checks for unnecessary conditional expressions.'
|
5109
5109
|
Enabled: true
|
5110
5110
|
VersionAdded: '0.76'
|
5111
|
+
VersionChanged: '1.73'
|
5112
|
+
AllowedMethods:
|
5113
|
+
- nonzero?
|
5111
5114
|
|
5112
5115
|
Style/RedundantConditional:
|
5113
5116
|
Description: "Don't return true/false from a conditional."
|
@@ -155,10 +155,10 @@ module RuboCop
|
|
155
155
|
end
|
156
156
|
|
157
157
|
def all_elements_aligned?(elements)
|
158
|
-
elements.
|
159
|
-
|
160
|
-
|
161
|
-
|
158
|
+
if elements.first.hash_type?
|
159
|
+
elements.first.each_child_node.map { |child| child.loc.column }
|
160
|
+
else
|
161
|
+
elements.flat_map do |e|
|
162
162
|
e.loc.column
|
163
163
|
end
|
164
164
|
end.uniq.count == 1
|
@@ -67,7 +67,6 @@ module RuboCop
|
|
67
67
|
|
68
68
|
MSG = 'Avoid `%<keyword>s` branches without a body.'
|
69
69
|
|
70
|
-
# rubocop:disable Metrics/AbcSize
|
71
70
|
def on_if(node)
|
72
71
|
return if node.body || same_line?(node.loc.begin, node.loc.end)
|
73
72
|
return if cop_config['AllowComments'] && contains_comments?(node)
|
@@ -75,15 +74,21 @@ module RuboCop
|
|
75
74
|
range = offense_range(node)
|
76
75
|
|
77
76
|
add_offense(range, message: format(MSG, keyword: node.keyword)) do |corrector|
|
78
|
-
|
79
|
-
|
80
|
-
autocorrect(corrector, node)
|
77
|
+
autocorrect(corrector, node) if do_autocorrect?(node)
|
81
78
|
end
|
82
79
|
end
|
83
|
-
# rubocop:enable Metrics/AbcSize
|
84
80
|
|
85
81
|
private
|
86
82
|
|
83
|
+
def do_autocorrect?(node)
|
84
|
+
# if condition; end.do_something
|
85
|
+
return false if (parent = node.parent)&.call_type?
|
86
|
+
# x = if condition; end
|
87
|
+
return false if (parent&.assignment? || parent&.operator_keyword?) && node.children.one?
|
88
|
+
|
89
|
+
true
|
90
|
+
end
|
91
|
+
|
87
92
|
def offense_range(node)
|
88
93
|
if node.loc.else
|
89
94
|
node.source_range.begin.join(node.loc.else.begin)
|
@@ -18,12 +18,15 @@ module RuboCop
|
|
18
18
|
# end
|
19
19
|
#
|
20
20
|
# # bad
|
21
|
-
#
|
21
|
+
# # We're only interested in the left hand side being a truthy literal,
|
22
|
+
# # because it affects the evaluation of the &&, whereas the right hand
|
23
|
+
# # side will be conditionally executed/called and can be a literal.
|
24
|
+
# if true && some_var
|
22
25
|
# do_something
|
23
26
|
# end
|
24
27
|
#
|
25
28
|
# # good
|
26
|
-
# if some_var
|
29
|
+
# if some_var
|
27
30
|
# do_something
|
28
31
|
# end
|
29
32
|
#
|
@@ -39,23 +42,13 @@ module RuboCop
|
|
39
42
|
MSG = 'Literal `%<literal>s` appeared as a condition.'
|
40
43
|
RESTRICT_ON_SEND = [:!].freeze
|
41
44
|
|
42
|
-
# rubocop:disable Metrics/AbcSize
|
43
45
|
def on_and(node)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
elsif node.lhs.truthy_literal?
|
49
|
-
add_offense(node.lhs) do |corrector|
|
50
|
-
corrector.replace(node, node.rhs.source)
|
51
|
-
end
|
52
|
-
elsif node.rhs.truthy_literal?
|
53
|
-
add_offense(node.rhs) do |corrector|
|
54
|
-
corrector.replace(node, node.lhs.source)
|
55
|
-
end
|
46
|
+
return unless node.lhs.truthy_literal?
|
47
|
+
|
48
|
+
add_offense(node.lhs) do |corrector|
|
49
|
+
corrector.replace(node, node.rhs.source)
|
56
50
|
end
|
57
51
|
end
|
58
|
-
# rubocop:enable Metrics/AbcSize
|
59
52
|
|
60
53
|
def on_if(node)
|
61
54
|
cond = condition(node)
|
@@ -57,7 +57,7 @@ module RuboCop
|
|
57
57
|
|
58
58
|
REGEXP = /(?<keyword>\S+).*#/.freeze
|
59
59
|
|
60
|
-
SUBCLASS_DEFINITION = /\A\s*class\s
|
60
|
+
SUBCLASS_DEFINITION = /\A\s*class\s+(\w|::)+\s*<\s*(\w|::)+/.freeze
|
61
61
|
METHOD_DEFINITION = /\A\s*def\s/.freeze
|
62
62
|
|
63
63
|
def on_new_investigation
|
@@ -58,7 +58,12 @@ module RuboCop
|
|
58
58
|
# # good
|
59
59
|
# a.nil? || a
|
60
60
|
#
|
61
|
+
# @example AllowedMethods: ['nonzero?'] (default)
|
62
|
+
# # good
|
63
|
+
# num.nonzero? ? true : false
|
64
|
+
#
|
61
65
|
class RedundantCondition < Base
|
66
|
+
include AllowedMethods
|
62
67
|
include CommentsHelp
|
63
68
|
include RangeHelp
|
64
69
|
extend AutoCorrector
|
@@ -172,11 +177,18 @@ module RuboCop
|
|
172
177
|
!use_hash_key_access?(if_branch)
|
173
178
|
end
|
174
179
|
|
180
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
175
181
|
def if_branch_is_true_type_and_else_is_not?(node)
|
176
182
|
return false unless node.ternary? || node.if?
|
177
183
|
|
184
|
+
cond = node.condition
|
185
|
+
if cond.call_type? && (!cond.predicate_method? || allowed_method?(cond.method_name))
|
186
|
+
return false
|
187
|
+
end
|
188
|
+
|
178
189
|
node.if_branch&.true_type? && node.else_branch && !node.else_branch.true_type?
|
179
190
|
end
|
191
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
180
192
|
|
181
193
|
def branches_have_assignment?(node)
|
182
194
|
_condition, if_branch, else_branch = *node # rubocop:disable InternalAffairs/NodeDestructuring
|
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.73.
|
4
|
+
version: 1.73.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-02-
|
12
|
+
date: 2025-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -1074,7 +1074,7 @@ licenses:
|
|
1074
1074
|
- MIT
|
1075
1075
|
metadata:
|
1076
1076
|
homepage_uri: https://rubocop.org/
|
1077
|
-
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.73.
|
1077
|
+
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.73.1
|
1078
1078
|
source_code_uri: https://github.com/rubocop/rubocop/
|
1079
1079
|
documentation_uri: https://docs.rubocop.org/rubocop/1.73/
|
1080
1080
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|