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
@@ -56,7 +56,8 @@ module RuboCop
56
56
 
57
57
  def correction(node)
58
58
  lambda do |corrector|
59
- b, e = node.loc.begin, node.loc.end
59
+ b = node.loc.begin
60
+ e = node.loc.end
60
61
  if b.is?('{')
61
62
  # If the left brace is not preceded by a whitespace character,
62
63
  # then we need a space before `do` to get valid Ruby code.
@@ -82,14 +83,6 @@ module RuboCop
82
83
  end
83
84
  end
84
85
 
85
- def parentheses?(send_node)
86
- send_node.loc.begin
87
- end
88
-
89
- def operator?(method_name)
90
- method_name =~ /^\W/
91
- end
92
-
93
86
  def proper_block_style?(node)
94
87
  case style
95
88
  when :line_count_based
@@ -40,7 +40,7 @@ module RuboCop
40
40
  end
41
41
 
42
42
  def autocorrect(node)
43
- @corrections << lambda do |corrector|
43
+ lambda do |corrector|
44
44
  indentation = indentation_of_block_start_line(node)
45
45
  corrector.insert_before(node.loc.end, "\n" + (' ' * indentation))
46
46
  end
@@ -48,7 +48,7 @@ module RuboCop
48
48
  end
49
49
 
50
50
  def autocorrect(node)
51
- @corrections << lambda do |corrector|
51
+ lambda do |corrector|
52
52
  if braces?(node)
53
53
  right_range = range_with_surrounding_space(node.loc.begin, :right)
54
54
  corrector.remove(right_range)
@@ -16,7 +16,7 @@ module RuboCop
16
16
  end
17
17
 
18
18
  def autocorrect(node)
19
- @corrections << lambda do |corrector|
19
+ lambda do |corrector|
20
20
  string = node.loc.expression.source[1..-1]
21
21
 
22
22
  if string.length == 1 # normal character
@@ -31,7 +31,7 @@ module RuboCop
31
31
  def autocorrect(node)
32
32
  _receiver, method_name, *_args = *node
33
33
 
34
- @corrections << lambda do |corrector|
34
+ lambda do |corrector|
35
35
  corrector.replace(node.loc.selector,
36
36
  method_name == :is_a? ? 'kind_of?' : 'is_a?')
37
37
  end
@@ -60,9 +60,7 @@ module RuboCop
60
60
  end
61
61
 
62
62
  def autocorrect(node)
63
- @corrections << lambda do |corrector|
64
- corrector.replace(node.loc.name, 'self')
65
- end
63
+ ->(corrector) { corrector.replace(node.loc.name, 'self') }
66
64
  end
67
65
  end
68
66
  end
@@ -26,7 +26,7 @@ module RuboCop
26
26
  end
27
27
 
28
28
  def autocorrect(node)
29
- @corrections << lambda do |corrector|
29
+ lambda do |corrector|
30
30
  corrector.replace(node.loc.selector,
31
31
  preferred_method(node.loc.selector.source))
32
32
  end
@@ -32,9 +32,7 @@ module RuboCop
32
32
  end
33
33
 
34
34
  def autocorrect(node)
35
- @corrections << lambda do |corrector|
36
- corrector.replace(node.loc.dot, '.')
37
- end
35
+ ->(corrector) { corrector.replace(node.loc.dot, '.') }
38
36
  end
39
37
  end
40
38
  end
@@ -101,7 +101,7 @@ module RuboCop
101
101
  end
102
102
 
103
103
  def autocorrect(node)
104
- fail CorrectionNotPossible if contains_backtick?(node)
104
+ return if contains_backtick?(node)
105
105
 
106
106
  if backtick_literal?(node)
107
107
  replacement = ['%x', ''].zip(preferred_delimiters).map(&:join)
@@ -109,7 +109,7 @@ module RuboCop
109
109
  replacement = %w(` `)
110
110
  end
111
111
 
112
- @corrections << lambda do |corrector|
112
+ lambda do |corrector|
113
113
  corrector.replace(node.loc.begin, replacement.first)
114
114
  corrector.replace(node.loc.end, replacement.last)
115
115
  end
@@ -18,16 +18,23 @@ module RuboCop
18
18
  !correct_annotation?(first_word, colon, space, note)
