rubocop 0.21.0 → 0.22.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 (159) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/{rubocop-todo.yml → .rubocop_todo.yml} +5 -5
  4. data/CHANGELOG.md +41 -0
  5. data/README.md +21 -11
  6. data/config/default.yml +33 -10
  7. data/config/disabled.yml +0 -4
  8. data/config/enabled.yml +27 -1
  9. data/lib/rubocop.rb +17 -1
  10. data/lib/rubocop/config.rb +32 -27
  11. data/lib/rubocop/config_loader.rb +21 -8
  12. data/lib/rubocop/cop/cop.rb +8 -8
  13. data/lib/rubocop/cop/lint/block_alignment.rb +22 -22
  14. data/lib/rubocop/cop/lint/condition_position.rb +3 -5
  15. data/lib/rubocop/cop/lint/debugger.rb +4 -5
  16. data/lib/rubocop/cop/lint/end_alignment.rb +11 -10
  17. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +10 -11
  18. data/lib/rubocop/cop/lint/require_parentheses.rb +7 -7
  19. data/lib/rubocop/cop/lint/rescue_exception.rb +3 -3
  20. data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +6 -7
  21. data/lib/rubocop/cop/lint/unreachable_code.rb +2 -3
  22. data/lib/rubocop/cop/lint/unused_block_argument.rb +2 -15
  23. data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -14
  24. data/lib/rubocop/cop/lint/useless_comparison.rb +4 -5
  25. data/lib/rubocop/cop/lint/void.rb +6 -8
  26. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +4 -2
  27. data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +1 -3
  28. data/lib/rubocop/cop/mixin/code_length.rb +5 -5
  29. data/lib/rubocop/cop/mixin/negative_conditional.rb +6 -6
  30. data/lib/rubocop/cop/mixin/percent_literal.rb +2 -3
  31. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +5 -5
  32. data/lib/rubocop/cop/mixin/space_inside.rb +10 -11
  33. data/lib/rubocop/cop/mixin/unused_argument.rb +35 -0
  34. data/lib/rubocop/cop/offense.rb +1 -1
  35. data/lib/rubocop/cop/rails/action_filter.rb +6 -8
  36. data/lib/rubocop/cop/rails/default_scope.rb +2 -4
  37. data/lib/rubocop/cop/rails/delegate.rb +2 -0
  38. data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +2 -3
  39. data/lib/rubocop/cop/rails/output.rb +2 -3
  40. data/lib/rubocop/cop/rails/read_write_attribute.rb +3 -4
  41. data/lib/rubocop/cop/rails/validation.rb +2 -3
  42. data/lib/rubocop/cop/style/alias.rb +3 -3
  43. data/lib/rubocop/cop/style/align_hash.rb +4 -4
  44. data/lib/rubocop/cop/style/align_parameters.rb +13 -1
  45. data/lib/rubocop/cop/style/and_or.rb +2 -5
  46. data/lib/rubocop/cop/style/array_join.rb +3 -4
  47. data/lib/rubocop/cop/style/ascii_identifiers.rb +2 -3
  48. data/lib/rubocop/cop/style/block_comments.rb +2 -3
  49. data/lib/rubocop/cop/style/block_nesting.rb +2 -3
  50. data/lib/rubocop/cop/style/blocks.rb +9 -9
  51. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +5 -5
  52. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
  53. data/lib/rubocop/cop/style/class_methods.rb +3 -5
  54. data/lib/rubocop/cop/style/collection_methods.rb +8 -11
  55. data/lib/rubocop/cop/style/comment_annotation.rb +9 -9
  56. data/lib/rubocop/cop/style/comment_indentation.rb +66 -0
  57. data/lib/rubocop/cop/style/constant_name.rb +3 -3
  58. data/lib/rubocop/cop/style/cyclomatic_complexity.rb +5 -5
  59. data/lib/rubocop/cop/style/deprecated_hash_methods.rb +6 -6
  60. data/lib/rubocop/cop/style/each_with_object.rb +38 -0
  61. data/lib/rubocop/cop/style/empty_lines.rb +8 -8
  62. data/lib/rubocop/cop/style/empty_lines_around_body.rb +7 -7
  63. data/lib/rubocop/cop/style/encoding.rb +6 -7
  64. data/lib/rubocop/cop/style/end_of_line.rb +10 -10
  65. data/lib/rubocop/cop/style/file_name.rb +11 -7
  66. data/lib/rubocop/cop/style/guard_clause.rb +32 -22
  67. data/lib/rubocop/cop/style/indentation_width.rb +25 -26
  68. data/lib/rubocop/cop/style/lambda.rb +8 -9
  69. data/lib/rubocop/cop/style/leading_comment_space.rb +4 -5
  70. data/lib/rubocop/cop/style/line_end_concatenation.rb +29 -6
  71. data/lib/rubocop/cop/style/line_length.rb +9 -9
  72. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +7 -6
  73. data/lib/rubocop/cop/style/module_function.rb +3 -4
  74. data/lib/rubocop/cop/style/multiline_if_then.rb +3 -3
  75. data/lib/rubocop/cop/style/negated_if.rb +2 -0
  76. data/lib/rubocop/cop/style/next.rb +80 -0
  77. data/lib/rubocop/cop/style/nil_comparison.rb +2 -3
  78. data/lib/rubocop/cop/style/non_nil_check.rb +15 -3
  79. data/lib/rubocop/cop/style/not.rb +4 -4
  80. data/lib/rubocop/cop/style/numeric_literals.rb +7 -8
  81. data/lib/rubocop/cop/style/op_method.rb +3 -5
  82. data/lib/rubocop/cop/style/parameter_lists.rb +4 -4
  83. data/lib/rubocop/cop/style/parentheses_around_condition.rb +5 -6
  84. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +5 -5
  85. data/lib/rubocop/cop/style/predicate_name.rb +2 -4
  86. data/lib/rubocop/cop/style/redundant_self.rb +11 -12
  87. data/lib/rubocop/cop/style/self_assignment.rb +8 -13
  88. data/lib/rubocop/cop/style/semicolon.rb +16 -19
  89. data/lib/rubocop/cop/style/signal_exception.rb +10 -11
  90. data/lib/rubocop/cop/style/single_line_block_params.rb +2 -3
  91. data/lib/rubocop/cop/style/single_line_methods.rb +3 -4
  92. data/lib/rubocop/cop/style/space_after_colon.rb +9 -9
  93. data/lib/rubocop/cop/style/space_after_control_keyword.rb +3 -3
  94. data/lib/rubocop/cop/style/space_after_method_name.rb +3 -3
  95. data/lib/rubocop/cop/style/space_after_not.rb +3 -4
  96. data/lib/rubocop/cop/style/space_around_operators.rb +5 -4
  97. data/lib/rubocop/cop/style/space_before_comment.rb +29 -0
  98. data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +6 -7
  99. data/lib/rubocop/cop/style/symbol_array.rb +2 -3
  100. data/lib/rubocop/cop/style/tab.rb +8 -8
  101. data/lib/rubocop/cop/style/trailing_blank_lines.rb +10 -10
  102. data/lib/rubocop/cop/style/trailing_whitespace.rb +6 -7
  103. data/lib/rubocop/cop/style/trivial_accessors.rb +3 -4
  104. data/lib/rubocop/cop/style/unless_else.rb +2 -3
  105. data/lib/rubocop/cop/style/unneeded_capital_w.rb +3 -3
  106. data/lib/rubocop/cop/style/unneeded_percent_x.rb +26 -0
  107. data/lib/rubocop/cop/style/when_then.rb +3 -3
  108. data/lib/rubocop/cop/style/while_until_do.rb +3 -6
  109. data/lib/rubocop/cop/style/word_array.rb +8 -7
  110. data/lib/rubocop/cop/team.rb +9 -11
  111. data/lib/rubocop/cop/util.rb +2 -3
  112. data/lib/rubocop/cop/variable_force.rb +2 -3
  113. data/lib/rubocop/cop/variable_force/variable_table.rb +1 -2
  114. data/lib/rubocop/file_inspector.rb +5 -0
  115. data/lib/rubocop/formatter/clang_style_formatter.rb +3 -4
  116. data/lib/rubocop/formatter/disabled_config_formatter.rb +6 -6
  117. data/lib/rubocop/options.rb +14 -11
  118. data/lib/rubocop/target_finder.rb +12 -1
  119. data/lib/rubocop/version.rb +1 -1
  120. data/relnotes/v0.21.0.md +11 -0
  121. data/relnotes/v0.22.0.md +77 -0
  122. data/spec/rubocop/cli_spec.rb +86 -40
  123. data/spec/rubocop/comment_config_spec.rb +1 -1
  124. data/spec/rubocop/config_loader_spec.rb +3 -3
  125. data/spec/rubocop/config_spec.rb +14 -3
  126. data/spec/rubocop/cop/force_spec.rb +1 -1
  127. data/spec/rubocop/cop/lint/unused_block_argument_spec.rb +164 -99
  128. data/spec/rubocop/cop/lint/unused_method_argument_spec.rb +195 -85
  129. data/spec/rubocop/cop/lint/void_spec.rb +8 -0
  130. data/spec/rubocop/cop/rails/delegate_spec.rb +17 -0
  131. data/spec/rubocop/cop/rails/output_spec.rb +3 -3
  132. data/spec/rubocop/cop/severity_spec.rb +5 -5
  133. data/spec/rubocop/cop/style/align_parameters_spec.rb +108 -0
  134. data/spec/rubocop/cop/style/block_nesting_spec.rb +3 -3
  135. data/spec/rubocop/cop/style/class_and_module_children_spec.rb +12 -10
  136. data/spec/rubocop/cop/style/comment_indentation_spec.rb +174 -0
  137. data/spec/rubocop/cop/style/each_with_object_spec.rb +44 -0
  138. data/spec/rubocop/cop/style/end_of_line_spec.rb +3 -5
  139. data/spec/rubocop/cop/style/guard_clause_spec.rb +135 -57
  140. data/spec/rubocop/cop/style/if_unless_modifier_spec.rb +7 -7
  141. data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +75 -1
  142. data/spec/rubocop/cop/style/line_length_spec.rb +7 -7
  143. data/spec/rubocop/cop/style/negated_if_spec.rb +5 -1
  144. data/spec/rubocop/cop/style/next_spec.rb +210 -0
  145. data/spec/rubocop/cop/style/non_nil_check_spec.rb +44 -13
  146. data/spec/rubocop/cop/style/self_assignment_spec.rb +1 -1
  147. data/spec/rubocop/cop/style/space_around_operators_spec.rb +1 -0
  148. data/spec/rubocop/cop/style/space_before_comment_spec.rb +34 -0
  149. data/spec/rubocop/cop/style/unneeded_percent_x_spec.rb +34 -0
  150. data/spec/rubocop/cop/style/while_until_modifier_spec.rb +2 -2
  151. data/spec/rubocop/cop/util_spec.rb +2 -2
  152. data/spec/rubocop/cop/variable_force_spec.rb +1 -1
  153. data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +4 -4
  154. data/spec/rubocop/formatter/disabled_lines_formatter_spec.rb +2 -2
  155. data/spec/rubocop/formatter/offense_count_formatter_spec.rb +2 -2
  156. data/spec/rubocop/options_spec.rb +3 -0
  157. data/spec/support/shared_context.rb +1 -3
  158. data/spec/support/statement_modifier_helper.rb +2 -2
  159. metadata +20 -3
