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.

Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -0
  3. data/README.md +10 -0
  4. data/config/default.yml +8 -1
  5. data/config/enabled.yml +28 -0
  6. data/lib/rubocop.rb +7 -0
  7. data/lib/rubocop/cli.rb +3 -2
  8. data/lib/rubocop/config.rb +12 -18
  9. data/lib/rubocop/cop/autocorrect_logic.rb +1 -1
  10. data/lib/rubocop/cop/cop.rb +35 -23
  11. data/lib/rubocop/cop/lint/block_alignment.rb +1 -1
  12. data/lib/rubocop/cop/lint/def_end_alignment.rb +6 -0
  13. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -1
  14. data/lib/rubocop/cop/lint/each_with_object_argument.rb +29 -0
  15. data/lib/rubocop/cop/lint/end_alignment.rb +5 -0
  16. data/lib/rubocop/cop/lint/require_parentheses.rb +1 -1
  17. data/lib/rubocop/cop/lint/space_before_first_arg.rb +1 -1
  18. data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +1 -1
  19. data/lib/rubocop/cop/metrics/class_length.rb +1 -25
  20. data/lib/rubocop/cop/metrics/module_length.rb +24 -0
  21. data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
  22. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +2 -2
  23. data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +2 -2
  24. data/lib/rubocop/cop/mixin/classish_length.rb +37 -0
  25. data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +1 -1
  26. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +14 -1
  27. data/lib/rubocop/cop/mixin/min_body_length.rb +19 -0
  28. data/lib/rubocop/cop/mixin/on_method_def.rb +1 -0
  29. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +2 -4
  30. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -3
  31. data/lib/rubocop/cop/mixin/space_inside.rb +1 -1
  32. data/lib/rubocop/cop/mixin/statement_modifier.rb +14 -7
  33. data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -1
  34. data/lib/rubocop/cop/mixin/unused_argument.rb +1 -3
  35. data/lib/rubocop/cop/performance/count.rb +84 -0
  36. data/lib/rubocop/cop/performance/detect.rb +1 -1
  37. data/lib/rubocop/cop/performance/flat_map.rb +2 -1
  38. data/lib/rubocop/cop/performance/parallel_assignment.rb +79 -0
  39. data/lib/rubocop/cop/performance/reverse_each.rb +1 -3
  40. data/lib/rubocop/cop/performance/sample.rb +25 -18
  41. data/lib/rubocop/cop/performance/size.rb +1 -3
  42. data/lib/rubocop/cop/rails/action_filter.rb +1 -1
  43. data/lib/rubocop/cop/rails/delegate.rb +2 -5
  44. data/lib/rubocop/cop/rails/find_by.rb +1 -1
  45. data/lib/rubocop/cop/rails/find_each.rb +1 -3
  46. data/lib/rubocop/cop/rails/read_write_attribute.rb +1 -3
  47. data/lib/rubocop/cop/rails/time_zone.rb +29 -7
  48. data/lib/rubocop/cop/style/alias.rb +1 -1
  49. data/lib/rubocop/cop/style/align_hash.rb +11 -14
  50. data/lib/rubocop/cop/style/array_join.rb +11 -0
  51. data/lib/rubocop/cop/style/attr.rb +1 -3
  52. data/lib/rubocop/cop/style/bare_percent_literals.rb +1 -1
  53. data/lib/rubocop/cop/style/block_comments.rb +1 -1
  54. data/lib/rubocop/cop/style/block_delimiters.rb +2 -9
  55. data/lib/rubocop/cop/style/block_end_newline.rb +1 -1
  56. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +1 -1
  57. data/lib/rubocop/cop/style/character_literal.rb +1 -1
  58. data/lib/rubocop/cop/style/class_check.rb +1 -1
  59. data/lib/rubocop/cop/style/class_methods.rb +1 -3
  60. data/lib/rubocop/cop/style/collection_methods.rb +1 -1
  61. data/lib/rubocop/cop/style/colon_method_call.rb +1 -3
  62. data/lib/rubocop/cop/style/command_literal.rb +2 -2
  63. data/lib/rubocop/cop/style/comment_annotation.rb +9 -2
  64. data/lib/rubocop/cop/style/copyright.rb +1 -1
  65. data/lib/rubocop/cop/style/def_with_parentheses.rb +1 -1
  66. data/lib/rubocop/cop/style/deprecated_hash_methods.rb +1 -1
  67. data/lib/rubocop/cop/style/dot_position.rb +1 -1
  68. data/lib/rubocop/cop/style/empty_line_between_defs.rb +1 -3
  69. data/lib/rubocop/cop/style/empty_lines.rb +1 -1
  70. data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +1 -1
  71. data/lib/rubocop/cop/style/empty_literal.rb +2 -6
  72. data/lib/rubocop/cop/style/encoding.rb +1 -1
  73. data/lib/rubocop/cop/style/even_odd.rb +2 -4
  74. data/lib/rubocop/cop/style/extra_spacing.rb +1 -3
  75. data/lib/rubocop/cop/style/guard_clause.rb +1 -11
  76. data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
  77. data/lib/rubocop/cop/style/if_unless_modifier.rb +11 -6
  78. data/lib/rubocop/cop/style/indentation_width.rb +11 -2
  79. data/lib/rubocop/cop/style/infinite_loop.rb +8 -8
  80. data/lib/rubocop/cop/style/lambda_call.rb +1 -1
  81. data/lib/rubocop/cop/style/leading_comment_space.rb +1 -3
  82. data/lib/rubocop/cop/style/line_end_concatenation.rb +5 -7
  83. data/lib/rubocop/cop/style/method_call_parentheses.rb +1 -8
  84. data/lib/rubocop/cop/style/method_def_parentheses.rb +1 -1
  85. data/lib/rubocop/cop/style/multiline_block_chain.rb +2 -1
  86. data/lib/rubocop/cop/style/multiline_block_layout.rb +11 -8
  87. data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
  88. data/lib/rubocop/cop/style/multiline_operation_indentation.rb +3 -2
  89. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +2 -1
  90. data/lib/rubocop/cop/style/negated_if.rb +1 -1
  91. data/lib/rubocop/cop/style/negated_while.rb +2 -2
  92. data/lib/rubocop/cop/style/next.rb +1 -11
  93. data/lib/rubocop/cop/style/nil_comparison.rb +3 -5
  94. data/lib/rubocop/cop/style/non_nil_check.rb +2 -2
  95. data/lib/rubocop/cop/style/not.rb +3 -5
  96. data/lib/rubocop/cop/style/numeric_literals.rb +2 -5
  97. data/lib/rubocop/cop/style/parentheses_around_condition.rb +1 -1
  98. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +1 -1
  99. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  100. data/lib/rubocop/cop/style/perl_backrefs.rb +1 -1
  101. data/lib/rubocop/cop/style/proc.rb +1 -3
  102. data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
  103. data/lib/rubocop/cop/style/redundant_exception.rb +6 -8
  104. data/lib/rubocop/cop/style/redundant_return.rb +1 -1
  105. data/lib/rubocop/cop/style/redundant_self.rb +2 -2
  106. data/lib/rubocop/cop/style/regexp_literal.rb +2 -2
  107. data/lib/rubocop/cop/style/self_assignment.rb +1 -1
  108. data/lib/rubocop/cop/style/semicolon.rb +2 -2
  109. data/lib/rubocop/cop/style/signal_exception.rb +1 -1
  110. data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
  111. data/lib/rubocop/cop/style/single_space_before_first_arg.rb +1 -1
  112. data/lib/rubocop/cop/style/space_after_colon.rb +1 -3
  113. data/lib/rubocop/cop/style/space_after_control_keyword.rb +1 -3
  114. data/lib/rubocop/cop/style/space_after_method_name.rb +1 -3
  115. data/lib/rubocop/cop/style/space_after_not.rb +1 -1
  116. data/lib/rubocop/cop/style/space_around_block_parameters.rb +34 -16
  117. data/lib/rubocop/cop/style/space_around_equals_in_parameter_default.rb +1 -3
  118. data/lib/rubocop/cop/style/space_around_operators.rb +3 -2
  119. data/lib/rubocop/cop/style/space_before_block_braces.rb +1 -1
  120. data/lib/rubocop/cop/style/space_before_comment.rb +1 -3
  121. data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +1 -3
  122. data/lib/rubocop/cop/style/space_inside_block_braces.rb +5 -3
  123. data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +1 -1
  124. data/lib/rubocop/cop/style/space_inside_range_literal.rb +1 -1
  125. data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
  126. data/lib/rubocop/cop/style/symbol_literal.rb +1 -1
  127. data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
  128. data/lib/rubocop/cop/style/tab.rb +1 -1
  129. data/lib/rubocop/cop/style/trailing_blank_lines.rb +2 -2
  130. data/lib/rubocop/cop/style/trailing_comma.rb +1 -1
  131. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +72 -0
  132. data/lib/rubocop/cop/style/trailing_whitespace.rb +1 -1
  133. data/lib/rubocop/cop/style/trivial_accessors.rb +5 -10
  134. data/lib/rubocop/cop/style/unneeded_capital_w.rb +1 -1
  135. data/lib/rubocop/cop/style/unneeded_percent_q.rb +1 -1
  136. data/lib/rubocop/cop/style/variable_interpolation.rb +2 -4
  137. data/lib/rubocop/cop/style/when_then.rb +1 -3
  138. data/lib/rubocop/cop/style/while_until_do.rb +5 -7
  139. data/lib/rubocop/cop/style/while_until_modifier.rb +4 -6
  140. data/lib/rubocop/cop/style/word_array.rb +1 -1
  141. data/lib/rubocop/cop/util.rb +6 -3
  142. data/lib/rubocop/formatter/progress_formatter.rb +3 -2
  143. data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
  144. data/lib/rubocop/rake_task.rb +2 -2
  145. data/lib/rubocop/runner.rb +2 -11
  146. data/lib/rubocop/string_util.rb +4 -2
  147. data/lib/rubocop/token.rb +3 -1
  148. data/lib/rubocop/version.rb +1 -1
  149. data/relnotes/v0.31.0.md +120 -0
  150. metadata +10 -2