19
19
 
20
20
  start = comment.loc.expression.begin_pos + margin.length
21
- length = first_word.length + (colon || '').length
21
+ length = first_word.length + colon.to_s.length + space.to_s.length
22
22
  range = Parser::Source::Range.new(processed_source.buffer,
23
23
  start,
24
24
  start + length)
25
- add_offense(nil, range)
25
+ add_offense(range, range)
26
26
  end
27
27
  end
28
28
 
29
29
  private
30
30
 
31
+ def autocorrect(range)
32
+ lambda do |corrector|
33
+ annotation_keyword = range.source.split(/:?\s+/).first
34
+ corrector.replace(range, annotation_keyword.upcase << ': ')
35
+ end
36
+ end
37
+
31
38
  def correct_annotation?(first_word, colon, space, note)
32
39
  keyword?(first_word) && (colon && space && note || !colon && !note)
33
40
  end
@@ -72,7 +72,7 @@ module RuboCop
72
72
  'your RuboCop config' if autocorrect_notice.empty?
73
73
  fail "AutocorrectNotice '#{autocorrect_notice}' must match " \
74
74
  "Notice /#{notice}/" unless autocorrect_notice =~ Regexp.new(notice)
75
- @corrections << lambda do |corrector|
75
+ lambda do |corrector|
76
76
  if token.nil?
77
77
  range = Parser::Source::Range.new('', 0, 0)
78
78
  else
@@ -22,7 +22,7 @@ module RuboCop
22
22
  end
23
23
 
24
24
  def autocorrect(node)
25
- @corrections << lambda do |corrector|
25
+ lambda do |corrector|
26
26
  corrector.remove(node.loc.begin)
27
27
  corrector.remove(node.loc.end)
28
28
  end
@@ -22,7 +22,7 @@ module RuboCop
22
22
  end
23
23
 
24
24
  def autocorrect(node)
25
- @corrections << lambda do |corrector|
25
+ lambda do |corrector|
26
26
  corrector.replace(node.loc.selector,
27
27
  proper_method_name(node.loc.selector.source))
28
28
  end
@@ -61,7 +61,7 @@ module RuboCop
61
61
  selector = node.loc.begin
62
62
  end
63
63
 
64
- @corrections << lambda do |corrector|
64
+ lambda do |corrector|
65
65
  corrector.remove(node.loc.dot)
66
66
  case style
67
67
  when :leading
@@ -36,9 +36,7 @@ module RuboCop
36
36
 
37
37
  def autocorrect(node)
38
38
  range = range_with_surrounding_space(node.loc.expression, :left)
39
- @corrections << lambda do |corrector|
40
- corrector.insert_before(range, "\n")
41
- end
39
+ ->(corrector) { corrector.insert_before(range, "\n") }
42
40
  end
43
41
  end
44
42
  end
@@ -36,7 +36,7 @@ module RuboCop
36
36
  end
37
37
 
38
38
  def autocorrect(range)
39
- @corrections << ->(corrector) { corrector.remove(range) }
39
+ ->(corrector) { corrector.remove(range) }
40
40
  end
41
41
  end
42
42
  end
@@ -18,7 +18,7 @@ module RuboCop
18
18
  end
19
19
 
20
20
  def autocorrect(node)
21
- @corrections << lambda do |corrector|
21
+ lambda do |corrector|
22
22
  send_line = node.loc.line
23
23
  previous_line = processed_source[send_line - 2]
24
24
  next_line = processed_source[send_line]
@@ -51,16 +51,12 @@ module RuboCop
51
51
  # because the braces are interpreted as a block, so we avoid
52
52
  # the correction. Parentheses around the arguments would
53
53
  # solve the problem, but we let the user add those manually.
54
- if first_arg_in_method_call_without_parentheses?(node)
55
- fail CorrectionNotPossible
56
- end
54
+ return if first_arg_in_method_call_without_parentheses?(node)
57
55
  '{}'
58
56
  when STR_NODE
59
57
  "''"
60
58
  end
61
- @corrections << lambda do |corrector|
62
- corrector.replace(node.loc.expression, name)
63
- end
59
+ ->(corrector) { corrector.replace(node.loc.expression, name) }
64
60
  end
