rubocop 1.18.0 → 1.18.4
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 -7
- data/lib/rubocop/config_loader_resolver.rb +1 -1
- data/lib/rubocop/config_validator.rb +18 -5
- data/lib/rubocop/cop/layout/class_structure.rb +5 -1
- data/lib/rubocop/cop/layout/end_alignment.rb +8 -1
- data/lib/rubocop/cop/layout/first_argument_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/hash_alignment.rb +16 -16
- data/lib/rubocop/cop/layout/indentation_style.rb +2 -2
- data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/space_around_operators.rb +4 -0
- data/lib/rubocop/cop/lint/duplicate_branch.rb +2 -1
- data/lib/rubocop/cop/lint/useless_times.rb +1 -1
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +2 -2
- data/lib/rubocop/cop/mixin/hash_transform_method.rb +6 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +15 -0
- data/lib/rubocop/cop/style/comment_annotation.rb +50 -6
- data/lib/rubocop/cop/style/double_cop_disable_directive.rb +1 -7
- data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +8 -2
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
- data/lib/rubocop/cop/style/mutable_constant.rb +6 -8
- data/lib/rubocop/cop/style/single_line_methods.rb +25 -15
- data/lib/rubocop/formatter/git_hub_actions_formatter.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca5a85edf6c093ecee74e82617e0c618424e907cbb6a71fb1f996492073a98e4
|
4
|
+
data.tar.gz: 1ceb28336ce8913d79d4260000f5a86ca93190f5e36f6809d690aa20559674fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c020a6c2b13ad36e18afac1a2293f7c30fec5d2d62a36f5f7ffea8887816985ec27b94295fba1e08f9f1b7f462c8b4ca28a4949a32baadcea17e15ff4181b0e3
|
7
|
+
data.tar.gz: 06e9a6431dc25b8152b0b380d4de434409579fcb0b66da5335b434798889fd8f6d6a58064a044595b1a45b2bad7830e8045011c7e20e64f1337ccdd11a04e29c
|
data/config/default.yml
CHANGED
@@ -1809,7 +1809,7 @@ Lint/MissingCopEnableDirective:
|
|
1809
1809
|
Lint/MissingSuper:
|
1810
1810
|
Description: >-
|
1811
1811
|
This cop checks for the presence of constructors and lifecycle callbacks
|
1812
|
-
without calls to `super
|
1812
|
+
without calls to `super`.
|
1813
1813
|
Enabled: true
|
1814
1814
|
VersionAdded: '0.89'
|
1815
1815
|
VersionChanged: '1.4'
|
@@ -2541,7 +2541,7 @@ Naming/InclusiveLanguage:
|
|
2541
2541
|
CheckIdentifiers: true
|
2542
2542
|
CheckConstants: true
|
2543
2543
|
CheckVariables: true
|
2544
|
-
CheckStrings:
|
2544
|
+
CheckStrings: false
|
2545
2545
|
CheckSymbols: true
|
2546
2546
|
CheckComments: true
|
2547
2547
|
CheckFilepaths: true
|
@@ -2556,11 +2556,6 @@ Naming/InclusiveLanguage:
|
|
2556
2556
|
Suggestions:
|
2557
2557
|
- denylist
|
2558
2558
|
- block
|
2559
|
-
master:
|
2560
|
-
Suggestions: ['main', 'primary', 'leader']
|
2561
|
-
AllowedRegex:
|
2562
|
-
- 'Master of None'
|
2563
|
-
- 'Master Boot Record'
|
2564
2559
|
slave:
|
2565
2560
|
Suggestions: ['replica', 'secondary', 'follower']
|
2566
2561
|
|
@@ -3155,6 +3150,7 @@ Style/CommentAnnotation:
|
|
3155
3150
|
- HACK
|
3156
3151
|
- REVIEW
|
3157
3152
|
- NOTE
|
3153
|
+
RequireColon: true
|
3158
3154
|
|
3159
3155
|
Style/CommentedKeyword:
|
3160
3156
|
Description: 'Do not place comments on the same line as certain keywords.'
|
@@ -23,7 +23,7 @@ module RuboCop
|
|
23
23
|
def resolve_inheritance(path, hash, file, debug) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
24
24
|
inherited_files = Array(hash['inherit_from'])
|
25
25
|
base_configs(path, inherited_files, file)
|
26
|
-
.
|
26
|
+
.each_with_index.reverse_each do |base_config, index|
|
27
27
|
override_department_setting_for_cops(base_config, hash)
|
28
28
|
override_enabled_for_disabled_departments(base_config, hash)
|
29
29
|
|
@@ -104,12 +104,9 @@ module RuboCop
|
|
104
104
|
# to do so than to pass the value around to various methods.
|
105
105
|
next if name == 'inherit_mode'
|
106
106
|
|
107
|
-
suggestions = NameSimilarity.find_similar_names(name, Cop::Registry.global.map(&:cop_name))
|
108
|
-
suggestion = "Did you mean `#{suggestions.join('`, `')}`?" if suggestions.any?
|
109
|
-
|
110
107
|
message = <<~MESSAGE.rstrip
|
111
|
-
unrecognized cop #{name} found in #{smart_loaded_path}
|
112
|
-
#{suggestion}
|
108
|
+
unrecognized cop or department #{name} found in #{smart_loaded_path}
|
109
|
+
#{suggestion(name)}
|
113
110
|
MESSAGE
|
114
111
|
|
115
112
|
unknown_cops << message
|
@@ -117,6 +114,22 @@ module RuboCop
|
|
117
114
|
raise ValidationError, unknown_cops.join("\n") if unknown_cops.any?
|
118
115
|
end
|
119
116
|
|
117
|
+
def suggestion(name)
|
118
|
+
registry = Cop::Registry.global
|
119
|
+
departments = registry.departments.map(&:to_s)
|
120
|
+
suggestions = NameSimilarity.find_similar_names(name, departments + registry.map(&:cop_name))
|
121
|
+
if suggestions.any?
|
122
|
+
"Did you mean `#{suggestions.join('`, `')}`?"
|
123
|
+
else
|
124
|
+
# Department names can contain slashes, e.g. Chef/Correctness, but there's no support for
|
125
|
+
# the concept of higher level departments in RuboCop. It's a flat structure. So if the user
|
126
|
+
# tries to configure a "top level department", we hint that it's the bottom level
|
127
|
+
# departments that should be configured.
|
128
|
+
suggestions = departments.select { |department| department.start_with?("#{name}/") }
|
129
|
+
"#{name} is not a department. Use `#{suggestions.join('`, `')}`." if suggestions.any?
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
120
133
|
def validate_syntax_cop
|
121
134
|
syntax_config = @config['Lint/Syntax']
|
122
135
|
default_config = ConfigLoader.default_configuration['Lint/Syntax']
|
@@ -289,12 +289,16 @@ module RuboCop
|
|
289
289
|
(node.first_line - 1).downto(1) do |annotation_line|
|
290
290
|
break unless (comment = processed_source.comment_at_line(annotation_line))
|
291
291
|
|
292
|
-
first_comment = comment
|
292
|
+
first_comment = comment if whole_line_comment_at_line?(annotation_line)
|
293
293
|
end
|
294
294
|
|
295
295
|
start_line_position(first_comment || node)
|
296
296
|
end
|
297
297
|
|
298
|
+
def whole_line_comment_at_line?(line)
|
299
|
+
/\A\s*#/.match?(processed_source.lines[line - 1])
|
300
|
+
end
|
301
|
+
|
298
302
|
def start_line_position(node)
|
299
303
|
buffer.line_range(node.loc.line).begin_pos - 1
|
300
304
|
end
|
@@ -167,7 +167,8 @@ module RuboCop
|
|
167
167
|
def alignment_node_for_variable_style(node)
|
168
168
|
return node.parent if node.case_type? && node.argument?
|
169
169
|
|
170
|
-
assignment = node
|
170
|
+
assignment = assignment_or_operator_method(node)
|
171
|
+
|
171
172
|
if assignment && !line_break_before_keyword?(assignment.source_range, node)
|
172
173
|
assignment
|
173
174
|
else
|
@@ -177,6 +178,12 @@ module RuboCop
|
|
177
178
|
node
|
178
179
|
end
|
179
180
|
end
|
181
|
+
|
182
|
+
def assignment_or_operator_method(node)
|
183
|
+
node.ancestors.find do |ancestor|
|
184
|
+
ancestor.assignment_or_similar? || ancestor.send_type? && ancestor.operator_method?
|
185
|
+
end
|
186
|
+
end
|
180
187
|
end
|
181
188
|
end
|
182
189
|
end
|
@@ -154,7 +154,7 @@ module RuboCop
|
|
154
154
|
|
155
155
|
def on_send(node)
|
156
156
|
return if style != :consistent && enforce_first_argument_with_fixed_indentation?
|
157
|
-
return if !node.arguments? || bare_operator?(node)
|
157
|
+
return if !node.arguments? || bare_operator?(node) || node.setter_method?
|
158
158
|
|
159
159
|
indent = base_indentation(node) + configured_indentation_width
|
160
160
|
|
@@ -213,18 +213,18 @@ module RuboCop
|
|
213
213
|
check_pairs(node)
|
214
214
|
end
|
215
215
|
|
216
|
-
attr_accessor :
|
216
|
+
attr_accessor :offenses_by, :column_deltas
|
217
217
|
|
218
218
|
private
|
219
219
|
|
220
220
|
def autocorrect_incompatible_with_other_cops?(node)
|
221
221
|
enforce_first_argument_with_fixed_indentation? &&
|
222
222
|
node.pairs.any? &&
|
223
|
-
node.parent&.call_type? && node.parent.loc.line == node.pairs.first.loc.line
|
223
|
+
node.parent&.call_type? && node.parent.loc.selector&.line == node.pairs.first.loc.line
|
224
224
|
end
|
225
225
|
|
226
226
|
def reset!
|
227
|
-
self.
|
227
|
+
self.offenses_by = {}
|
228
228
|
self.column_deltas = Hash.new { |hash, key| hash[key] = {} }
|
229
229
|
end
|
230
230
|
|
@@ -248,33 +248,33 @@ module RuboCop
|
|
248
248
|
end
|
249
249
|
end
|
250
250
|
|
251
|
-
|
251
|
+
add_offenses
|
252
252
|
end
|
253
253
|
|
254
|
-
def
|
255
|
-
|
256
|
-
|
254
|
+
def add_offenses
|
255
|
+
kwsplat_offenses = offenses_by.delete(KeywordSplatAlignment)
|
256
|
+
register_offenses_with_format(kwsplat_offenses, KeywordSplatAlignment)
|
257
257
|
|
258
|
-
format,
|
259
|
-
|
258
|
+
format, offenses = offenses_by.min_by { |_, v| v.length }
|
259
|
+
register_offenses_with_format(offenses, format)
|
260
260
|
end
|
261
261
|
|
262
|
-
def
|
263
|
-
(
|
264
|
-
add_offense(
|
265
|
-
delta = column_deltas[alignment_for(
|
262
|
+
def register_offenses_with_format(offenses, format)
|
263
|
+
(offenses || []).each do |offense|
|
264
|
+
add_offense(offense, message: MESSAGES[format]) do |corrector|
|
265
|
+
delta = column_deltas[alignment_for(offense).first.class][offense]
|
266
266
|
|
267
|
-
correct_node(corrector,
|
267
|
+
correct_node(corrector, offense, delta) unless delta.nil?
|
268
268
|
end
|
269
269
|
end
|
270
270
|
end
|
271
271
|
|
272
272
|
def check_delta(delta, node:, alignment:)
|
273
|
-
|
273
|
+
offenses_by[alignment.class] ||= []
|
274
274
|
return if good_alignment? delta
|
275
275
|
|
276
276
|
column_deltas[alignment.class][node] = delta
|
277
|
-
|
277
|
+
offenses_by[alignment.class].push(node)
|
278
278
|
end
|
279
279
|
|
280
280
|
def ignore_hash_argument?(node)
|
@@ -43,7 +43,7 @@ module RuboCop
|
|
43
43
|
str_ranges = string_literal_ranges(processed_source.ast)
|
44
44
|
|
45
45
|
processed_source.lines.each.with_index(1) do |line, lineno|
|
46
|
-
next unless (range =
|
46
|
+
next unless (range = find_offense(line, lineno))
|
47
47
|
next if in_string_literal?(str_ranges, range)
|
48
48
|
|
49
49
|
add_offense(range) { |corrector| autocorrect(corrector, range) }
|
@@ -60,7 +60,7 @@ module RuboCop
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
def
|
63
|
+
def find_offense(line, lineno)
|
64
64
|
match = if style == :spaces
|
65
65
|
line.match(/\A\s*\t+/)
|
66
66
|
else
|
@@ -85,9 +85,9 @@ module RuboCop
|
|
85
85
|
private
|
86
86
|
|
87
87
|
def strings_concatenated_with_backslash?(dstr_node)
|
88
|
-
|
89
|
-
dstr_node.children.
|
90
|
-
dstr_node.children.
|
88
|
+
dstr_node.multiline? &&
|
89
|
+
dstr_node.children.all? { |c| c.str_type? || c.dstr_type? } &&
|
90
|
+
dstr_node.children.none?(&:multiline?)
|
91
91
|
end
|
92
92
|
|
93
93
|
def always_indented?(dstr_node)
|
@@ -4,7 +4,7 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
module Lint
|
6
6
|
# This cop checks that there are no repeated bodies
|
7
|
-
# within `if/unless`, `case-when` and `rescue` constructs.
|
7
|
+
# within `if/unless`, `case-when`, `case-in` and `rescue` constructs.
|
8
8
|
#
|
9
9
|
# With `IgnoreLiteralBranches: true`, branches are not registered
|
10
10
|
# as offenses if they return a basic literal value (string, symbol,
|
@@ -97,6 +97,7 @@ module RuboCop
|
|
97
97
|
end
|
98
98
|
alias on_if on_branching_statement
|
99
99
|
alias on_case on_branching_statement
|
100
|
+
alias on_case_match on_branching_statement
|
100
101
|
alias on_rescue on_branching_statement
|
101
102
|
|
102
103
|
private
|
@@ -81,7 +81,7 @@ module RuboCop
|
|
81
81
|
return if block_reassigns_arg?(node, block_arg)
|
82
82
|
|
83
83
|
source = node.body.source
|
84
|
-
source.gsub!(/\b#{block_arg}\b/, '
|
84
|
+
source.gsub!(/\b#{block_arg}\b/, '0') if block_arg
|
85
85
|
|
86
86
|
corrector.replace(node, fix_indentation(source, node.loc.column...node.body.loc.column))
|
87
87
|
end
|
@@ -97,9 +97,9 @@ module RuboCop
|
|
97
97
|
# If a send node contains a heredoc argument, splitting cannot happen
|
98
98
|
# after the heredoc or else it will cause a syntax error.
|
99
99
|
def shift_elements_for_heredoc_arg(node, elements, index)
|
100
|
-
return index unless node.send_type?
|
100
|
+
return index unless node.send_type? || node.array_type?
|
101
101
|
|
102
|
-
heredoc_index = elements.index { |arg|
|
102
|
+
heredoc_index = elements.index { |arg| arg.respond_to?(:heredoc?) && arg.heredoc? }
|
103
103
|
return index unless heredoc_index
|
104
104
|
return nil if heredoc_index.zero?
|
105
105
|
|
@@ -175,7 +175,12 @@ module RuboCop
|
|
175
175
|
end
|
176
176
|
|
177
177
|
def set_new_body_expression(transforming_body_expr, corrector)
|
178
|
-
|
178
|
+
body_source = transforming_body_expr.loc.expression.source
|
179
|
+
if transforming_body_expr.hash_type? && !transforming_body_expr.braces?
|
180
|
+
body_source = "{ #{body_source} }"
|
181
|
+
end
|
182
|
+
|
183
|
+
corrector.replace(block_node.body, body_source)
|
179
184
|
end
|
180
185
|
end
|
181
186
|
end
|
@@ -135,6 +135,7 @@ module RuboCop
|
|
135
135
|
class BlockDelimiters < Base
|
136
136
|
include ConfigurableEnforcedStyle
|
137
137
|
include IgnoredMethods
|
138
|
+
include RangeHelp
|
138
139
|
extend AutoCorrector
|
139
140
|
|
140
141
|
ALWAYS_BRACES_MESSAGE = 'Prefer `{...}` over `do...end` for blocks.'
|
@@ -231,6 +232,11 @@ module RuboCop
|
|
231
232
|
corrector.insert_before(e, ' ') unless whitespace_before?(e)
|
232
233
|
corrector.insert_after(b, ' ') unless whitespace_after?(b)
|
233
234
|
corrector.replace(b, 'do')
|
235
|
+
|
236
|
+
if (comment = processed_source.comment_at_line(e.line))
|
237
|
+
move_comment_before_block(corrector, comment, loc.node, e)
|
238
|
+
end
|
239
|
+
|
234
240
|
corrector.replace(e, 'end')
|
235
241
|
end
|
236
242
|
|
@@ -252,6 +258,15 @@ module RuboCop
|
|
252
258
|
/\s/.match?(range.source_buffer.source[range.begin_pos + length, 1])
|
253
259
|
end
|
254
260
|
|
261
|
+
def move_comment_before_block(corrector, comment, block_node, closing_brace)
|
262
|
+
range = range_between(closing_brace.end_pos, comment.loc.expression.end_pos)
|
263
|
+
|
264
|
+
corrector.remove(range_with_surrounding_space(range: range, side: :right))
|
265
|
+
corrector.insert_after(closing_brace, "\n")
|
266
|
+
|
267
|
+
corrector.insert_before(block_node, "#{comment.text}\n")
|
268
|
+
end
|
269
|
+
|
255
270
|
def get_blocks(node, &block)
|
256
271
|
case node.type
|
257
272
|
when :block
|
@@ -12,7 +12,7 @@ module RuboCop
|
|
12
12
|
# incorrect registering of keywords (eg. `review`) inside a paragraph as an
|
13
13
|
# annotation.
|
14
14
|
#
|
15
|
-
# @example
|
15
|
+
# @example RequireColon: true (default)
|
16
16
|
# # bad
|
17
17
|
# # TODO make better
|
18
18
|
#
|
@@ -36,14 +36,36 @@ module RuboCop
|
|
36
36
|
#
|
37
37
|
# # good
|
38
38
|
# # OPTIMIZE: does not work
|
39
|
+
#
|
40
|
+
# @example RequireColon: false
|
41
|
+
# # bad
|
42
|
+
# # TODO: make better
|
43
|
+
#
|
44
|
+
# # good
|
45
|
+
# # TODO make better
|
46
|
+
#
|
47
|
+
# # bad
|
48
|
+
# # fixme does not work
|
49
|
+
#
|
50
|
+
# # good
|
51
|
+
# # FIXME does not work
|
52
|
+
#
|
53
|
+
# # bad
|
54
|
+
# # Optimize does not work
|
55
|
+
#
|
56
|
+
# # good
|
57
|
+
# # OPTIMIZE does not work
|
39
58
|
class CommentAnnotation < Base
|
40
59
|
include AnnotationComment
|
41
60
|
include RangeHelp
|
42
61
|
extend AutoCorrector
|
43
62
|
|
44
|
-
|
45
|
-
|
46
|
-
|
63
|
+
MSG_COLON_STYLE = 'Annotation keywords like `%<keyword>s` should be all ' \
|
64
|
+
'upper case, followed by a colon, and a space, ' \
|
65
|
+
'then a note describing the problem.'
|
66
|
+
MSG_SPACE_STYLE = 'Annotation keywords like `%<keyword>s` should be all ' \
|
67
|
+
'upper case, followed by a space, ' \
|
68
|
+
'then a note describing the problem.'
|
47
69
|
MISSING_NOTE = 'Annotation comment, with keyword `%<keyword>s`, is missing a note.'
|
48
70
|
|
49
71
|
def on_new_investigation
|
@@ -63,13 +85,15 @@ module RuboCop
|
|
63
85
|
private
|
64
86
|
|
65
87
|
def register_offense(range, note, first_word)
|
88
|
+
message = requires_colon? ? MSG_COLON_STYLE : MSG_SPACE_STYLE
|
89
|
+
|
66
90
|
add_offense(
|
67
91
|
range,
|
68
|
-
message: format(note ?
|
92
|
+
message: format(note ? message : MISSING_NOTE, keyword: first_word)
|
69
93
|
) do |corrector|
|
70
94
|
next if note.nil?
|
71
95
|
|
72
|
-
corrector
|
96
|
+
correct_offense(corrector, range, first_word)
|
73
97
|
end
|
74
98
|
end
|
75
99
|
|
@@ -92,8 +116,28 @@ module RuboCop
|
|
92
116
|
end
|
93
117
|
|
94
118
|
def correct_annotation?(first_word, colon, space, note)
|
119
|
+
return correct_colon_annotation?(first_word, colon, space, note) if requires_colon?
|
120
|
+
|
121
|
+
correct_space_annotation?(first_word, colon, space, note)
|
122
|
+
end
|
123
|
+
|
124
|
+
def correct_colon_annotation?(first_word, colon, space, note)
|
95
125
|
keyword?(first_word) && (colon && space && note || !colon && !note)
|
96
126
|
end
|
127
|
+
|
128
|
+
def correct_space_annotation?(first_word, colon, space, note)
|
129
|
+
keyword?(first_word) && (!colon && space && note || !colon && !note)
|
130
|
+
end
|
131
|
+
|
132
|
+
def correct_offense(corrector, range, first_word)
|
133
|
+
return corrector.replace(range, "#{first_word.upcase}: ") if requires_colon?
|
134
|
+
|
135
|
+
corrector.replace(range, "#{first_word.upcase} ")
|
136
|
+
end
|
137
|
+
|
138
|
+
def requires_colon?
|
139
|
+
cop_config['RequireColon']
|
140
|
+
end
|
97
141
|
end
|
98
142
|
end
|
99
143
|
end
|
@@ -36,13 +36,7 @@ module RuboCop
|
|
36
36
|
next unless comment.text.scan(/# rubocop:(?:disable|todo)/).size > 1
|
37
37
|
|
38
38
|
add_offense(comment) do |corrector|
|
39
|
-
|
40
|
-
'# rubocop:disable'
|
41
|
-
else
|
42
|
-
'# rubocop:todo'
|
43
|
-
end
|
44
|
-
|
45
|
-
corrector.replace(comment, comment.text[/#{prefix} \S+/])
|
39
|
+
corrector.replace(comment, comment.text.gsub(%r{ # rubocop:(disable|todo)}, ','))
|
46
40
|
end
|
47
41
|
end
|
48
42
|
end
|
@@ -43,7 +43,7 @@ module RuboCop
|
|
43
43
|
# RUBY
|
44
44
|
#
|
45
45
|
# This cop works only when a string literal is given as a code string.
|
46
|
-
# No
|
46
|
+
# No offense is reported if a string variable is given as below:
|
47
47
|
#
|
48
48
|
# @example
|
49
49
|
# # not checked
|
@@ -5,11 +5,17 @@ module RuboCop
|
|
5
5
|
module Style
|
6
6
|
# This cop is designed to help you transition from mutable string literals
|
7
7
|
# to frozen string literals.
|
8
|
-
# It will add the
|
9
|
-
# files to enable frozen string literals. Frozen string literals may be
|
8
|
+
# It will add the `# frozen_string_literal: true` magic comment to the top
|
9
|
+
# of files to enable frozen string literals. Frozen string literals may be
|
10
10
|
# default in future Ruby. The comment will be added below a shebang and
|
11
11
|
# encoding comment.
|
12
12
|
#
|
13
|
+
# Note that the cop will ignore files where the comment exists but is set
|
14
|
+
# to `false` instead of `true`.
|
15
|
+
#
|
16
|
+
# To require a blank line after this comment, please see
|
17
|
+
# `Layout/EmptyLineAfterMagicComment` cop.
|
18
|
+
#
|
13
19
|
# @example EnforcedStyle: always (default)
|
14
20
|
# # The `always` style will always add the frozen string literal comment
|
15
21
|
# # to a file, regardless of the Ruby version or if `freeze` or `<<` are
|
@@ -61,13 +61,12 @@ module RuboCop
|
|
61
61
|
|
62
62
|
def on_casgn(node)
|
63
63
|
_scope, _const_name, value = *node
|
64
|
-
|
65
|
-
|
64
|
+
if value.nil? # This is only the case for `CONST += ...` or similarg66
|
65
|
+
parent = node.parent
|
66
|
+
return unless parent.or_asgn_type? # We only care about `CONST ||= ...`
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
return unless lhs&.casgn_type?
|
68
|
+
value = parent.children.last
|
69
|
+
end
|
71
70
|
|
72
71
|
on_assignment(value)
|
73
72
|
end
|
@@ -118,14 +117,13 @@ module RuboCop
|
|
118
117
|
end
|
119
118
|
|
120
119
|
def mutable_literal?(value)
|
121
|
-
return false if value.nil?
|
122
120
|
return false if frozen_regexp_or_range_literals?(value)
|
123
121
|
|
124
122
|
value.mutable_literal?
|
125
123
|
end
|
126
124
|
|
127
125
|
def immutable_literal?(node)
|
128
|
-
|
126
|
+
frozen_regexp_or_range_literals?(node) || node.immutable_literal?
|
129
127
|
end
|
130
128
|
|
131
129
|
def frozen_string_literal?(node)
|
@@ -36,6 +36,7 @@ module RuboCop
|
|
36
36
|
extend AutoCorrector
|
37
37
|
|
38
38
|
MSG = 'Avoid single-line method definitions.'
|
39
|
+
NOT_SUPPORTED_ENDLESS_METHOD_BODY_TYPES = %i[return break next].freeze
|
39
40
|
|
40
41
|
def on_def(node)
|
41
42
|
return unless node.single_line?
|
@@ -62,29 +63,24 @@ module RuboCop
|
|
62
63
|
|
63
64
|
def correct_to_endless?(body_node)
|
64
65
|
return false if target_ruby_version < 3.0
|
65
|
-
|
66
|
-
endless_method_config = config.for_cop('Style/EndlessMethod')
|
67
|
-
|
68
|
-
return false unless endless_method_config['Enabled']
|
69
|
-
return false if endless_method_config['EnforcedStyle'] == 'disallow'
|
66
|
+
return false if disallow_endless_method_style?
|
70
67
|
return false unless body_node
|
71
|
-
return false if body_node.parent.assignment_method?
|
68
|
+
return false if body_node.parent.assignment_method? ||
|
69
|
+
NOT_SUPPORTED_ENDLESS_METHOD_BODY_TYPES.include?(body_node.type)
|
72
70
|
|
73
71
|
!(body_node.begin_type? || body_node.kwbegin_type?)
|
74
72
|
end
|
75
73
|
|
76
74
|
def correct_to_multiline(corrector, node)
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
75
|
+
if (body = node.body) && body.begin_type? && body.parenthesized_call?
|
76
|
+
break_line_before(corrector, node, body)
|
77
|
+
else
|
78
|
+
each_part(body) do |part|
|
79
|
+
break_line_before(corrector, node, part)
|
80
|
+
end
|
82
81
|
end
|
83
82
|
|
84
|
-
|
85
|
-
range: node.loc.end, node: node, corrector: corrector,
|
86
|
-
indent_steps: 0, configured_width: configured_indentation_width
|
87
|
-
)
|
83
|
+
break_line_before(corrector, node, node.loc.end, indent_steps: 0)
|
88
84
|
|
89
85
|
move_comment(node, corrector)
|
90
86
|
end
|
@@ -98,6 +94,13 @@ module RuboCop
|
|
98
94
|
corrector.replace(node, replacement)
|
99
95
|
end
|
100
96
|
|
97
|
+
def break_line_before(corrector, node, range, indent_steps: 1)
|
98
|
+
LineBreakCorrector.break_line_before(
|
99
|
+
range: range, node: node, corrector: corrector,
|
100
|
+
configured_width: configured_indentation_width, indent_steps: indent_steps
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
101
104
|
def each_part(body)
|
102
105
|
return unless body
|
103
106
|
|
@@ -129,6 +132,13 @@ module RuboCop
|
|
129
132
|
def require_parentheses?(method_body)
|
130
133
|
method_body.send_type? && !method_body.arguments.empty? && !method_body.comparison_method?
|
131
134
|
end
|
135
|
+
|
136
|
+
def disallow_endless_method_style?
|
137
|
+
endless_method_config = config.for_cop('Style/EndlessMethod')
|
138
|
+
return false unless endless_method_config['Enabled']
|
139
|
+
|
140
|
+
endless_method_config['EnforcedStyle'] == 'disallow'
|
141
|
+
end
|
132
142
|
end
|
133
143
|
end
|
134
144
|
end
|
@@ -33,7 +33,7 @@ module RuboCop
|
|
33
33
|
output.printf(
|
34
34
|
"\n::%<severity>s file=%<file>s,line=%<line>d,col=%<column>d::%<message>s\n",
|
35
35
|
severity: github_severity(offense),
|
36
|
-
file: file,
|
36
|
+
file: PathUtil.smart_path(file),
|
37
37
|
line: offense.line,
|
38
38
|
column: offense.real_column,
|
39
39
|
message: github_escape(offense.message)
|
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.18.
|
4
|
+
version: 1.18.4
|
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: 2021-
|
13
|
+
date: 2021-07-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parallel
|
@@ -100,7 +100,7 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 1.
|
103
|
+
version: 1.8.0
|
104
104
|
- - "<"
|
105
105
|
- !ruby/object:Gem::Version
|
106
106
|
version: '2.0'
|
@@ -110,7 +110,7 @@ dependencies:
|
|
110
110
|
requirements:
|
111
111
|
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version: 1.
|
113
|
+
version: 1.8.0
|
114
114
|
- - "<"
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '2.0'
|