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
@@ -47,9 +47,10 @@ module RuboCop
|
|
47
47
|
receiver, _flatten, flatten_param = *node
|
48
48
|
flatten_level, = *flatten_param
|
49
49
|
return if flatten_level.nil?
|
50
|
+
|
50
51
|
array, = *receiver
|
51
52
|
|
52
|
-
|
53
|
+
lambda do |corrector|
|
53
54
|
range = Parser::Source::Range.new(node.loc.expression.source_buffer,
|
54
55
|
node.loc.dot.begin_pos,
|
55
56
|
node.loc.expression.end_pos)
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module Performance
|
6
|
+
# Checks for simple usages of parallel assignment.
|
7
|
+
# This will only complain when the number of variables
|
8
|
+
# being assigned matched the number of assigning variables.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # bad
|
12
|
+
# a, b, c = 1, 2, 3
|
13
|
+
# a, b, c = [1, 2, 3]
|
14
|
+
#
|
15
|
+
# # good
|
16
|
+
# one, two = *foo
|
17
|
+
# a, b = foo()
|
18
|
+
#
|
19
|
+
# a = 1
|
20
|
+
# b = 2
|
21
|
+
# c = 3
|
22
|
+
class ParallelAssignment < Cop
|
23
|
+
MSG = 'Do not use parallel assignment.'
|
24
|
+
|
25
|
+
def on_masgn(node)
|
26
|
+
left, right = *node
|
27
|
+
left_elements = *left
|
28
|
+
right_elements = [*right].compact # edge case for one constant
|
29
|
+
|
30
|
+
# only complain when the number of variables matches
|
31
|
+
return if left_elements.size != right_elements.size
|
32
|
+
|
33
|
+
# account for edge cases using one variable with a comma
|
34
|
+
return if left_elements.size == 1
|
35
|
+
|
36
|
+
# allow mass assignment as the return of a method call
|
37
|
+
return if right.block_type? || right.send_type?
|
38
|
+
|
39
|
+
# allow mass assignment when using splat
|
40
|
+
return if (left_elements + right_elements).any?(&:splat_type?)
|
41
|
+
|
42
|
+
return if variable_reassignment?(left_elements, right_elements)
|
43
|
+
|
44
|
+
add_offense(node, :expression)
|
45
|
+
end
|
46
|
+
|
47
|
+
def autocorrect(node)
|
48
|
+
left, right = *node
|
49
|
+
|
50
|
+
lambda do |corrector|
|
51
|
+
l_vars = extract_sources(left)
|
52
|
+
r_vars = extract_sources(right)
|
53
|
+
groups = l_vars.zip(r_vars)
|
54
|
+
|
55
|
+
assignment = groups.map { |pair| pair.join(' = ') }
|
56
|
+
|
57
|
+
space_offset = node.loc.expression.column
|
58
|
+
corrector.replace(node.loc.expression,
|
59
|
+
assignment.join("\n" << ' ' * space_offset))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def extract_sources(node)
|
66
|
+
node.children.map { |child| child.loc.expression.source }
|
67
|
+
end
|
68
|
+
|
69
|
+
def variable_reassignment?(left_elements, right_elements)
|
70
|
+
left_elements.any? do |le|
|
71
|
+
right_elements.any? do |re|
|
72
|
+
re.loc.expression.is?(le.loc.expression.source)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -15,32 +15,23 @@ module RuboCop
|
|
15
15
|
# [1, 2, 3].shuffle(random: Random.new(1))
|
16
16
|
#
|
17
17
|
# # good
|
18
|
+
# [1, 2, 3].shuffle
|
18
19
|
# [1, 2, 3].sample
|
19
20
|
# [1, 2, 3].sample(3)
|
20
21
|
# [1, 2, 3].sample(random: Random.new(1))
|
21
22
|
class Sample < Cop
|
22
23
|
MSG = 'Use `sample` instead of `shuffle%s`.'
|
23
24
|
RANGE_TYPES = [:irange, :erange]
|
25
|
+
VALID_ARRAY_SELECTORS = [:first, :last, :[], nil]
|
24
26
|
|
25
27
|
def on_send(node)
|
26
|
-
_receiver,
|
27
|
-
return unless
|
28
|
-
_receiver,
|
28
|
+
_receiver, first_method, params, = *node
|
29
|
+
return unless first_method == :shuffle
|
30
|
+
_receiver, second_method, params, = *node.parent if params.nil?
|
31
|
+
return unless VALID_ARRAY_SELECTORS.include?(second_method)
|
32
|
+
return if second_method.nil? && params.nil?
|
29
33
|
|
30
|
-
|
31
|
-
format(MSG, shuffle_params(node))
|
32
|
-
elsif node.parent
|
33
|
-
_params, selector = *node.parent
|
34
|
-
if selector == :[]
|
35
|
-
format(MSG, node.parent.loc.selector.source)
|
36
|
-
else
|
37
|
-
format(MSG, ".#{node.parent.loc.selector.source}")
|
38
|
-
end
|
39
|
-
else
|
40
|
-
format(MSG, shuffle_params(node))
|
41
|
-
end
|
42
|
-
|
43
|
-
add_offense(node, range_of_shuffle(node), message)
|
34
|
+
add_offense(node, range_of_shuffle(node), message(node, params))
|
44
35
|
end
|
45
36
|
|
46
37
|
def autocorrect(node)
|
@@ -57,7 +48,7 @@ module RuboCop
|
|
57
48
|
node.parent.loc.selector.end_pos)
|
58
49
|
end
|
59
50
|
|
60
|
-
|
51
|
+
lambda do |corrector|
|
61
52
|
corrector.replace(range, 'sample')
|
62
53
|
return if selector.nil?
|
63
54
|
corrector.insert_after(range, "(#{selector.loc.expression.source})")
|
@@ -66,6 +57,21 @@ module RuboCop
|
|
66
57
|
|
67
58
|
private
|
68
59
|
|
60
|
+
def message(node, params)
|
61
|
+
if params && params.lvar_type?
|
62
|
+
format(MSG, shuffle_params(node))
|
63
|
+
elsif node.parent
|
64
|
+
_params, selector = *node.parent
|
65
|
+
if selector == :[]
|
66
|
+
format(MSG, node.parent.loc.selector.source)
|
67
|
+
else
|
68
|
+
format(MSG, ".#{node.parent.loc.selector.source}")
|
69
|
+
end
|
70
|
+
else
|
71
|
+
format(MSG, shuffle_params(node))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
69
75
|
def range_of_shuffle(node)
|
70
76
|
Parser::Source::Range.new(node.loc.expression.source_buffer,
|
71
77
|
node.loc.selector.begin_pos,
|
@@ -76,6 +82,7 @@ module RuboCop
|
|
76
82
|
params = Parser::Source::Range.new(node.loc.expression.source_buffer,
|
77
83
|
node.loc.selector.end_pos,
|
78
84
|
node.loc.expression.end_pos)
|
85
|
+
|
79
86
|
params.source
|
80
87
|
end
|
81
88
|
end
|
@@ -41,17 +41,14 @@ module RuboCop
|
|
41
41
|
private
|
42
42
|
|
43
43
|
def autocorrect(node)
|
44
|
-
method_name,
|
45
|
-
return unless trivial_delegate?(method_name, args, body)
|
46
|
-
return if private_or_protected_delegation(node)
|
47
|
-
|
44
|
+
method_name, _args, body = *node
|
48
45
|
delegation = ["delegate :#{body.children[1]}",
|
49
46
|
"to: :#{body.children[0].children[1]}"]
|
50
47
|
if method_name == prefixed_method_name(body)
|
51
48
|
delegation << ['prefix: true']
|
52
49
|
end
|
53
50
|
|
54
|
-
|
51
|
+
lambda do |corrector|
|
55
52
|
corrector.replace(node.loc.expression, delegation.join(', '))
|
56
53
|
end
|
57
54
|
end
|
@@ -47,9 +47,7 @@ module RuboCop
|
|
47
47
|
replacement = write_attribute_replacement(node)
|
48
48
|
end
|
49
49
|
|
50
|
-
|
51
|
-
corrector.replace(node.loc.expression, replacement)
|
52
|
-
end
|
50
|
+
->(corrector) { corrector.replace(node.loc.expression, replacement) }
|
53
51
|
end
|
54
52
|
|
55
53
|
private
|
@@ -31,6 +31,8 @@ module RuboCop
|
|
31
31
|
|
32
32
|
MSG = 'Do not use `%s` without zone. Use `%s` instead.'
|
33
33
|
|
34
|
+
MSG_ACCEPTABLE = 'Do not use `%s` without zone. Use one of %s instead.'
|
35
|
+
|
34
36
|
MSG_LOCALTIME = 'Do not use `Time.localtime` without offset or zone.'
|
35
37
|
|
36
38
|
TIMECLASS = [:Time, :DateTime]
|
@@ -58,13 +60,29 @@ module RuboCop
|
|
58
60
|
return check_localtime(node) if need_check_localtime?(chain)
|
59
61
|
|
60
62
|
method_name = (chain & DANGER_METHODS).join('.')
|
61
|
-
safe_method_name = safe_method(method_name, node)
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
message = build_message(klass, method_name, node)
|
65
|
+
|
66
|
+
add_offense(node, :selector, message)
|
67
|
+
end
|
68
|
+
|
69
|
+
def build_message(klass, method_name, node)
|
70
|
+
if acceptable?
|
71
|
+
accepted_methods = ACCEPTED_METHODS.map do |am|
|
72
|
+
"`#{klass}.#{method_name}.#{am}`"
|
73
|
+
end
|
74
|
+
|
75
|
+
format(MSG_ACCEPTABLE,
|
76
|
+
"#{klass}.#{method_name}",
|
77
|
+
accepted_methods.join(', ')
|
78
|
+
)
|
79
|
+
else
|
80
|
+
safe_method_name = safe_method(method_name, node)
|
81
|
+
format(MSG,
|
82
|
+
"#{klass}.#{method_name}",
|
83
|
+
"#{klass}.zone.#{safe_method_name}"
|
84
|
+
)
|
85
|
+
end
|
68
86
|
end
|
69
87
|
|
70
88
|
def extract_method_chain(node)
|
@@ -118,7 +136,11 @@ module RuboCop
|
|
118
136
|
end
|
119
137
|
|
120
138
|
def need_check_localtime?(chain)
|
121
|
-
|
139
|
+
acceptable? && chain.include?(:localtime)
|
140
|
+
end
|
141
|
+
|
142
|
+
def acceptable?
|
143
|
+
style == :acceptable
|
122
144
|
end
|
123
145
|
|
124
146
|
def good_methods
|
@@ -19,11 +19,11 @@ module RuboCop
|
|
19
19
|
{} # The first pair is always considered correct.
|
20
20
|
end
|
21
21
|
|
22
|
-
def deltas(first_pair,
|
23
|
-
if current_pair.loc.
|
24
|
-
{}
|
25
|
-
else
|
22
|
+
def deltas(first_pair, current_pair)
|
23
|
+
if Util.begins_its_line?(current_pair.loc.expression)
|
26
24
|
{ key: first_pair.loc.column - current_pair.loc.column }
|
25
|
+
else
|
26
|
+
{}
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -35,7 +35,7 @@ module RuboCop
|
|
35
35
|
!any_pairs_on_the_same_line?(node) && all_have_same_separator?(node)
|
36
36
|
end
|
37
37
|
|
38
|
-
def deltas(first_pair,
|
38
|
+
def deltas(first_pair, current_pair)
|
39
39
|
key_delta = key_delta(first_pair, current_pair)
|
40
40
|
current_separator = current_pair.loc.operator
|
41
41
|
separator_delta = separator_delta(first_pair, current_separator,
|
@@ -57,11 +57,9 @@ module RuboCop
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def any_pairs_on_the_same_line?(node)
|
60
|
-
|
61
|
-
|
62
|
-
key.loc.line
|
60
|
+
node.children[1..-1].any? do |pair|
|
61
|
+
!Util.begins_its_line?(pair.loc.expression)
|
63
62
|
end
|
64
|
-
lines_of_the_children.uniq.size < lines_of_the_children.size
|
65
63
|
end
|
66
64
|
|
67
65
|
def all_have_same_separator?(node)
|
@@ -103,7 +101,7 @@ module RuboCop
|
|
103
101
|
end
|
104
102
|
|
105
103
|
def value_delta(first_pair, current_pair)
|
106
|
-
first_key,
|
104
|
+
first_key, = *first_pair
|
107
105
|
_, current_value = *current_pair
|
108
106
|
correct_value_column = first_key.loc.column +
|
109
107
|
spaced_separator(current_pair).length +
|
@@ -180,9 +178,8 @@ module RuboCop
|
|
180
178
|
.deltas_for_first_pair(first_pair, node)
|
181
179
|
add_offense(first_pair, :expression) unless good_alignment?
|
182
180
|
|
183
|
-
node.children.
|
184
|
-
@column_deltas = alignment_for(current).deltas(first_pair,
|
185
|
-
current)
|
181
|
+
node.children.each do |current|
|
182
|
+
@column_deltas = alignment_for(current).deltas(first_pair, current)
|
186
183
|
add_offense(current, :expression) unless good_alignment?
|
187
184
|
end
|
188
185
|
end
|
@@ -233,7 +230,7 @@ module RuboCop
|
|
233
230
|
|
234
231
|
key, value = *node
|
235
232
|
|
236
|
-
|
233
|
+
lambda do |corrector|
|
237
234
|
adjust(corrector, key_delta, key.loc.expression)
|
238
235
|
adjust(corrector, separator_delta, node.loc.operator)
|
239
236
|
adjust(corrector, value_delta, value.loc.expression)
|
@@ -18,6 +18,17 @@ module RuboCop
|
|
18
18
|
|
19
19
|
add_offense(node, :selector)
|
20
20
|
end
|
21
|
+
|
22
|
+
def autocorrect(node)
|
23
|
+
receiver_node, _method_name, *arg_nodes = *node
|
24
|
+
expr = node.loc.expression
|
25
|
+
array = receiver_node.loc.expression.source
|
26
|
+
join_arg = arg_nodes[0].loc.expression.source
|
27
|
+
|
28
|
+
lambda do |corrector|
|
29
|
+
corrector.replace(expr, "#{array}.join(#{join_arg})")
|
30
|
+
end
|
31
|
+
end
|
21
32
|
end
|
22
33
|
end
|
23
34
|
end
|
@@ -36,7 +36,7 @@ module RuboCop
|
|
36
36
|
def autocorrect(node)
|
37
37
|
src = node.loc.begin.source
|
38
38
|
replacement = src.start_with?('%Q') ? '%' : '%Q'
|
39
|
-
|
39
|
+
lambda do |corrector|
|
40
40
|
corrector.replace(node.loc.begin, src.sub(/%Q?/, replacement))
|
41
41
|
end
|
42
42
|
end
|