65
61
 
66
62
  def first_arg_in_method_call_without_parentheses?(node)
@@ -33,7 +33,7 @@ module RuboCop
33
33
  def autocorrect(node)
34
34
  encoding = cop_config['AutoCorrectEncodingComment']
35
35
  if encoding && encoding =~ ENCODING_PATTERN
36
- @corrections << lambda do |corrector|
36
+ lambda do |corrector|
37
37
  corrector.replace(node.pos, "#{encoding}\n#{node.pos.source}")
38
38
  end
39
39
  else
@@ -26,10 +26,8 @@ module RuboCop
26
26
  end
27
27
 
28
28
  def autocorrect(node)
29
- @corrections << lambda do |corrector|
30
- correction = "#{base_number(node)}.#{offense_type(node)}?"
31
- corrector.replace(node.loc.expression, correction)
32
- end
29
+ correction = "#{base_number(node)}.#{offense_type(node)}?"
30
+ ->(corrector) { corrector.replace(node.loc.expression, correction) }
33
31
  end
34
32
 
35
33
  private
@@ -25,9 +25,7 @@ module RuboCop
25
25
  end
26
26
 
27
27
  def autocorrect(range)
28
- @corrections << lambda do |corrector|
29
- corrector.remove(range)
30
- end
28
+ ->(corrector) { corrector.remove(range) }
31
29
  end
32
30
  end
33
31
  end
@@ -27,6 +27,7 @@ module RuboCop
27
27
  class GuardClause < Cop
28
28
  include ConfigurableEnforcedStyle
29
29
  include IfNode
30
+ include MinBodyLength
30
31
 
31
32
  MSG = 'Use a guard clause instead of wrapping the code inside a ' \
32
33
  'conditional expression.'
@@ -62,17 +63,6 @@ module RuboCop
62
63
 
63
64
  add_offense(node, :keyword, MSG)
64
65
  end
65
-
66
- def min_body_length?(node)
67
- (node.loc.end.line - node.loc.keyword.line) > min_body_length
68
- end
69
-
70
- def min_body_length
71
- length = cop_config['MinBodyLength'] || 1
72
- return length if length.is_a?(Integer) && length > 0
73
-
74
- fail 'MinBodyLength needs to be a positive integer!'
75
- end
76
66
  end
77
67
  end
78
68
  end
@@ -58,7 +58,7 @@ module RuboCop
58
58
  end
59
59
 
60
60
  def autocorrect(node)
61
- @corrections << lambda do |corrector|
61
+ lambda do |corrector|
62
62
  if style == :hash_rockets || @force_hash_rockets
63
63
  autocorrect_hash_rockets(corrector, node)
64
64
  elsif style == :ruby19_no_mixed_keys
@@ -25,18 +25,23 @@ module RuboCop
25
25
  end
26
26
 
27
27
  def autocorrect(node)
28
- if node.loc.keyword.source == 'if'
28
+ if node.loc.keyword.is?('if')
29
29
  cond, body = *node
30
30
  else
31
31
  cond, _else, body = *node
32
32
  end
33
33
 
34
- @corrections << lambda do |corrector|
35
- oneline = "#{body.loc.expression.source} " \
36
- "#{node.loc.keyword.source} " +
37
- cond.loc.expression.source
38
- corrector.replace(node.loc.expression, oneline)
34
+ oneline =
35
+ "#{body.loc.expression.source} #{node.loc.keyword.source} " +
36
+ cond.loc.expression.source
37
+ first_line_comment = processed_source.comments.find do |c|
38
+ c.loc.line == node.loc.line
39
39
  end
40
+ if first_line_comment
41
+ oneline << ' ' << first_line_comment.loc.expression.source
42
+ end
43
+
44
+ ->(corrector) { corrector.replace(node.loc.expression, oneline) }
40
45
  end
41
46
  end
42
47
  end
@@ -86,7 +86,15 @@ module RuboCop
86
86
  args)
87
87
 
88
88
  _method_name, _args, body = *args.first
