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
@@ -62,9 +62,7 @@ module RuboCop
62
62
  m = range.source.match(/=\s*(\S+)/)
63
63
  rest = m ? m.captures[0] : ''
64
64
  replacement = style == :space ? ' = ' : '='
65
- @corrections << lambda do |corrector|
66
- corrector.replace(range, replacement + rest)
67
- end
65
+ ->(corrector) { corrector.replace(range, replacement + rest) }
68
66
  end
69
67
  end
70
68
  end
@@ -41,7 +41,8 @@ module RuboCop
41
41
  end
42
42
 
43
43
  def unary_operation?(node)
44
- whole, selector = node.loc.expression, node.loc.selector
44
+ whole = node.loc.expression
45
+ selector = node.loc.selector
45
46
  return unless selector
46
47
  operator?(selector) && whole.begin_pos == selector.begin_pos
47
48
  end
@@ -79,7 +80,7 @@ module RuboCop
79
80
  end
80
81
 
81
82
  def autocorrect(range)
82
- @corrections << lambda do |corrector|
83
+ lambda do |corrector|
83
84
  case range.source
84
85
  when /\*\*/
85
86
  corrector.replace(range, '**')
@@ -51,7 +51,7 @@ module RuboCop
51
51
  end
52
52
 
53
53
  def autocorrect(range)
54
- @corrections << lambda do |corrector|
54
+ lambda do |corrector|
55
55
  case range.source
56
56
  when /\s/ then corrector.remove(range)
57
57
  else corrector.insert_before(range, ' ')
@@ -19,9 +19,7 @@ module RuboCop
19
19
  private
20
20
 
21
21
  def autocorrect(range)
22
- @corrections << lambda do |corrector|
23
- corrector.insert_before(range, ' ')
24
- end
22
+ ->(corrector) { corrector.insert_before(range, ' ') }
25
23
  end
26
24
  end
27
25
  end
@@ -29,9 +29,7 @@ module RuboCop
29
29
  end
30
30
 
31
31
  def autocorrect(node)
32
- @corrections << lambda do |corrector|
33
- corrector.insert_before(node.loc.keyword, ' ')
34
- end
32
+ ->(corrector) { corrector.insert_before(node.loc.keyword, ' ') }
35
33
  end
36
34
  end
37
35
  end
@@ -23,7 +23,8 @@ module RuboCop
23
23
  return
24
24
  end
25
25
 
26
- left_brace, right_brace = node.loc.begin, node.loc.end
26
+ left_brace = node.loc.begin
27
+ right_brace = node.loc.end
27
28
 
28
29
  check_inside(node, left_brace, right_brace)
29
30
  end
@@ -58,7 +59,8 @@ module RuboCop
58
59
 
59
60
  def braces_with_contents_inside(node, inner, sb)
60
61
  _method, args, _body = *node
61
- left_brace, right_brace = node.loc.begin, node.loc.end
62
+ left_brace = node.loc.begin
63
+ right_brace = node.loc.end
62
64
  args_delimiter = args.loc.begin # Can be ( | or nil.
63
65
 
64
66
  if inner =~ /^\S/
@@ -148,7 +150,7 @@ module RuboCop
148
150
  end
149
151
 
150
152
  def autocorrect(range)
151
- @corrections << lambda do |corrector|
153
+ lambda do |corrector|
152
154
  case range.source
153
155
  when /\s/ then corrector.remove(range)
154
156
  when '{}' then corrector.replace(range, '{ }')
@@ -68,7 +68,7 @@ module RuboCop
68
68
  end
69
69
 
70
70
  def autocorrect(range)
71
- @corrections << lambda do |corrector|
71
+ lambda do |corrector|
72
72
  # It is possible that BracesAroundHashParameters will remove the
73
73
  # braces while this cop inserts spaces. This can lead to unwanted
74
74
  # changes to the inspected code. If we replace the brace with a
@@ -48,7 +48,7 @@ module RuboCop
48
48
  operator = node.loc.operator.source