@@ -58,7 +58,7 @@ module RuboCop
58
58
 
59
59
  receiver, _args, _body = *receiver if receiver.block_type?
60
60
 
61
- @corrections << lambda do |corrector|
61
+ lambda do |corrector|
62
62
  corrector.remove(first_range)
63
63
  corrector.replace(receiver.loc.selector, replacement)
64
64
  end
@@ -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
- @corrections << lambda do |corrector|
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
@@ -33,9 +33,7 @@ module RuboCop
33
33
  end
34
34
 
35
35
  def autocorrect(node)
36
- @corrections << lambda do |corrector|
37
- corrector.replace(node.loc.dot, '_')
38
- end
36
+ ->(corrector) { corrector.replace(node.loc.dot, '_') }
39
37
  end
40
38
  end
41
39
  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, method, params, = *node
27
- return unless method == :shuffle
28
- _receiver, _method, params, = *node.parent if params.nil?
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
- message = if params && params.lvar_type?
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
- @corrections << lambda do |corrector|
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
@@ -38,9 +38,7 @@ module RuboCop
38
38
  end
39
39
 
40
40
  def autocorrect(node)
41
- @corrections << lambda do |corrector|
42
- corrector.replace(node.loc.selector, 'size')
43
- end
41
+ ->(corrector) { corrector.replace(node.loc.selector, 'size') }
44
42
  end
