rubocop 0.67.2 → 0.68.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/README.md +1 -1
- data/config/default.yml +86 -233
- data/exe/rubocop +0 -12
- data/lib/rubocop.rb +13 -30
- data/lib/rubocop/ast/builder.rb +4 -0
- data/lib/rubocop/ast/node/alias_node.rb +24 -0
- data/lib/rubocop/ast/node/class_node.rb +31 -0
- data/lib/rubocop/ast/node/module_node.rb +24 -0
- data/lib/rubocop/ast/node/range_node.rb +7 -0
- data/lib/rubocop/ast/node/resbody_node.rb +12 -0
- data/lib/rubocop/ast/node/self_class_node.rb +24 -0
- data/lib/rubocop/cli.rb +40 -4
- data/lib/rubocop/config.rb +9 -7
- data/lib/rubocop/config_loader.rb +48 -7
- data/lib/rubocop/config_loader_resolver.rb +5 -4
- data/lib/rubocop/cop/commissioner.rb +24 -0
- data/lib/rubocop/cop/correctors/unused_arg_corrector.rb +18 -6
- data/lib/rubocop/cop/internal_affairs/node_destructuring.rb +12 -14
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +9 -20
- data/lib/rubocop/cop/layout/align_arguments.rb +93 -0
- data/lib/rubocop/cop/layout/align_parameters.rb +57 -33
- data/lib/rubocop/cop/layout/class_structure.rb +5 -5
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +6 -8
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +3 -6
- data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +1 -2
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +1 -0
- data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +292 -0
- data/lib/rubocop/cop/layout/{first_parameter_indentation.rb → indent_first_argument.rb} +11 -12
- data/lib/rubocop/cop/layout/{indent_array.rb → indent_first_array_element.rb} +2 -2
- data/lib/rubocop/cop/layout/{indent_hash.rb → indent_first_hash_element.rb} +2 -2
- data/lib/rubocop/cop/layout/indent_first_parameter.rb +96 -0
- data/lib/rubocop/cop/layout/indentation_width.rb +4 -16
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +2 -4
- data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -16
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -2
- data/lib/rubocop/cop/lint/duplicate_methods.rb +6 -8
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +4 -8
- data/lib/rubocop/cop/lint/heredoc_method_call_position.rb +157 -0
- data/lib/rubocop/cop/lint/inherit_exception.rb +3 -4
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +18 -1
- data/lib/rubocop/cop/lint/non_local_exit_from_iterator.rb +3 -5
- data/lib/rubocop/cop/lint/underscore_prefixed_variable_name.rb +25 -5
- data/lib/rubocop/cop/lint/useless_assignment.rb +2 -6
- data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -2
- data/lib/rubocop/cop/message_annotator.rb +1 -0
- data/lib/rubocop/cop/metrics/line_length.rb +139 -28
- data/lib/rubocop/cop/metrics/perceived_complexity.rb +3 -4
- data/lib/rubocop/cop/mixin/check_line_breakable.rb +190 -0
- data/lib/rubocop/cop/mixin/{array_hash_indentation.rb → multiline_element_indentation.rb} +3 -2
- data/lib/rubocop/cop/mixin/too_many_lines.rb +3 -7
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +33 -4
- data/lib/rubocop/cop/rails/active_record_override.rb +23 -8
- data/lib/rubocop/cop/rails/delegate.rb +5 -8
- data/lib/rubocop/cop/rails/environment_comparison.rb +5 -3
- data/lib/rubocop/cop/rails/find_each.rb +1 -1
- data/lib/rubocop/cop/rails/redundant_allow_nil.rb +3 -3
- data/lib/rubocop/cop/rails/reflection_class_name.rb +1 -1
- data/lib/rubocop/cop/rails/skips_model_validations.rb +6 -7
- data/lib/rubocop/cop/rails/time_zone.rb +3 -10
- data/lib/rubocop/cop/rails/validation.rb +3 -0
- data/lib/rubocop/cop/registry.rb +3 -3
- data/lib/rubocop/cop/style/alias.rb +13 -7
- data/lib/rubocop/cop/style/block_delimiters.rb +20 -0
- data/lib/rubocop/cop/style/class_and_module_children.rb +19 -21
- data/lib/rubocop/cop/style/class_methods.rb +16 -24
- data/lib/rubocop/cop/style/conditional_assignment.rb +20 -49
- data/lib/rubocop/cop/style/documentation.rb +3 -7
- data/lib/rubocop/cop/style/format_string.rb +18 -21
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
- data/lib/rubocop/cop/style/inverse_methods.rb +4 -0
- data/lib/rubocop/cop/style/lambda.rb +12 -8
- data/lib/rubocop/cop/style/mixin_grouping.rb +8 -10
- data/lib/rubocop/cop/style/module_function.rb +2 -3
- data/lib/rubocop/cop/style/next.rb +10 -14
- data/lib/rubocop/cop/style/one_line_conditional.rb +5 -3
- data/lib/rubocop/cop/style/optional_arguments.rb +1 -4
- data/lib/rubocop/cop/style/random_with_offset.rb +44 -47
- data/lib/rubocop/cop/style/redundant_return.rb +6 -14
- data/lib/rubocop/cop/style/redundant_sort_by.rb +1 -1
- data/lib/rubocop/cop/style/safe_navigation.rb +3 -0
- data/lib/rubocop/cop/style/struct_inheritance.rb +2 -3
- data/lib/rubocop/cop/style/symbol_proc.rb +20 -40
- data/lib/rubocop/cop/style/unless_else.rb +1 -2
- data/lib/rubocop/cop/style/yoda_condition.rb +8 -7
- data/lib/rubocop/cop/util.rb +2 -4
- data/lib/rubocop/file_finder.rb +5 -10
- data/lib/rubocop/formatter/disabled_config_formatter.rb +5 -0
- data/lib/rubocop/node_pattern.rb +304 -170
- data/lib/rubocop/options.rb +4 -1
- data/lib/rubocop/rspec/shared_contexts.rb +3 -0
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop/yaml_duplication_checker.rb +1 -1
- metadata +26 -50
- data/lib/rubocop/cop/performance/caller.rb +0 -69
- data/lib/rubocop/cop/performance/case_when_splat.rb +0 -177
- data/lib/rubocop/cop/performance/casecmp.rb +0 -108
- data/lib/rubocop/cop/performance/chain_array_allocation.rb +0 -78
- data/lib/rubocop/cop/performance/compare_with_block.rb +0 -122
- data/lib/rubocop/cop/performance/count.rb +0 -102
- data/lib/rubocop/cop/performance/detect.rb +0 -110
- data/lib/rubocop/cop/performance/double_start_end_with.rb +0 -94
- data/lib/rubocop/cop/performance/end_with.rb +0 -56
- data/lib/rubocop/cop/performance/fixed_size.rb +0 -97
- data/lib/rubocop/cop/performance/flat_map.rb +0 -78
- data/lib/rubocop/cop/performance/inefficient_hash_search.rb +0 -99
- data/lib/rubocop/cop/performance/open_struct.rb +0 -46
- data/lib/rubocop/cop/performance/range_include.rb +0 -50
- data/lib/rubocop/cop/performance/redundant_block_call.rb +0 -93
- data/lib/rubocop/cop/performance/redundant_match.rb +0 -56
- data/lib/rubocop/cop/performance/redundant_merge.rb +0 -183
- data/lib/rubocop/cop/performance/regexp_match.rb +0 -265
- data/lib/rubocop/cop/performance/reverse_each.rb +0 -42
- data/lib/rubocop/cop/performance/size.rb +0 -77
- data/lib/rubocop/cop/performance/start_with.rb +0 -59
- data/lib/rubocop/cop/performance/string_replacement.rb +0 -173
- data/lib/rubocop/cop/performance/times_map.rb +0 -71
- data/lib/rubocop/cop/performance/unfreeze_string.rb +0 -50
- data/lib/rubocop/cop/performance/uri_default_parser.rb +0 -47
@@ -36,10 +36,8 @@ module RuboCop
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def on_class(node)
|
39
|
-
|
40
|
-
|
41
|
-
@class_or_module_def_first_line = if superclass
|
42
|
-
superclass.first_line
|
39
|
+
@class_or_module_def_first_line = if node.parent_class
|
40
|
+
node.parent_class.first_line
|
43
41
|
else
|
44
42
|
node.source_range.first_line
|
45
43
|
end
|
@@ -52,10 +50,10 @@ module RuboCop
|
|
52
50
|
end
|
53
51
|
|
54
52
|
def on_sclass(node)
|
55
|
-
|
56
|
-
|
57
|
-
@
|
58
|
-
|
53
|
+
@class_or_module_def_first_line =
|
54
|
+
node.identifier.source_range.first_line
|
55
|
+
@class_or_module_def_last_line =
|
56
|
+
node.source_range.last_line
|
59
57
|
end
|
60
58
|
|
61
59
|
def on_block(node)
|
@@ -70,16 +70,13 @@ module RuboCop
|
|
70
70
|
KIND = 'class'.freeze
|
71
71
|
|
72
72
|
def on_class(node)
|
73
|
-
|
73
|
+
first_line = node.parent_class.first_line if node.parent_class
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
check(node, body, adjusted_first_line: adjusted_first_line)
|
75
|
+
check(node, node.body, adjusted_first_line: first_line)
|
78
76
|
end
|
79
77
|
|
80
78
|
def on_sclass(node)
|
81
|
-
|
82
|
-
check(node, body)
|
79
|
+
check(node, node.body)
|
83
80
|
end
|
84
81
|
|
85
82
|
def autocorrect(node)
|
@@ -0,0 +1,292 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Layout
|
6
|
+
# This cop checks for the placement of the closing parenthesis
|
7
|
+
# in a method call that passes a HEREDOC string as an argument.
|
8
|
+
# It should be placed at the end of the line containing the
|
9
|
+
# opening HEREDOC tag.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# # bad
|
13
|
+
#
|
14
|
+
# foo(<<-SQL
|
15
|
+
# bar
|
16
|
+
# SQL
|
17
|
+
# )
|
18
|
+
#
|
19
|
+
# foo(<<-SQL, 123, <<-NOSQL,
|
20
|
+
# bar
|
21
|
+
# SQL
|
22
|
+
# baz
|
23
|
+
# NOSQL
|
24
|
+
# )
|
25
|
+
#
|
26
|
+
# foo(
|
27
|
+
# bar(<<-SQL
|
28
|
+
# baz
|
29
|
+
# SQL
|
30
|
+
# ),
|
31
|
+
# 123,
|
32
|
+
# )
|
33
|
+
#
|
34
|
+
# # good
|
35
|
+
#
|
36
|
+
# foo(<<-SQL)
|
37
|
+
# bar
|
38
|
+
# SQL
|
39
|
+
#
|
40
|
+
# foo(<<-SQL, 123, <<-NOSQL)
|
41
|
+
# bar
|
42
|
+
# SQL
|
43
|
+
# baz
|
44
|
+
# NOSQL
|
45
|
+
#
|
46
|
+
# foo(
|
47
|
+
# bar(<<-SQL),
|
48
|
+
# baz
|
49
|
+
# SQL
|
50
|
+
# 123,
|
51
|
+
# )
|
52
|
+
#
|
53
|
+
class HeredocArgumentClosingParenthesis < Cop
|
54
|
+
include RangeHelp
|
55
|
+
|
56
|
+
MSG = 'Put the closing parenthesis for a method call with a ' \
|
57
|
+
'HEREDOC parameter on the same line as the HEREDOC opening.'.freeze
|
58
|
+
|
59
|
+
STRING_TYPES = %i[str dstr xstr].freeze
|
60
|
+
def on_send(node)
|
61
|
+
heredoc_arg = extract_heredoc_argument(node)
|
62
|
+
return unless heredoc_arg
|
63
|
+
|
64
|
+
outermost_send = outermost_send_on_same_line(heredoc_arg)
|
65
|
+
return unless outermost_send
|
66
|
+
return unless outermost_send.loc.end
|
67
|
+
return unless heredoc_arg.first_line != outermost_send.loc.end.line
|
68
|
+
|
69
|
+
add_offense(outermost_send, location: :end)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Autocorrection note:
|
73
|
+
#
|
74
|
+
# Commas are a bit tricky to handle when the method call is
|
75
|
+
# embedded in another expression. Here's an example:
|
76
|
+
#
|
77
|
+
# [
|
78
|
+
# first_array_value,
|
79
|
+
# foo(<<-SQL, 123, 456,
|
80
|
+
# SELECT * FROM db
|
81
|
+
# SQL
|
82
|
+
# ),
|
83
|
+
# third_array_value,
|
84
|
+
# ]
|
85
|
+
#
|
86
|
+
# The "internal" trailing comma is after `456`.
|
87
|
+
# The "external" trailing comma is after `)`.
|
88
|
+
#
|
89
|
+
# To autocorrect, we remove the latter, and move the former up:
|
90
|
+
#
|
91
|
+
# [
|
92
|
+
# first_array_value,
|
93
|
+
# foo(<<-SQL, 123, 456),
|
94
|
+
# SELECT * FROM db
|
95
|
+
# SQL
|
96
|
+
# third_array_value,
|
97
|
+
# ]
|
98
|
+
def autocorrect(node)
|
99
|
+
lambda do |corrector|
|
100
|
+
fix_closing_parenthesis(node, corrector)
|
101
|
+
|
102
|
+
if internal_trailing_comma?(node)
|
103
|
+
remove_internal_trailing_comma(node, corrector)
|
104
|
+
end
|
105
|
+
|
106
|
+
if external_trailing_comma?(node)
|
107
|
+
fix_external_trailing_comma(node, corrector)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def outermost_send_on_same_line(heredoc)
|
115
|
+
previous = heredoc
|
116
|
+
current = previous.parent
|
117
|
+
until send_missing_closing_parens?(current, previous, heredoc)
|
118
|
+
previous = current
|
119
|
+
current = current.parent
|
120
|
+
return unless previous && current
|
121
|
+
end
|
122
|
+
current
|
123
|
+
end
|
124
|
+
|
125
|
+
def send_missing_closing_parens?(parent, child, heredoc)
|
126
|
+
send_node?(parent) &&
|
127
|
+
parent.arguments.include?(child) &&
|
128
|
+
parent.loc.begin &&
|
129
|
+
parent.loc.end.line != heredoc.last_line
|
130
|
+
end
|
131
|
+
|
132
|
+
def send_node?(node)
|
133
|
+
return nil unless node
|
134
|
+
|
135
|
+
node.send_type? || node.csend_type?
|
136
|
+
end
|
137
|
+
|
138
|
+
def extract_heredoc_argument(node)
|
139
|
+
node.arguments.find do |arg_node|
|
140
|
+
extract_heredoc(arg_node)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def extract_heredoc(node)
|
145
|
+
return node if heredoc_node?(node)
|
146
|
+
return node.receiver if single_line_send_with_heredoc_receiver?(node)
|
147
|
+
|
148
|
+
return unless node.hash_type?
|
149
|
+
|
150
|
+
node.values.find do |v|
|
151
|
+
heredoc = extract_heredoc(v)
|
152
|
+
return heredoc if heredoc
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def heredoc_node?(node)
|
157
|
+
node && STRING_TYPES.include?(node.type) && node.heredoc?
|
158
|
+
end
|
159
|
+
|
160
|
+
def single_line_send_with_heredoc_receiver?(node)
|
161
|
+
return false unless node.send_type?
|
162
|
+
return false unless heredoc_node?(node.receiver)
|
163
|
+
|
164
|
+
node.receiver.location.heredoc_end.end_pos > node.source_range.end_pos
|
165
|
+
end
|
166
|
+
|
167
|
+
# Closing parenthesis helpers.
|
168
|
+
|
169
|
+
def fix_closing_parenthesis(node, corrector)
|
170
|
+
remove_incorrect_closing_paren(node, corrector)
|
171
|
+
add_correct_closing_paren(node, corrector)
|
172
|
+
end
|
173
|
+
|
174
|
+
def add_correct_closing_paren(node, corrector)
|
175
|
+
corrector.insert_after(node.arguments.last.source_range, ')')
|
176
|
+
end
|
177
|
+
|
178
|
+
def remove_incorrect_closing_paren(node, corrector)
|
179
|
+
corrector.remove(
|
180
|
+
range_between(
|
181
|
+
incorrect_parenthesis_removal_begin(node),
|
182
|
+
incorrect_parenthesis_removal_end(node)
|
183
|
+
)
|
184
|
+
)
|
185
|
+
end
|
186
|
+
|
187
|
+
def incorrect_parenthesis_removal_begin(node)
|
188
|
+
end_pos = node.source_range.end_pos
|
189
|
+
if safe_to_remove_line_containing_closing_paren?(node)
|
190
|
+
last_line_length = node.source.scan(/\n(.*)$/).last[0].size
|
191
|
+
end_pos - last_line_length - 1 # Add one for the line break itself.
|
192
|
+
else
|
193
|
+
end_pos - 1 # Just the `)` at the end of the string
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def safe_to_remove_line_containing_closing_paren?(node)
|
198
|
+
last_line = processed_source[node.loc.end.line - 1]
|
199
|
+
# Safe to remove if last line only contains `)`, `,`, and whitespace.
|
200
|
+
last_line.match(/^[ ]*\)[ ]{0,20},{0,1}[ ]*$/)
|
201
|
+
end
|
202
|
+
|
203
|
+
def incorrect_parenthesis_removal_end(node)
|
204
|
+
end_pos = node.source_range.end_pos
|
205
|
+
if processed_source.buffer.source[end_pos] == ','
|
206
|
+
end_pos + 1
|
207
|
+
else
|
208
|
+
end_pos
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
# Internal trailing comma helpers.
|
213
|
+
|
214
|
+
def remove_internal_trailing_comma(node, corrector)
|
215
|
+
offset = internal_trailing_comma_offset_from_last_arg(node)
|
216
|
+
last_arg_end_pos = node.children.last.source_range.end_pos
|
217
|
+
corrector.remove(
|
218
|
+
range_between(
|
219
|
+
last_arg_end_pos,
|
220
|
+
last_arg_end_pos + offset
|
221
|
+
)
|
222
|
+
)
|
223
|
+
end
|
224
|
+
|
225
|
+
def internal_trailing_comma?(node)
|
226
|
+
!internal_trailing_comma_offset_from_last_arg(node).nil?
|
227
|
+
end
|
228
|
+
|
229
|
+
# Returns nil if no trailing internal comma.
|
230
|
+
def internal_trailing_comma_offset_from_last_arg(node)
|
231
|
+
source_after_last_arg = range_between(
|
232
|
+
node.children.last.source_range.end_pos,
|
233
|
+
node.loc.end.begin_pos
|
234
|
+
).source
|
235
|
+
|
236
|
+
first_comma_offset = source_after_last_arg.index(',')
|
237
|
+
first_new_line_offset = source_after_last_arg.index("\n")
|
238
|
+
return if first_comma_offset.nil?
|
239
|
+
return if first_new_line_offset.nil?
|
240
|
+
return if first_comma_offset > first_new_line_offset
|
241
|
+
|
242
|
+
first_comma_offset + 1
|
243
|
+
end
|
244
|
+
|
245
|
+
# External trailing comma helpers.
|
246
|
+
|
247
|
+
def fix_external_trailing_comma(node, corrector)
|
248
|
+
remove_incorrect_external_trailing_comma(node, corrector)
|
249
|
+
add_correct_external_trailing_comma(node, corrector)
|
250
|
+
end
|
251
|
+
|
252
|
+
def add_correct_external_trailing_comma(node, corrector)
|
253
|
+
return unless external_trailing_comma?(node)
|
254
|
+
|
255
|
+
corrector.insert_after(node.arguments.last.source_range, ',')
|
256
|
+
end
|
257
|
+
|
258
|
+
def remove_incorrect_external_trailing_comma(node, corrector)
|
259
|
+
end_pos = node.source_range.end_pos
|
260
|
+
return unless external_trailing_comma?(node)
|
261
|
+
|
262
|
+
corrector.remove(
|
263
|
+
range_between(
|
264
|
+
end_pos,
|
265
|
+
end_pos + external_trailing_comma_offset_from_loc_end(node)
|
266
|
+
)
|
267
|
+
)
|
268
|
+
end
|
269
|
+
|
270
|
+
def external_trailing_comma?(node)
|
271
|
+
!external_trailing_comma_offset_from_loc_end(node).nil?
|
272
|
+
end
|
273
|
+
|
274
|
+
# Returns nil if no trailing external comma.
|
275
|
+
def external_trailing_comma_offset_from_loc_end(node)
|
276
|
+
end_pos = node.source_range.end_pos
|
277
|
+
offset = 0
|
278
|
+
limit = 20
|
279
|
+
offset += 1 while offset < limit && space?(end_pos + offset)
|
280
|
+
char = processed_source.buffer.source[end_pos + offset]
|
281
|
+
return unless char == ','
|
282
|
+
|
283
|
+
offset + 1 # Add one to include the comma.
|
284
|
+
end
|
285
|
+
|
286
|
+
def space?(pos)
|
287
|
+
processed_source.buffer.source[pos] == ' '
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
@@ -4,9 +4,8 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
# rubocop:disable Metrics/LineLength
|
6
6
|
module Layout
|
7
|
-
# This cop checks the indentation of the first
|
8
|
-
#
|
9
|
-
# not by this cop.
|
7
|
+
# This cop checks the indentation of the first argument in a method call
|
8
|
+
# or definition.
|
10
9
|
#
|
11
10
|
# @example
|
12
11
|
#
|
@@ -33,7 +32,7 @@ module RuboCop
|
|
33
32
|
# second_param
|
34
33
|
#
|
35
34
|
# @example EnforcedStyle: consistent
|
36
|
-
# # The first
|
35
|
+
# # The first argument should always be indented one step more than the
|
37
36
|
# # preceding line.
|
38
37
|
#
|
39
38
|
# # good
|
@@ -59,8 +58,8 @@ module RuboCop
|
|
59
58
|
# second_param
|
60
59
|
#
|
61
60
|
# @example EnforcedStyle: consistent_relative_to_receiver
|
62
|
-
# # The first
|
63
|
-
# # the parent that is receiving the
|
61
|
+
# # The first argument should always be indented one level relative to
|
62
|
+
# # the parent that is receiving the argument
|
64
63
|
#
|
65
64
|
# # good
|
66
65
|
# some_method(
|
@@ -85,9 +84,9 @@ module RuboCop
|
|
85
84
|
# second_params
|
86
85
|
#
|
87
86
|
# @example EnforcedStyle: special_for_inner_method_call
|
88
|
-
# # The first
|
89
|
-
# # the preceding line, but if it's a
|
90
|
-
# # is itself a
|
87
|
+
# # The first argument should normally be indented one step more than
|
88
|
+
# # the preceding line, but if it's a argument for a method call that
|
89
|
+
# # is itself a argument in a method call, then the inner argument
|
91
90
|
# # should be indented relative to the inner method.
|
92
91
|
#
|
93
92
|
# # good
|
@@ -139,13 +138,13 @@ module RuboCop
|
|
139
138
|
# nested_first_param),
|
140
139
|
# second_param
|
141
140
|
#
|
142
|
-
class
|
141
|
+
class IndentFirstArgument < Cop
|
143
142
|
# rubocop:enable Metrics/LineLength
|
144
143
|
include Alignment
|
145
144
|
include ConfigurableEnforcedStyle
|
146
145
|
include RangeHelp
|
147
146
|
|
148
|
-
MSG = 'Indent the first
|
147
|
+
MSG = 'Indent the first argument one step more than %<base>s.'.freeze
|
149
148
|
|
150
149
|
def on_send(node)
|
151
150
|
return if !node.arguments? || node.operator_method?
|
@@ -163,7 +162,7 @@ module RuboCop
|
|
163
162
|
private
|
164
163
|
|
165
164
|
def message(arg_node)
|
166
|
-
return 'Bad indentation of the first
|
165
|
+
return 'Bad indentation of the first argument.' unless arg_node
|
167
166
|
|
168
167
|
send_node = arg_node.parent
|
169
168
|
text = base_range(send_node, arg_node).source.strip
|
@@ -79,10 +79,10 @@ module RuboCop
|
|
79
79
|
# and_now_for_something = [
|
80
80
|
# :completely_different
|
81
81
|
# ]
|
82
|
-
class
|
82
|
+
class IndentFirstArrayElement < Cop
|
83
83
|
include Alignment
|
84
84
|
include ConfigurableEnforcedStyle
|
85
|
-
include
|
85
|
+
include MultilineElementIndentation
|
86
86
|
|
87
87
|
MSG = 'Use %<configured_indentation_width>d spaces for indentation ' \
|
88
88
|
'in an array, relative to %<base_description>s.'.freeze
|
@@ -77,10 +77,10 @@ module RuboCop
|
|
77
77
|
# and_now_for_something = {
|
78
78
|
# completely: :different
|
79
79
|
# }
|
80
|
-
class
|
80
|
+
class IndentFirstHashElement < Cop
|
81
81
|
include Alignment
|
82
82
|
include ConfigurableEnforcedStyle
|
83
|
-
include
|
83
|
+
include MultilineElementIndentation
|
84
84
|
|
85
85
|
MSG = 'Use %<configured_indentation_width>d spaces for indentation ' \
|
86
86
|
'in a hash, relative to %<base_description>s.'.freeze
|