rubocop 0.30.1 → 0.31.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +38 -0
- data/README.md +10 -0
- data/config/default.yml +8 -1
- data/config/enabled.yml +28 -0
- data/lib/rubocop.rb +7 -0
- data/lib/rubocop/cli.rb +3 -2
- data/lib/rubocop/config.rb +12 -18
- data/lib/rubocop/cop/autocorrect_logic.rb +1 -1
- data/lib/rubocop/cop/cop.rb +35 -23
- data/lib/rubocop/cop/lint/block_alignment.rb +1 -1
- data/lib/rubocop/cop/lint/def_end_alignment.rb +6 -0
- data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +29 -0
- data/lib/rubocop/cop/lint/end_alignment.rb +5 -0
- data/lib/rubocop/cop/lint/require_parentheses.rb +1 -1
- data/lib/rubocop/cop/lint/space_before_first_arg.rb +1 -1
- data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +1 -1
- data/lib/rubocop/cop/metrics/class_length.rb +1 -25
- data/lib/rubocop/cop/metrics/module_length.rb +24 -0
- data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +2 -2
- data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +2 -2
- data/lib/rubocop/cop/mixin/classish_length.rb +37 -0
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -1
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +14 -1
- data/lib/rubocop/cop/mixin/min_body_length.rb +19 -0
- data/lib/rubocop/cop/mixin/on_method_def.rb +1 -0
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +2 -4
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -3
- data/lib/rubocop/cop/mixin/space_inside.rb +1 -1
- data/lib/rubocop/cop/mixin/statement_modifier.rb +14 -7
- data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
- data/lib/rubocop/cop/mixin/unused_argument.rb +1 -3
- data/lib/rubocop/cop/performance/count.rb +84 -0
- data/lib/rubocop/cop/performance/detect.rb +1 -1
- data/lib/rubocop/cop/performance/flat_map.rb +2 -1
- data/lib/rubocop/cop/performance/parallel_assignment.rb +79 -0
- data/lib/rubocop/cop/performance/reverse_each.rb +1 -3
- data/lib/rubocop/cop/performance/sample.rb +25 -18
- data/lib/rubocop/cop/performance/size.rb +1 -3
- data/lib/rubocop/cop/rails/action_filter.rb +1 -1
- data/lib/rubocop/cop/rails/delegate.rb +2 -5
- data/lib/rubocop/cop/rails/find_by.rb +1 -1
- data/lib/rubocop/cop/rails/find_each.rb +1 -3
- data/lib/rubocop/cop/rails/read_write_attribute.rb +1 -3
- data/lib/rubocop/cop/rails/time_zone.rb +29 -7
- data/lib/rubocop/cop/style/alias.rb +1 -1
- data/lib/rubocop/cop/style/align_hash.rb +11 -14
- data/lib/rubocop/cop/style/array_join.rb +11 -0
- data/lib/rubocop/cop/style/attr.rb +1 -3
- data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
- data/lib/rubocop/cop/style/block_comments.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +2 -9
- data/lib/rubocop/cop/style/block_end_newline.rb +1 -1
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +1 -1
- data/lib/rubocop/cop/style/character_literal.rb +1 -1
- data/lib/rubocop/cop/style/class_check.rb +1 -1
- data/lib/rubocop/cop/style/class_methods.rb +1 -3
- data/lib/rubocop/cop/style/collection_methods.rb +1 -1
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -3
- data/lib/rubocop/cop/style/command_literal.rb +2 -2
- data/lib/rubocop/cop/style/comment_annotation.rb +9 -2
- data/lib/rubocop/cop/style/copyright.rb +1 -1
- data/lib/rubocop/cop/style/def_with_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/deprecated_hash_methods.rb +1 -1
- data/lib/rubocop/cop/style/dot_position.rb +1 -1
- data/lib/rubocop/cop/style/empty_line_between_defs.rb +1 -3
- data/lib/rubocop/cop/style/empty_lines.rb +1 -1
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +1 -1
- data/lib/rubocop/cop/style/empty_literal.rb +2 -6
- data/lib/rubocop/cop/style/encoding.rb +1 -1
- data/lib/rubocop/cop/style/even_odd.rb +2 -4
- data/lib/rubocop/cop/style/extra_spacing.rb +1 -3
- data/lib/rubocop/cop/style/guard_clause.rb +1 -11
- data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +11 -6
- data/lib/rubocop/cop/style/indentation_width.rb +11 -2
- data/lib/rubocop/cop/style/infinite_loop.rb +8 -8
- data/lib/rubocop/cop/style/lambda_call.rb +1 -1
- data/lib/rubocop/cop/style/leading_comment_space.rb +1 -3
- data/lib/rubocop/cop/style/line_end_concatenation.rb +5 -7
- data/lib/rubocop/cop/style/method_call_parentheses.rb +1 -8
- data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/multiline_block_chain.rb +2 -1
- data/lib/rubocop/cop/style/multiline_block_layout.rb +11 -8
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
- data/lib/rubocop/cop/style/multiline_operation_indentation.rb +3 -2
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +2 -1
- data/lib/rubocop/cop/style/negated_if.rb +1 -1
- data/lib/rubocop/cop/style/negated_while.rb +2 -2
- data/lib/rubocop/cop/style/next.rb +1 -11
- data/lib/rubocop/cop/style/nil_comparison.rb +3 -5
- data/lib/rubocop/cop/style/non_nil_check.rb +2 -2
- data/lib/rubocop/cop/style/not.rb +3 -5
- data/lib/rubocop/cop/style/numeric_literals.rb +2 -5
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -1
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
- data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
- data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +1 -3
- data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
- data/lib/rubocop/cop/style/redundant_exception.rb +6 -8
- data/lib/rubocop/cop/style/redundant_return.rb +1 -1
- data/lib/rubocop/cop/style/redundant_self.rb +2 -2
- data/lib/rubocop/cop/style/regexp_literal.rb +2 -2
- data/lib/rubocop/cop/style/self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +2 -2
- data/lib/rubocop/cop/style/signal_exception.rb +1 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
- data/lib/rubocop/cop/style/single_space_before_first_arg.rb +1 -1
- data/lib/rubocop/cop/style/space_after_colon.rb +1 -3
- data/lib/rubocop/cop/style/space_after_control_keyword.rb +1 -3
- data/lib/rubocop/cop/style/space_after_method_name.rb +1 -3
- data/lib/rubocop/cop/style/space_after_not.rb +1 -1
- data/lib/rubocop/cop/style/space_around_block_parameters.rb +34 -16
- data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +1 -3
- data/lib/rubocop/cop/style/space_around_operators.rb +3 -2
- data/lib/rubocop/cop/style/space_before_block_braces.rb +1 -1
- data/lib/rubocop/cop/style/space_before_comment.rb +1 -3
- data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +1 -3
- data/lib/rubocop/cop/style/space_inside_block_braces.rb +5 -3
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +1 -1
- data/lib/rubocop/cop/style/space_inside_range_literal.rb +1 -1
- data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
- data/lib/rubocop/cop/style/symbol_literal.rb +1 -1
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
- data/lib/rubocop/cop/style/tab.rb +1 -1
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +2 -2
- data/lib/rubocop/cop/style/trailing_comma.rb +1 -1
- data/lib/rubocop/cop/style/trailing_underscore_variable.rb +72 -0
- data/lib/rubocop/cop/style/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/style/trivial_accessors.rb +5 -10
- data/lib/rubocop/cop/style/unneeded_capital_w.rb +1 -1
- data/lib/rubocop/cop/style/unneeded_percent_q.rb +1 -1
- data/lib/rubocop/cop/style/variable_interpolation.rb +2 -4
- data/lib/rubocop/cop/style/when_then.rb +1 -3
- data/lib/rubocop/cop/style/while_until_do.rb +5 -7
- data/lib/rubocop/cop/style/while_until_modifier.rb +4 -6
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/util.rb +6 -3
- data/lib/rubocop/formatter/progress_formatter.rb +3 -2
- data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
- data/lib/rubocop/rake_task.rb +2 -2
- data/lib/rubocop/runner.rb +2 -11
- data/lib/rubocop/string_util.rb +4 -2
- data/lib/rubocop/token.rb +3 -1
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.31.0.md +120 -0
- metadata +10 -2
@@ -24,7 +24,8 @@ module RuboCop
|
|
24
24
|
|
25
25
|
# The begin and end could also be braces, but we call the
|
26
26
|
# variables do... and end...
|
27
|
-
do_kw_loc
|
27
|
+
do_kw_loc = receiver.loc.begin
|
28
|
+
end_kw_loc = receiver.loc.end
|
28
29
|
next if do_kw_loc.line == end_kw_loc.line
|
29
30
|
|
30
31
|
range =
|
@@ -50,14 +50,17 @@ module RuboCop
|
|
50
50
|
# with arguments and the expression start on the same line.
|
51
51
|
_block_start, args, last_expression = node.children
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
return unless do_loc.line == expression_loc.line
|
59
|
-
add_offense_for_expression(node, last_expression, MSG)
|
53
|
+
unless args.children.empty?
|
54
|
+
line = args.loc.end.nil? ? args.loc.line : args.loc.end.line
|
55
|
+
if do_loc.line != line
|
56
|
+
add_offense_for_expression(node, args, ARG_MSG)
|
57
|
+
end
|
60
58
|
end
|
59
|
+
|
60
|
+
return unless last_expression
|
61
|
+
expression_loc = last_expression.loc
|
62
|
+
return unless do_loc.line == expression_loc.line
|
63
|
+
add_offense_for_expression(node, last_expression, MSG)
|
61
64
|
end
|
62
65
|
|
63
66
|
def add_offense_for_expression(node, expr, msg)
|
@@ -70,7 +73,7 @@ module RuboCop
|
|
70
73
|
end
|
71
74
|
|
72
75
|
def autocorrect(node)
|
73
|
-
|
76
|
+
lambda do |corrector|
|
74
77
|
_method, args, block_body = *node
|
75
78
|
unless args.children.empty? ||
|
76
79
|
args.loc.end.line == node.loc.begin.line
|
@@ -29,7 +29,8 @@ module RuboCop
|
|
29
29
|
return unless receiver
|
30
30
|
return if method_name == :[] # Don't check parameters inside [].
|
31
31
|
|
32
|
-
lhs
|
32
|
+
lhs = left_hand_side(receiver)
|
33
|
+
rhs = right_hand_side(node)
|
33
34
|
range = offending_range(node, lhs, rhs, style)
|
34
35
|
check(range, node, lhs, rhs)
|
35
36
|
end
|
@@ -148,7 +149,7 @@ module RuboCop
|
|
148
149
|
|
149
150
|
case a.type
|
150
151
|
when :if, :while, :until then condition, = *a
|
151
|
-
when :for then _, collection,
|
152
|
+
when :for then _, collection, = *a
|
152
153
|
end
|
153
154
|
|
154
155
|
if condition || collection
|
@@ -9,12 +9,13 @@ module RuboCop
|
|
9
9
|
' use `if`/`unless` instead.'
|
10
10
|
|
11
11
|
def on_if(node)
|
12
|
+
_condition, _if_branch, else_branch = *node
|
12
13
|
loc = node.loc
|
13
14
|
|
14
15
|
# discard non-ternary ops
|
15
16
|
return unless loc.respond_to?(:question)
|
16
17
|
|
17
|
-
add_offense(node, :expression) if loc.line != loc.
|
18
|
+
add_offense(node, :expression) if loc.line != else_branch.loc.line
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
28
28
|
private
|
29
29
|
|
30
30
|
def autocorrect(node)
|
31
|
-
|
31
|
+
lambda do |corrector|
|
32
32
|
condition, _body, _rest = *node
|
33
33
|
# look inside parentheses around the condition
|
34
34
|
condition = condition.children.first while condition.type == :begin
|
@@ -28,10 +28,10 @@ module RuboCop
|
|
28
28
|
private
|
29
29
|
|
30
30
|
def autocorrect(node)
|
31
|
-
|
31
|
+
lambda do |corrector|
|
32
32
|
condition, _body, _rest = *node
|
33
33
|
# Look inside parentheses around the condition, if any.
|
34
|
-
condition,
|
34
|
+
condition, = *condition while condition.type == :begin
|
35
35
|
# Unwrap the negated portion of the condition (a send node).
|
36
36
|
pos_condition, _method, = *condition
|
37
37
|
corrector.replace(
|
@@ -21,6 +21,7 @@ module RuboCop
|
|
21
21
|
class Next < Cop
|
22
22
|
include IfNode
|
23
23
|
include ConfigurableEnforcedStyle
|
24
|
+
include MinBodyLength
|
24
25
|
|
25
26
|
MSG = 'Use `next` to skip iteration.'
|
26
27
|
ENUMERATORS = [:collect, :detect, :downto, :each, :find, :find_all,
|
@@ -56,17 +57,6 @@ module RuboCop
|
|
56
57
|
|
57
58
|
private
|
58
59
|
|
59
|
-
def min_body_length?(node)
|
60
|
-
(node.loc.end.line - node.loc.keyword.line) > min_body_length
|
61
|
-
end
|
62
|
-
|
63
|
-
def min_body_length
|
64
|
-
length = cop_config['MinBodyLength'] || 1
|
65
|
-
return length if length.is_a?(Integer) && length > 0
|
66
|
-
|
67
|
-
fail 'MinBodyLength needs to be a positive integer!'
|
68
|
-
end
|
69
|
-
|
70
60
|
def enumerator?(method_name)
|
71
61
|
ENUMERATORS.include?(method_name) || /\Aeach_/.match(method_name)
|
72
62
|
end
|
@@ -29,11 +29,9 @@ module RuboCop
|
|
29
29
|
private
|
30
30
|
|
31
31
|
def autocorrect(node)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
corrector.replace(expr, new_code)
|
36
|
-
end
|
32
|
+
expr = node.loc.expression
|
33
|
+
new_code = expr.source.sub(/\s*={2,3}\s*nil/, '.nil?')
|
34
|
+
->(corrector) { corrector.replace(expr, new_code) }
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
@@ -84,7 +84,7 @@ module RuboCop
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def autocorrect_comparison(node)
|
87
|
-
|
87
|
+
lambda do |corrector|
|
88
88
|
expr = node.loc.expression
|
89
89
|
new_code =
|
90
90
|
if include_semantic_changes?
|
@@ -97,7 +97,7 @@ module RuboCop
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def autocorrect_non_nil(node, inner_node)
|
100
|
-
|
100
|
+
lambda do |corrector|
|
101
101
|
receiver, _method, _args = *inner_node
|
102
102
|
if receiver
|
103
103
|
corrector.replace(node.loc.expression,
|
@@ -22,11 +22,9 @@ module RuboCop
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def correction(node)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
corrector.replace(node.loc.expression, new_source)
|
29
|
-
end
|
25
|
+
old_source = node.loc.expression.source
|
26
|
+
new_source = old_source.sub(/not\s+/, '!')
|
27
|
+
->(corrector) { corrector.replace(node.loc.expression, new_source) }
|
30
28
|
end
|
31
29
|
end
|
32
30
|
end
|
@@ -46,11 +46,8 @@ module RuboCop
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def autocorrect(node)
|
49
|
-
|
50
|
-
corrector.replace(
|
51
|
-
node.loc.expression,
|
52
|
-
format_number(node)
|
53
|
-
)
|
49
|
+
lambda do |corrector|
|
50
|
+
corrector.replace(node.loc.expression, format_number(node))
|
54
51
|
end
|
55
52
|
end
|
56
53
|
|
@@ -55,7 +55,7 @@ module RuboCop
|
|
55
55
|
expression_indentation + expression + closing_newline +
|
56
56
|
closing_indentation + closing_delimiter + reg_opt
|
57
57
|
|
58
|
-
|
58
|
+
lambda do |corrector|
|
59
59
|
corrector.replace(node.loc.expression, corrected_source)
|
60
60
|
end
|
61
61
|
end
|
@@ -29,14 +29,12 @@ module RuboCop
|
|
29
29
|
|
30
30
|
# switch `raise RuntimeError, 'message'` to `raise 'message'`
|
31
31
|
def autocorrect(node)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
corrector.replace(final_range, '')
|
39
|
-
end
|
32
|
+
start_range = node.loc.expression.begin
|
33
|
+
no_comma = range_with_surrounding_comma(node.loc.expression.end,
|
34
|
+
:right)
|
35
|
+
comma_range = start_range.join(no_comma)
|
36
|
+
final_range = range_with_surrounding_space(comma_range, :right)
|
37
|
+
->(corrector) { corrector.replace(final_range, '') }
|
40
38
|
end
|
41
39
|
end
|
42
40
|
end
|
@@ -103,7 +103,7 @@ module RuboCop
|
|
103
103
|
|
104
104
|
def autocorrect(node)
|
105
105
|
receiver, _method_name, *_args = *node
|
106
|
-
|
106
|
+
lambda do |corrector|
|
107
107
|
corrector.remove(receiver.loc.expression)
|
108
108
|
corrector.remove(node.loc.dot)
|
109
109
|
end
|
@@ -112,7 +112,7 @@ module RuboCop
|
|
112
112
|
private
|
113
113
|
|
114
114
|
def on_argument(node)
|
115
|
-
name,
|
115
|
+
name, = *node
|
116
116
|
@local_variables << name
|
117
117
|
end
|
118
118
|
|
@@ -97,7 +97,7 @@ module RuboCop
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def autocorrect(node)
|
100
|
-
|
100
|
+
return if contains_slash?(node)
|
101
101
|
|
102
102
|
if slash_literal?(node)
|
103
103
|
replacement = ['%r', ''].zip(preferred_delimiters).map(&:join)
|
@@ -105,7 +105,7 @@ module RuboCop
|
|
105
105
|
replacement = %w(/ /)
|
106
106
|
end
|
107
107
|
|
108
|
-
|
108
|
+
lambda do |corrector|
|
109
109
|
corrector.replace(node.loc.begin, replacement.first)
|
110
110
|
corrector.replace(node.loc.end, replacement.last)
|
111
111
|
end
|
@@ -84,7 +84,7 @@ module RuboCop
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def apply_autocorrect(node, rhs, operator, new_rhs)
|
87
|
-
|
87
|
+
lambda do |corrector|
|
88
88
|
corrector.insert_before(node.loc.operator, operator)
|
89
89
|
corrector.replace(rhs.loc.expression, new_rhs.loc.expression.source)
|
90
90
|
end
|
@@ -32,7 +32,7 @@ module RuboCop
|
|
32
32
|
eol_comment = processed_source.comments.find do |c|
|
33
33
|
c.loc.line == node.loc.expression.line
|
34
34
|
end
|
35
|
-
|
35
|
+
lambda do |corrector|
|
36
36
|
if body.type == :begin
|
37
37
|
body.children.each do |part|
|
38
38
|
break_line_before(part.loc.expression, node, corrector, 1)
|
@@ -17,7 +17,8 @@ module RuboCop
|
|
17
17
|
|
18
18
|
def on_block(node)
|
19
19
|
_method, args, body = *node
|
20
|
-
opening_pipe
|
20
|
+
opening_pipe = args.loc.begin
|
21
|
+
closing_pipe = args.loc.end
|
21
22
|
return unless !args.children.empty? && opening_pipe
|
22
23
|
|
23
24
|
check_inside_pipes(args.children, opening_pipe, closing_pipe)
|
@@ -37,25 +38,42 @@ module RuboCop
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def check_inside_pipes(args, opening_pipe, closing_pipe)
|
40
|
-
first, last = args.first.loc.expression, args.last.loc.expression
|
41
|
-
|
42
41
|
if style == :no_space
|
43
|
-
|
44
|
-
'Space before first')
|
45
|
-
check_no_space(last.end_pos, closing_pipe.begin_pos,
|
46
|
-
'Space after last')
|
42
|
+
check_no_space_style_inside_pipes(args, opening_pipe, closing_pipe)
|
47
43
|
elsif style == :space
|
48
|
-
|
49
|
-
'before first block parameter')
|
50
|
-
check_space(last.end_pos, closing_pipe.begin_pos, last,
|
51
|
-
'after last block parameter')
|
52
|
-
check_no_space(opening_pipe.end_pos, first.begin_pos - 1,
|
53
|
-
'Extra space before first')
|
54
|
-
check_no_space(last.end_pos + 1, closing_pipe.begin_pos,
|
55
|
-
'Extra space after last')
|
44
|
+
check_space_style_inside_pipes(args, opening_pipe, closing_pipe)
|
56
45
|
end
|
57
46
|
end
|
58
47
|
|
48
|
+
def check_no_space_style_inside_pipes(args, opening_pipe, closing_pipe)
|
49
|
+
first = args.first.loc.expression
|
50
|
+
last = args.last.loc.expression
|
51
|
+
|
52
|
+
check_no_space(opening_pipe.end_pos, first.begin_pos,
|
53
|
+
'Space before first')
|
54
|
+
check_no_space(last_end_pos_inside_pipes(last.end_pos),
|
55
|
+
closing_pipe.begin_pos, 'Space after last')
|
56
|
+
end
|
57
|
+
|
58
|
+
def check_space_style_inside_pipes(args, opening_pipe, closing_pipe)
|
59
|
+
first = args.first.loc.expression
|
60
|
+
last = args.last.loc.expression
|
61
|
+
last_end_pos = last_end_pos_inside_pipes(last.end_pos)
|
62
|
+
|
63
|
+
check_space(opening_pipe.end_pos, first.begin_pos, first,
|
64
|
+
'before first block parameter')
|
65
|
+
check_space(last_end_pos, closing_pipe.begin_pos, last,
|
66
|
+
'after last block parameter')
|
67
|
+
check_no_space(opening_pipe.end_pos, first.begin_pos - 1,
|
68
|
+
'Extra space before first')
|
69
|
+
check_no_space(last_end_pos + 1, closing_pipe.begin_pos,
|
70
|
+
'Extra space after last')
|
71
|
+
end
|
72
|
+
|
73
|
+
def last_end_pos_inside_pipes(pos)
|
74
|
+
processed_source.buffer.source[pos] == ',' ? pos + 1 : pos
|
75
|
+
end
|
76
|
+
|
59
77
|
def check_each_arg(args)
|
60
78
|
args.children[1..-1].each do |arg|
|
61
79
|
expr = arg.loc.expression
|
@@ -79,7 +97,7 @@ module RuboCop
|
|
79
97
|
end
|
80
98
|
|
81
99
|
def autocorrect(range)
|
82
|
-
|
100
|
+
lambda do |corrector|
|
83
101
|
case range.source
|
84
102
|
when /^\s+$/ then corrector.remove(range)
|
85
103
|
else corrector.insert_after(range, ' ')
|