@@ -3,6 +3,11 @@
3
3
  require 'yaml'
4
4
  require 'pathname'
5
5
 
6
+ # Psych can give an error when reading an empty file, so we use syck in Ruby
7
+ # versions where it's available. Also, the problem with empty files does not
8
+ # appear in Ruby 2.
9
+ YAML::ENGINE.yamler = 'syck' if RUBY_VERSION < '2.0.0'
10
+
6
11
  module Rubocop
7
12
  # This class represents the configuration of the RuboCop application
8
13
  # and all its cops. A Config is associated with a YAML configuration
@@ -13,7 +18,7 @@ module Rubocop
13
18
  DOTFILE = '.rubocop.yml'
14
19
  RUBOCOP_HOME = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
15
20
  DEFAULT_FILE = File.join(RUBOCOP_HOME, 'config', 'default.yml')
16
- AUTO_GENERATED_FILE = 'rubocop-todo.yml'
21
+ AUTO_GENERATED_FILE = '.rubocop_todo.yml'
17
22
 
18
23
  class << self
19
24
  attr_accessor :debug, :auto_gen_config
@@ -34,7 +39,6 @@ module Rubocop
34
39
 
35
40
  config.deprecation_check do |deprecation_message|
36
41
  warn("#{path} - #{deprecation_message}")