49
49
  operator_escaped = operator.gsub(/\./, '\.')
50
50
 
51
- @corrections << lambda do |corrector|
51
+ lambda do |corrector|
52
52
  corrector.replace(
53
53
  node.loc.expression,
54
54
  expression
@@ -71,7 +71,7 @@ module RuboCop
71
71
  end
72
72
 
73
73
  def autocorrect(node)
74
- @corrections << lambda do |corrector|
74
+ lambda do |corrector|
75
75
  global_var, = *node
76
76
  parent_type = node.parent ? node.parent.type : nil
77
77
  if [:dstr, :xstr, :regexp].include?(parent_type)
@@ -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
  current_name = node.loc.expression.source
29
29
  corrector.replace(node.loc.expression,
30
30
  current_name.gsub(/["']/, ''))
@@ -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
  _block_method, _block_args, block_body = *node
45
45
  _receiver, method_name, _args = *block_body
46
46
 
@@ -25,7 +25,7 @@ module RuboCop
25
25
  private
26
26
 
27
27
  def autocorrect(range)
28
- @corrections << lambda do |corrector|
28
+ lambda do |corrector|
29
29
  corrector.replace(range, range.source.gsub(/\t/, ' '))
30
30
  end
31
31
  end
@@ -43,7 +43,7 @@ module RuboCop
43
43
  return false if processed_source.tokens.empty?
44
44
 
45
45
  extra = sb.source[processed_source.tokens.last.pos.end_pos..-1]
46
- extra.strip.start_with?('__END__')
46
+ extra && extra.strip.start_with?('__END__')
47
47
  end
48
48
 
49
49
  def message(wanted_blank_lines, blank_lines)
@@ -64,7 +64,7 @@ module RuboCop
64
64
  end
65
65
 
66
66
  def autocorrect(range)
67
- @corrections << lambda do |corrector|
67
+ lambda do |corrector|
68
68
  corrector.replace(range, style == :final_newline ? "\n" : "\n\n")
69
69
  end
70
70
  end
@@ -159,7 +159,7 @@ module RuboCop
159
159
  end
160
160
 
161
161
  def autocorrect(range)
162
- @corrections << lambda do |corrector|
162
+ lambda do |corrector|
163
163
  case range.source
164
164
  when ',' then corrector.remove(range)
165
165
  else corrector.insert_after(range, ',')
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Style
6
+ # This cop checks for extra underscores in variable assignment.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # a, b, _ = foo()
11
+ # a, b, _, = foo()
12
+ # a, _, _ = foo()
13
+ # a, _, _, = foo()
14
+ #
15
+ # #good
16
+ # a, b, = foo()
17
+ # a, = foo()
18
+ class TrailingUnderscoreVariable < Cop
19
+ include SurroundingSpace
20
+
21
+ MSG = 'Do not use trailing `_`s in parallel assignment.'
22
+
23
+ def on_masgn(node)
24
+ left, = *node
25
+ variables = *left
26
+ first_offense = find_first_offense(variables)
27
+
28
+ return if first_offense.nil?
29
+
30
+ range =
31
+ Parser::Source::Range.new(node.loc.expression.source_buffer,
32
+ first_offense.loc.expression.begin_pos,
33
+ variables.last.loc.expression.end_pos)
34
+ add_offense(node, range)
35
+ end
36
+
37
+ def autocorrect(node)
38
+ left, right = *node
39
+ variables = *left
40
+ first_offense = find_first_offense(variables)
41
+
42
+ end_position =
43
+ if first_offense.loc.expression == variables.first.loc.expression
44
+ right.loc.expression.begin_pos
45
+ else
46
+ node.loc.operator.begin_pos
47
+ end
48
+
49
+ range =
50
+ Parser::Source::Range.new(node.loc.expression.source_buffer,
51
+ first_offense.loc.expression.begin_pos,
52
+ end_position)
53
+
54
+ ->(corrector) { corrector.remove(range) unless range.nil? }
55
+ end
56
+
57
+ private
58
+
59
+ def find_first_offense(variables)
60
+ first_offense = nil
61
+
62
+ variables.reverse_each do |variable|
63
+ break unless variable.children.first == :_
64
+ first_offense = variable
65
+ end
66
+
67
+ first_offense
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -20,7 +20,7 @@ module RuboCop
20
20
  end
21
21
 
22
22
  def autocorrect(range)
23
- @corrections << ->(corrector) { corrector.remove(range) }
23
+ ->(corrector) { corrector.remove(range) }
24
24
  end
25
25
  end
26
26
  end
@@ -121,8 +121,6 @@ module RuboCop
121
121
  autocorrect_instance(node)
122
122
  elsif node.type == :defs && node.children.first.type == :self
123
123
  autocorrect_class(node)
124
- else
125
- fail CorrectionNotPossible
126
124
  end
127
125
  end
128
126
 
@@ -130,14 +128,11 @@ module RuboCop
130
128
  method_name, args, body = *node
131
129
  unless names_match?(method_name, body) &&
132
130
  (kind = trivial_accessor_kind(method_name, args, body))
133
- fail CorrectionNotPossible
131
+ return
134
132
  end
135
133
 
136
- @corrections << lambda do |corrector|
137
- corrector.replace(
138
- node.loc.expression,
139
- accessor(kind, method_name)
140
- )
134
+ lambda do |corrector|
135
+ corrector.replace(node.loc.expression, accessor(kind, method_name))
141
136
  end
142
137
  end
143
138
 
@@ -145,10 +140,10 @@ module RuboCop
145
140
  _, method_name, args, body = *node
146
141
  unless names_match?(method_name, body) &&
147
142
  (kind = trivial_accessor_kind(method_name, args, body))
148
- fail CorrectionNotPossible
143
+ return
149
144
  end
150
145
 
151
- @corrections << lambda do |corrector|
146
+ lambda do |corrector|
152
147
  indent = ' ' * node.loc.column
153
148
  corrector.replace(
154
149
  node.loc.expression,
@@ -25,7 +25,7 @@ module RuboCop
25
25
  end
26
26
 
27
27
  def autocorrect(node)
28
- @corrections << lambda do |corrector|
28
+ lambda do |corrector|
29
29
  src = node.loc.begin.source
30
30
  corrector.replace(node.loc.begin, src.tr('W', 'w'))
31
31
  end
@@ -47,7 +47,7 @@ module RuboCop
47
47
 
48
48
  def autocorrect(node)
49
49
  delimiter = node.loc.expression.source =~ /^%Q[^"]+$|'/ ? '"' : "'"
50
- @corrections << lambda do |corrector|
50
+ lambda do |corrector|
51
51
  corrector.replace(node.loc.begin, delimiter)
52
52
  corrector.replace(node.loc.end, delimiter)
53
53
  end
@@ -30,10 +30,8 @@ module RuboCop
30
30
  end
31
31
 
32
32
  def autocorrect(node)
33
- @corrections << lambda do |corrector|
34
- expr = node.loc.expression
35
- corrector.replace(expr, "{#{expr.source}}")
36
- end
33
+ expr = node.loc.expression
34
+ ->(corrector) { corrector.replace(expr, "{#{expr.source}}") }
37
35
  end
38
36
 
39
37
  def var_nodes(nodes)
@@ -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.begin, ' then')
19
- end
17
+ ->(corrector) { corrector.replace(node.loc.begin, ' then') }
20
18
  end
21
19
  end
22
20
  end
@@ -28,13 +28,11 @@ module RuboCop
28
28
  end
29
29
 
30
30
  def autocorrect(node)
31
- @corrections << lambda do |corrector|
32
- condition_node, = *node
33
- end_of_condition_range = condition_node.loc.expression.end
34
- do_range = node.loc.begin
35
- whitespaces_and_do_range = end_of_condition_range.join(do_range)
36
- corrector.remove(whitespaces_and_do_range)
37
- end
31
+ condition_node, = *node
32
+ end_of_condition_range = condition_node.loc.expression.end
33
+ do_range = node.loc.begin
34
+ whitespaces_and_do_range = end_of_condition_range.join(do_range)
35
+ ->(corrector) { corrector.remove(whitespaces_and_do_range) }
38
36
  end
39
37
  end
40
38
  end
@@ -19,12 +19,10 @@ module RuboCop
19
19
 
20
20
  def autocorrect(node)
21
21
  cond, body = *node
22
- @corrections << lambda do |corrector|
23
- oneline = "#{body.loc.expression.source} " \
24
- "#{node.loc.keyword.source} " +
25
- cond.loc.expression.source
26
- corrector.replace(node.loc.expression, oneline)
27
- end
22
+ oneline = "#{body.loc.expression.source} " \
23
+ "#{node.loc.keyword.source} " +
24
+ cond.loc.expression.source
25
+ ->(corrector) { corrector.replace(node.loc.expression, oneline) }
28
26
  end
29
27
 
30
28
  private
@@ -64,7 +64,7 @@ module RuboCop
64
64
  contents = node.children.map { |n| source_for(n) }.join(' ')
65
65
  char = @interpolated ? 'W' : 'w'
66
66
 
67
- @corrections << lambda do |corrector|
67
+ lambda do |corrector|
68
68
  corrector.replace(node.loc.expression, "%#{char}(#{contents})")
69
69
  end
70
70
  end
@@ -147,7 +147,8 @@ module RuboCop
147
147
 
148
148
  go_left, go_right = directions(side)
149
149
 
150
- begin_pos, end_pos = range.begin_pos, range.end_pos
150
+ begin_pos = range.begin_pos
151
+ end_pos = range.end_pos
151
152
  begin_pos = move_pos(src, begin_pos, -1, go_left, /,/)
152
153
  end_pos = move_pos(src, end_pos, 1, go_right, /,/)
153
154
 
@@ -161,7 +162,8 @@ module RuboCop
161
162
 
162
163
  go_left, go_right = directions(side)
163
164
 
164
- begin_pos, end_pos = range.begin_pos, range.end_pos
165
+ begin_pos = range.begin_pos
166
+ end_pos = range.end_pos
165
167
  begin_pos = move_pos(src, begin_pos, -1, go_left, /[ \t]/)
166
168
  begin_pos = move_pos(src, begin_pos, -1, go_left && with_newline, /\n/)
167
169
  end_pos = move_pos(src, end_pos, 1, go_right, /[ \t]/)
@@ -189,7 +191,8 @@ module RuboCop
189
191
  end
190
192
 
191
193
  def within_node?(inner, outer)
192
- o, i = outer.loc.expression, inner.loc.expression
194
+ o = outer.loc.expression
195
+ i = inner.loc.expression
193
196
  i.begin_pos >= o.begin_pos && i.end_pos <= o.end_pos
194
197
  end
195
198
 
@@ -6,11 +6,12 @@ module RuboCop
6
6
  # letters for files with problems in the them. In the end it
7
7
  # appends the regular report data in the clang style format.
8
8
  class ProgressFormatter < ClangStyleFormatter
9
+ include TextUtil
10
+
9
11
  def started(target_files)
10
12
  super
11
13
  @offenses_for_files = {}
12
- file_phrase = target_files.count == 1 ? 'file' : 'files'
13
- output.puts "Inspecting #{target_files.count} #{file_phrase}"
14
+ output.puts "Inspecting #{pluralize(target_files.size, 'file')}"
14
15
  end
15
16
 
16
17
  def file_finished(file, offenses)
@@ -70,7 +70,7 @@ module RuboCop
70
70
 
71
71
  def count_stats(offenses)
72
72
  @total_offense_count += offenses.count
73
- @total_correction_count += offenses.select(&:corrected?).count
73
+ @total_correction_count += offenses.count(&:corrected?)
74
74
  end
75
75
 
76
76
  def smart_path(path)