89
- check_indentation(node.loc.expression, body)
89
+ def_end_config = config.for_cop('Lint/DefEndAlignment')
90
+ style = if def_end_config['Enabled']
91
+ def_end_config['AlignWith']
92
+ else
93
+ 'start_of_line'
94
+ end
95
+ base = style == 'def' ? args.first : node
96
+
97
+ check_indentation(base.loc.expression, body)
90
98
  ignore_node(args.first)
91
99
  end
92
100
 
@@ -232,7 +240,8 @@ module RuboCop
232
240
 
233
241
  def offending_range(body_node, indentation)
234
242
  expr = body_node.loc.expression
235
- begin_pos, ind = expr.begin_pos, expr.begin_pos - indentation
243
+ begin_pos = expr.begin_pos
244
+ ind = expr.begin_pos - indentation
236
245
  pos = indentation >= 0 ? ind..begin_pos : begin_pos..ind
237
246
  Parser::Source::Range.new(expr.source_buffer, pos.begin, pos.end)
238
247
  end
@@ -40,14 +40,14 @@ module RuboCop
40
40
  end
41
41
 
42
42
  def autocorrect(node)
43
- @corrections << lambda do |corrector|
44
- condition_node, = *node
45
- start_range = node.loc.keyword.begin
46
- end_range = if node.loc.begin
47
- node.loc.begin.end
48
- else
49
- condition_node.loc.expression.end
50
- end
43
+ condition_node, = *node
44
+ start_range = node.loc.keyword.begin
45
+ end_range = if node.loc.begin
46
+ node.loc.begin.end
47
+ else
48
+ condition_node.loc.expression.end
49
+ end
50
+ lambda do |corrector|
51
51
  corrector.replace(start_range.join(end_range), 'loop do')
52
52
  end
53
53
  end
@@ -37,7 +37,7 @@ module RuboCop
37
37
  end
38
38
 
39
39
  def autocorrect(node)
40
- @corrections << lambda do |corrector|
40
+ lambda do |corrector|
41
41
  if style == :call
42
42
  receiver_node, = *node
43
43
  expr = node.loc.expression
@@ -23,9 +23,7 @@ module RuboCop
23
23
  expr = comment.loc.expression
24
24
  b = expr.begin_pos
25
25
  hash_mark = Parser::Source::Range.new(expr.source_buffer, b, b + 1)
26
- @corrections << lambda do |corrector|
27
- corrector.insert_after(hash_mark, ' ')
28
- end
26
+ ->(corrector) { corrector.insert_after(hash_mark, ' ') }
29
27
  end
30
28
  end
31
29
  end
@@ -35,13 +35,11 @@ module RuboCop
35
35
  end
36
36
 
37
37
  def autocorrect(operator_range)
38
- @corrections << lambda do |corrector|
39
- # Include any trailing whitespace so we don't create a syntax error.
40
- operator_range = range_with_surrounding_space(operator_range,
41
- :right, nil,
42
- !:with_newline)
43
- corrector.replace(operator_range, '\\')
44
- end
38
+ # Include any trailing whitespace so we don't create a syntax error.
39
+ operator_range = range_with_surrounding_space(operator_range,
40
+ :right, nil,
41
+ !:with_newline)
42
+ ->(corrector) { corrector.replace(operator_range, '\\') }
45
43
  end
46
44
 
47
45
  private
@@ -17,14 +17,7 @@ module RuboCop
17
17
  end
18
18
 
19
19
  def autocorrect(node)
20
- # Bail out if the call is going to be auto-corrected by EmptyLiteral.
21
- if config.for_cop('Style/EmptyLiteral')['Enabled'] &&
22
- [EmptyLiteral::HASH_NODE,
23
- EmptyLiteral::ARRAY_NODE,
24
- EmptyLiteral::STR_NODE].include?(node)
25
- return
26
- end
27
- @corrections << lambda do |corrector|
20
+ lambda do |corrector|
28
21
  corrector.remove(node.loc.begin)
29
22
  corrector.remove(node.loc.end)
30
23
  end
@@ -24,7 +24,7 @@ module RuboCop
24
24
  end
25
25
 
26
26
  def autocorrect(node)
27
- @corrections << lambda do |corrector|
27
+ lambda do |corrector|
28
28
  if style == :require_parentheses
29
29
  args_expr = args_node(node).loc.expression
30
30
  args_with_space = range_with_surrounding_space(args_expr, :left)