37
- exit(-1)
38
42
  end
39
43
 
40
44
  config.warn_unless_valid
@@ -49,9 +53,8 @@ module Rubocop
49
53
  result = base_hash.merge(derived_hash)
50
54
  keys_appearing_in_both = base_hash.keys & derived_hash.keys
51
55
  keys_appearing_in_both.each do |key|
52
- if base_hash[key].is_a?(Hash)
53
- result[key] = merge(base_hash[key], derived_hash[key])
54
- end
56
+ next unless base_hash[key].is_a?(Hash)
57
+ result[key] = merge(base_hash[key], derived_hash[key])
55
58
  end
56
59
  result
57
60
  end
@@ -59,10 +62,14 @@ module Rubocop
59
62
  def base_configs(path, inherit_from)
60
63
  configs = Array(inherit_from).map do |f|
61
64
  f = File.join(File.dirname(path), f) unless f.start_with?('/')
62
- unless auto_gen_config? && f.include?(AUTO_GENERATED_FILE)
63
- print 'Inheriting ' if debug?
64
- load_file(f)
65
+
66
+ if auto_gen_config?
67
+ next if f.include?(AUTO_GENERATED_FILE)
68
+ old_auto_config_file_warning if f.include?('rubocop-todo.yml')
65
69
  end