45
43
 
46
44
  private
@@ -31,7 +31,7 @@ module RuboCop
31
31
  end
32
32
 
33
33
  def autocorrect(node)
34
- @corrections << lambda do |corrector|
34
+ lambda do |corrector|
35
35
  corrector.replace(node.loc.selector,
36
36
  preferred_method(node.loc.selector.source).to_s)
37
37
  end
@@ -41,17 +41,14 @@ module RuboCop
41
41
  private
42
42
 
43
43
  def autocorrect(node)
44
- method_name, args, body = *node
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
- @corrections << lambda do |corrector|
51
+ lambda do |corrector|
55
52
  corrector.replace(node.loc.expression, delegation.join(', '))
56
53
  end
57
54
  end
@@ -41,7 +41,7 @@ module RuboCop
41
41
  node.loc.selector.end_pos
42
42
  )
43
43
 
44
- @corrections << lambda do |corrector|
44
+ lambda do |corrector|
45
45
  corrector.replace(where_loc, 'find_by')
46
46
  corrector.replace(first_loc, '')
47
47
  end
@@ -31,9 +31,7 @@ module RuboCop
31
31
  def autocorrect(node)
32
32
  each_loc = node.loc.selector
33
33
 
34
- @corrections << lambda do |corrector|
35
- corrector.replace(each_loc, 'find_each')
36
- end
34
+ ->(corrector) { corrector.replace(each_loc, 'find_each') }
37
35
  end
