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
@@ -16,11 +16,11 @@ module Rubocop
|
|
16
16
|
|
17
17
|
def check(node, *_)
|
18
18
|
length = code_length(node)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
return unless length > max_length
|
20
|
+
|
21
|
+
add_offense(node, :keyword, format(message, length,
|
22
|
+
max_length)) do
|
23
|
+
self.max = length
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -11,13 +11,13 @@ module Rubocop
|
|
11
11
|
# Look at last expression of contents if there's a parenthesis
|
12
12
|
# around condition.
|
13
13
|
condition = condition.children.last while condition.type == :begin
|
14
|
+
return unless condition.type == :send
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
16
|
+
_object, method = *condition
|
17
|
+
return unless method == :! && !(node.loc.respond_to?(:else) &&
|
18
|
+
node.loc.else)
|
19
|
+
|
20
|
+
add_offense(node, :expression)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -5,9 +5,8 @@ module Rubocop
|
|
5
5
|
# Common functionality for handling percent literals.
|
6
6
|
module PercentLiteral
|
7
7
|
def percent_literal?(node)
|
8
|
-
|
9
|
-
|
10
|
-
end
|
8
|
+
return unless (begin_source = begin_source(node))
|
9
|
+
begin_source.start_with?('%')
|
11
10
|
end
|
12
11
|
|
13
12
|
def process(node, *types)
|
@@ -9,11 +9,11 @@ module Rubocop
|
|
9
9
|
|
10
10
|
def investigate(processed_source)
|
11
11
|
processed_source.tokens.each_cons(2) do |t1, t2|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
next unless kind(t1) && t1.pos.line == t2.pos.line &&
|
13
|
+
t2.pos.column == t1.pos.column + offset &&
|
14
|
+
![:tRPAREN, :tRBRACK].include?(t2.type)
|
15
|
+
|
16
|
+
add_offense(t1, t1.pos, format(MSG, kind(t1)))
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -12,18 +12,17 @@ module Rubocop
|
|
12
12
|
@processed_source = processed_source
|
13
13
|
left, right, kind = specifics
|
14
14
|
processed_source.tokens.each_cons(2) do |t1, t2|
|
15
|
-
|
16
|
-
# If the second token is a comment, that means that a line break
|
17
|
-
# follows, and that the rules for space inside don't apply.
|
18
|
-
next if t2.type == :tCOMMENT
|
15
|
+
next unless t1.type == left || t2.type == right
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
# If the second token is a comment, that means that a line break
|
18
|
+
# follows, and that the rules for space inside don't apply.
|
19
|
+
next if t2.type == :tCOMMENT
|
20
|
+
next unless t2.pos.line == t1.pos.line && space_between?(t1, t2)
|
21
|
+
|
22
|
+
range = Parser::Source::Range.new(processed_source.buffer,
|
23
|
+
t1.pos.end_pos,
|
24
|
+
t2.pos.begin_pos)
|
25
|
+
add_offense(range, range, format(MSG, kind))
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rubocop
|
4
|
+
module Cop
|
5
|
+
module Lint
|
6
|
+
# Common functionality for cops handling unused arguments.
|
7
|
+
module UnusedArgument
|
8
|
+
def join_force?(force_class)
|
9
|
+
force_class == VariableForce
|
10
|
+
end
|
11
|
+
|
12
|
+
def autocorrect(node)
|
13
|
+
new_name = node.loc.expression.source.sub(/(\W?)(\w+)/, '\\1_\\2')
|
14
|
+
@corrections << lambda do |corrector|
|
15
|
+
corrector.replace(node.loc.expression, new_name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def after_leaving_scope(scope, _variable_table)
|
20
|
+
scope.variables.each_value do |variable|
|
21
|
+
check_argument(variable)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def check_argument(variable)
|
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)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/rubocop/cop/offense.rb
CHANGED
@@ -41,15 +41,13 @@ module Rubocop
|
|
41
41
|
|
42
42
|
def check_method_node(node)
|
43
43
|
_receiver, method_name, *_args = *node
|
44
|
+
return unless offending_method?(method_name)
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
method_name)
|
51
|
-
)
|
52
|
-
end
|
46
|
+
add_offense(node, :selector,
|
47
|
+
format(MSG,
|
48
|
+
preferred_method(method_name),
|
49
|
+
method_name)
|
50
|
+
)
|
53
51
|
end
|
54
52
|
|
55
53
|
def offending_method?(method_name)
|
@@ -20,14 +20,12 @@ module Rubocop
|
|
20
20
|
return unless command?(:default_scope, node)
|
21
21
|
|
22
22
|
_receiver, _method_name, *args = *node
|
23
|
-
|
24
23
|
return unless args.size == 1
|
25
24
|
|
26
25
|
first_arg = args[0]
|
26
|
+
return unless first_arg.type != :block || lambda_or_proc?(first_arg)
|
27
27
|
|
28
|
-
|
29
|
-
add_offense(first_arg, :expression)
|
30
|
-
end
|
28
|
+
add_offense(first_arg, :expression)
|
31
29
|
end
|
32
30
|
end
|
33
31
|
end
|
@@ -8,9 +8,8 @@ module Rubocop
|
|
8
8
|
MSG = 'Prefer `has_many :through` to `has_and_belongs_to_many`.'
|
9
9
|
|
10
10
|
def on_send(node)
|
11
|
-
|
12
|
-
|
13
|
-
end
|
11
|
+
return unless command?(:has_and_belongs_to_many, node)
|
12
|
+
add_offense(node, :selector)
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
@@ -15,10 +15,9 @@ module Rubocop
|
|
15
15
|
|
16
16
|
def on_send(node)
|
17
17
|
receiver, method_name, *_args = *node
|
18
|
+
return unless receiver.nil? && BLACKLIST.include?(method_name)
|
18
19
|
|
19
|
-
|
20
|
-
add_offense(node, :selector)
|
21
|
-
end
|
20
|
+
add_offense(node, :selector)
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
@@ -20,12 +20,11 @@ module Rubocop
|
|
20
20
|
|
21
21
|
def on_send(node)
|
22
22
|
receiver, method_name, *_args = *node
|
23
|
-
|
24
23
|
return if receiver
|
24
|
+
return unless [:read_attribute,
|
25
|
+
:write_attribute].include?(method_name)
|
25
26
|
|
26
|
-
|
27
|
-
add_offense(node, :selector)
|
28
|
-
end
|
27
|
+
add_offense(node, :selector)
|
29
28
|
end
|
30
29
|
|
31
30
|
def message(node)
|
@@ -20,10 +20,9 @@ module Rubocop
|
|
20
20
|
|
21
21
|
def on_send(node)
|
22
22
|
receiver, method_name, *_args = *node
|
23
|
+
return unless receiver.nil? && BLACKLIST.include?(method_name)
|
23
24
|
|
24
|
-
|
25
|
-
add_offense(node, :selector)
|
26
|
-
end
|
25
|
+
add_offense(node, :selector)
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end
|
@@ -14,9 +14,9 @@ module Rubocop
|
|
14
14
|
|
15
15
|
# using alias is the only option in certain scenarios
|
16
16
|
# in such scenarios we don't want to report an offense
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
return unless method_name == :instance_exec
|
18
|
+
|
19
|
+
on_node(:alias, body) { |n| ignore_node(n) }
|
20
20
|
end
|
21
21
|
|
22
22
|
def on_alias(node)
|
@@ -147,10 +147,10 @@ module Rubocop
|
|
147
147
|
'one line.'
|
148
148
|
|
149
149
|
def on_send(node)
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
150
|
+
return unless (last_child = node.children.last) &&
|
151
|
+
hash?(last_child) && ignore_last_argument_hash?(last_child)
|
152
|
+
|
153
|
+
ignore_node(last_child)
|
154
154
|
end
|
155
155
|
|
156
156
|
def on_hash(node)
|
@@ -28,11 +28,23 @@ module Rubocop
|
|
28
28
|
|
29
29
|
def base_column(node, args)
|
30
30
|
if fixed_indentation?
|
31
|
-
|
31
|
+
lineno = target_method_lineno(node)
|
32
|
+
line = node.loc.expression.source_buffer.source_line(lineno)
|
33
|
+
indentation_of_line = /\S.*/.match(line).begin(0)
|
34
|
+
indentation_of_line + 2
|
32
35
|
else
|
33
36
|
args.first.loc.column
|
34
37
|
end
|
35
38
|
end
|
39
|
+
|
40
|
+
def target_method_lineno(node)
|
41
|
+
if node.loc.selector
|
42
|
+
node.loc.selector.line
|
43
|
+
else
|
44
|
+
# l.(1) has no selector, so we use the opening parenthesis instead
|
45
|
+
node.loc.begin.line
|
46
|
+
end
|
47
|
+
end
|
36
48
|
end
|
37
49
|
end
|
38
50
|
end
|
@@ -24,12 +24,9 @@ module Rubocop
|
|
24
24
|
def process_logical_op(node)
|
25
25
|
op = node.loc.operator.source
|
26
26
|
op_type = node.type.to_s
|
27
|
+
return unless op == op_type
|
27
28
|
|
28
|
-
|
29
|
-
add_offense(node,
|
30
|
-
:operator,
|
31
|
-
format(MSG, OPS[op], op))
|
32
|
-
end
|
29
|
+
add_offense(node, :operator, format(MSG, OPS[op], op))
|
33
30
|
end
|
34
31
|
|
35
32
|
def correction(node)
|
@@ -13,11 +13,10 @@ module Rubocop
|
|
13
13
|
|
14
14
|
def on_send(node)
|
15
15
|
receiver_node, method_name, *arg_nodes = *node
|
16
|
+
return unless receiver_node && receiver_node.type == :array &&
|
17
|
+
method_name == :* && arg_nodes[0].type == :str
|
16
18
|
|
17
|
-
|
18
|
-
method_name == :* && arg_nodes[0].type == :str
|
19
|
-
add_offense(node, :selector)
|
20
|
-
end
|
19
|
+
add_offense(node, :selector)
|
21
20
|
end
|
22
21
|
end
|
23
22
|
end
|
@@ -9,9 +9,8 @@ module Rubocop
|
|
9
9
|
|
10
10
|
def investigate(processed_source)
|
11
11
|
processed_source.tokens.each do |t|
|
12
|
-
|
13
|
-
|
14
|
-
end
|
12
|
+
next unless t.type == :tIDENTIFIER && !t.text.ascii_only?
|
13
|
+
add_offense(nil, t.pos)
|
15
14
|
end
|
16
15
|
end
|
17
16
|
end
|
@@ -9,9 +9,8 @@ module Rubocop
|
|
9
9
|
|
10
10
|
def investigate(processed_source)
|
11
11
|
processed_source.comments.each do |comment|
|
12
|
-
|
13
|
-
|
14
|
-
end
|
12
|
+
next unless comment.text.start_with?('=begin')
|
13
|
+
add_offense(comment, :expression)
|
15
14
|
end
|
16
15
|
end
|
17
16
|
end
|
@@ -40,9 +40,8 @@ module Rubocop
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
node.children.each do |child|
|
43
|
-
|
44
|
-
|
45
|
-
end
|
43
|
+
next unless child.is_a?(Parser::AST::Node)
|
44
|
+
check_nesting_level(child, max, current_level)
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
@@ -13,15 +13,15 @@ module Rubocop
|
|
13
13
|
|
14
14
|
def on_send(node)
|
15
15
|
_receiver, method_name, *args = *node
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
return unless args.any?
|
17
|
+
|
18
|
+
block = get_block(args.last)
|
19
|
+
return unless block && !parentheses?(node) && !operator?(method_name)
|
20
|
+
|
21
|
+
# If there are no parentheses around the arguments, then braces and
|
22
|
+
# do-end have different meaning due to how they bind, so we allow
|
23
|
+
# either.
|
24
|
+
ignore_node(block)
|
25
25
|
end
|
26
26
|
|
27
27
|
def on_block(node)
|
@@ -63,11 +63,11 @@ module Rubocop
|
|
63
63
|
Parser::Source::Range.new(sb, pos_after_last_pair,
|
64
64
|
node.loc.end.begin_pos)
|
65
65
|
trailing_comma_offset = range_after_last_pair.source =~ /,/
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
66
|
+
return unless trailing_comma_offset
|
67
|
+
|
68
|
+
comma_begin = pos_after_last_pair + trailing_comma_offset
|
69
|
+
corrector.remove(Parser::Source::Range.new(sb, comma_begin,
|
70
|
+
comma_begin + 1))
|
71
71
|
end
|
72
72
|
|
73
73
|
def non_empty_hash?(arg)
|
@@ -33,12 +33,10 @@ module Rubocop
|
|
33
33
|
|
34
34
|
def check_defs(node)
|
35
35
|
definee, method_name, _args, _body = *node
|
36
|
+
return unless definee.type == :const
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
add_offense(definee, :name,
|
40
|
-
message(class_name, method_name))
|
41
|
-
end
|
38
|
+
_, class_name = *definee
|
39
|
+
add_offense(definee, :name, message(class_name, method_name))
|
42
40
|
end
|
43
41
|
|
44
42
|
def message(class_name, method_name)
|