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
@@ -24,10 +24,8 @@ module Rubocop
|
|
24
24
|
|
25
25
|
def check(node, method_name, _args, _body)
|
26
26
|
prefix_blacklist.each do |prefix|
|
27
|
-
|
28
|
-
|
29
|
-
message(method_name.to_s, prefix))
|
30
|
-
end
|
27
|
+
next unless method_name.to_s.start_with?(prefix)
|
28
|
+
add_offense(node, :name, message(method_name.to_s, prefix))
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
@@ -92,14 +92,13 @@ module Rubocop
|
|
92
92
|
|
93
93
|
def on_send(node)
|
94
94
|
receiver, method_name, *_args = *node
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
95
|
+
return unless receiver && receiver.type == :self
|
96
|
+
return if operator?(method_name) || keyword?(method_name) ||
|
97
|
+
constant_name?(method_name) ||
|
98
|
+
@allowed_send_nodes.include?(node) ||
|
99
|
+
@local_variables.include?(method_name)
|
100
|
+
|
101
|
+
add_offense(node, :expression)
|
103
102
|
end
|
104
103
|
|
105
104
|
def autocorrect(node)
|
@@ -134,10 +133,10 @@ module Rubocop
|
|
134
133
|
end
|
135
134
|
|
136
135
|
def allow_self(node)
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
136
|
+
return unless node.type == :send
|
137
|
+
|
138
|
+
receiver, _method_name, *_args = *node
|
139
|
+
@allowed_send_nodes << node if receiver && receiver.type == :self
|
141
140
|
end
|
142
141
|
end
|
143
142
|
end
|
@@ -15,6 +15,7 @@ module Rubocop
|
|
15
15
|
class SelfAssignment < Cop
|
16
16
|
include AST::Sexp
|
17
17
|
|
18
|
+
MSG = 'Use self-assignment shorthand `%s=`.'
|
18
19
|
OPS = [:+, :-, :*, :**, :/, :|, :&]
|
19
20
|
|
20
21
|
def on_lvasgn(node)
|
@@ -29,9 +30,10 @@ module Rubocop
|
|
29
30
|
check(node, :cvar)
|
30
31
|
end
|
31
32
|
|
33
|
+
private
|
34
|
+
|
32
35
|
def check(node, var_type)
|
33
36
|
var_name, rhs = *node
|
34
|
-
|
35
37
|
return unless rhs
|
36
38
|
|
37
39
|
if rhs.type == :send
|
@@ -43,29 +45,22 @@ module Rubocop
|
|
43
45
|
|
44
46
|
def check_send_node(node, rhs, var_name, var_type)
|
45
47
|
receiver, method_name, *_args = *rhs
|
46
|
-
|
47
48
|
return unless OPS.include?(method_name)
|
48
49
|
|
49
50
|
target_node = s(var_type, var_name)
|
51
|
+
return unless receiver == target_node
|
50
52
|
|
51
|
-
|
52
|
-
add_offense(node,
|
53
|
-
:expression,
|
54
|
-
"Use self-assignment shorthand `#{method_name}=`.")
|
55
|
-
end
|
53
|
+
add_offense(node, :expression, format(MSG, method_name))
|
56
54
|
end
|
57
55
|
|
58
56
|
def check_boolean_node(node, rhs, var_name, var_type)
|
59
57
|
first_operand, _second_operand = *rhs
|
60
58
|
|
61
59
|
target_node = s(var_type, var_name)
|
60
|
+
return unless first_operand == target_node
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
add_offense(node,
|
66
|
-
:expression,
|
67
|
-
"Use self-assignment shorthand `#{operator}=`.")
|
68
|
-
end
|
62
|
+
operator = rhs.loc.operator.source
|
63
|
+
add_offense(node, :expression, format(MSG, operator))
|
69
64
|
end
|
70
65
|
end
|
71
66
|
end
|
@@ -16,25 +16,23 @@ module Rubocop
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def on_begin(node)
|
19
|
-
|
20
|
-
|
19
|
+
return if cop_config['AllowAsExpressionSeparator']
|
20
|
+
exprs = node.children
|
21
21
|
|
22
|
-
|
22
|
+
return if exprs.size < 2
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
# create a map matching lines to the number of expressions on them
|
25
|
+
exprs_lines = exprs.map { |e| e.loc.expression.line }
|
26
|
+
lines = exprs_lines.group_by { |i| i }
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
28
|
+
# every line with more than 1 expression on it is an offense
|
29
|
+
lines.each do |line, expr_on_line|
|
30
|
+
next unless expr_on_line.size > 1
|
31
|
+
# TODO: Find the correct position of the semicolon. We don't know
|
32
|
+
# if the first semicolon on the line is a separator of
|
33
|
+
# expressions. It's just a guess.
|
34
|
+
column = @processed_source[line - 1].index(';')
|
35
|
+
convention_on(line, column, !:last_on_line)
|
38
36
|
end
|
39
37
|
end
|
40
38
|
|
@@ -46,9 +44,8 @@ module Rubocop
|
|
46
44
|
end
|
47
45
|
|
48
46
|
tokens_for_lines.each do |line, tokens|
|
49
|
-
|
50
|
-
|
51
|
-
end
|
47
|
+
next unless tokens.last.type == :tSEMI
|
48
|
+
convention_on(line, tokens.last.pos.column, :last_on_line)
|
52
49
|
end
|
53
50
|
end
|
54
51
|
|
@@ -11,15 +11,14 @@ module Rubocop
|
|
11
11
|
RAISE_MSG = 'Use `raise` instead of `fail` to rethrow exceptions.'
|
12
12
|
|
13
13
|
def on_rescue(node)
|
14
|
-
|
15
|
-
begin_node, *rescue_nodes, _else_node = *node
|
14
|
+
return unless style == :semantic
|
16
15
|
|
17
|
-
|
16
|
+
begin_node, *rescue_nodes, _else_node = *node
|
17
|
+
check_for(:raise, begin_node)
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
19
|
+
rescue_nodes.each do |rescue_node|
|
20
|
+
check_for(:fail, rescue_node)
|
21
|
+
allow(:raise, rescue_node)
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
@@ -65,10 +64,10 @@ module Rubocop
|
|
65
64
|
|
66
65
|
if style == :semantic
|
67
66
|
each_command(method_name, node) do |send_node|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
67
|
+
next if ignored_node?(send_node)
|
68
|
+
|
69
|
+
add_offense(send_node, :selector, message(method_name))
|
70
|
+
ignore_node(send_node)
|
72
71
|
end
|
73
72
|
else
|
74
73
|
_receiver, selector, _args = *node
|
@@ -24,10 +24,9 @@ module Rubocop
|
|
24
24
|
args = *args_node
|
25
25
|
|
26
26
|
return true unless args.all? { |n| n.type == :arg }
|
27
|
+
return if args_match?(method_name, args)
|
27
28
|
|
28
|
-
|
29
|
-
add_offense(args_node, :expression, message(method_name))
|
30
|
-
end
|
29
|
+
add_offense(args_node, :expression, message(method_name))
|
31
30
|
end
|
32
31
|
|
33
32
|
private
|
@@ -21,11 +21,10 @@ module Rubocop
|
|
21
21
|
end_line = node.loc.end.line
|
22
22
|
|
23
23
|
empty_body = body.nil?
|
24
|
+
return unless start_line == end_line && !(allow_empty? && empty_body)
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
add_offense(node, :expression)
|
28
|
-
end
|
26
|
+
@body = body
|
27
|
+
add_offense(node, :expression)
|
29
28
|
end
|
30
29
|
|
31
30
|
def autocorrect(node)
|
@@ -11,18 +11,18 @@ module Rubocop
|
|
11
11
|
|
12
12
|
def on_pair(node)
|
13
13
|
oper = node.loc.operator
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
return unless oper.is?(':') &&
|
15
|
+
oper.source_buffer.source[oper.end_pos] =~ /\S/
|
16
|
+
|
17
|
+
add_offense(oper, oper)
|
17
18
|
end
|
18
19
|
|
19
20
|
def on_if(node)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
21
|
+
return unless ternary_op?(node)
|
22
|
+
colon = node.loc.colon
|
23
|
+
return unless colon.source_buffer.source[colon.end_pos] =~ /\S/
|
24
|
+
|
25
|
+
add_offense(colon, colon)
|
26
26
|
end
|
27
27
|
|
28
28
|
def autocorrect(range)
|
@@ -15,9 +15,9 @@ module Rubocop
|
|
15
15
|
exp = node.loc.expression
|
16
16
|
kw = node.loc.keyword
|
17
17
|
kw_offset = kw.begin_pos - exp.begin_pos
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
return unless exp.source[kw_offset..-1].start_with?(kw.source + '(')
|
19
|
+
|
20
|
+
add_offense(node, kw)
|
21
21
|
end
|
22
22
|
|
23
23
|
KEYWORDS.each do |keyword|
|
@@ -24,9 +24,9 @@ module Rubocop
|
|
24
24
|
pos_before_left_paren = Parser::Source::Range.new(expr.source_buffer,
|
25
25
|
expr.begin_pos - 1,
|
26
26
|
expr.begin_pos)
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
return unless pos_before_left_paren.source =~ /\s/
|
28
|
+
|
29
|
+
add_offense(pos_before_left_paren, pos_before_left_paren)
|
30
30
|
end
|
31
31
|
|
32
32
|
def autocorrect(pos_before_left_paren)
|
@@ -18,11 +18,10 @@ module Rubocop
|
|
18
18
|
_receiver, method_name, *_args = *node
|
19
19
|
|
20
20
|
return unless method_name == :!
|
21
|
+
return unless node.loc.expression.source =~ /^!\s+\w+/
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
add_offense(node, :selector)
|
25
|
-
end
|
23
|
+
# TODO: Improve source range to highlight the redundant whitespace.
|
24
|
+
add_offense(node, :selector)
|
26
25
|
end
|
27
26
|
|
28
27
|
def autocorrect(node)
|
@@ -15,10 +15,10 @@ module Rubocop
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def on_if(node)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
return unless node.loc.respond_to?(:question)
|
19
|
+
|
20
|
+
check_operator(node.loc.question)
|
21
|
+
check_operator(node.loc.colon)
|
22
22
|
end
|
23
23
|
|
24
24
|
def on_resbody(node)
|
@@ -42,6 +42,7 @@ module Rubocop
|
|
42
42
|
|
43
43
|
def unary_operation?(node)
|
44
44
|
whole, selector = node.loc.expression, node.loc.selector
|
45
|
+
return unless selector
|
45
46
|
operator?(selector) && whole.begin_pos == selector.begin_pos
|
46
47
|
end
|
47
48
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rubocop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cop checks for missing space between a token and a comment on the
|
7
|
+
# same line.
|
8
|
+
class SpaceBeforeComment < Cop
|
9
|
+
MSG = 'Put a space before an end-of-line comment.'
|
10
|
+
|
11
|
+
def investigate(processed_source)
|
12
|
+
processed_source.tokens.each_cons(2) do |t1, t2|
|
13
|
+
next unless t2.type == :tCOMMENT
|
14
|
+
next unless t1.pos.line == t2.pos.line
|
15
|
+
add_offense(t2.pos, t2.pos) if t1.pos.end == t2.pos.begin
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def autocorrect(range)
|
22
|
+
@corrections << lambda do |corrector|
|
23
|
+
corrector.insert_before(range, ' ')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -8,14 +8,13 @@ module Rubocop
|
|
8
8
|
MSG = 'Put a space before the modifier keyword.'
|
9
9
|
|
10
10
|
def on_if(node)
|
11
|
-
|
12
|
-
kw = node.loc.keyword
|
13
|
-
b = kw.begin_pos
|
14
|
-
left_of_kw = Parser::Source::Range.new(kw.source_buffer, b - 1, b)
|
15
|
-
add_offense(node, left_of_kw) unless left_of_kw.is?(' ')
|
16
|
-
end
|
17
|
-
end
|
11
|
+
return unless modifier?(node)
|
18
12
|
|
13
|
+
kw = node.loc.keyword
|
14
|
+
b = kw.begin_pos
|
15
|
+
left_of_kw = Parser::Source::Range.new(kw.source_buffer, b - 1, b)
|
16
|
+
add_offense(node, left_of_kw) unless left_of_kw.is?(' ')
|
17
|
+
end
|
19
18
|
alias_method :on_while, :on_if
|
20
19
|
alias_method :on_until, :on_if
|
21
20
|
|
@@ -14,9 +14,8 @@ module Rubocop
|
|
14
14
|
|
15
15
|
def on_array(node)
|
16
16
|
# %i and %I were introduced in Ruby 2.0
|
17
|
-
|
18
|
-
|
19
|
-
end
|
17
|
+
return if RUBY_VERSION < '2.0.0'
|
18
|
+
add_offense(node, :expression) if array_of?(:sym, node)
|
20
19
|
end
|
21
20
|
end
|
22
21
|
end
|
@@ -10,14 +10,14 @@ module Rubocop
|
|
10
10
|
def investigate(processed_source)
|
11
11
|
processed_source.lines.each_with_index do |line, index|
|
12
12
|
match = line.match(/^( *)\t/)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
next unless match
|
14
|
+
|
15
|
+
spaces = match.captures[0]
|
16
|
+
add_offense(nil,
|
17
|
+
source_range(processed_source.buffer,
|
18
|
+
processed_source[0...index],
|
19
|
+
spaces.length, 1),
|
20
|
+
MSG)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -16,16 +16,16 @@ module Rubocop
|
|
16
16
|
blank_lines = whitespace_at_end.count("\n") - 1
|
17
17
|
wanted_blank_lines = style == :final_newline ? 0 : 1
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
19
|
+
return unless blank_lines != wanted_blank_lines
|
20
|
+
|
21
|
+
begin_pos = sb.source.length - whitespace_at_end.length
|
22
|
+
autocorrect_range = Parser::Source::Range.new(sb, begin_pos,
|
23
|
+
sb.source.length)
|
24
|
+
begin_pos += "\n".length unless whitespace_at_end.length == 0
|
25
|
+
report_range = Parser::Source::Range.new(sb, begin_pos,
|
26
|
+
sb.source.length)
|
27
|
+
add_offense(autocorrect_range, report_range,
|
28
|
+
message(wanted_blank_lines, blank_lines))
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
@@ -9,13 +9,12 @@ module Rubocop
|
|
9
9
|
|
10
10
|
def investigate(processed_source)
|
11
11
|
processed_source.lines.each_with_index do |line, index|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
12
|
+
next unless line =~ /.*[ \t]+$/
|
13
|
+
range = source_range(processed_source.buffer,
|
14
|
+
processed_source[0...index],
|
15
|
+
line.rstrip.length,
|
16
|
+
line.length - line.rstrip.length)
|
17
|
+
add_offense(range, range)
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|