70
+
71
+ print 'Inheriting ' if debug?
72
+ load_file(f)
66
73
  end
67
74
 
68
75
  configs.compact
@@ -125,6 +132,12 @@ module Rubocop
125
132
  end
126
133
  dirs_to_search << Dir.home
127
134
  end
135
+
136
+ def old_auto_config_file_warning
137
+ warn 'Attention: rubocop-todo.yml has been renamed to ' \
138
+ "#{AUTO_GENERATED_FILE}".color(:red)
139
+ exit(1)
140
+ end
128
141
  end
129
142
  end
130
143
  end
@@ -189,14 +189,14 @@ module Rubocop
189
189
 
190
190
  def custom_severity
191
191
  severity = cop_config && cop_config['Severity']
192
- if severity
193
- if Severity::NAMES.include?(severity.to_sym)
194
- severity.to_sym
195
- else
196
- warn "Warning: Invalid severity '#{severity}'. " +
197
- "Valid severities are #{Severity::NAMES.join(', ')}."
198
- .color(:red)
199
- end
192
+ return unless severity
193
+
194
+ if Severity::NAMES.include?(severity.to_sym)
195
+ severity.to_sym
196
+ else
197
+ warn "Warning: Invalid severity '#{severity}'. " +
198
+ "Valid severities are #{Severity::NAMES.join(', ')}."
199
+ .color(:red)
200
200
  end
201
201
  end
202
202
  end
@@ -30,10 +30,10 @@ module Rubocop
30
30
  return if already_processed_node?(node)
31
31
 
32
32
  _left, right = *node
33
- if right.type == :block
34
- check_block_alignment(node, right)
35
- @inspected_blocks << right
36
- end
33
+ return unless right.type == :block
34
+
35
+ check_block_alignment(node, right)
36
+ @inspected_blocks << right
37
37
  end
38
38
 
39
39
  alias_method :on_or, :on_and
@@ -106,24 +106,24 @@ module Rubocop
106
106
  end_loc = block_node.loc.end
107
107
  do_loc = block_node.loc.begin # Actually it's either do or {.
