rubocop 1.82.1 → 1.84.0
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/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/config/default.yml +44 -0
- data/lib/rubocop/cli/command/lsp.rb +1 -1
- data/lib/rubocop/cli.rb +2 -1
- data/lib/rubocop/comment_config.rb +1 -0
- data/lib/rubocop/cop/bundler/gem_version.rb +28 -28
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +20 -2
- data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +8 -8
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +9 -9
- data/lib/rubocop/cop/internal_affairs/useless_message_assertion.rb +4 -4
- data/lib/rubocop/cop/layout/case_indentation.rb +3 -1
- data/lib/rubocop/cop/layout/class_structure.rb +12 -5
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +32 -1
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +26 -0
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +25 -25
- data/lib/rubocop/cop/layout/heredoc_indentation.rb +34 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +102 -9
- data/lib/rubocop/cop/layout/line_length.rb +5 -2
- data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +57 -57
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +56 -56
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +8 -8
- data/lib/rubocop/cop/lint/duplicate_methods.rb +57 -5
- data/lib/rubocop/cop/lint/float_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/literal_as_condition.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/struct_new_override.rb +17 -1
- data/lib/rubocop/cop/lint/to_json.rb +12 -16
- data/lib/rubocop/cop/lint/useless_or.rb +1 -1
- data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +1 -1
- data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +4 -4
- data/lib/rubocop/cop/naming/predicate_prefix.rb +11 -11
- data/lib/rubocop/cop/offense.rb +2 -1
- data/lib/rubocop/cop/security/json_load.rb +1 -1
- data/lib/rubocop/cop/style/access_modifier_declarations.rb +1 -2
- data/lib/rubocop/cop/style/documentation.rb +6 -6
- data/lib/rubocop/cop/style/documentation_method.rb +8 -8
- data/lib/rubocop/cop/style/empty_class_definition.rb +144 -0
- data/lib/rubocop/cop/style/guard_clause.rb +7 -4
- data/lib/rubocop/cop/style/hash_lookup_method.rb +94 -0
- data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +12 -12
- data/lib/rubocop/cop/style/lambda_call.rb +8 -8
- data/lib/rubocop/cop/style/module_member_existence_check.rb +56 -13
- data/lib/rubocop/cop/style/negative_array_index.rb +218 -0
- data/lib/rubocop/cop/style/preferred_hash_methods.rb +12 -12
- data/lib/rubocop/cop/style/redundant_condition.rb +1 -1
- data/lib/rubocop/cop/style/reverse_find.rb +51 -0
- data/lib/rubocop/cop/team.rb +3 -3
- data/lib/rubocop/cop/variable_force/branch.rb +28 -4
- data/lib/rubocop/formatter/clang_style_formatter.rb +5 -2
- data/lib/rubocop/formatter/formatter_set.rb +1 -1
- data/lib/rubocop/formatter/tap_formatter.rb +5 -2
- data/lib/rubocop/remote_config.rb +5 -2
- data/lib/rubocop/rspec/shared_contexts.rb +4 -0
- data/lib/rubocop/rspec/support.rb +1 -0
- data/lib/rubocop/target_ruby.rb +3 -1
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop.rb +4 -0
- metadata +9 -5
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Style
|
|
6
|
+
# Identifies usages of `arr[arr.length - n]`, `arr[arr.size - n]`, or
|
|
7
|
+
# `arr[arr.count - n]` and suggests to change them to use `arr[-n]` instead.
|
|
8
|
+
# Also handles range patterns like `arr[0..(arr.length - n)]`.
|
|
9
|
+
#
|
|
10
|
+
# The cop recognizes preserving methods (`sort`, `reverse`, `shuffle`, `rotate`)
|
|
11
|
+
# and their combinations, allowing safe replacement when the receiver matches.
|
|
12
|
+
# It works with variables, instance variables, class variables, and constants.
|
|
13
|
+
#
|
|
14
|
+
# @example
|
|
15
|
+
# # bad
|
|
16
|
+
# arr[arr.count - 2]
|
|
17
|
+
# arr[0..(arr.length - 2)]
|
|
18
|
+
# arr[0...(arr.length - 4)]
|
|
19
|
+
# arr.sort[arr.reverse.length - 2]
|
|
20
|
+
# arr.sort.reverse[arr.sort.size - 2]
|
|
21
|
+
#
|
|
22
|
+
# # good
|
|
23
|
+
# arr[-2]
|
|
24
|
+
# arr[0..-2]
|
|
25
|
+
# arr[0...-4]
|
|
26
|
+
# arr.sort[-2]
|
|
27
|
+
# arr.sort.reverse[-2]
|
|
28
|
+
#
|
|
29
|
+
class NegativeArrayIndex < Base
|
|
30
|
+
extend AutoCorrector
|
|
31
|
+
include RangeHelp
|
|
32
|
+
|
|
33
|
+
MSG = 'Use `%<receiver>s[-%<index>s]` instead of `%<current>s`.'
|
|
34
|
+
MSG_RANGE = 'Use `%<receiver>s[%<start>s%<range_op>s-%<index>s]` instead of `%<current>s`.'
|
|
35
|
+
RESTRICT_ON_SEND = %i[[]].freeze
|
|
36
|
+
|
|
37
|
+
LENGTH_METHODS = %i[length size count].freeze
|
|
38
|
+
|
|
39
|
+
PRESERVING_METHODS = %i[sort reverse shuffle rotate].freeze
|
|
40
|
+
|
|
41
|
+
# @!method length_subtraction?(node)
|
|
42
|
+
def_node_matcher :length_subtraction?, <<~PATTERN
|
|
43
|
+
(send
|
|
44
|
+
(send $_ {:length :size :count}) :-
|
|
45
|
+
(int $_))
|
|
46
|
+
PATTERN
|
|
47
|
+
|
|
48
|
+
def on_send(node)
|
|
49
|
+
return if node.arguments.empty?
|
|
50
|
+
|
|
51
|
+
index_arg = node.first_argument
|
|
52
|
+
range_node = extract_range_from_begin(index_arg)
|
|
53
|
+
if range_with_length_subtraction?(range_node, node.receiver)
|
|
54
|
+
receiver = node.receiver.source
|
|
55
|
+
return handle_range_pattern(receiver, range_node, index_arg)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
handle_simple_index_pattern(node, index_arg)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
alias on_csend on_send
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def handle_simple_index_pattern(node, index_arg)
|
|
66
|
+
length_receiver, negative_index = length_subtraction?(index_arg)
|
|
67
|
+
|
|
68
|
+
return unless negative_index&.positive?
|
|
69
|
+
return unless receivers_match?(length_receiver, node.receiver)
|
|
70
|
+
|
|
71
|
+
add_offense_for_subtraction(node, index_arg, negative_index)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def extract_range_from_begin(node)
|
|
75
|
+
node.begin_type? ? node.children.first : node
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def extract_inner_end(node)
|
|
79
|
+
node.children.size == 1 ? node.children.first : node
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def add_offense_for_subtraction(node, index_arg, negative_index)
|
|
83
|
+
receiver = node.receiver.source
|
|
84
|
+
offense_range = index_arg.source_range
|
|
85
|
+
current = "#{receiver}[#{index_arg.source}]"
|
|
86
|
+
|
|
87
|
+
message = format(MSG, receiver: receiver, index: negative_index, current: current)
|
|
88
|
+
|
|
89
|
+
add_offense(offense_range, message: message) do |corrector|
|
|
90
|
+
corrector.replace(offense_range, "-#{negative_index}")
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def range_with_length_subtraction?(range_node, array_receiver)
|
|
95
|
+
return false unless range_node.range_type?
|
|
96
|
+
|
|
97
|
+
range_end = range_node.end
|
|
98
|
+
range_start = range_node.begin
|
|
99
|
+
return false unless range_end && range_start
|
|
100
|
+
|
|
101
|
+
return false unless preserving_method?(range_start)
|
|
102
|
+
|
|
103
|
+
inner_end = extract_inner_end(range_end)
|
|
104
|
+
length_receiver, negative_index = length_subtraction?(inner_end)
|
|
105
|
+
|
|
106
|
+
return false unless negative_index&.positive?
|
|
107
|
+
|
|
108
|
+
receivers_match_strict?(length_receiver, array_receiver)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def handle_range_pattern(receiver, range_node, index_arg)
|
|
112
|
+
range_end = range_node.end
|
|
113
|
+
inner_end = extract_inner_end(range_end)
|
|
114
|
+
_length_receiver, negative_index = length_subtraction?(inner_end)
|
|
115
|
+
|
|
116
|
+
message, replacement = build_range_offense_data(
|
|
117
|
+
receiver, range_node, range_end, inner_end, negative_index, index_arg
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
add_offense(range_end, message: message) do |corrector|
|
|
121
|
+
corrector.replace(index_arg, replacement)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# rubocop:disable Metrics/ParameterLists
|
|
126
|
+
def build_range_offense_data(receiver, range_node, range_end, inner_end, negative_index,
|
|
127
|
+
index_arg)
|
|
128
|
+
range_op = range_node.erange_type? ? '...' : '..'
|
|
129
|
+
range_start = range_node.begin.source
|
|
130
|
+
|
|
131
|
+
range_without_parens =
|
|
132
|
+
build_range_without_parens(range_start, range_op, range_end, inner_end)
|
|
133
|
+
current_source = build_current_source(receiver, range_without_parens, index_arg)
|
|
134
|
+
start, index = format_range_message_parts(range_start, negative_index, index_arg)
|
|
135
|
+
|
|
136
|
+
message = build_message_for_range(receiver, start, range_op, index, current_source)
|
|
137
|
+
replacement = build_replacement_string(range_start, range_op, negative_index, index_arg)
|
|
138
|
+
|
|
139
|
+
[message, replacement]
|
|
140
|
+
end
|
|
141
|
+
# rubocop:enable Metrics/ParameterLists
|
|
142
|
+
|
|
143
|
+
def format_range_message_parts(range_start, negative_index, index_arg)
|
|
144
|
+
has_parentheses = index_arg.begin_type?
|
|
145
|
+
start = has_parentheses ? "(#{range_start}" : range_start
|
|
146
|
+
index = has_parentheses ? "#{negative_index})" : negative_index
|
|
147
|
+
|
|
148
|
+
[start, index]
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def build_message_for_range(receiver, start, range_op, index, current)
|
|
152
|
+
format(
|
|
153
|
+
MSG_RANGE,
|
|
154
|
+
receiver: receiver, start: start, range_op: range_op, index: index, current: current
|
|
155
|
+
)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def build_replacement_string(range_start, range_op, negative_index, index_arg)
|
|
159
|
+
has_parentheses = index_arg.begin_type?
|
|
160
|
+
|
|
161
|
+
if has_parentheses
|
|
162
|
+
"(#{range_start}#{range_op}-#{negative_index})"
|
|
163
|
+
else
|
|
164
|
+
"#{range_start}#{range_op}-#{negative_index}"
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def build_current_source(receiver, range_without_parens, index_arg)
|
|
169
|
+
has_parentheses = index_arg.begin_type?
|
|
170
|
+
|
|
171
|
+
if has_parentheses
|
|
172
|
+
"#{receiver}[(#{range_without_parens})]"
|
|
173
|
+
else
|
|
174
|
+
"#{receiver}[#{range_without_parens}]"
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def build_range_without_parens(range_start, range_op, range_end, inner_end)
|
|
179
|
+
end_expression = range_end.begin_type? ? range_end.source : inner_end.source
|
|
180
|
+
|
|
181
|
+
"#{range_start}#{range_op}#{end_expression}"
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def receivers_match?(length_receiver, array_receiver)
|
|
185
|
+
unless preserving_method?(array_receiver) && preserving_method?(length_receiver)
|
|
186
|
+
return false
|
|
187
|
+
end
|
|
188
|
+
return true if length_receiver.source == array_receiver.source
|
|
189
|
+
|
|
190
|
+
!extract_base_receiver(array_receiver).nil?
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def receivers_match_strict?(length_receiver, array_receiver)
|
|
194
|
+
preserving_method?(array_receiver) &&
|
|
195
|
+
length_receiver.source == array_receiver.source
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def extract_base_receiver(node)
|
|
199
|
+
receiver = node.receiver
|
|
200
|
+
|
|
201
|
+
return nil unless receiver
|
|
202
|
+
return receiver unless receiver.receiver
|
|
203
|
+
|
|
204
|
+
extract_base_receiver(receiver)
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def preserving_method?(node)
|
|
208
|
+
return true if node.receiver.nil?
|
|
209
|
+
|
|
210
|
+
method_name = node.method_name
|
|
211
|
+
return false unless PRESERVING_METHODS.include?(method_name)
|
|
212
|
+
|
|
213
|
+
preserving_method?(node.receiver)
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
@@ -14,22 +14,22 @@ module RuboCop
|
|
|
14
14
|
# is a `Hash` or responds to the replacement methods.
|
|
15
15
|
#
|
|
16
16
|
# @example EnforcedStyle: short (default)
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
17
|
+
# # bad
|
|
18
|
+
# Hash#has_key?
|
|
19
|
+
# Hash#has_value?
|
|
20
20
|
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
21
|
+
# # good
|
|
22
|
+
# Hash#key?
|
|
23
|
+
# Hash#value?
|
|
24
24
|
#
|
|
25
25
|
# @example EnforcedStyle: verbose
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
26
|
+
# # bad
|
|
27
|
+
# Hash#key?
|
|
28
|
+
# Hash#value?
|
|
29
29
|
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
30
|
+
# # good
|
|
31
|
+
# Hash#has_key?
|
|
32
|
+
# Hash#has_value?
|
|
33
33
|
class PreferredHashMethods < Base
|
|
34
34
|
include ConfigurableEnforcedStyle
|
|
35
35
|
extend AutoCorrector
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module Style
|
|
6
|
+
# Identifies places where `array.reverse.find` can be replaced by `array.rfind`.
|
|
7
|
+
#
|
|
8
|
+
# @safety
|
|
9
|
+
# This cop is unsafe because it cannot be guaranteed that the receiver
|
|
10
|
+
# is an `Array` or responds to the replacement method.
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# # bad
|
|
14
|
+
# array.reverse.find { |item| item.even? }
|
|
15
|
+
# array.reverse.detect { |item| item.even? }
|
|
16
|
+
# array.reverse_each.find { |item| item.even? }
|
|
17
|
+
# array.reverse_each.detect { |item| item.even? }
|
|
18
|
+
#
|
|
19
|
+
# # good
|
|
20
|
+
# array.rfind { |item| item.even? }
|
|
21
|
+
#
|
|
22
|
+
class ReverseFind < Base
|
|
23
|
+
extend AutoCorrector
|
|
24
|
+
extend TargetRubyVersion
|
|
25
|
+
|
|
26
|
+
MSG = 'Use `rfind` instead.'
|
|
27
|
+
RESTRICT_ON_SEND = %i[find detect].freeze
|
|
28
|
+
|
|
29
|
+
minimum_target_ruby_version 4.0
|
|
30
|
+
|
|
31
|
+
# @!method reverse_find?(node)
|
|
32
|
+
def_node_matcher :reverse_find?, <<~PATTERN
|
|
33
|
+
(call
|
|
34
|
+
(call
|
|
35
|
+
_ {:reverse :reverse_each}) {:find :detect} (block_pass sym)?)
|
|
36
|
+
PATTERN
|
|
37
|
+
|
|
38
|
+
def on_send(node)
|
|
39
|
+
return unless reverse_find?(node)
|
|
40
|
+
|
|
41
|
+
range = node.children.first.loc.selector.join(node.loc.selector)
|
|
42
|
+
|
|
43
|
+
add_offense(range) do |corrector|
|
|
44
|
+
corrector.replace(range, 'rfind')
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
alias on_csend on_send
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
data/lib/rubocop/cop/team.rb
CHANGED
|
@@ -211,10 +211,10 @@ module RuboCop
|
|
|
211
211
|
|
|
212
212
|
each_corrector(report) do |to_merge|
|
|
213
213
|
suppress_clobbering do
|
|
214
|
-
if
|
|
215
|
-
corrector.import!(to_merge, offset: offset)
|
|
216
|
-
else
|
|
214
|
+
if corrector.source_buffer == to_merge.source_buffer
|
|
217
215
|
corrector.merge!(to_merge)
|
|
216
|
+
else
|
|
217
|
+
corrector.import!(to_merge, offset: offset)
|
|
218
218
|
end
|
|
219
219
|
end
|
|
220
220
|
end
|
|
@@ -254,8 +254,8 @@ module RuboCop
|
|
|
254
254
|
end
|
|
255
255
|
end
|
|
256
256
|
|
|
257
|
-
# Mix-in module for
|
|
258
|
-
module
|
|
257
|
+
# Mix-in module for operator control structures.
|
|
258
|
+
module Operator
|
|
259
259
|
def always_run?
|
|
260
260
|
left_body?
|
|
261
261
|
end
|
|
@@ -263,7 +263,15 @@ module RuboCop
|
|
|
263
263
|
|
|
264
264
|
# left_body && right_body
|
|
265
265
|
class And < Base
|
|
266
|
-
include
|
|
266
|
+
include Operator
|
|
267
|
+
|
|
268
|
+
define_predicate :left_body?, child_index: 0
|
|
269
|
+
define_predicate :right_body?, child_index: 1
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
# left_body &&= right_body
|
|
273
|
+
class AndAsgn < Base
|
|
274
|
+
include Operator
|
|
267
275
|
|
|
268
276
|
define_predicate :left_body?, child_index: 0
|
|
269
277
|
define_predicate :right_body?, child_index: 1
|
|
@@ -271,7 +279,23 @@ module RuboCop
|
|
|
271
279
|
|
|
272
280
|
# left_body || right_body
|
|
273
281
|
class Or < Base
|
|
274
|
-
include
|
|
282
|
+
include Operator
|
|
283
|
+
|
|
284
|
+
define_predicate :left_body?, child_index: 0
|
|
285
|
+
define_predicate :right_body?, child_index: 1
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
# left_body ||= right_body
|
|
289
|
+
class OrAsgn < Base
|
|
290
|
+
include Operator
|
|
291
|
+
|
|
292
|
+
define_predicate :left_body?, child_index: 0
|
|
293
|
+
define_predicate :right_body?, child_index: 1
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
# e.g. left_body += right_body
|
|
297
|
+
class OpAsgn < Base
|
|
298
|
+
include Operator
|
|
275
299
|
|
|
276
300
|
define_predicate :left_body?, child_index: 0
|
|
277
301
|
define_predicate :right_body?, child_index: 1
|
|
@@ -47,8 +47,11 @@ module RuboCop
|
|
|
47
47
|
def report_highlighted_area(highlighted_area)
|
|
48
48
|
space_area = highlighted_area.source_buffer.slice(0...highlighted_area.begin_pos)
|
|
49
49
|
source_area = highlighted_area.source
|
|
50
|
-
output.puts("#{'
|
|
51
|
-
|
|
50
|
+
output.puts("#{to_whitespace(space_area)}#{'^' * Unicode::DisplayWidth.of(source_area)}")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def to_whitespace(string)
|
|
54
|
+
"#{string.delete("^\t")}#{' ' * Unicode::DisplayWidth.of(string.delete("\t"))}"
|
|
52
55
|
end
|
|
53
56
|
end
|
|
54
57
|
end
|
|
@@ -86,7 +86,7 @@ module RuboCop
|
|
|
86
86
|
|
|
87
87
|
def builtin_formatter_class(specified_key)
|
|
88
88
|
matching_keys = BUILTIN_FORMATTERS_FOR_KEYS.keys.select do |key|
|
|
89
|
-
|
|
89
|
+
key.start_with?("[#{specified_key}]") || specified_key == key.delete('[]')
|
|
90
90
|
end
|
|
91
91
|
|
|
92
92
|
if matching_keys.empty?
|
|
@@ -39,8 +39,11 @@ module RuboCop
|
|
|
39
39
|
def report_highlighted_area(highlighted_area)
|
|
40
40
|
space_area = highlighted_area.source_buffer.slice(0...highlighted_area.begin_pos)
|
|
41
41
|
source_area = highlighted_area.source
|
|
42
|
-
output.puts("# #{'
|
|
43
|
-
|
|
42
|
+
output.puts("# #{to_whitespace(space_area)}#{'^' * Unicode::DisplayWidth.of(source_area)}")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def to_whitespace(string)
|
|
46
|
+
"#{string.delete("^\t")}#{' ' * Unicode::DisplayWidth.of(string.delete("\t"))}"
|
|
44
47
|
end
|
|
45
48
|
|
|
46
49
|
def report_offense(file, offense)
|
|
@@ -81,7 +81,7 @@ module RuboCop
|
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
def cache_path
|
|
84
|
-
@cache_path ||= File.expand_path(
|
|
84
|
+
@cache_path ||= File.expand_path(cache_name_from_uri, @cache_root)
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
def cache_path_exists?
|
|
@@ -98,7 +98,10 @@ module RuboCop
|
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
def cache_name_from_uri
|
|
101
|
-
|
|
101
|
+
# The md5 checksum suffix is 37 bytes, so we play it save and
|
|
102
|
+
# allow 254 bytes total - this should be safe on Linux/macOS/Windows
|
|
103
|
+
filename = File.basename(@uri.path).gsub(/\.ya?ml\z/i, '').byteslice(0, 217).scrub('')
|
|
104
|
+
"#{filename}-#{Digest::MD5.hexdigest(@uri.to_s)}.yml"
|
|
102
105
|
end
|
|
103
106
|
|
|
104
107
|
def cloned_url
|
data/lib/rubocop/target_ruby.rb
CHANGED
|
@@ -4,7 +4,9 @@ module RuboCop
|
|
|
4
4
|
# The kind of Ruby that code inspected by RuboCop is written in.
|
|
5
5
|
# @api private
|
|
6
6
|
class TargetRuby
|
|
7
|
-
KNOWN_RUBIES = [
|
|
7
|
+
KNOWN_RUBIES = [
|
|
8
|
+
2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3, 3.4, 4.0, 4.1
|
|
9
|
+
].freeze
|
|
8
10
|
DEFAULT_VERSION = 2.7
|
|
9
11
|
|
|
10
12
|
OBSOLETE_RUBIES = {
|
data/lib/rubocop/version.rb
CHANGED
data/lib/rubocop.rb
CHANGED
|
@@ -541,6 +541,7 @@ require_relative 'rubocop/cop/style/each_for_simple_loop'
|
|
|
541
541
|
require_relative 'rubocop/cop/style/each_with_object'
|
|
542
542
|
require_relative 'rubocop/cop/style/empty_block_parameter'
|
|
543
543
|
require_relative 'rubocop/cop/style/empty_case_condition'
|
|
544
|
+
require_relative 'rubocop/cop/style/empty_class_definition'
|
|
544
545
|
require_relative 'rubocop/cop/style/empty_else'
|
|
545
546
|
require_relative 'rubocop/cop/style/empty_heredoc'
|
|
546
547
|
require_relative 'rubocop/cop/style/empty_lambda_parameter'
|
|
@@ -577,6 +578,7 @@ require_relative 'rubocop/cop/style/hash_each_methods'
|
|
|
577
578
|
require_relative 'rubocop/cop/style/hash_except'
|
|
578
579
|
require_relative 'rubocop/cop/style/hash_fetch_chain'
|
|
579
580
|
require_relative 'rubocop/cop/style/hash_like_case'
|
|
581
|
+
require_relative 'rubocop/cop/style/hash_lookup_method'
|
|
580
582
|
require_relative 'rubocop/cop/style/hash_slice'
|
|
581
583
|
require_relative 'rubocop/cop/style/hash_syntax'
|
|
582
584
|
require_relative 'rubocop/cop/style/hash_transform_keys'
|
|
@@ -633,6 +635,7 @@ require_relative 'rubocop/cop/style/redundant_regexp_constructor'
|
|
|
633
635
|
require_relative 'rubocop/cop/style/redundant_self_assignment'
|
|
634
636
|
require_relative 'rubocop/cop/style/redundant_self_assignment_branch'
|
|
635
637
|
require_relative 'rubocop/cop/style/require_order'
|
|
638
|
+
require_relative 'rubocop/cop/style/reverse_find'
|
|
636
639
|
require_relative 'rubocop/cop/style/safe_navigation_chain_length'
|
|
637
640
|
require_relative 'rubocop/cop/style/single_line_do_end_block'
|
|
638
641
|
require_relative 'rubocop/cop/style/sole_nested_conditional'
|
|
@@ -659,6 +662,7 @@ require_relative 'rubocop/cop/style/negated_if'
|
|
|
659
662
|
require_relative 'rubocop/cop/style/negated_if_else_condition'
|
|
660
663
|
require_relative 'rubocop/cop/style/negated_unless'
|
|
661
664
|
require_relative 'rubocop/cop/style/negated_while'
|
|
665
|
+
require_relative 'rubocop/cop/style/negative_array_index'
|
|
662
666
|
require_relative 'rubocop/cop/style/nested_file_dirname'
|
|
663
667
|
require_relative 'rubocop/cop/style/nested_modifier'
|
|
664
668
|
require_relative 'rubocop/cop/style/nested_parenthesized_calls'
|
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.
|
|
4
|
+
version: 1.84.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bozhidar Batsov
|
|
@@ -127,7 +127,7 @@ dependencies:
|
|
|
127
127
|
requirements:
|
|
128
128
|
- - ">="
|
|
129
129
|
- !ruby/object:Gem::Version
|
|
130
|
-
version: 1.
|
|
130
|
+
version: 1.49.0
|
|
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.
|
|
140
|
+
version: 1.49.0
|
|
141
141
|
- - "<"
|
|
142
142
|
- !ruby/object:Gem::Version
|
|
143
143
|
version: '2.0'
|
|
@@ -761,6 +761,7 @@ files:
|
|
|
761
761
|
- lib/rubocop/cop/style/each_with_object.rb
|
|
762
762
|
- lib/rubocop/cop/style/empty_block_parameter.rb
|
|
763
763
|
- lib/rubocop/cop/style/empty_case_condition.rb
|
|
764
|
+
- lib/rubocop/cop/style/empty_class_definition.rb
|
|
764
765
|
- lib/rubocop/cop/style/empty_else.rb
|
|
765
766
|
- lib/rubocop/cop/style/empty_heredoc.rb
|
|
766
767
|
- lib/rubocop/cop/style/empty_lambda_parameter.rb
|
|
@@ -797,6 +798,7 @@ files:
|
|
|
797
798
|
- lib/rubocop/cop/style/hash_except.rb
|
|
798
799
|
- lib/rubocop/cop/style/hash_fetch_chain.rb
|
|
799
800
|
- lib/rubocop/cop/style/hash_like_case.rb
|
|
801
|
+
- lib/rubocop/cop/style/hash_lookup_method.rb
|
|
800
802
|
- lib/rubocop/cop/style/hash_slice.rb
|
|
801
803
|
- lib/rubocop/cop/style/hash_syntax.rb
|
|
802
804
|
- lib/rubocop/cop/style/hash_transform_keys.rb
|
|
@@ -854,6 +856,7 @@ files:
|
|
|
854
856
|
- lib/rubocop/cop/style/negated_if_else_condition.rb
|
|
855
857
|
- lib/rubocop/cop/style/negated_unless.rb
|
|
856
858
|
- lib/rubocop/cop/style/negated_while.rb
|
|
859
|
+
- lib/rubocop/cop/style/negative_array_index.rb
|
|
857
860
|
- lib/rubocop/cop/style/nested_file_dirname.rb
|
|
858
861
|
- lib/rubocop/cop/style/nested_modifier.rb
|
|
859
862
|
- lib/rubocop/cop/style/nested_parenthesized_calls.rb
|
|
@@ -928,6 +931,7 @@ files:
|
|
|
928
931
|
- lib/rubocop/cop/style/rescue_standard_error.rb
|
|
929
932
|
- lib/rubocop/cop/style/return_nil.rb
|
|
930
933
|
- lib/rubocop/cop/style/return_nil_in_predicate_method_definition.rb
|
|
934
|
+
- lib/rubocop/cop/style/reverse_find.rb
|
|
931
935
|
- lib/rubocop/cop/style/safe_navigation.rb
|
|
932
936
|
- lib/rubocop/cop/style/safe_navigation_chain_length.rb
|
|
933
937
|
- lib/rubocop/cop/style/sample.rb
|
|
@@ -1092,9 +1096,9 @@ licenses:
|
|
|
1092
1096
|
- MIT
|
|
1093
1097
|
metadata:
|
|
1094
1098
|
homepage_uri: https://rubocop.org/
|
|
1095
|
-
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.
|
|
1099
|
+
changelog_uri: https://github.com/rubocop/rubocop/releases/tag/v1.84.0
|
|
1096
1100
|
source_code_uri: https://github.com/rubocop/rubocop/
|
|
1097
|
-
documentation_uri: https://docs.rubocop.org/rubocop/1.
|
|
1101
|
+
documentation_uri: https://docs.rubocop.org/rubocop/1.84/
|
|
1098
1102
|
bug_tracker_uri: https://github.com/rubocop/rubocop/issues
|
|
1099
1103
|
rubygems_mfa_required: 'true'
|
|
1100
1104
|
rdoc_options: []
|