rubocop 1.56.2 → 1.56.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/default.yml +0 -6
- data/lib/rubocop/cop/bundler/duplicated_group.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb +11 -2
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +33 -8
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +3 -0
- data/lib/rubocop/cop/layout/redundant_line_break.rb +1 -1
- data/lib/rubocop/cop/layout/space_after_not.rb +1 -1
- data/lib/rubocop/cop/lint/useless_assignment.rb +37 -10
- data/lib/rubocop/cop/metrics/method_length.rb +1 -1
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +5 -7
- data/lib/rubocop/cop/style/arguments_forwarding.rb +8 -6
- data/lib/rubocop/cop/style/array_intersect.rb +13 -5
- data/lib/rubocop/cop/style/combinable_loops.rb +3 -2
- data/lib/rubocop/cop/style/empty_case_condition.rb +6 -1
- data/lib/rubocop/cop/style/for.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +1 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +3 -1
- data/lib/rubocop/cop/style/symbol_array.rb +10 -11
- data/lib/rubocop/cop/style/yoda_expression.rb +8 -7
- data/lib/rubocop/file_finder.rb +4 -7
- data/lib/rubocop/rspec/shared_contexts.rb +2 -3
- data/lib/rubocop/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19e42173e0ae7c2aec912c3dbd560db4189c426d6ba0f051694c6c5c11a913e1
|
4
|
+
data.tar.gz: c1511a9611875e3d38869837d31840687e6c2004a6e7c27c19630a04b7f064fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97f5377116914b0f45233a7ed193ae08c2a4e12f0bdd0739f3129b4a36fd13eee1a38a6f4486e5de602b00486c37fe271db2bcfd1fbe4289430ea61644edaef6
|
7
|
+
data.tar.gz: d194d95290db68e6431b49d0dbad8559c657704fa283643057470d584f316c512f5d95681f07fda3f4f57f157b86add28fa135a60452944a0a6c6f8758659b13
|
data/config/default.yml
CHANGED
@@ -4130,12 +4130,6 @@ Style/InvertibleUnlessCondition:
|
|
4130
4130
|
:none?: :any?
|
4131
4131
|
:even?: :odd?
|
4132
4132
|
:odd?: :even?
|
4133
|
-
# `ActiveSupport` defines some common inverse methods. They are listed below,
|
4134
|
-
# and not enabled by default.
|
4135
|
-
# :present?: :blank?
|
4136
|
-
# :blank?: :present?
|
4137
|
-
# :include?: :exclude?
|
4138
|
-
# :exclude?: :include?
|
4139
4133
|
|
4140
4134
|
Style/IpAddresses:
|
4141
4135
|
Description: "Don't include literal IP addresses in code."
|
@@ -14,6 +14,12 @@ module RuboCop
|
|
14
14
|
# node.method_name
|
15
15
|
#
|
16
16
|
# # bad
|
17
|
+
# node.send_node.method?(:method_name)
|
18
|
+
#
|
19
|
+
# # good
|
20
|
+
# node.method?(:method_name)
|
21
|
+
#
|
22
|
+
# # bad
|
17
23
|
# node.send_node.receiver
|
18
24
|
#
|
19
25
|
# # good
|
@@ -24,11 +30,14 @@ module RuboCop
|
|
24
30
|
extend AutoCorrector
|
25
31
|
|
26
32
|
MSG = 'Remove the redundant `send_node`.'
|
27
|
-
RESTRICT_ON_SEND = %i[method_name receiver].freeze
|
33
|
+
RESTRICT_ON_SEND = %i[method_name method? receiver].freeze
|
28
34
|
|
29
35
|
# @!method dispatch_method(node)
|
30
36
|
def_node_matcher :dispatch_method, <<~PATTERN
|
31
|
-
|
37
|
+
{
|
38
|
+
(send $(send _ :send_node) {:method_name :receiver})
|
39
|
+
(send $(send _ :send_node) :method? _)
|
40
|
+
}
|
32
41
|
PATTERN
|
33
42
|
|
34
43
|
def on_send(node)
|
@@ -3,7 +3,23 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Layout
|
6
|
-
# Enforces empty line after guard clause
|
6
|
+
# Enforces empty line after guard clause.
|
7
|
+
#
|
8
|
+
# This cop allows `# :nocov:` directive after guard clause because
|
9
|
+
# SimpleCov excludes code from the coverage report by wrapping it in `# :nocov:`:
|
10
|
+
#
|
11
|
+
# [source,ruby]
|
12
|
+
# ----
|
13
|
+
# def foo
|
14
|
+
# # :nocov:
|
15
|
+
# return if condition
|
16
|
+
# # :nocov:
|
17
|
+
# bar
|
18
|
+
# end
|
19
|
+
# ----
|
20
|
+
#
|
21
|
+
# Refer to SimpleCov's documentation for more details:
|
22
|
+
# https://github.com/simplecov-ruby/simplecov#ignoringskipping-code
|
7
23
|
#
|
8
24
|
# @example
|
9
25
|
#
|
@@ -42,19 +58,22 @@ module RuboCop
|
|
42
58
|
|
43
59
|
MSG = 'Add empty line after guard clause.'
|
44
60
|
END_OF_HEREDOC_LINE = 1
|
61
|
+
SIMPLE_DIRECTIVE_COMMENT_PATTERN = /\A# *:nocov:\z/.freeze
|
45
62
|
|
46
63
|
def on_if(node)
|
47
64
|
return if correct_style?(node)
|
48
65
|
return if multiple_statements_on_line?(node)
|
49
66
|
|
50
67
|
if node.modifier_form? && (heredoc_node = last_heredoc_argument(node))
|
51
|
-
|
68
|
+
if next_line_empty_or_allowed_directive_comment?(heredoc_line(node, heredoc_node))
|
69
|
+
return
|
70
|
+
end
|
52
71
|
|
53
72
|
add_offense(heredoc_node.loc.heredoc_end) do |corrector|
|
54
73
|
autocorrect(corrector, heredoc_node)
|
55
74
|
end
|
56
75
|
else
|
57
|
-
return if
|
76
|
+
return if next_line_empty_or_allowed_directive_comment?(node.last_line)
|
58
77
|
|
59
78
|
add_offense(offense_location(node)) { |corrector| autocorrect(corrector, node) }
|
60
79
|
end
|
@@ -70,7 +89,7 @@ module RuboCop
|
|
70
89
|
end
|
71
90
|
|
72
91
|
next_line = node_range.last_line + 1
|
73
|
-
if
|
92
|
+
if next_line_allowed_directive_comment?(next_line)
|
74
93
|
node_range = processed_source.comment_at_line(next_line)
|
75
94
|
end
|
76
95
|
|
@@ -88,21 +107,21 @@ module RuboCop
|
|
88
107
|
node.if_branch&.guard_clause?
|
89
108
|
end
|
90
109
|
|
91
|
-
def
|
110
|
+
def next_line_empty_or_allowed_directive_comment?(line)
|
92
111
|
return true if next_line_empty?(line)
|
93
112
|
|
94
113
|
next_line = line + 1
|
95
|
-
|
114
|
+
next_line_allowed_directive_comment?(next_line) && next_line_empty?(next_line)
|
96
115
|
end
|
97
116
|
|
98
117
|
def next_line_empty?(line)
|
99
118
|
processed_source[line].blank?
|
100
119
|
end
|
101
120
|
|
102
|
-
def
|
121
|
+
def next_line_allowed_directive_comment?(line)
|
103
122
|
return false unless (comment = processed_source.comment_at_line(line))
|
104
123
|
|
105
|
-
DirectiveComment.new(comment).enabled?
|
124
|
+
DirectiveComment.new(comment).enabled? || simplecov_directive_comment?(comment)
|
106
125
|
end
|
107
126
|
|
108
127
|
def next_line_rescue_or_ensure?(node)
|
@@ -175,6 +194,12 @@ module RuboCop
|
|
175
194
|
|
176
195
|
parent.begin_type? && parent.single_line?
|
177
196
|
end
|
197
|
+
|
198
|
+
# SimpleCov excludes code from the coverage report by wrapping it in `# :nocov:`:
|
199
|
+
# https://github.com/simplecov-ruby/simplecov#ignoringskipping-code
|
200
|
+
def simplecov_directive_comment?(comment)
|
201
|
+
SIMPLE_DIRECTIVE_COMMENT_PATTERN.match?(comment.text)
|
202
|
+
end
|
178
203
|
end
|
179
204
|
end
|
180
205
|
end
|
@@ -25,6 +25,9 @@ module RuboCop
|
|
25
25
|
include Alignment
|
26
26
|
include Heredoc
|
27
27
|
extend AutoCorrector
|
28
|
+
extend TargetRubyVersion
|
29
|
+
|
30
|
+
minimum_target_ruby_version 2.3
|
28
31
|
|
29
32
|
TYPE_MSG = 'Use %<indentation_width>d spaces for indentation in a ' \
|
30
33
|
'heredoc by using `<<~` instead of `%<current_indent_type>s`.'
|
@@ -108,7 +108,7 @@ module RuboCop
|
|
108
108
|
!comment_within?(node) &&
|
109
109
|
node.each_descendant(:if, :case, :kwbegin, :def, :defs).none? &&
|
110
110
|
node.each_descendant(:dstr, :str).none? { |n| n.heredoc? || n.value.include?("\n") } &&
|
111
|
-
node.each_descendant(:begin).none? { |b| !b.single_line? }
|
111
|
+
node.each_descendant(:begin, :sym).none? { |b| !b.single_line? }
|
112
112
|
end
|
113
113
|
|
114
114
|
def convertible_block?(node)
|
@@ -7,12 +7,18 @@ module RuboCop
|
|
7
7
|
# scope.
|
8
8
|
# The basic idea for this cop was from the warning of `ruby -cw`:
|
9
9
|
#
|
10
|
-
#
|
10
|
+
# [source,console]
|
11
|
+
# ----
|
12
|
+
# assigned but unused variable - foo
|
13
|
+
# ----
|
11
14
|
#
|
12
15
|
# Currently this cop has advanced logic that detects unreferenced
|
13
16
|
# reassignments and properly handles varied cases such as branch, loop,
|
14
17
|
# rescue, ensure, etc.
|
15
18
|
#
|
19
|
+
# NOTE: Given the assignment `foo = 1, bar = 2`, removing unused variables
|
20
|
+
# can lead to a syntax error, so this case is not autocorrected.
|
21
|
+
#
|
16
22
|
# @safety
|
17
23
|
# This cop's autocorrection is unsafe because removing assignment from
|
18
24
|
# operator assignment can cause NameError if this assignment has been used to declare
|
@@ -51,25 +57,24 @@ module RuboCop
|
|
51
57
|
scope.variables.each_value { |variable| check_for_unused_assignments(variable) }
|
52
58
|
end
|
53
59
|
|
60
|
+
# rubocop:disable Metrics/AbcSize
|
54
61
|
def check_for_unused_assignments(variable)
|
55
62
|
return if variable.should_be_unused?
|
56
63
|
|
57
64
|
variable.assignments.each do |assignment|
|
58
|
-
next if assignment.used?
|
65
|
+
next if assignment.used? || part_of_ignored_node?(assignment.node)
|
59
66
|
|
60
67
|
message = message_for_useless_assignment(assignment)
|
68
|
+
range = offense_range(assignment)
|
61
69
|
|
62
|
-
|
63
|
-
|
64
|
-
else
|
65
|
-
assignment.node.loc.name
|
66
|
-
end
|
67
|
-
|
68
|
-
add_offense(location, message: message) do |corrector|
|
69
|
-
autocorrect(corrector, assignment)
|
70
|
+
add_offense(range, message: message) do |corrector|
|
71
|
+
autocorrect(corrector, assignment) unless sequential_assignment?(assignment.node)
|
70
72
|
end
|
73
|
+
|
74
|
+
ignore_node(assignment.node) if chained_assignment?(assignment.node)
|
71
75
|
end
|
72
76
|
end
|
77
|
+
# rubocop:enable Metrics/AbcSize
|
73
78
|
|
74
79
|
def message_for_useless_assignment(assignment)
|
75
80
|
variable = assignment.variable
|
@@ -77,6 +82,28 @@ module RuboCop
|
|
77
82
|
format(MSG, variable: variable.name) + message_specification(assignment, variable).to_s
|
78
83
|
end
|
79
84
|
|
85
|
+
def offense_range(assignment)
|
86
|
+
if assignment.regexp_named_capture?
|
87
|
+
assignment.node.children.first.source_range
|
88
|
+
else
|
89
|
+
assignment.node.loc.name
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def sequential_assignment?(node)
|
94
|
+
if node.lvasgn_type? && node.expression&.array_type? &&
|
95
|
+
node.each_descendant.any?(&:assignment?)
|
96
|
+
return true
|
97
|
+
end
|
98
|
+
return false unless node.parent
|
99
|
+
|
100
|
+
sequential_assignment?(node.parent)
|
101
|
+
end
|
102
|
+
|
103
|
+
def chained_assignment?(node)
|
104
|
+
node.respond_to?(:expression) && node.expression&.lvasgn_type?
|
105
|
+
end
|
106
|
+
|
80
107
|
def message_specification(assignment, variable)
|
81
108
|
if assignment.multiple_assignment?
|
82
109
|
multiple_assignment_message(variable.name)
|
@@ -75,7 +75,7 @@ module RuboCop
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def aligned_token?(range, line)
|
78
|
-
aligned_words?(range, line) ||
|
78
|
+
aligned_words?(range, line) || aligned_assignment?(range, line)
|
79
79
|
end
|
80
80
|
|
81
81
|
def aligned_operator?(range, line)
|
@@ -83,13 +83,11 @@ module RuboCop
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def aligned_words?(range, line)
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
def aligned_dot?(range, line)
|
90
|
-
char = line[range.column]
|
86
|
+
left_edge = range.column
|
87
|
+
return true if /\s\S/.match?(line[left_edge - 1, 2])
|
91
88
|
|
92
|
-
|
89
|
+
token = range.source
|
90
|
+
token == line[left_edge, token.length]
|
93
91
|
end
|
94
92
|
|
95
93
|
def aligned_assignment?(range, line)
|
@@ -116,11 +116,11 @@ module RuboCop
|
|
116
116
|
end
|
117
117
|
|
118
118
|
def only_forwards_all?(send_classifications)
|
119
|
-
send_classifications.
|
119
|
+
send_classifications.all? { |_, c, _, _| c == :all }
|
120
120
|
end
|
121
121
|
|
122
122
|
def add_forward_all_offenses(node, send_classifications, forwardable_args)
|
123
|
-
send_classifications.each do |send_node,
|
123
|
+
send_classifications.each do |send_node, _c, forward_rest, _forward_kwrest|
|
124
124
|
register_forward_all_offense(send_node, send_node, forward_rest)
|
125
125
|
end
|
126
126
|
|
@@ -133,7 +133,7 @@ module RuboCop
|
|
133
133
|
|
134
134
|
rest_arg, kwrest_arg, _block_arg = *forwardable_args
|
135
135
|
|
136
|
-
send_classifications.each do |send_node,
|
136
|
+
send_classifications.each do |send_node, _c, forward_rest, forward_kwrest|
|
137
137
|
if forward_rest
|
138
138
|
register_forward_args_offense(def_node.arguments, rest_arg)
|
139
139
|
register_forward_args_offense(send_node, forward_rest)
|
@@ -157,7 +157,7 @@ module RuboCop
|
|
157
157
|
end
|
158
158
|
|
159
159
|
def classify_send_nodes(def_node, send_nodes, referenced_lvars, forwardable_args)
|
160
|
-
send_nodes.
|
160
|
+
send_nodes.filter_map do |send_node|
|
161
161
|
classification_and_forwards = classification_and_forwards(
|
162
162
|
def_node,
|
163
163
|
send_node,
|
@@ -165,8 +165,10 @@ module RuboCop
|
|
165
165
|
forwardable_args
|
166
166
|
)
|
167
167
|
|
168
|
-
|
169
|
-
|
168
|
+
next unless classification_and_forwards
|
169
|
+
|
170
|
+
[send_node, *classification_and_forwards]
|
171
|
+
end
|
170
172
|
end
|
171
173
|
|
172
174
|
def classification_and_forwards(def_node, send_node, referenced_lvars, forwardable_args)
|
@@ -11,6 +11,15 @@ module RuboCop
|
|
11
11
|
# The `array1.intersect?(array2)` method is faster than
|
12
12
|
# `(array1 & array2).any?` and is more readable.
|
13
13
|
#
|
14
|
+
# In cases like the following, compatibility is not ensured,
|
15
|
+
# so it will not be detected when using block argument.
|
16
|
+
#
|
17
|
+
# [source,ruby]
|
18
|
+
# ----
|
19
|
+
# ([1] & [1,2]).any? { |x| false } # => false
|
20
|
+
# [1].intersect?([1,2]) { |x| false } # => true
|
21
|
+
# ----
|
22
|
+
#
|
14
23
|
# @safety
|
15
24
|
# This cop cannot guarantee that `array1` and `array2` are
|
16
25
|
# actually arrays while method `intersect?` is for arrays only.
|
@@ -68,16 +77,15 @@ module RuboCop
|
|
68
77
|
RESTRICT_ON_SEND = (STRAIGHT_METHODS + NEGATED_METHODS).freeze
|
69
78
|
|
70
79
|
def on_send(node)
|
80
|
+
return if (parent = node.parent) && (parent.block_type? || parent.numblock_type?)
|
71
81
|
return unless (receiver, argument, method_name = bad_intersection_check?(node))
|
72
82
|
|
73
83
|
message = message(receiver.source, argument.source, method_name)
|
74
84
|
|
75
85
|
add_offense(node, message: message) do |corrector|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
corrector.replace(node, "!#{receiver.source}.intersect?(#{argument.source})")
|
80
|
-
end
|
86
|
+
bang = straight?(method_name) ? '' : '!'
|
87
|
+
|
88
|
+
corrector.replace(node, "#{bang}#{receiver.source}.intersect?(#{argument.source})")
|
81
89
|
end
|
82
90
|
end
|
83
91
|
|
@@ -93,8 +93,9 @@ module RuboCop
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def same_collection_looping_block?(node, sibling)
|
96
|
-
(sibling
|
97
|
-
|
96
|
+
return false if sibling.nil? || (!sibling.block_type? && !sibling.numblock_type?)
|
97
|
+
|
98
|
+
sibling.method?(node.method_name) &&
|
98
99
|
sibling.receiver == node.receiver &&
|
99
100
|
sibling.send_node.arguments == node.send_node.arguments
|
100
101
|
end
|
@@ -40,9 +40,13 @@ module RuboCop
|
|
40
40
|
extend AutoCorrector
|
41
41
|
|
42
42
|
MSG = 'Do not use empty `case` condition, instead use an `if` expression.'
|
43
|
+
NOT_SUPPORTED_PARENT_TYPES = %i[return break next send csend].freeze
|
43
44
|
|
45
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
44
46
|
def on_case(case_node)
|
45
|
-
|
47
|
+
if case_node.condition || NOT_SUPPORTED_PARENT_TYPES.include?(case_node.parent&.type)
|
48
|
+
return
|
49
|
+
end
|
46
50
|
|
47
51
|
branch_bodies = [*case_node.when_branches.map(&:body), case_node.else_branch].compact
|
48
52
|
|
@@ -52,6 +56,7 @@ module RuboCop
|
|
52
56
|
|
53
57
|
add_offense(case_node.loc.keyword) { |corrector| autocorrect(corrector, case_node) }
|
54
58
|
end
|
59
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
55
60
|
|
56
61
|
private
|
57
62
|
|
@@ -39,7 +39,7 @@ module RuboCop
|
|
39
39
|
|
40
40
|
MSG_IF = 'Avoid multi-line ternary operators, use `if` or `unless` instead.'
|
41
41
|
MSG_SINGLE_LINE = 'Avoid multi-line ternary operators, use single-line instead.'
|
42
|
-
SINGLE_LINE_TYPES = %i[return break next send].freeze
|
42
|
+
SINGLE_LINE_TYPES = %i[return break next send csend].freeze
|
43
43
|
|
44
44
|
def on_if(node)
|
45
45
|
return unless offense?(node)
|
@@ -173,7 +173,9 @@ module RuboCop
|
|
173
173
|
end
|
174
174
|
|
175
175
|
def correct_for_comment(corrector, node, if_branch)
|
176
|
-
comments = processed_source.ast_with_comments[if_branch]
|
176
|
+
comments = processed_source.ast_with_comments[if_branch].select do |comment|
|
177
|
+
comment.loc.line < if_branch.condition.first_line
|
178
|
+
end
|
177
179
|
comment_text = comments.map(&:text).join("\n") << "\n"
|
178
180
|
|
179
181
|
corrector.insert_before(node.loc.keyword, comment_text) unless comments.empty?
|
@@ -50,6 +50,14 @@ module RuboCop
|
|
50
50
|
PERCENT_MSG = 'Use `%i` or `%I` for an array of symbols.'
|
51
51
|
ARRAY_MSG = 'Use %<prefer>s for an array of symbols.'
|
52
52
|
DELIMITERS = ['[', ']', '(', ')'].freeze
|
53
|
+
SPECIAL_GVARS = %w[
|
54
|
+
$! $" $$ $& $' $* $+ $, $/ $; $: $. $< $= $> $? $@ $\\ $_ $` $~ $0
|
55
|
+
$-0 $-F $-I $-K $-W $-a $-d $-i $-l $-p $-v $-w
|
56
|
+
].freeze
|
57
|
+
REDEFINABLE_OPERATORS = %w(
|
58
|
+
| ^ & <=> == === =~ > >= < <= << >>
|
59
|
+
+ - * / % ** ~ +@ -@ [] []= ` ! != !~
|
60
|
+
).freeze
|
53
61
|
|
54
62
|
class << self
|
55
63
|
attr_accessor :largest_brackets
|
@@ -109,15 +117,6 @@ module RuboCop
|
|
109
117
|
end
|
110
118
|
|
111
119
|
def symbol_without_quote?(string)
|
112
|
-
special_gvars = %w[
|
113
|
-
$! $" $$ $& $' $* $+ $, $/ $; $: $. $< $= $> $? $@ $\\ $_ $` $~ $0
|
114
|
-
$-0 $-F $-I $-K $-W $-a $-d $-i $-l $-p $-v $-w
|
115
|
-
]
|
116
|
-
redefinable_operators = %w(
|
117
|
-
| ^ & <=> == === =~ > >= < <= << >>
|
118
|
-
+ - * / % ** ~ +@ -@ [] []= ` ! != !~
|
119
|
-
)
|
120
|
-
|
121
120
|
# method name
|
122
121
|
/\A[a-zA-Z_]\w*[!?]?\z/.match?(string) ||
|
123
122
|
# instance / class variable
|
@@ -125,8 +124,8 @@ module RuboCop
|
|
125
124
|
# global variable
|
126
125
|
/\A\$[1-9]\d*\z/.match?(string) ||
|
127
126
|
/\A\$[a-zA-Z_]\w*\z/.match?(string) ||
|
128
|
-
|
129
|
-
|
127
|
+
SPECIAL_GVARS.include?(string) ||
|
128
|
+
REDEFINABLE_OPERATORS.include?(string)
|
130
129
|
end
|
131
130
|
end
|
132
131
|
end
|
@@ -19,22 +19,23 @@ module RuboCop
|
|
19
19
|
# differently on different classes, and are not guaranteed to
|
20
20
|
# have the same result if reversed.
|
21
21
|
#
|
22
|
-
# @example SupportedOperators: ['*', '+', '&'']
|
22
|
+
# @example SupportedOperators: ['*', '+', '&', '|', '^'] (default)
|
23
23
|
# # bad
|
24
|
-
# 1 + x
|
25
24
|
# 10 * y
|
25
|
+
# 1 + x
|
26
26
|
# 1 & z
|
27
|
+
# 1 | x
|
28
|
+
# 1 ^ x
|
27
29
|
# 1 + CONST
|
28
30
|
#
|
29
31
|
# # good
|
30
|
-
# 60 * 24
|
31
|
-
# x + 1
|
32
32
|
# y * 10
|
33
|
+
# x + 1
|
33
34
|
# z & 1
|
35
|
+
# x | 1
|
36
|
+
# x ^ 1
|
34
37
|
# CONST + 1
|
35
|
-
#
|
36
|
-
# # good
|
37
|
-
# 1 | x
|
38
|
+
# 60 * 24
|
38
39
|
#
|
39
40
|
class YodaExpression < Base
|
40
41
|
extend AutoCorrector
|
data/lib/rubocop/file_finder.rb
CHANGED
@@ -6,12 +6,8 @@ module RuboCop
|
|
6
6
|
# Common methods for finding files.
|
7
7
|
# @api private
|
8
8
|
module FileFinder
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.root_level?(path, stop_dir)
|
14
|
-
(@root_level || stop_dir) == path.to_s
|
9
|
+
class << self
|
10
|
+
attr_accessor :root_level
|
15
11
|
end
|
16
12
|
|
17
13
|
def find_file_upwards(filename, start_dir, stop_dir = nil)
|
@@ -34,7 +30,8 @@ module RuboCop
|
|
34
30
|
file = dir + filename
|
35
31
|
yield(file.to_s) if file.exist?
|
36
32
|
|
37
|
-
|
33
|
+
dir = dir.to_s
|
34
|
+
break if dir == stop_dir || dir == FileFinder.root_level
|
38
35
|
end
|
39
36
|
end
|
40
37
|
end
|
@@ -11,6 +11,8 @@ RSpec.shared_context 'isolated environment' do # rubocop:disable Metrics/BlockLe
|
|
11
11
|
# Make sure to expand all symlinks in the path first. Otherwise we may
|
12
12
|
# get mismatched pathnames when loading config files later on.
|
13
13
|
tmpdir = File.realpath(tmpdir)
|
14
|
+
# Make upwards search for .rubocop.yml files stop at this directory.
|
15
|
+
RuboCop::FileFinder.root_level = tmpdir
|
14
16
|
|
15
17
|
virtual_home = File.expand_path(File.join(tmpdir, 'home'))
|
16
18
|
Dir.mkdir(virtual_home)
|
@@ -21,9 +23,6 @@ RSpec.shared_context 'isolated environment' do # rubocop:disable Metrics/BlockLe
|
|
21
23
|
root = example.metadata[:root]
|
22
24
|
working_dir = root ? File.join(base_dir, 'work', root) : File.join(base_dir, 'work')
|
23
25
|
|
24
|
-
# Make upwards search for .rubocop.yml files stop at this directory.
|
25
|
-
RuboCop::FileFinder.root_level = working_dir
|
26
|
-
|
27
26
|
begin
|
28
27
|
FileUtils.mkdir_p(working_dir)
|
29
28
|
|
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.56.
|
4
|
+
version: 1.56.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bozhidar Batsov
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-
|
13
|
+
date: 2023-09-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: base64
|