108
108
  return if do_loc.line == end_loc.line # One-liner, not interesting.
109
- if start_loc.column != end_loc.column
110
- # We've found that "end" is not aligned with the start node (which
111
- # can be a block, a variable assignment, etc). But we also allow
112
- # the "end" to be aligned with the start of the line where the "do"
113
- # is, which is a style some people use in multi-line chains of
114
- # blocks.
115
- match = /\S.*/.match(do_loc.source_line)
116
- indentation_of_do_line = match.begin(0)
117
- if end_loc.column != indentation_of_do_line
118
- add_offense(nil,
119
- end_loc,
120
- format(MSG, end_loc.line, end_loc.column,
121
- start_loc.source.lines.to_a.first.chomp,
122
- start_loc.line, start_loc.column,
123
- alt_start_msg(match, start_loc, do_loc,
124
- indentation_of_do_line)))
125
- end
126
- end
109
+ return unless start_loc.column != end_loc.column
110
+
111
+ # We've found that "end" is not aligned with the start node (which
112
+ # can be a block, a variable assignment, etc). But we also allow
113
+ # the "end" to be aligned with the start of the line where the "do"
114
+ # is, which is a style some people use in multi-line chains of
115
+ # blocks.
116
+ match = /\S.*/.match(do_loc.source_line)
117
+ indentation_of_do_line = match.begin(0)
118
+ return unless end_loc.column != indentation_of_do_line
119
+
120
+ add_offense(nil,
121
+ end_loc,
122
+ format(MSG, end_loc.line, end_loc.column,
123
+ start_loc.source.lines.to_a.first.chomp,
124
+ start_loc.line, start_loc.column,
125
+ alt_start_msg(match, start_loc, do_loc,
126
+ indentation_of_do_line)))
127
127
  end
128
128
 
129
129
  def alt_start_msg(match, start_loc, do_loc, indentation_of_do_line)
@@ -33,12 +33,10 @@ module Rubocop
33
33
  return if !node.loc.keyword.is?('elsif') && node.loc.end.nil?
34
34
 
35
35
  condition, = *node
36
+ return unless on_different_line?(node.loc.keyword.line,
37
+ condition.loc.expression.line)
36
38
 
37
- if on_different_line?(node.loc.keyword.line,
38
- condition.loc.expression.line)
39
- add_offense(condition, :expression,
40
- message(node.loc.keyword.source))
41
- end
39
+ add_offense(condition, :expression, message(node.loc.keyword.source))
42
40
  end
43
41
 
44
42
  def message(keyword)
@@ -37,11 +37,10 @@ module Rubocop
37
37
  ]
38
38
 
39
39
  def on_send(node)
40
- if DEBUGGER_NODES.include?(node)
41
- add_offense(node,
42
- :expression,
43
- format(MSG, node.loc.expression.source))
44
- end
40
+ return unless DEBUGGER_NODES.include?(node)
41
+ add_offense(node,
42
+ :expression,
43
+ format(MSG, node.loc.expression.source))
45
44
  end
46
45
  end
47
46
  end
@@ -46,16 +46,17 @@ module Rubocop
46
46
  super
47
47
 
48
48
  receiver, method_name, *args = *node
49
- if visibility_and_def_on_same_line?(receiver, method_name, args)
50
- expr = node.loc.expression
51
- method_def = args.first
52
- range = Parser::Source::Range.new(expr.source_buffer,
53
- expr.begin_pos,
54
- method_def.loc.keyword.end_pos)
55
- check_offset(method_def, range.source,
56
- method_def.loc.keyword.begin_pos - expr.begin_pos)
57
- ignore_node(method_def) # Don't check the same `end` again.
58
- end
49
+ return unless visibility_and_def_on_same_line?(receiver, method_name,
50
+ args)
51
+
52
+ expr = node.loc.expression
53
+ method_def = args.first
54
+ range = Parser::Source::Range.new(expr.source_buffer,
55
+ expr.begin_pos,
56
+ method_def.loc.keyword.end_pos)
57
+ check_offset(method_def, range.source,
58
+ method_def.loc.keyword.begin_pos - expr.begin_pos)
59
+ ignore_node(method_def) # Don't check the same `end` again.
59
60
  end