38
36
  end
39
37
  end
@@ -47,9 +47,7 @@ module RuboCop
47
47
  replacement = write_attribute_replacement(node)
48
48
  end
49
49
 
50
- @corrections << lambda do |corrector|
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
- add_offense(node, :selector,
64
- format(MSG,
65
- "#{klass}.#{method_name}",
66
- "Time.zone.#{safe_method_name}")
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
- (style == :acceptable) && chain.include?(:localtime)
139
+ acceptable? && chain.include?(:localtime)
140
+ end
141
+
142
+ def acceptable?
143
+ style == :acceptable
122
144
  end
123
145
 
124
146
  def good_methods
@@ -31,7 +31,7 @@ module RuboCop
31
31
  end
32
32
 
33
33
  def autocorrect(node)
34
- @corrections << lambda do |corrector|
34
+ lambda do |corrector|
35
35
  # replace alias with alias_method
36
36
  corrector.replace(node.loc.keyword, 'alias_method')
37
37
  # insert a comma
@@ -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, prev_pair, current_pair)
23
- if current_pair.loc.line == prev_pair.loc.line
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, _prev_pair, current_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
- lines_of_the_children = node.children.map do |pair|
61
- key, _value = *pair
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, _ = *first_pair
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.each_cons(2) do |prev, current|
184
- @column_deltas = alignment_for(current).deltas(first_pair, prev,
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
- @corrections << lambda do |corrector|
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
@@ -14,9 +14,7 @@ module RuboCop
14
14
  end
15
15
 
16
16
  def autocorrect(node)
17
- @corrections << lambda do |corrector|
18
- corrector.replace(node.loc.selector, 'attr_reader')
19
- end
17
+ ->(corrector) { corrector.replace(node.loc.selector, 'attr_reader') }
20
18
  end
21
19
  end
22
20
  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
- @corrections << lambda do |corrector|
39
+ lambda do |corrector|
40
40
  corrector.replace(node.loc.begin, src.sub(/%Q?/, replacement))
41
41
  end
42
42
  end
@@ -18,7 +18,7 @@ module RuboCop
18
18
  def autocorrect(comment)
19
19
  eq_begin, eq_end, contents = parts(comment)
20
20
 
21
- @corrections << lambda do |corrector|
21
+ lambda do |corrector|
22
22
  corrector.remove(eq_begin)
23
23
  unless contents.length == 0
24
24
  corrector.replace(contents,