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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/{rubocop-todo.yml → .rubocop_todo.yml} +5 -5
- data/CHANGELOG.md +41 -0
- data/README.md +21 -11
- data/config/default.yml +33 -10
- data/config/disabled.yml +0 -4
- data/config/enabled.yml +27 -1
- data/lib/rubocop.rb +17 -1
- data/lib/rubocop/config.rb +32 -27
- data/lib/rubocop/config_loader.rb +21 -8
- data/lib/rubocop/cop/cop.rb +8 -8
- data/lib/rubocop/cop/lint/block_alignment.rb +22 -22
- data/lib/rubocop/cop/lint/condition_position.rb +3 -5
- data/lib/rubocop/cop/lint/debugger.rb +4 -5
- data/lib/rubocop/cop/lint/end_alignment.rb +11 -10
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +10 -11
- data/lib/rubocop/cop/lint/require_parentheses.rb +7 -7
- data/lib/rubocop/cop/lint/rescue_exception.rb +3 -3
- data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +6 -7
- data/lib/rubocop/cop/lint/unreachable_code.rb +2 -3
- data/lib/rubocop/cop/lint/unused_block_argument.rb +2 -15
- data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -14
- data/lib/rubocop/cop/lint/useless_comparison.rb +4 -5
- data/lib/rubocop/cop/lint/void.rb +6 -8
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +4 -2
- data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +1 -3
- data/lib/rubocop/cop/mixin/code_length.rb +5 -5
- data/lib/rubocop/cop/mixin/negative_conditional.rb +6 -6
- data/lib/rubocop/cop/mixin/percent_literal.rb +2 -3
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +5 -5
- data/lib/rubocop/cop/mixin/space_inside.rb +10 -11
- data/lib/rubocop/cop/mixin/unused_argument.rb +35 -0
- data/lib/rubocop/cop/offense.rb +1 -1
- data/lib/rubocop/cop/rails/action_filter.rb +6 -8
- data/lib/rubocop/cop/rails/default_scope.rb +2 -4
- data/lib/rubocop/cop/rails/delegate.rb +2 -0
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +2 -3
- data/lib/rubocop/cop/rails/output.rb +2 -3
- data/lib/rubocop/cop/rails/read_write_attribute.rb +3 -4
- data/lib/rubocop/cop/rails/validation.rb +2 -3
- data/lib/rubocop/cop/style/alias.rb +3 -3
- data/lib/rubocop/cop/style/align_hash.rb +4 -4
- data/lib/rubocop/cop/style/align_parameters.rb +13 -1
- data/lib/rubocop/cop/style/and_or.rb +2 -5
- data/lib/rubocop/cop/style/array_join.rb +3 -4
- data/lib/rubocop/cop/style/ascii_identifiers.rb +2 -3
- data/lib/rubocop/cop/style/block_comments.rb +2 -3
- data/lib/rubocop/cop/style/block_nesting.rb +2 -3
- data/lib/rubocop/cop/style/blocks.rb +9 -9
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +5 -5
- data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
- data/lib/rubocop/cop/style/class_methods.rb +3 -5
- data/lib/rubocop/cop/style/collection_methods.rb +8 -11
- data/lib/rubocop/cop/style/comment_annotation.rb +9 -9
- data/lib/rubocop/cop/style/comment_indentation.rb +66 -0
- data/lib/rubocop/cop/style/constant_name.rb +3 -3
- data/lib/rubocop/cop/style/cyclomatic_complexity.rb +5 -5
- data/lib/rubocop/cop/style/deprecated_hash_methods.rb +6 -6
- data/lib/rubocop/cop/style/each_with_object.rb +38 -0
- data/lib/rubocop/cop/style/empty_lines.rb +8 -8
- data/lib/rubocop/cop/style/empty_lines_around_body.rb +7 -7
- data/lib/rubocop/cop/style/encoding.rb +6 -7
- data/lib/rubocop/cop/style/end_of_line.rb +10 -10
- data/lib/rubocop/cop/style/file_name.rb +11 -7
- data/lib/rubocop/cop/style/guard_clause.rb +32 -22
- data/lib/rubocop/cop/style/indentation_width.rb +25 -26
- data/lib/rubocop/cop/style/lambda.rb +8 -9
- data/lib/rubocop/cop/style/leading_comment_space.rb +4 -5
- data/lib/rubocop/cop/style/line_end_concatenation.rb +29 -6
- data/lib/rubocop/cop/style/line_length.rb +9 -9
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +7 -6
- data/lib/rubocop/cop/style/module_function.rb +3 -4
- data/lib/rubocop/cop/style/multiline_if_then.rb +3 -3
- data/lib/rubocop/cop/style/negated_if.rb +2 -0
- data/lib/rubocop/cop/style/next.rb +80 -0
- data/lib/rubocop/cop/style/nil_comparison.rb +2 -3
- data/lib/rubocop/cop/style/non_nil_check.rb +15 -3
- data/lib/rubocop/cop/style/not.rb +4 -4
- data/lib/rubocop/cop/style/numeric_literals.rb +7 -8
- data/lib/rubocop/cop/style/op_method.rb +3 -5
- data/lib/rubocop/cop/style/parameter_lists.rb +4 -4
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +5 -6
- data/lib/rubocop/cop/style/percent_literal_delimiters.rb +5 -5
- data/lib/rubocop/cop/style/predicate_name.rb +2 -4
- data/lib/rubocop/cop/style/redundant_self.rb +11 -12
- data/lib/rubocop/cop/style/self_assignment.rb +8 -13
- data/lib/rubocop/cop/style/semicolon.rb +16 -19
- data/lib/rubocop/cop/style/signal_exception.rb +10 -11
- data/lib/rubocop/cop/style/single_line_block_params.rb +2 -3
- data/lib/rubocop/cop/style/single_line_methods.rb +3 -4
- data/lib/rubocop/cop/style/space_after_colon.rb +9 -9
- data/lib/rubocop/cop/style/space_after_control_keyword.rb +3 -3
- data/lib/rubocop/cop/style/space_after_method_name.rb +3 -3
- data/lib/rubocop/cop/style/space_after_not.rb +3 -4
- data/lib/rubocop/cop/style/space_around_operators.rb +5 -4
- data/lib/rubocop/cop/style/space_before_comment.rb +29 -0
- data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +6 -7
- data/lib/rubocop/cop/style/symbol_array.rb +2 -3
- data/lib/rubocop/cop/style/tab.rb +8 -8
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +10 -10
- data/lib/rubocop/cop/style/trailing_whitespace.rb +6 -7
- data/lib/rubocop/cop/style/trivial_accessors.rb +3 -4
- data/lib/rubocop/cop/style/unless_else.rb +2 -3
- data/lib/rubocop/cop/style/unneeded_capital_w.rb +3 -3
- data/lib/rubocop/cop/style/unneeded_percent_x.rb +26 -0
- data/lib/rubocop/cop/style/when_then.rb +3 -3
- data/lib/rubocop/cop/style/while_until_do.rb +3 -6
- data/lib/rubocop/cop/style/word_array.rb +8 -7
- data/lib/rubocop/cop/team.rb +9 -11
- data/lib/rubocop/cop/util.rb +2 -3
- data/lib/rubocop/cop/variable_force.rb +2 -3
- data/lib/rubocop/cop/variable_force/variable_table.rb +1 -2
- data/lib/rubocop/file_inspector.rb +5 -0
- data/lib/rubocop/formatter/clang_style_formatter.rb +3 -4
- data/lib/rubocop/formatter/disabled_config_formatter.rb +6 -6
- data/lib/rubocop/options.rb +14 -11
- data/lib/rubocop/target_finder.rb +12 -1
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.21.0.md +11 -0
- data/relnotes/v0.22.0.md +77 -0
- data/spec/rubocop/cli_spec.rb +86 -40
- data/spec/rubocop/comment_config_spec.rb +1 -1
- data/spec/rubocop/config_loader_spec.rb +3 -3
- data/spec/rubocop/config_spec.rb +14 -3
- data/spec/rubocop/cop/force_spec.rb +1 -1
- data/spec/rubocop/cop/lint/unused_block_argument_spec.rb +164 -99
- data/spec/rubocop/cop/lint/unused_method_argument_spec.rb +195 -85
- data/spec/rubocop/cop/lint/void_spec.rb +8 -0
- data/spec/rubocop/cop/rails/delegate_spec.rb +17 -0
- data/spec/rubocop/cop/rails/output_spec.rb +3 -3
- data/spec/rubocop/cop/severity_spec.rb +5 -5
- data/spec/rubocop/cop/style/align_parameters_spec.rb +108 -0
- data/spec/rubocop/cop/style/block_nesting_spec.rb +3 -3
- data/spec/rubocop/cop/style/class_and_module_children_spec.rb +12 -10
- data/spec/rubocop/cop/style/comment_indentation_spec.rb +174 -0
- data/spec/rubocop/cop/style/each_with_object_spec.rb +44 -0
- data/spec/rubocop/cop/style/end_of_line_spec.rb +3 -5
- data/spec/rubocop/cop/style/guard_clause_spec.rb +135 -57
- data/spec/rubocop/cop/style/if_unless_modifier_spec.rb +7 -7
- data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +75 -1
- data/spec/rubocop/cop/style/line_length_spec.rb +7 -7
- data/spec/rubocop/cop/style/negated_if_spec.rb +5 -1
- data/spec/rubocop/cop/style/next_spec.rb +210 -0
- data/spec/rubocop/cop/style/non_nil_check_spec.rb +44 -13
- data/spec/rubocop/cop/style/self_assignment_spec.rb +1 -1
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +1 -0
- data/spec/rubocop/cop/style/space_before_comment_spec.rb +34 -0
- data/spec/rubocop/cop/style/unneeded_percent_x_spec.rb +34 -0
- data/spec/rubocop/cop/style/while_until_modifier_spec.rb +2 -2
- data/spec/rubocop/cop/util_spec.rb +2 -2
- data/spec/rubocop/cop/variable_force_spec.rb +1 -1
- data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +4 -4
- data/spec/rubocop/formatter/disabled_lines_formatter_spec.rb +2 -2
- data/spec/rubocop/formatter/offense_count_formatter_spec.rb +2 -2
- data/spec/rubocop/options_spec.rb +3 -0
- data/spec/support/shared_context.rb +1 -3
- data/spec/support/statement_modifier_helper.rb +2 -2
- 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 = '
|
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
|
-
|
53
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
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
|
data/lib/rubocop/cop/cop.rb
CHANGED
@@ -189,14 +189,14 @@ module Rubocop
|
|
189
189
|
|
190
190
|
def custom_severity
|
191
191
|
severity = cop_config && cop_config['Severity']
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
20
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
22
|
-
|
20
|
+
op = node.loc.selector.source
|
21
|
+
return unless OPS.include?(op)
|
23
22
|
|
24
|
-
|
25
|
-
|
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
|
-
|
40
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
12
|
-
|
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
|