60
61
 
61
62
  private
@@ -15,18 +15,17 @@ module Rubocop
15
15
  def on_send(node)
16
16
  _receiver, method_name, args = *node
17
17
  return if operator?(method_name) || method_name.to_s.end_with?('=')
18
+ return unless args && args.loc.expression.source.start_with?('(')
18
19
 
19
- if args && args.loc.expression.source.start_with?('(')
20
- space_length = spaces_before_left_parenthesis(node)
21
- if space_length > 0
22
- expr = args.loc.expression
23
- space_range =
24
- Parser::Source::Range.new(expr.source_buffer,
25
- expr.begin_pos - space_length,
26
- expr.begin_pos)
27
- add_offense(nil, space_range)
28
- end
29
- end
20
+ space_length = spaces_before_left_parenthesis(node)
21
+ return unless space_length > 0
22
+ expr = args.loc.expression
23
+ space_range =
24
+ Parser::Source::Range.new(expr.source_buffer,
25
+ expr.begin_pos - space_length,
26
+ expr.begin_pos)
27
+
28
+ add_offense(nil, space_range)
30
29
  end
31
30
 
32
31
  private
@@ -42,13 +42,13 @@ module Rubocop
42
42
 
43
43
  def check_ternary(arg, node)
44
44
  condition, _, _ = *arg
45
- if offense?(condition)
46
- expr = node.loc.expression
47
- range = Parser::Source::Range.new(expr.source_buffer,
48
- expr.begin_pos,
49
- condition.loc.expression.end_pos)
50
- add_offense(range, range)
51
- end
45
+ return unless offense?(condition)
46
+
47
+ expr = node.loc.expression
48
+ range = Parser::Source::Range.new(expr.source_buffer,
49
+ expr.begin_pos,
50
+ condition.loc.expression.end_pos)
51
+ add_offense(range, range)
52
52
  end
53
53
 
54
54
  def check_send(arg, node)
@@ -10,9 +10,9 @@ module Rubocop
10
10
  def on_resbody(node)
11
11
  return unless node.children.first
12
12
  rescue_args = node.children.first.children
13
- if rescue_args.any? { |a| targets_exception?(a) }
14
- add_offense(node, :expression)
15
- end
13
+ return unless rescue_args.any? { |a| targets_exception?(a) }
14
+
15
+ add_offense(node, :expression)
16
16
  end
17
17
 
18
18
  def targets_exception?(rescue_arg_node)
@@ -19,14 +19,13 @@ module Rubocop
19
19
  next unless final_node && final_node.type == :send
20
20
 
21
21
  receiver, method_name, *args = *final_node
22
+ next unless method_name == :to_s && args.empty?
22
23
 
23
- if method_name == :to_s && args.empty?
24
- add_offense(
25
- final_node,
26
- :selector,
27
- receiver ? MSG_DEFAULT : MSG_SELF
28
- )
29
- end
24
+ add_offense(
25
+ final_node,
26
+ :selector,
27
+ receiver ? MSG_DEFAULT : MSG_SELF
28
+ )
30
29
  end
31
30
  end
32
31
 
@@ -16,9 +16,8 @@ module Rubocop
16
16
  expressions = *node
17
17
 
18
18
  expressions.each_cons(2) do |e1, e2|
19
- if NODE_TYPES.include?(e1.type) || flow_command?(e1)
20
- add_offense(e2, :expression)
21
- end
19
+ next unless NODE_TYPES.include?(e1.type) || flow_command?(e1)
20
+ add_offense(e2, :expression)
22
21
  end
23
22
  end
24
23
 
@@ -11,25 +11,12 @@ module Rubocop
11
11
  # puts used
12
12
  # end
13
13
  class UnusedBlockArgument < Cop
14
+ include UnusedArgument
14
15
  include Util
15
16
 
16
- def join_force?(force_class)
17
- force_class == VariableForce
18
- end
19
-
20
- def after_leaving_scope(scope, _variable_table)
21
- scope.variables.each_value do |variable|
22
- check_argument(variable)
23
- end
24
- end
25
-
26
17
  def check_argument(variable)
