rubocop 1.15.0 → 1.18.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/README.md +1 -1
- data/config/default.yml +104 -31
- data/lib/rubocop.rb +7 -0
- data/lib/rubocop/cli/command/suggest_extensions.rb +3 -3
- data/lib/rubocop/config_loader.rb +1 -1
- data/lib/rubocop/config_validator.rb +5 -5
- data/lib/rubocop/cop/base.rb +2 -2
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
- data/lib/rubocop/cop/bundler/gem_version.rb +38 -4
- data/lib/rubocop/cop/corrector.rb +4 -4
- data/lib/rubocop/cop/generator.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
- data/lib/rubocop/cop/layout/argument_alignment.rb +4 -3
- data/lib/rubocop/cop/layout/array_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/block_alignment.rb +1 -1
- data/lib/rubocop/cop/layout/case_indentation.rb +57 -9
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +7 -1
- data/lib/rubocop/cop/layout/comment_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/dot_position.rb +7 -1
- data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +13 -15
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/hash_alignment.rb +26 -8
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +1 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +8 -0
- data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +122 -0
- data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +6 -6
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +2 -2
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +6 -6
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +6 -6
- data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +6 -6
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +3 -3
- data/lib/rubocop/cop/layout/parameter_alignment.rb +2 -2
- data/lib/rubocop/cop/layout/redundant_line_break.rb +11 -9
- data/lib/rubocop/cop/layout/space_around_keyword.rb +28 -0
- data/lib/rubocop/cop/layout/space_around_operators.rb +7 -1
- data/lib/rubocop/cop/lint/empty_in_pattern.rb +62 -0
- data/lib/rubocop/cop/lint/literal_as_condition.rb +13 -1
- data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +32 -17
- data/lib/rubocop/cop/lint/nested_percent_literal.rb +1 -1
- data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +105 -74
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +5 -0
- data/lib/rubocop/cop/lint/symbol_conversion.rb +3 -13
- data/lib/rubocop/cop/lint/unused_block_argument.rb +1 -1
- data/lib/rubocop/cop/lint/useless_assignment.rb +1 -1
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
- data/lib/rubocop/cop/migration/department_name.rb +3 -1
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +10 -1
- data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +14 -3
- data/lib/rubocop/cop/mixin/string_literals_help.rb +2 -4
- data/lib/rubocop/cop/mixin/symbol_help.rb +13 -0
- data/lib/rubocop/cop/naming/inclusive_language.rb +249 -0
- data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +2 -2
- data/lib/rubocop/cop/style/class_and_module_children.rb +14 -0
- data/lib/rubocop/cop/style/hash_each_methods.rb +18 -1
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +58 -8
- data/lib/rubocop/cop/style/in_pattern_then.rb +56 -0
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -1
- data/lib/rubocop/cop/style/multiline_in_pattern_then.rb +62 -0
- data/lib/rubocop/cop/style/multiline_when_then.rb +2 -11
- data/lib/rubocop/cop/style/multiple_comparison.rb +1 -1
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/quoted_symbols.rb +110 -0
- data/lib/rubocop/cop/style/raise_args.rb +2 -0
- data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +1 -1
- data/lib/rubocop/cop/style/redundant_self.rb +24 -2
- data/lib/rubocop/cop/style/regexp_literal.rb +10 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +3 -3
- data/lib/rubocop/cop/style/string_concatenation.rb +32 -5
- data/lib/rubocop/cop/style/string_literals.rb +3 -2
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +1 -0
- data/lib/rubocop/cop/style/swap_values.rb +1 -1
- data/lib/rubocop/cop/style/top_level_method_definition.rb +10 -2
- data/lib/rubocop/cop/style/unpack_first.rb +1 -1
- data/lib/rubocop/cop/style/when_then.rb +6 -2
- data/lib/rubocop/cop/variable_force/variable_table.rb +1 -1
- data/lib/rubocop/directive_comment.rb +58 -6
- data/lib/rubocop/options.rb +4 -4
- data/lib/rubocop/rake_task.rb +1 -1
- data/lib/rubocop/remote_config.rb +10 -2
- data/lib/rubocop/rspec/cop_helper.rb +1 -1
- data/lib/rubocop/rspec/expect_offense.rb +1 -1
- data/lib/rubocop/version.rb +1 -1
- metadata +12 -5
@@ -178,10 +178,10 @@ module RuboCop
|
|
178
178
|
'Indent the right brace the same as the left brace.'
|
179
179
|
elsif style == :special_inside_parentheses && left_parenthesis
|
180
180
|
'Indent the right brace the same as the first position ' \
|
181
|
-
|
181
|
+
'after the preceding left parenthesis.'
|
182
182
|
else
|
183
183
|
'Indent the right brace the same as the start of the line ' \
|
184
|
-
|
184
|
+
'where the left brace is.'
|
185
185
|
end
|
186
186
|
end
|
187
187
|
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
48
48
|
extend AutoCorrector
|
49
49
|
|
50
50
|
MSG = 'Use %<configured_indentation_width>d spaces for indentation ' \
|
51
|
-
|
51
|
+
'in method args, relative to %<base_description>s.'
|
52
52
|
|
53
53
|
def on_def(node)
|
54
54
|
return if node.arguments.empty?
|
@@ -180,12 +180,15 @@ module RuboCop
|
|
180
180
|
include RangeHelp
|
181
181
|
extend AutoCorrector
|
182
182
|
|
183
|
-
MESSAGES = {
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
183
|
+
MESSAGES = {
|
184
|
+
KeyAlignment => 'Align the keys of a hash literal if they span more than one line.',
|
185
|
+
SeparatorAlignment => 'Align the separators of a hash literal if they span more than ' \
|
186
|
+
'one line.',
|
187
|
+
TableAlignment => 'Align the keys and values of a hash literal if they span more than ' \
|
188
|
+
'one line.',
|
189
|
+
KeywordSplatAlignment => 'Align keyword splats with the rest of the hash if it spans ' \
|
190
|
+
'more than one line.'
|
191
|
+
}.freeze
|
189
192
|
|
190
193
|
def on_send(node)
|
191
194
|
return if double_splat?(node)
|
@@ -201,7 +204,7 @@ module RuboCop
|
|
201
204
|
alias on_yield on_send
|
202
205
|
|
203
206
|
def on_hash(node)
|
204
|
-
return if
|
207
|
+
return if autocorrect_incompatible_with_other_cops?(node) || ignored_node?(node) ||
|
205
208
|
node.pairs.empty? || node.single_line?
|
206
209
|
|
207
210
|
proc = ->(a) { a.checkable_layout?(node) }
|
@@ -214,6 +217,12 @@ module RuboCop
|
|
214
217
|
|
215
218
|
private
|
216
219
|
|
220
|
+
def autocorrect_incompatible_with_other_cops?(node)
|
221
|
+
enforce_first_argument_with_fixed_indentation? &&
|
222
|
+
node.pairs.any? &&
|
223
|
+
node.parent&.call_type? && node.parent.loc.selector.line == node.pairs.first.loc.line
|
224
|
+
end
|
225
|
+
|
217
226
|
def reset!
|
218
227
|
self.offences_by = {}
|
219
228
|
self.column_deltas = Hash.new { |hash, key| hash[key] = {} }
|
@@ -243,7 +252,14 @@ module RuboCop
|
|
243
252
|
end
|
244
253
|
|
245
254
|
def add_offences
|
255
|
+
kwsplat_offences = offences_by.delete(KeywordSplatAlignment)
|
256
|
+
register_offences_with_format(kwsplat_offences, KeywordSplatAlignment)
|
257
|
+
|
246
258
|
format, offences = offences_by.min_by { |_, v| v.length }
|
259
|
+
register_offences_with_format(offences, format)
|
260
|
+
end
|
261
|
+
|
262
|
+
def register_offences_with_format(offences, format)
|
247
263
|
(offences || []).each do |offence|
|
248
264
|
add_offense(offence, message: MESSAGES[format]) do |corrector|
|
249
265
|
delta = column_deltas[alignment_for(offence).first.class][offence]
|
@@ -271,7 +287,9 @@ module RuboCop
|
|
271
287
|
end
|
272
288
|
|
273
289
|
def alignment_for(pair)
|
274
|
-
if pair.
|
290
|
+
if pair.kwsplat_type?
|
291
|
+
[KeywordSplatAlignment.new]
|
292
|
+
elsif pair.hash_rocket?
|
275
293
|
alignment_for_hash_rockets
|
276
294
|
else
|
277
295
|
alignment_for_colons
|
@@ -55,7 +55,7 @@ module RuboCop
|
|
55
55
|
extend AutoCorrector
|
56
56
|
|
57
57
|
MSG = 'Put the closing parenthesis for a method call with a ' \
|
58
|
-
|
58
|
+
'HEREDOC parameter on the same line as the HEREDOC opening.'
|
59
59
|
|
60
60
|
def self.autocorrect_incompatible_with
|
61
61
|
[Style::TrailingCommaInArguments]
|
@@ -138,6 +138,14 @@ module RuboCop
|
|
138
138
|
check_indentation(case_node.when_branches.last.loc.keyword, case_node.else_branch)
|
139
139
|
end
|
140
140
|
|
141
|
+
def on_case_match(case_match)
|
142
|
+
case_match.each_in_pattern do |in_pattern_node|
|
143
|
+
check_indentation(in_pattern_node.loc.keyword, in_pattern_node.body)
|
144
|
+
end
|
145
|
+
|
146
|
+
check_indentation(case_match.in_pattern_branches.last.loc.keyword, case_match.else_branch)
|
147
|
+
end
|
148
|
+
|
141
149
|
def on_if(node, base = node)
|
142
150
|
return if ignored_node?(node)
|
143
151
|
return if node.ternary? || node.modifier_form?
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Layout
|
6
|
+
# This cop checks the indentation of the next line after a line that ends with a string
|
7
|
+
# literal and a backslash.
|
8
|
+
#
|
9
|
+
# If `EnforcedStyle: aligned` is set, the concatenated string parts shall be aligned with the
|
10
|
+
# first part. There are some exceptions, such as implicit return values, where the
|
11
|
+
# concatenated string parts shall be indented regardless of `EnforcedStyle` configuration.
|
12
|
+
#
|
13
|
+
# If `EnforcedStyle: indented` is set, it's the second line that shall be indented one step
|
14
|
+
# more than the first line. Lines 3 and forward shall be aligned with line 2. Here too there
|
15
|
+
# are exceptions. Values in a hash literal are always aligned.
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
# # bad
|
19
|
+
# def some_method
|
20
|
+
# 'x' \
|
21
|
+
# 'y' \
|
22
|
+
# 'z'
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# my_hash = {
|
26
|
+
# first: 'a message' \
|
27
|
+
# 'in two parts'
|
28
|
+
# }
|
29
|
+
#
|
30
|
+
# # good
|
31
|
+
# def some_method
|
32
|
+
# 'x' \
|
33
|
+
# 'y' \
|
34
|
+
# 'z'
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# my_hash = {
|
38
|
+
# first: 'a message' \
|
39
|
+
# 'in two parts'
|
40
|
+
# }
|
41
|
+
#
|
42
|
+
# @example EnforcedStyle: aligned (default)
|
43
|
+
# # bad
|
44
|
+
# puts 'x' \
|
45
|
+
# 'y'
|
46
|
+
#
|
47
|
+
# # good
|
48
|
+
# puts 'x' \
|
49
|
+
# 'y'
|
50
|
+
#
|
51
|
+
# @example EnforcedStyle: indented
|
52
|
+
# # bad
|
53
|
+
# result = 'x' \
|
54
|
+
# 'y'
|
55
|
+
#
|
56
|
+
# # good
|
57
|
+
# result = 'x' \
|
58
|
+
# 'y'
|
59
|
+
#
|
60
|
+
class LineEndStringConcatenationIndentation < Base
|
61
|
+
include ConfigurableEnforcedStyle
|
62
|
+
include Alignment
|
63
|
+
extend AutoCorrector
|
64
|
+
|
65
|
+
MSG_ALIGN = 'Align parts of a string concatenated with backslash.'
|
66
|
+
MSG_INDENT = 'Indent the first part of a string concatenated with backslash.'
|
67
|
+
PARENT_TYPES_FOR_INDENTED = [nil, :block, :begin, :def, :defs, :if].freeze
|
68
|
+
|
69
|
+
def on_dstr(node)
|
70
|
+
return unless strings_concatenated_with_backslash?(node)
|
71
|
+
|
72
|
+
children = node.children
|
73
|
+
if style == :aligned && !always_indented?(node) || always_aligned?(node)
|
74
|
+
check_aligned(children, 1)
|
75
|
+
else
|
76
|
+
check_indented(children)
|
77
|
+
check_aligned(children, 2)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def autocorrect(corrector, node)
|
82
|
+
AlignmentCorrector.correct(corrector, processed_source, node, @column_delta)
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def strings_concatenated_with_backslash?(dstr_node)
|
88
|
+
!dstr_node.heredoc? &&
|
89
|
+
dstr_node.children.length > 1 &&
|
90
|
+
dstr_node.children.all? { |c| c.str_type? || c.dstr_type? }
|
91
|
+
end
|
92
|
+
|
93
|
+
def always_indented?(dstr_node)
|
94
|
+
PARENT_TYPES_FOR_INDENTED.include?(dstr_node.parent&.type)
|
95
|
+
end
|
96
|
+
|
97
|
+
def always_aligned?(dstr_node)
|
98
|
+
dstr_node.parent&.pair_type?
|
99
|
+
end
|
100
|
+
|
101
|
+
def check_aligned(children, start_index)
|
102
|
+
base_column = children[start_index - 1].loc.column
|
103
|
+
children[start_index..-1].each do |child|
|
104
|
+
@column_delta = base_column - child.loc.column
|
105
|
+
add_offense_and_correction(child, MSG_ALIGN) if @column_delta != 0
|
106
|
+
base_column = child.loc.column
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def check_indented(children)
|
111
|
+
base_column = children[0].source_range.source_line =~ /\S/
|
112
|
+
@column_delta = base_column + configured_indentation_width - children[1].loc.column
|
113
|
+
add_offense_and_correction(children[1], MSG_INDENT) if @column_delta != 0
|
114
|
+
end
|
115
|
+
|
116
|
+
def add_offense_and_correction(node, message)
|
117
|
+
add_offense(node, message: message) { |corrector| autocorrect(corrector, node) }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -93,18 +93,18 @@ module RuboCop
|
|
93
93
|
extend AutoCorrector
|
94
94
|
|
95
95
|
SAME_LINE_MESSAGE = 'The closing array brace must be on the same ' \
|
96
|
-
|
97
|
-
|
96
|
+
'line as the last array element when the opening brace is on the ' \
|
97
|
+
'same line as the first array element.'
|
98
98
|
|
99
99
|
NEW_LINE_MESSAGE = 'The closing array brace must be on the line ' \
|
100
|
-
|
101
|
-
|
100
|
+
'after the last array element when the opening brace is on a ' \
|
101
|
+
'separate line from the first array element.'
|
102
102
|
|
103
103
|
ALWAYS_NEW_LINE_MESSAGE = 'The closing array brace must be on the ' \
|
104
|
-
|
104
|
+
'line after the last array element.'
|
105
105
|
|
106
106
|
ALWAYS_SAME_LINE_MESSAGE = 'The closing array brace must be on the ' \
|
107
|
-
|
107
|
+
'same line as the last array element.'
|
108
108
|
|
109
109
|
def on_array(node)
|
110
110
|
check_brace_layout(node)
|
@@ -64,10 +64,10 @@ module RuboCop
|
|
64
64
|
extend AutoCorrector
|
65
65
|
|
66
66
|
NEW_LINE_OFFENSE = 'Right hand side of multi-line assignment is on ' \
|
67
|
-
|
67
|
+
'the same line as the assignment operator `=`.'
|
68
68
|
|
69
69
|
SAME_LINE_OFFENSE = 'Right hand side of multi-line assignment is not ' \
|
70
|
-
|
70
|
+
'on the same line as the assignment operator `=`.'
|
71
71
|
|
72
72
|
def check_assignment(node, rhs)
|
73
73
|
return if node.send_type? && node.loc.operator&.source != '='
|
@@ -93,18 +93,18 @@ module RuboCop
|
|
93
93
|
extend AutoCorrector
|
94
94
|
|
95
95
|
SAME_LINE_MESSAGE = 'Closing hash brace must be on the same line as ' \
|
96
|
-
|
97
|
-
|
96
|
+
'the last hash element when opening brace is on the same line as ' \
|
97
|
+
'the first hash element.'
|
98
98
|
|
99
99
|
NEW_LINE_MESSAGE = 'Closing hash brace must be on the line after ' \
|
100
|
-
|
101
|
-
|
100
|
+
'the last hash element when opening brace is on a separate line ' \
|
101
|
+
'from the first hash element.'
|
102
102
|
|
103
103
|
ALWAYS_NEW_LINE_MESSAGE = 'Closing hash brace must be on the line ' \
|
104
|
-
|
104
|
+
'after the last hash element.'
|
105
105
|
|
106
106
|
ALWAYS_SAME_LINE_MESSAGE = 'Closing hash brace must be on the same ' \
|
107
|
-
|
107
|
+
'line as the last hash element.'
|
108
108
|
|
109
109
|
def on_hash(node)
|
110
110
|
check_brace_layout(node)
|
@@ -93,18 +93,18 @@ module RuboCop
|
|
93
93
|
extend AutoCorrector
|
94
94
|
|
95
95
|
SAME_LINE_MESSAGE = 'Closing method call brace must be on the ' \
|
96
|
-
|
97
|
-
|
96
|
+
'same line as the last argument when opening brace is on the same ' \
|
97
|
+
'line as the first argument.'
|
98
98
|
|
99
99
|
NEW_LINE_MESSAGE = 'Closing method call brace must be on the ' \
|
100
|
-
|
101
|
-
|
100
|
+
'line after the last argument when opening brace is on a separate ' \
|
101
|
+
'line from the first argument.'
|
102
102
|
|
103
103
|
ALWAYS_NEW_LINE_MESSAGE = 'Closing method call brace must be on ' \
|
104
|
-
|
104
|
+
'the line after the last argument.'
|
105
105
|
|
106
106
|
ALWAYS_SAME_LINE_MESSAGE = 'Closing method call brace must be on ' \
|
107
|
-
|
107
|
+
'the same line as the last argument.'
|
108
108
|
|
109
109
|
def on_send(node)
|
110
110
|
check_brace_layout(node)
|
@@ -105,18 +105,18 @@ module RuboCop
|
|
105
105
|
extend AutoCorrector
|
106
106
|
|
107
107
|
SAME_LINE_MESSAGE = 'Closing method definition brace must be on the ' \
|
108
|
-
|
109
|
-
|
108
|
+
'same line as the last parameter when opening brace is on the same ' \
|
109
|
+
'line as the first parameter.'
|
110
110
|
|
111
111
|
NEW_LINE_MESSAGE = 'Closing method definition brace must be on the ' \
|
112
|
-
|
113
|
-
|
112
|
+
'line after the last parameter when opening brace is on a separate ' \
|
113
|
+
'line from the first parameter.'
|
114
114
|
|
115
115
|
ALWAYS_NEW_LINE_MESSAGE = 'Closing method definition brace must be ' \
|
116
|
-
|
116
|
+
'on the line after the last parameter.'
|
117
117
|
|
118
118
|
ALWAYS_SAME_LINE_MESSAGE = 'Closing method definition brace must be ' \
|
119
|
-
|
119
|
+
'on the same line as the last parameter.'
|
120
120
|
|
121
121
|
def on_def(node)
|
122
122
|
check_brace_layout(node.arguments)
|
@@ -59,9 +59,9 @@ module RuboCop
|
|
59
59
|
return unless style == :aligned && cop_config['IndentationWidth']
|
60
60
|
|
61
61
|
raise ValidationError, 'The `Layout/MultilineOperationIndentation`' \
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
' cop only accepts an `IndentationWidth` ' \
|
63
|
+
'configuration parameter when ' \
|
64
|
+
'`EnforcedStyle` is `indented`.'
|
65
65
|
end
|
66
66
|
|
67
67
|
private
|
@@ -73,10 +73,10 @@ module RuboCop
|
|
73
73
|
extend AutoCorrector
|
74
74
|
|
75
75
|
ALIGN_PARAMS_MSG = 'Align the parameters of a method definition if ' \
|
76
|
-
|
76
|
+
'they span more than one line.'
|
77
77
|
|
78
78
|
FIXED_INDENT_MSG = 'Use one level of indentation for parameters ' \
|
79
|
-
|
79
|
+
'following the first line of a multi-line method definition.'
|
80
80
|
|
81
81
|
def on_def(node)
|
82
82
|
return if node.arguments.size < 2
|
@@ -42,8 +42,9 @@ module RuboCop
|
|
42
42
|
# # good
|
43
43
|
# foo(a) { |x| puts x }
|
44
44
|
#
|
45
|
-
class RedundantLineBreak <
|
45
|
+
class RedundantLineBreak < Base
|
46
46
|
include CheckAssignment
|
47
|
+
extend AutoCorrector
|
47
48
|
|
48
49
|
MSG = 'Redundant line break detected.'
|
49
50
|
|
@@ -55,23 +56,24 @@ module RuboCop
|
|
55
56
|
|
56
57
|
return unless offense?(node) && !part_of_ignored_node?(node)
|
57
58
|
|
58
|
-
|
59
|
-
ignore_node(node)
|
59
|
+
register_offense(node)
|
60
60
|
end
|
61
61
|
|
62
|
+
private
|
63
|
+
|
62
64
|
def check_assignment(node, _rhs)
|
63
65
|
return unless offense?(node)
|
64
66
|
|
65
|
-
|
66
|
-
ignore_node(node)
|
67
|
+
register_offense(node)
|
67
68
|
end
|
68
69
|
|
69
|
-
def
|
70
|
-
|
70
|
+
def register_offense(node)
|
71
|
+
add_offense(node) do |corrector|
|
72
|
+
corrector.replace(node.source_range, to_single_line(node.source).strip)
|
73
|
+
end
|
74
|
+
ignore_node(node)
|
71
75
|
end
|
72
76
|
|
73
|
-
private
|
74
|
-
|
75
77
|
def offense?(node)
|
76
78
|
return false if configured_to_not_be_inspected?(node)
|
77
79
|
|
@@ -53,6 +53,10 @@ module RuboCop
|
|
53
53
|
check(node, %i[keyword else].freeze)
|
54
54
|
end
|
55
55
|
|
56
|
+
def on_case_match(node)
|
57
|
+
check(node, %i[keyword else].freeze)
|
58
|
+
end
|
59
|
+
|
56
60
|
def on_ensure(node)
|
57
61
|
check(node, [:keyword].freeze)
|
58
62
|
end
|
@@ -65,10 +69,30 @@ module RuboCop
|
|
65
69
|
check(node, %i[keyword else begin end].freeze, 'then')
|
66
70
|
end
|
67
71
|
|
72
|
+
def on_if_guard(node)
|
73
|
+
check(node, [:keyword].freeze)
|
74
|
+
end
|
75
|
+
|
76
|
+
def on_in_pattern(node)
|
77
|
+
check(node, [:keyword].freeze)
|
78
|
+
end
|
79
|
+
|
68
80
|
def on_kwbegin(node)
|
69
81
|
check(node, %i[begin end].freeze, nil)
|
70
82
|
end
|
71
83
|
|
84
|
+
# Handle one-line pattern matching syntax (`in`) with `Parser::Ruby27`.
|
85
|
+
def on_match_pattern(node)
|
86
|
+
return if target_ruby_version >= 3.0
|
87
|
+
|
88
|
+
check(node, [:operator].freeze)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Handle one-line pattern matching syntax (`in`) with `Parser::Ruby30`.
|
92
|
+
def on_match_pattern_p(node)
|
93
|
+
check(node, [:operator].freeze)
|
94
|
+
end
|
95
|
+
|
72
96
|
def on_next(node)
|
73
97
|
check(node, [:keyword].freeze)
|
74
98
|
end
|
@@ -109,6 +133,10 @@ module RuboCop
|
|
109
133
|
check(node, [:keyword].freeze)
|
110
134
|
end
|
111
135
|
|
136
|
+
def on_unless_guard(node)
|
137
|
+
check(node, [:keyword].freeze)
|
138
|
+
end
|
139
|
+
|
112
140
|
def on_until(node)
|
113
141
|
check(node, %i[begin end keyword].freeze)
|
114
142
|
end
|