rubocop 0.52.0 → 0.52.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -5
- data/config/default.yml +1 -11
- data/config/disabled.yml +5 -0
- data/config/enabled.yml +6 -8
- data/lib/rubocop.rb +13 -2
- data/lib/rubocop/ast/node.rb +23 -15
- data/lib/rubocop/cli.rb +25 -2
- data/lib/rubocop/config.rb +23 -8
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -2
- data/lib/rubocop/cop/bundler/ordered_gems.rb +9 -0
- data/lib/rubocop/cop/commissioner.rb +1 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +121 -0
- data/lib/rubocop/cop/correctors/condition_corrector.rb +28 -0
- data/lib/rubocop/cop/correctors/empty_line_corrector.rb +26 -0
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +62 -0
- data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +44 -0
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +31 -0
- data/lib/rubocop/cop/correctors/punctuation_corrector.rb +29 -0
- data/lib/rubocop/cop/correctors/space_corrector.rb +34 -0
- data/lib/rubocop/cop/correctors/string_literal_corrector.rb +25 -0
- data/lib/rubocop/cop/correctors/unused_arg_corrector.rb +31 -0
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +9 -0
- data/lib/rubocop/cop/generator.rb +18 -87
- data/lib/rubocop/cop/generator/require_file_injector.rb +78 -0
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +5 -1
- data/lib/rubocop/cop/layout/align_array.rb +5 -1
- data/lib/rubocop/cop/layout/align_hash.rb +1 -1
- data/lib/rubocop/cop/layout/align_parameters.rb +5 -1
- data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/class_structure.rb +2 -2
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +5 -1
- data/lib/rubocop/cop/layout/comment_indentation.rb +5 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +5 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +3 -3
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +17 -19
- data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +4 -0
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +4 -0
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +4 -0
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +4 -0
- data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +4 -0
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +6 -2
- data/lib/rubocop/cop/layout/indent_array.rb +6 -2
- data/lib/rubocop/cop/layout/indent_assignment.rb +6 -2
- data/lib/rubocop/cop/layout/indent_hash.rb +5 -1
- data/lib/rubocop/cop/layout/indentation_consistency.rb +5 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +5 -1
- data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +4 -0
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +3 -3
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -2
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +4 -0
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +4 -0
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +6 -2
- data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +4 -0
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +6 -2
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +3 -1
- data/lib/rubocop/cop/layout/space_after_comma.rb +4 -0
- data/lib/rubocop/cop/layout/space_after_semicolon.rb +4 -0
- data/lib/rubocop/cop/layout/space_before_comma.rb +4 -0
- data/lib/rubocop/cop/layout/space_before_semicolon.rb +4 -0
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +3 -2
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +16 -7
- data/lib/rubocop/cop/layout/tab.rb +1 -1
- data/lib/rubocop/cop/lint/block_alignment.rb +1 -1
- data/lib/rubocop/cop/lint/def_end_alignment.rb +2 -2
- data/lib/rubocop/cop/lint/end_alignment.rb +3 -1
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/unused_block_argument.rb +4 -0
- data/lib/rubocop/cop/lint/unused_method_argument.rb +6 -0
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -1
- data/lib/rubocop/cop/mixin/alignment.rb +70 -0
- data/lib/rubocop/cop/mixin/array_hash_indentation.rb +2 -0
- data/lib/rubocop/cop/mixin/array_syntax.rb +2 -0
- data/lib/rubocop/cop/mixin/code_length.rb +2 -0
- data/lib/rubocop/cop/mixin/configurable_max.rb +2 -0
- data/lib/rubocop/cop/mixin/def_node.rb +3 -1
- data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +3 -15
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -25
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +0 -6
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +5 -9
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +2 -2
- data/lib/rubocop/cop/mixin/ignored_pattern.rb +2 -0
- data/lib/rubocop/cop/mixin/integer_node.rb +2 -0
- data/lib/rubocop/cop/mixin/match_range.rb +2 -0
- data/lib/rubocop/cop/mixin/min_body_length.rb +2 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -0
- data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +9 -48
- data/lib/rubocop/cop/mixin/negative_conditional.rb +2 -16
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +12 -31
- data/lib/rubocop/cop/mixin/parentheses.rb +2 -19
- data/lib/rubocop/cop/mixin/percent_literal.rb +3 -3
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +2 -0
- data/lib/rubocop/cop/mixin/rescue_node.rb +2 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +2 -0
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -3
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -3
- data/lib/rubocop/cop/mixin/statement_modifier.rb +4 -2
- data/lib/rubocop/cop/mixin/string_help.rb +2 -0
- data/lib/rubocop/cop/mixin/string_literals_help.rb +2 -13
- data/lib/rubocop/cop/mixin/surrounding_space.rb +4 -21
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -10
- data/lib/rubocop/cop/mixin/unused_argument.rb +2 -15
- data/lib/rubocop/cop/performance/case_when_splat.rb +1 -1
- data/lib/rubocop/cop/rails/action_filter.rb +3 -2
- data/lib/rubocop/cop/rails/active_support_aliases.rb +3 -2
- data/lib/rubocop/cop/rails/application_job.rb +6 -0
- data/lib/rubocop/cop/rails/application_record.rb +6 -0
- data/lib/rubocop/cop/rails/blank.rb +10 -9
- data/lib/rubocop/cop/rails/date.rb +22 -14
- data/lib/rubocop/cop/rails/delegate.rb +1 -1
- data/lib/rubocop/cop/rails/dynamic_find_by.rb +3 -2
- data/lib/rubocop/cop/rails/enum_uniqueness.rb +4 -2
- data/lib/rubocop/cop/rails/environment_comparison.rb +2 -2
- data/lib/rubocop/cop/rails/file_path.rb +1 -1
- data/lib/rubocop/cop/rails/find_by.rb +2 -2
- data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +15 -7
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +2 -2
- data/lib/rubocop/cop/rails/inverse_of.rb +130 -8
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +3 -3
- data/lib/rubocop/cop/rails/pluralization_grammar.rb +3 -2
- data/lib/rubocop/cop/rails/presence.rb +31 -18
- data/lib/rubocop/cop/rails/present.rb +11 -8
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +52 -10
- data/lib/rubocop/cop/rails/request_referer.rb +2 -3
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +9 -2
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +38 -10
- data/lib/rubocop/cop/style/class_and_module_children.rb +76 -0
- data/lib/rubocop/cop/style/commented_keyword.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
- data/lib/rubocop/cop/style/format_string_token.rb +24 -4
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +46 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +4 -3
- data/lib/rubocop/cop/style/if_unless_modifier.rb +14 -0
- data/lib/rubocop/cop/style/method_def_parentheses.rb +79 -0
- data/lib/rubocop/cop/style/mixin_usage.rb +13 -2
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +19 -0
- data/lib/rubocop/cop/style/negated_if.rb +1 -1
- data/lib/rubocop/cop/style/negated_while.rb +6 -4
- data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +4 -0
- data/lib/rubocop/cop/style/redundant_conditional.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +4 -0
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
- data/lib/rubocop/cop/style/string_literals.rb +4 -0
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +4 -0
- data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +4 -0
- data/lib/rubocop/cop/style/trailing_comma_in_literal.rb +4 -0
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +33 -24
- data/lib/rubocop/options.rb +33 -10
- data/lib/rubocop/path_util.rb +7 -0
- data/lib/rubocop/token.rb +4 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +14 -4
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +0 -149
- data/lib/rubocop/cop/style/extend_self.rb +0 -92
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
# This default style is called 'special_inside_parentheses'. Alternative
|
20
20
|
# styles are 'consistent' and 'align_brackets'. Here are examples:
|
21
21
|
#
|
22
|
-
# @example EnforcedStyle: special_inside_parentheses
|
22
|
+
# @example EnforcedStyle: special_inside_parentheses (default)
|
23
23
|
# # The `special_inside_parentheses` style enforces that the first
|
24
24
|
# # element in an array literal where the opening bracket and first
|
25
25
|
# # element are on seprate lines is indented one step (two spaces) more
|
@@ -80,7 +80,7 @@ module RuboCop
|
|
80
80
|
# :completely_different
|
81
81
|
# ]
|
82
82
|
class IndentArray < Cop
|
83
|
-
include
|
83
|
+
include Alignment
|
84
84
|
include ConfigurableEnforcedStyle
|
85
85
|
include ArrayHashIndentation
|
86
86
|
|
@@ -97,6 +97,10 @@ module RuboCop
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
+
def autocorrect(node)
|
101
|
+
AlignmentCorrector.correct(processed_source, node, @column_delta)
|
102
|
+
end
|
103
|
+
|
100
104
|
private
|
101
105
|
|
102
106
|
def brace_alignment_style
|
@@ -23,7 +23,7 @@ module RuboCop
|
|
23
23
|
# other cops such as `IndentationConsistency` and `EndAlignment`.
|
24
24
|
class IndentAssignment < Cop
|
25
25
|
include CheckAssignment
|
26
|
-
include
|
26
|
+
include Alignment
|
27
27
|
|
28
28
|
MSG = 'Indent the first line of the right-hand-side of a ' \
|
29
29
|
'multi-line assignment.'.freeze
|
@@ -31,11 +31,15 @@ module RuboCop
|
|
31
31
|
def check_assignment(node, rhs)
|
32
32
|
return unless rhs
|
33
33
|
return unless node.loc.operator
|
34
|
-
return if node.loc.operator.line == rhs.
|
34
|
+
return if node.loc.operator.line == rhs.first_line
|
35
35
|
|
36
36
|
base = display_column(node.source_range)
|
37
37
|
check_alignment([rhs], base + configured_indentation_width)
|
38
38
|
end
|
39
|
+
|
40
|
+
def autocorrect(node)
|
41
|
+
AlignmentCorrector.correct(processed_source, node, column_delta)
|
42
|
+
end
|
39
43
|
end
|
40
44
|
end
|
41
45
|
end
|
@@ -78,7 +78,7 @@ module RuboCop
|
|
78
78
|
# completely: :different
|
79
79
|
# }
|
80
80
|
class IndentHash < Cop
|
81
|
-
include
|
81
|
+
include Alignment
|
82
82
|
include ConfigurableEnforcedStyle
|
83
83
|
include ArrayHashIndentation
|
84
84
|
|
@@ -95,6 +95,10 @@ module RuboCop
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
+
def autocorrect(node)
|
99
|
+
AlignmentCorrector.correct(processed_source, node, @column_delta)
|
100
|
+
end
|
101
|
+
|
98
102
|
private
|
99
103
|
|
100
104
|
def brace_alignment_style
|
@@ -14,7 +14,7 @@ module RuboCop
|
|
14
14
|
# end
|
15
15
|
# end
|
16
16
|
class IndentationConsistency < Cop
|
17
|
-
include
|
17
|
+
include Alignment
|
18
18
|
include ConfigurableEnforcedStyle
|
19
19
|
|
20
20
|
MSG = 'Inconsistent indentation detected.'.freeze
|
@@ -27,6 +27,10 @@ module RuboCop
|
|
27
27
|
check(node)
|
28
28
|
end
|
29
29
|
|
30
|
+
def autocorrect(node)
|
31
|
+
AlignmentCorrector.correct(processed_source, node, column_delta)
|
32
|
+
end
|
33
|
+
|
30
34
|
private
|
31
35
|
|
32
36
|
def check(node)
|
@@ -44,7 +44,7 @@ module RuboCop
|
|
44
44
|
# end
|
45
45
|
class IndentationWidth < Cop
|
46
46
|
include EndKeywordAlignment
|
47
|
-
include
|
47
|
+
include Alignment
|
48
48
|
include CheckAssignment
|
49
49
|
include IgnoredPattern
|
50
50
|
|
@@ -141,6 +141,10 @@ module RuboCop
|
|
141
141
|
check_if(node, node.body, node.else_branch, base.loc)
|
142
142
|
end
|
143
143
|
|
144
|
+
def autocorrect(node)
|
145
|
+
AlignmentCorrector.correct(processed_source, node, @column_delta)
|
146
|
+
end
|
147
|
+
|
144
148
|
private
|
145
149
|
|
146
150
|
def check_members(base, members)
|
@@ -44,7 +44,7 @@ module RuboCop
|
|
44
44
|
def check_assignment(node, rhs)
|
45
45
|
return unless rhs
|
46
46
|
return unless supported_types.include?(rhs.type)
|
47
|
-
return if rhs.
|
47
|
+
return if rhs.first_line == rhs.last_line
|
48
48
|
|
49
49
|
case style
|
50
50
|
when :new_line
|
@@ -55,13 +55,13 @@ module RuboCop
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def check_new_line_offense(node, rhs)
|
58
|
-
return unless node.loc.operator.line == rhs.
|
58
|
+
return unless node.loc.operator.line == rhs.first_line
|
59
59
|
|
60
60
|
add_offense(node, message: NEW_LINE_OFFENSE)
|
61
61
|
end
|
62
62
|
|
63
63
|
def check_same_line_offense(node, rhs)
|
64
|
-
return unless node.loc.operator.line != rhs.
|
64
|
+
return unless node.loc.operator.line != rhs.first_line
|
65
65
|
|
66
66
|
add_offense(node, message: SAME_LINE_OFFENSE)
|
67
67
|
end
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
48
48
|
add_offense_for_expression(node, node.arguments, ARG_MSG)
|
49
49
|
end
|
50
50
|
|
51
|
-
return unless node.body && node.loc.begin.line == node.body.
|
51
|
+
return unless node.body && node.loc.begin.line == node.body.first_line
|
52
52
|
|
53
53
|
add_offense_for_expression(node, node.body, MSG)
|
54
54
|
end
|
@@ -64,7 +64,7 @@ module RuboCop
|
|
64
64
|
|
65
65
|
expr_before_body ||= node.loc.begin
|
66
66
|
|
67
|
-
if expr_before_body.line == node.body.
|
67
|
+
if expr_before_body.line == node.body.first_line
|
68
68
|
autocorrect_body(corrector, node, node.body)
|
69
69
|
end
|
70
70
|
end
|
@@ -48,7 +48,7 @@ module RuboCop
|
|
48
48
|
# .c
|
49
49
|
class MultilineMethodCallIndentation < Cop
|
50
50
|
include ConfigurableEnforcedStyle
|
51
|
-
include
|
51
|
+
include Alignment
|
52
52
|
include MultilineExpressionIndentation
|
53
53
|
|
54
54
|
def validate_config
|
@@ -61,6 +61,10 @@ module RuboCop
|
|
61
61
|
'`EnforcedStyle` is `indented`.'
|
62
62
|
end
|
63
63
|
|
64
|
+
def autocorrect(node)
|
65
|
+
AlignmentCorrector.correct(processed_source, node, @column_delta)
|
66
|
+
end
|
67
|
+
|
64
68
|
private
|
65
69
|
|
66
70
|
def relevant_node?(send_node)
|
@@ -191,7 +195,7 @@ module RuboCop
|
|
191
195
|
node = node.parent
|
192
196
|
node = node.parent until node.loc.dot
|
193
197
|
|
194
|
-
return if node.loc.dot.line != node.
|
198
|
+
return if node.loc.dot.line != node.first_line
|
195
199
|
node
|
196
200
|
end
|
197
201
|
|
@@ -20,7 +20,7 @@ module RuboCop
|
|
20
20
|
# end
|
21
21
|
class MultilineOperationIndentation < Cop
|
22
22
|
include ConfigurableEnforcedStyle
|
23
|
-
include
|
23
|
+
include Alignment
|
24
24
|
include MultilineExpressionIndentation
|
25
25
|
|
26
26
|
def on_and(node)
|
@@ -40,6 +40,10 @@ module RuboCop
|
|
40
40
|
'`EnforcedStyle` is `indented`.'
|
41
41
|
end
|
42
42
|
|
43
|
+
def autocorrect(node)
|
44
|
+
AlignmentCorrector.correct(processed_source, node, @column_delta)
|
45
|
+
end
|
46
|
+
|
43
47
|
private
|
44
48
|
|
45
49
|
def relevant_node?(node)
|
@@ -54,7 +58,7 @@ module RuboCop
|
|
54
58
|
|
55
59
|
def offending_range(node, lhs, rhs, given_style)
|
56
60
|
return false unless begins_its_line?(rhs)
|
57
|
-
return false if lhs.
|
61
|
+
return false if lhs.first_line == rhs.line # Needed for unary op.
|
58
62
|
return false if not_for_this_cop?(node)
|
59
63
|
|
60
64
|
correct_column = if should_align?(node, rhs, given_style)
|
@@ -86,7 +86,9 @@ module RuboCop
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def ancestor_node(node)
|
89
|
-
|
89
|
+
types = %i[kwbegin def defs class module]
|
90
|
+
types << :block if target_ruby_version >= 2.5
|
91
|
+
node.each_ancestor(*types).first
|
90
92
|
end
|
91
93
|
end
|
92
94
|
end
|
@@ -17,6 +17,10 @@ module RuboCop
|
|
17
17
|
class SpaceAfterComma < Cop
|
18
18
|
include SpaceAfterPunctuation
|
19
19
|
|
20
|
+
def autocorrect(comma)
|
21
|
+
PunctuationCorrector.add_space(comma)
|
22
|
+
end
|
23
|
+
|
20
24
|
def space_style_before_rcurly
|
21
25
|
cfg = config.for_cop('Layout/SpaceInsideHashLiteralBraces')
|
22
26
|
cfg['EnforcedStyle'] || 'space'
|
@@ -14,6 +14,10 @@ module RuboCop
|
|
14
14
|
class SpaceAfterSemicolon < Cop
|
15
15
|
include SpaceAfterPunctuation
|
16
16
|
|
17
|
+
def autocorrect(semicolon)
|
18
|
+
PunctuationCorrector.add_space(semicolon)
|
19
|
+
end
|
20
|
+
|
17
21
|
def space_style_before_rcurly
|
18
22
|
cfg = config.for_cop('Layout/SpaceInsideBlockBraces')
|
19
23
|
cfg['EnforcedStyle'] || 'space'
|
@@ -63,9 +63,10 @@ module RuboCop
|
|
63
63
|
if empty_brackets?(left, right)
|
64
64
|
empty_corrections(corrector, left, right)
|
65
65
|
elsif style == :no_space
|
66
|
-
|
66
|
+
SpaceCorrector.remove_space(processed_source, corrector,
|
67
|
+
left, right)
|
67
68
|
elsif style == :space
|
68
|
-
|
69
|
+
SpaceCorrector.add_space(processed_source, corrector, left, right)
|
69
70
|
else
|
70
71
|
compact_corrections(corrector, node, left, right)
|
71
72
|
end
|
@@ -39,7 +39,7 @@ module RuboCop
|
|
39
39
|
return if node.multiline?
|
40
40
|
return unless left_ref_bracket(node)
|
41
41
|
left_token = left_ref_bracket(node)
|
42
|
-
right_token =
|
42
|
+
right_token = closing_bracket(node, left_token)
|
43
43
|
|
44
44
|
if style == :no_space
|
45
45
|
no_space_offenses(node, left_token, right_token, MSG)
|
@@ -53,9 +53,10 @@ module RuboCop
|
|
53
53
|
left, right = reference_brackets(node)
|
54
54
|
|
55
55
|
if style == :no_space
|
56
|
-
|
56
|
+
SpaceCorrector.remove_space(processed_source, corrector,
|
57
|
+
left, right)
|
57
58
|
else
|
58
|
-
|
59
|
+
SpaceCorrector.add_space(processed_source, corrector, left, right)
|
59
60
|
end
|
60
61
|
end
|
61
62
|
end
|
@@ -64,16 +65,24 @@ module RuboCop
|
|
64
65
|
|
65
66
|
def reference_brackets(node)
|
66
67
|
left = left_ref_bracket(node)
|
67
|
-
[left,
|
68
|
+
[left, closing_bracket(node, left)]
|
68
69
|
end
|
69
70
|
|
70
71
|
def left_ref_bracket(node)
|
71
72
|
tokens(node).reverse.find(&:left_ref_bracket?)
|
72
73
|
end
|
73
74
|
|
74
|
-
def
|
75
|
-
i = tokens(node).index(
|
76
|
-
|
75
|
+
def closing_bracket(node, opening_bracket)
|
76
|
+
i = tokens(node).index(opening_bracket)
|
77
|
+
inner_left_brackets_needing_closure = 0
|
78
|
+
|
79
|
+
tokens(node)[i..-1].each do |token|
|
80
|
+
inner_left_brackets_needing_closure += 1 if token.left_bracket?
|
81
|
+
inner_left_brackets_needing_closure -= 1 if token.right_bracket?
|
82
|
+
if inner_left_brackets_needing_closure.zero? && token.right_bracket?
|
83
|
+
return token
|
84
|
+
end
|
85
|
+
end
|
77
86
|
end
|
78
87
|
end
|
79
88
|
end
|
@@ -62,9 +62,9 @@ module RuboCop
|
|
62
62
|
|
63
63
|
def autocorrect(node)
|
64
64
|
if style == :start_of_line && node.parent && node.parent.send_type?
|
65
|
-
|
65
|
+
AlignmentCorrector.align_end(processed_source, node, node.parent)
|
66
66
|
else
|
67
|
-
|
67
|
+
AlignmentCorrector.align_end(processed_source, node, node)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
@@ -49,7 +49,7 @@ module RuboCop
|
|
49
49
|
node.children.each_cons(2) do |child1, child2|
|
50
50
|
# `'abc' 'def'` -> (dstr (str "abc") (str "def"))
|
51
51
|
next unless string_literal?(child1) && string_literal?(child2)
|
52
|
-
next unless child1.
|
52
|
+
next unless child1.last_line == child2.first_line
|
53
53
|
|
54
54
|
# Make sure we don't flag a string literal which simply has
|
55
55
|
# embedded newlines
|