27
18
  return unless variable.block_argument?
28
- return if variable.name.to_s.start_with?('_')
29
- return if variable.referenced?
30
-
31
- message = message(variable)
32
- add_offense(variable.declaration_node, :name, message)
19
+ super
33
20
  end
34
21
 
35
22
  def message(variable)
@@ -11,23 +11,11 @@ module Rubocop
11
11
  # puts used
12
12
  # end
13
13
  class UnusedMethodArgument < Cop
14
- def join_force?(force_class)
15
- force_class == VariableForce
16
- end
17
-
18
- def after_leaving_scope(scope, _variable_table)
19
- scope.variables.each_value do |variable|
20
- check_argument(variable)
21
- end
22
- end
14
+ include UnusedArgument
23
15
 
24
16
  def check_argument(variable)
25
17
  return unless variable.method_argument?
26
- return if variable.name.to_s.start_with?('_')
27
- return if variable.referenced?
28
-
29
- message = message(variable)
30
- add_offense(variable.declaration_node, :name, message)
18
+ super
31
19
  end
32
20
 
33
21
  def message(variable)
@@ -16,13 +16,12 @@ module Rubocop
16
16
  def on_send(node)
17
17
  # lambda.() does not have a selector
18
18
  return unless node.loc.selector
19
- op = node.loc.selector.source
20
19
 
21
- if OPS.include?(op)
22
- receiver, _method, args = *node
20
+ op = node.loc.selector.source
21
+ return unless OPS.include?(op)
23
22
 
24
- add_offense(node, :selector) if receiver == args
25
- end
23
+ receiver, _method, args = *node
24
+ add_offense(node, :selector) if receiver == args
26
25
  end
27
26
  end
28
27
  end
@@ -29,6 +29,7 @@ module Rubocop
29
29
 
30
30
  def check_for_void_op(node)
31
31
  return unless node.type == :send
32
+ return unless node.loc.selector
32
33
 
33
34
  op = node.loc.selector.source
34
35
 
@@ -36,17 +37,14 @@ module Rubocop
36
37
  end
37
38
 
38
39
  def check_for_var(node)
39
- if VARS.include?(node.type)
40
- add_offense(node, :name,
41
- format(VAR_MSG, node.loc.name.source))
42
- end
40
+ return unless VARS.include?(node.type)
41
+ add_offense(node, :name, format(VAR_MSG, node.loc.name.source))
43
42
  end
44
43
 
45
44
  def check_for_literal(node)
46
- if LITERALS.include?(node.type)
47
- add_offense(node, :expression,
48
- format(LIT_MSG, node.loc.expression.source))
49
- end
45
+ return unless LITERALS.include?(node.type)
46
+ add_offense(node, :expression,
47
+ format(LIT_MSG, node.loc.expression.source))
50
48
  end
51
49
  end
52
50
  end
@@ -8,11 +8,13 @@ module Rubocop
8
8
  module AutocorrectAlignment
9
9
  def check_alignment(items, base_column = nil)
10
10
  base_column ||= items.first.loc.column unless items.empty?
11
- items.each_cons(2) do |prev, current|
12
- if current.loc.line > prev.loc.line && start_of_line?(current.loc)
11
+ prev_line = -1
12
+ items.each do |current|
13
+ if current.loc.line > prev_line && start_of_line?(current.loc)
13
14
  @column_delta = base_column - current.loc.column
14
15
  add_offense(current, :expression) if @column_delta != 0
15
16
  end
17
+ prev_line = current.loc.line
16
18
  end
17
19
  end
18
20
 
@@ -11,9 +11,7 @@ module Rubocop
11
11
  new_source = rewrite_node(node)
12
12
 
13
13
  # Make the correction only if it doesn't change the AST.
14
- if node != SourceParser.parse(new_source).ast
15
- fail CorrectionNotPossible
16
- end
14
+ fail CorrectionNotPossible if node != SourceParser.parse(new_source).ast
17
15
 
18
16
  @corrections << c
19
17
  end