rubocop 0.12.0 → 0.13.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.
- data/CHANGELOG.md +40 -0
- data/README.md +49 -8
- data/config/default.yml +40 -0
- data/config/enabled.yml +37 -9
- data/lib/rubocop.rb +24 -10
- data/lib/rubocop/cli.rb +41 -106
- data/lib/rubocop/config.rb +3 -2
- data/lib/rubocop/cop/commissioner.rb +15 -5
- data/lib/rubocop/cop/cop.rb +47 -32
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +2 -2
- data/lib/rubocop/cop/lint/block_alignment.rb +30 -9
- data/lib/rubocop/cop/lint/empty_ensure.rb +1 -1
- data/lib/rubocop/cop/lint/end_alignment.rb +4 -4
- data/lib/rubocop/cop/lint/end_in_method.rb +1 -1
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -1
- data/lib/rubocop/cop/lint/eval.rb +1 -3
- data/lib/rubocop/cop/lint/handle_exceptions.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_condition.rb +6 -4
- data/lib/rubocop/cop/lint/loop.rb +1 -1
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/rescue_exception.rb +1 -1
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +5 -8
- data/lib/rubocop/cop/lint/unreachable_code.rb +1 -1
- data/lib/rubocop/cop/lint/useless_assignment.rb +57 -60
- data/lib/rubocop/cop/lint/useless_comparison.rb +1 -1
- data/lib/rubocop/cop/lint/useless_setter_call.rb +85 -0
- data/lib/rubocop/cop/lint/void.rb +6 -8
- data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +1 -1
- data/lib/rubocop/cop/rails/read_attribute.rb +1 -1
- data/lib/rubocop/cop/rails/validation.rb +1 -1
- data/lib/rubocop/cop/style/access_control.rb +4 -6
- data/lib/rubocop/cop/style/alias.rb +1 -3
- data/lib/rubocop/cop/style/align_array.rb +47 -0
- data/lib/rubocop/cop/style/align_hash.rb +145 -0
- data/lib/rubocop/cop/style/align_parameters.rb +9 -3
- data/lib/rubocop/cop/style/and_or.rb +3 -4
- data/lib/rubocop/cop/style/ascii_comments.rb +1 -3
- data/lib/rubocop/cop/style/ascii_identifiers.rb +1 -1
- data/lib/rubocop/cop/style/attr.rb +1 -4
- data/lib/rubocop/cop/style/begin_block.rb +1 -1
- data/lib/rubocop/cop/style/block_comments.rb +1 -1
- data/lib/rubocop/cop/style/block_nesting.rb +2 -2
- data/lib/rubocop/cop/style/blocks.rb +14 -2
- data/lib/rubocop/cop/style/case_equality.rb +1 -3
- data/lib/rubocop/cop/style/case_indentation.rb +1 -1
- data/lib/rubocop/cop/style/character_literal.rb +1 -2
- data/lib/rubocop/cop/style/class_and_module_camel_case.rb +1 -1
- data/lib/rubocop/cop/style/class_methods.rb +1 -3
- data/lib/rubocop/cop/style/{avoid_class_vars.rb → class_vars.rb} +6 -2
- data/lib/rubocop/cop/style/collection_methods.rb +7 -9
- data/lib/rubocop/cop/style/colon_method_call.rb +1 -2
- data/lib/rubocop/cop/style/comment_annotation.rb +6 -6
- data/lib/rubocop/cop/style/constant_name.rb +1 -3
- data/lib/rubocop/cop/style/def_parentheses.rb +4 -12
- data/lib/rubocop/cop/style/documentation.rb +2 -2
- data/lib/rubocop/cop/style/dot_position.rb +2 -4
- data/lib/rubocop/cop/style/empty_line_between_defs.rb +21 -6
- data/lib/rubocop/cop/style/empty_lines.rb +1 -1
- data/lib/rubocop/cop/style/empty_literal.rb +3 -12
- data/lib/rubocop/cop/style/encoding.rb +6 -6
- data/lib/rubocop/cop/style/end_block.rb +1 -1
- data/lib/rubocop/cop/style/end_of_line.rb +5 -5
- data/lib/rubocop/cop/style/even_odd.rb +2 -2
- data/lib/rubocop/cop/style/favor_join.rb +1 -3
- data/lib/rubocop/cop/style/favor_modifier.rb +7 -3
- data/lib/rubocop/cop/style/favor_sprintf.rb +1 -1
- data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +1 -1
- data/lib/rubocop/cop/style/final_newline.rb +23 -0
- data/lib/rubocop/cop/style/{avoid_for.rb → for.rb} +2 -2
- data/lib/rubocop/cop/style/{avoid_global_vars.rb → global_vars.rb} +19 -6
- data/lib/rubocop/cop/style/hash_methods.rb +3 -5
- data/lib/rubocop/cop/style/hash_syntax.rb +4 -4
- data/lib/rubocop/cop/style/if_then_else.rb +1 -1
- data/lib/rubocop/cop/style/indentation_width.rb +4 -4
- data/lib/rubocop/cop/style/lambda.rb +2 -2
- data/lib/rubocop/cop/style/leading_comment_space.rb +1 -1
- data/lib/rubocop/cop/style/line_length.rb +7 -8
- data/lib/rubocop/cop/style/method_and_variable_snake_case.rb +1 -1
- data/lib/rubocop/cop/style/method_call_parentheses.rb +1 -4
- data/lib/rubocop/cop/style/method_length.rb +4 -4
- data/lib/rubocop/cop/style/module_function.rb +1 -3
- data/lib/rubocop/cop/style/multiline_block_chain.rb +44 -0
- data/lib/rubocop/cop/style/nil_comparison.rb +1 -3
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/numeric_literals.rb +26 -6
- data/lib/rubocop/cop/style/op_method.rb +2 -2
- data/lib/rubocop/cop/style/parameter_lists.rb +4 -4
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +2 -2
- data/lib/rubocop/cop/style/perl_backrefs.rb +26 -0
- data/lib/rubocop/cop/style/proc.rb +1 -3
- data/lib/rubocop/cop/style/reduce_arguments.rb +7 -5
- data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
- data/lib/rubocop/cop/style/redundant_return.rb +9 -2
- data/lib/rubocop/cop/style/redundant_self.rb +9 -2
- data/lib/rubocop/cop/style/regexp_literal.rb +7 -8
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
- data/lib/rubocop/cop/style/semicolon.rb +10 -10
- data/lib/rubocop/cop/style/signal_exception.rb +2 -4
- data/lib/rubocop/cop/style/single_line_methods.rb +2 -4
- data/lib/rubocop/cop/style/space_after_comma_etc.rb +1 -1
- data/lib/rubocop/cop/style/space_after_control_keyword.rb +1 -1
- data/lib/rubocop/cop/style/space_after_method_name.rb +1 -1
- data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +34 -0
- data/lib/rubocop/cop/style/{avoid_perlisms.rb → special_global_vars.rb} +17 -8
- data/lib/rubocop/cop/style/string_literals.rb +1 -2
- data/lib/rubocop/cop/style/surrounding_space.rb +9 -8
- data/lib/rubocop/cop/style/symbol_array.rb +1 -1
- data/lib/rubocop/cop/style/symbol_name.rb +9 -2
- data/lib/rubocop/cop/style/tab.rb +5 -5
- data/lib/rubocop/cop/style/ternary_operator.rb +2 -6
- data/lib/rubocop/cop/style/trailing_blank_lines.rb +32 -0
- data/lib/rubocop/cop/style/trailing_whitespace.rb +5 -6
- data/lib/rubocop/cop/style/trivial_accessors.rb +5 -5
- data/lib/rubocop/cop/style/unless_else.rb +1 -1
- data/lib/rubocop/cop/style/variable_interpolation.rb +1 -3
- data/lib/rubocop/cop/style/when_then.rb +1 -4
- data/lib/rubocop/cop/style/while_until_do.rb +7 -5
- data/lib/rubocop/cop/style/word_array.rb +1 -1
- data/lib/rubocop/cop/team.rb +100 -0
- data/lib/rubocop/cop/variable_inspector.rb +323 -235
- data/lib/rubocop/cop/variable_inspector/assignment.rb +103 -0
- data/lib/rubocop/cop/variable_inspector/locatable.rb +162 -0
- data/lib/rubocop/cop/variable_inspector/reference.rb +31 -0
- data/lib/rubocop/cop/variable_inspector/scope.rb +70 -0
- data/lib/rubocop/cop/variable_inspector/variable.rb +87 -0
- data/lib/rubocop/cop/variable_inspector/variable_table.rb +129 -0
- data/lib/rubocop/formatter/json_formatter.rb +8 -8
- data/lib/rubocop/formatter/progress_formatter.rb +4 -4
- data/lib/rubocop/processed_source.rb +22 -1
- data/lib/rubocop/version.rb +1 -1
- data/rubocop.gemspec +1 -1
- data/spec/rubocop/cli_spec.rb +32 -30
- data/spec/rubocop/config_spec.rb +4 -6
- data/spec/rubocop/cop/commissioner_spec.rb +4 -5
- data/spec/rubocop/cop/cop_spec.rb +8 -26
- data/spec/rubocop/cop/lint/assignment_in_condition_spec.rb +5 -9
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +105 -57
- data/spec/rubocop/cop/lint/empty_ensure_spec.rb +1 -1
- data/spec/rubocop/cop/lint/end_alignment_spec.rb +1 -1
- data/spec/rubocop/cop/lint/end_in_method_spec.rb +1 -1
- data/spec/rubocop/cop/lint/ensure_return_spec.rb +1 -1
- data/spec/rubocop/cop/lint/eval_spec.rb +3 -3
- data/spec/rubocop/cop/lint/handle_exceptions_spec.rb +2 -2
- data/spec/rubocop/cop/lint/literal_in_condition_spec.rb +1 -1
- data/spec/rubocop/cop/lint/loop_spec.rb +1 -1
- data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +1 -1
- data/spec/rubocop/cop/lint/rescue_exception_spec.rb +5 -5
- data/spec/rubocop/cop/lint/unreachable_code_spec.rb +1 -1
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +1545 -108
- data/spec/rubocop/cop/lint/useless_comparison_spec.rb +1 -1
- data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +101 -0
- data/spec/rubocop/cop/lint/void_spec.rb +1 -1
- data/spec/rubocop/cop/offence_spec.rb +4 -4
- data/spec/rubocop/cop/rails/has_and_belongs_to_many_spec.rb +1 -1
- data/spec/rubocop/cop/rails/read_attribute_spec.rb +1 -1
- data/spec/rubocop/cop/rails/validation_spec.rb +1 -1
- data/spec/rubocop/cop/style/access_control_spec.rb +20 -20
- data/spec/rubocop/cop/style/alias_spec.rb +3 -3
- data/spec/rubocop/cop/style/align_array_spec.rb +62 -0
- data/spec/rubocop/cop/style/align_hash_spec.rb +267 -0
- data/spec/rubocop/cop/style/align_parameters_spec.rb +2 -2
- data/spec/rubocop/cop/style/and_or_spec.rb +1 -1
- data/spec/rubocop/cop/style/ascii_comments_spec.rb +2 -2
- data/spec/rubocop/cop/style/ascii_identifiers_spec.rb +2 -2
- data/spec/rubocop/cop/style/attr_spec.rb +1 -1
- data/spec/rubocop/cop/style/begin_block_spec.rb +1 -1
- data/spec/rubocop/cop/style/block_comments_spec.rb +1 -1
- data/spec/rubocop/cop/style/block_nesting_spec.rb +3 -3
- data/spec/rubocop/cop/style/blocks_spec.rb +25 -1
- data/spec/rubocop/cop/style/case_equality_spec.rb +1 -1
- data/spec/rubocop/cop/style/case_indentation_spec.rb +5 -5
- data/spec/rubocop/cop/style/character_literal_spec.rb +1 -1
- data/spec/rubocop/cop/style/class_and_module_camel_case_spec.rb +1 -1
- data/spec/rubocop/cop/style/class_methods_spec.rb +1 -1
- data/spec/rubocop/cop/style/class_vars_spec.rb +25 -0
- data/spec/rubocop/cop/style/collection_methods_spec.rb +5 -6
- data/spec/rubocop/cop/style/colon_method_call_spec.rb +0 -3
- data/spec/rubocop/cop/style/comment_annotation_spec.rb +20 -18
- data/spec/rubocop/cop/style/constant_name_spec.rb +1 -1
- data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +1 -1
- data/spec/rubocop/cop/style/def_without_parentheses_spec.rb +1 -1
- data/spec/rubocop/cop/style/documentation_spec.rb +1 -1
- data/spec/rubocop/cop/style/dot_position_spec.rb +5 -5
- data/spec/rubocop/cop/style/empty_line_between_defs_spec.rb +35 -4
- data/spec/rubocop/cop/style/empty_lines_spec.rb +1 -1
- data/spec/rubocop/cop/style/empty_literal_spec.rb +7 -7
- data/spec/rubocop/cop/style/encoding_spec.rb +11 -5
- data/spec/rubocop/cop/style/end_block_spec.rb +1 -1
- data/spec/rubocop/cop/style/end_of_line_spec.rb +4 -3
- data/spec/rubocop/cop/style/even_odd_spec.rb +1 -1
- data/spec/rubocop/cop/style/favor_join_spec.rb +2 -2
- data/spec/rubocop/cop/style/favor_modifier_spec.rb +13 -10
- data/spec/rubocop/cop/style/favor_sprintf_spec.rb +4 -4
- data/spec/rubocop/cop/style/favor_unless_over_negated_if_spec.rb +1 -1
- data/spec/rubocop/cop/style/favor_until_over_negated_while_spec.rb +4 -4
- data/spec/rubocop/cop/style/final_newline_spec.rb +25 -0
- data/spec/rubocop/cop/style/{avoid_for_spec.rb → for_spec.rb} +8 -12
- data/spec/rubocop/cop/style/{avoid_global_vars_spec.rb → global_vars_spec.rb} +13 -3
- data/spec/rubocop/cop/style/hash_methods_spec.rb +1 -1
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +20 -9
- data/spec/rubocop/cop/style/if_with_semicolon_spec.rb +3 -3
- data/spec/rubocop/cop/style/indentation_width_spec.rb +19 -19
- data/spec/rubocop/cop/style/lambda_spec.rb +6 -6
- data/spec/rubocop/cop/style/leading_comment_space_spec.rb +1 -1
- data/spec/rubocop/cop/style/line_length_spec.rb +3 -3
- data/spec/rubocop/cop/style/method_and_variable_snake_case_spec.rb +8 -9
- data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +1 -1
- data/spec/rubocop/cop/style/method_length_spec.rb +18 -17
- data/spec/rubocop/cop/style/module_function_spec.rb +1 -1
- data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +84 -0
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +2 -2
- data/spec/rubocop/cop/style/nil_comparison_spec.rb +1 -1
- data/spec/rubocop/cop/style/not_spec.rb +1 -1
- data/spec/rubocop/cop/style/numeric_literals_spec.rb +15 -25
- data/spec/rubocop/cop/style/one_line_conditional_spec.rb +2 -2
- data/spec/rubocop/cop/style/op_method_spec.rb +3 -3
- data/spec/rubocop/cop/style/parameter_lists_spec.rb +5 -5
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +4 -8
- data/spec/rubocop/cop/style/perl_backrefs_spec.rb +23 -0
- data/spec/rubocop/cop/style/proc_spec.rb +1 -1
- data/spec/rubocop/cop/style/reduce_arguments_spec.rb +18 -11
- data/spec/rubocop/cop/style/redundant_begin_spec.rb +1 -1
- data/spec/rubocop/cop/style/redundant_return_spec.rb +16 -1
- data/spec/rubocop/cop/style/redundant_self_spec.rb +6 -1
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +19 -23
- data/spec/rubocop/cop/style/rescue_modifier_spec.rb +3 -3
- data/spec/rubocop/cop/style/semicolon_spec.rb +3 -3
- data/spec/rubocop/cop/style/signal_exception_spec.rb +1 -1
- data/spec/rubocop/cop/style/single_line_methods_spec.rb +22 -18
- data/spec/rubocop/cop/style/space_after_colon_spec.rb +4 -4
- data/spec/rubocop/cop/style/space_after_comma_spec.rb +4 -4
- data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +1 -1
- data/spec/rubocop/cop/style/space_after_method_name_spec.rb +1 -1
- data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +3 -3
- data/spec/rubocop/cop/style/space_around_braces_spec.rb +13 -12
- data/spec/rubocop/cop/style/space_around_equals_in_default_parameter_spec.rb +3 -3
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +25 -25
- data/spec/rubocop/cop/style/space_before_modifier_keyword_spec.rb +53 -0
- data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +9 -9
- data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +47 -61
- data/spec/rubocop/cop/style/space_inside_parens_spec.rb +4 -4
- data/spec/rubocop/cop/style/special_global_vars_spec.rb +52 -0
- data/spec/rubocop/cop/style/string_literals_spec.rb +5 -5
- data/spec/rubocop/cop/style/symbol_array_spec.rb +1 -1
- data/spec/rubocop/cop/style/symbol_name_spec.rb +27 -18
- data/spec/rubocop/cop/style/tab_spec.rb +1 -1
- data/spec/rubocop/cop/style/ternary_operator_spec.rb +2 -2
- data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +24 -0
- data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +7 -7
- data/spec/rubocop/cop/style/trivial_accessors_spec.rb +6 -14
- data/spec/rubocop/cop/style/unless_else_spec.rb +3 -3
- data/spec/rubocop/cop/style/variable_interpolation_spec.rb +5 -5
- data/spec/rubocop/cop/style/when_then_spec.rb +15 -15
- data/spec/rubocop/cop/style/while_until_do_spec.rb +3 -3
- data/spec/rubocop/cop/style/word_array_spec.rb +1 -1
- data/spec/rubocop/cop/team_spec.rb +158 -0
- data/spec/rubocop/cop/variable_inspector/assignment_spec.rb +217 -0
- data/spec/rubocop/cop/variable_inspector/locatable_spec.rb +740 -0
- data/spec/rubocop/cop/variable_inspector/scope_spec.rb +191 -0
- data/spec/rubocop/cop/variable_inspector/variable_spec.rb +79 -0
- data/spec/rubocop/cop/variable_inspector/variable_table_spec.rb +275 -0
- data/spec/rubocop/cop/variable_inspector_spec.rb +13 -533
- data/spec/rubocop/formatter/clang_style_formatter_spec.rb +4 -4
- data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +1 -1
- data/spec/rubocop/formatter/emacs_style_formatter_spec.rb +3 -3
- data/spec/rubocop/formatter/file_list_formatter_spec.rb +3 -3
- data/spec/rubocop/formatter/progress_formatter_spec.rb +1 -1
- data/spec/spec_helper.rb +5 -1
- data/spec/support/ast_helper.rb +15 -0
- data/spec/support/shared_context.rb +18 -0
- data/spec/support/shared_examples.rb +1 -1
- metadata +95 -32
- checksums.yaml +0 -7
- data/lib/rubocop/cop/lint/unused_local_variable.rb +0 -32
- data/lib/rubocop/cop/style/avoid_perl_backrefs.rb +0 -19
- data/spec/rubocop/cop/lint/unused_local_variable_spec.rb +0 -588
- data/spec/rubocop/cop/style/avoid_class_vars_spec.rb +0 -27
- data/spec/rubocop/cop/style/avoid_perl_backrefs_spec.rb +0 -20
- data/spec/rubocop/cop/style/avoid_perlisms_spec.rb +0 -47
@@ -17,8 +17,8 @@ module Rubocop
|
|
17
17
|
|
18
18
|
if name !~ /\A\w/ && !BLACKLISTED.include?(name) &&
|
19
19
|
args.children.size == 1 && args != TARGET_ARGS
|
20
|
-
|
21
|
-
|
20
|
+
convention(args.children[0], :expression,
|
21
|
+
sprintf(MSG, name))
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -12,8 +12,8 @@ module Rubocop
|
|
12
12
|
|
13
13
|
def on_args(node)
|
14
14
|
if args_count(node) > max_params
|
15
|
-
|
16
|
-
|
15
|
+
convention(node, :expression,
|
16
|
+
sprintf(MSG, max_params))
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -28,11 +28,11 @@ module Rubocop
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def max_params
|
31
|
-
|
31
|
+
cop_config['Max']
|
32
32
|
end
|
33
33
|
|
34
34
|
def count_keyword_args?
|
35
|
-
|
35
|
+
cop_config['CountKeywordArgs']
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -31,7 +31,7 @@ module Rubocop
|
|
31
31
|
# allow safe assignment
|
32
32
|
return if safe_assignment?(cond) && safe_assignment_allowed?
|
33
33
|
|
34
|
-
|
34
|
+
convention(cond, :expression)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -40,7 +40,7 @@ module Rubocop
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def safe_assignment_allowed?
|
43
|
-
|
43
|
+
cop_config['AllowSafeAssignment']
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rubocop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# This cop looks for uses of Perl-style regexp match
|
7
|
+
# backreferences like $1, $2, etc.
|
8
|
+
class PerlBackrefs < Cop
|
9
|
+
MSG = 'Avoid the use of Perl-style backrefs.'
|
10
|
+
|
11
|
+
def on_nth_ref(node)
|
12
|
+
convention(node, :expression)
|
13
|
+
end
|
14
|
+
|
15
|
+
def autocorrect_action(node)
|
16
|
+
@corrections << lambda do |corrector|
|
17
|
+
backref, = *node
|
18
|
+
|
19
|
+
corrector.replace(node.loc.expression,
|
20
|
+
"Regexp.last_match[#{backref}]")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -5,9 +5,9 @@ module Rubocop
|
|
5
5
|
module Style
|
6
6
|
# This cop checks whether the block arguments of a single-line
|
7
7
|
# reduce(inject) call are named *a*(for accumulator) and *e*
|
8
|
-
# (for element)
|
8
|
+
# (for element).
|
9
9
|
class ReduceArguments < Cop
|
10
|
-
MSG = 'Name reduce arguments |a, e| (accumulator, element).'
|
10
|
+
MSG = 'Name reduce block arguments |a, e| (accumulator, element).'
|
11
11
|
|
12
12
|
ARGS_NODE = s(:args, s(:arg, :a), s(:arg, :e))
|
13
13
|
|
@@ -22,9 +22,11 @@ module Rubocop
|
|
22
22
|
return unless receiver
|
23
23
|
return unless [:reduce, :inject].include?(method_name)
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
# discard second argument destructuring
|
26
|
+
_, element_node = *args_node
|
27
|
+
return unless element_node.type == :arg
|
28
|
+
|
29
|
+
convention(args_node, :expression) unless args_node == ARGS_NODE
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
@@ -37,17 +37,24 @@ module Rubocop
|
|
37
37
|
|
38
38
|
private
|
39
39
|
|
40
|
+
def autocorrect_action(node)
|
41
|
+
@corrections << lambda do |corrector|
|
42
|
+
corrector.replace(node.loc.expression,
|
43
|
+
node.loc.expression.source.sub('return ', ''))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
40
47
|
def check(node)
|
41
48
|
return unless node
|
42
49
|
|
43
50
|
if node.type == :return
|
44
|
-
|
51
|
+
convention(node, :keyword)
|
45
52
|
elsif node.type == :begin
|
46
53
|
expressions = *node
|
47
54
|
last_expr = expressions.last
|
48
55
|
|
49
56
|
if last_expr && last_expr.type == :return
|
50
|
-
|
57
|
+
convention(last_expr, :keyword)
|
51
58
|
end
|
52
59
|
end
|
53
60
|
end
|
@@ -13,7 +13,7 @@ module Rubocop
|
|
13
13
|
class RedundantSelf < Cop
|
14
14
|
MSG = 'Redundant `self` detected.'
|
15
15
|
|
16
|
-
def initialize
|
16
|
+
def initialize(config = nil, options = nil)
|
17
17
|
super
|
18
18
|
@allowed_send_nodes = []
|
19
19
|
@local_variables = []
|
@@ -56,11 +56,18 @@ module Rubocop
|
|
56
56
|
unless operator?(method_name) || keyword?(method_name) ||
|
57
57
|
@allowed_send_nodes.include?(node) ||
|
58
58
|
@local_variables.include?(method_name)
|
59
|
-
|
59
|
+
convention(node, :expression)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
def autocorrect_action(node)
|
65
|
+
@corrections << lambda do |corrector|
|
66
|
+
corrector.replace(node.loc.expression,
|
67
|
+
node.loc.expression.source.gsub(/self\./, ''))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
64
71
|
private
|
65
72
|
|
66
73
|
def operator?(method_name)
|
@@ -9,18 +9,17 @@ module Rubocop
|
|
9
9
|
class RegexpLiteral < Cop
|
10
10
|
def on_regexp(node)
|
11
11
|
slashes = node.loc.expression.source.count('/')
|
12
|
-
max = RegexpLiteral.max_slashes
|
13
12
|
msg = if node.loc.begin.is?('/')
|
14
13
|
slashes -= 2 # subtract delimiters
|
15
|
-
error_message('') if slashes >
|
14
|
+
error_message('') if slashes > max_slashes
|
16
15
|
else
|
17
|
-
error_message('only ') if slashes <=
|
16
|
+
error_message('only ') if slashes <= max_slashes
|
18
17
|
end
|
19
|
-
|
18
|
+
convention(node, :expression, msg) if msg
|
20
19
|
end
|
21
20
|
|
22
|
-
def
|
23
|
-
|
21
|
+
def max_slashes
|
22
|
+
cop_config['MaxSlashes']
|
24
23
|
end
|
25
24
|
|
26
25
|
private
|
@@ -29,8 +28,8 @@ module Rubocop
|
|
29
28
|
sprintf('Use %%r %sfor regular expressions matching more ' +
|
30
29
|
"than %d '/' character%s.",
|
31
30
|
word,
|
32
|
-
|
33
|
-
|
31
|
+
max_slashes,
|
32
|
+
max_slashes == 1 ? '' : 's')
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
@@ -27,11 +27,11 @@ module Rubocop
|
|
27
27
|
# know if the first semicolon on the line is a separator of
|
28
28
|
# expressions. It's just a guess.
|
29
29
|
column = processed_source[line - 1].index(';')
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
convention(nil,
|
31
|
+
source_range(processed_source.buffer,
|
32
|
+
processed_source[0...(line - 1)],
|
33
|
+
column, 1),
|
34
|
+
MSG)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -43,11 +43,11 @@ module Rubocop
|
|
43
43
|
tokens_for_lines.each do |line, tokens|
|
44
44
|
if tokens.last.type == :tSEMI # rubocop:disable SymbolName
|
45
45
|
column = tokens.last.pos.column
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
convention(nil,
|
47
|
+
source_range(processed_source.buffer,
|
48
|
+
processed_source[0...(line - 1)],
|
49
|
+
column, 1),
|
50
|
+
MSG)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -29,8 +29,7 @@ module Rubocop
|
|
29
29
|
|
30
30
|
on_node(:send, node, :rescue) do |send_node|
|
31
31
|
if command?(:raise, send_node)
|
32
|
-
|
33
|
-
do_autocorrect(send_node)
|
32
|
+
convention(send_node, :selector, FAIL_MSG)
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
@@ -40,8 +39,7 @@ module Rubocop
|
|
40
39
|
|
41
40
|
on_node(:send, node, :rescue) do |send_node|
|
42
41
|
if command?(:fail, send_node)
|
43
|
-
|
44
|
-
do_autocorrect(send_node)
|
42
|
+
convention(send_node, :selector, RAISE_MSG)
|
45
43
|
end
|
46
44
|
end
|
47
45
|
end
|
@@ -9,7 +9,7 @@ module Rubocop
|
|
9
9
|
MSG = 'Avoid single-line method definitions.'
|
10
10
|
|
11
11
|
def allow_empty?
|
12
|
-
|
12
|
+
cop_config['AllowIfMethodIsEmpty']
|
13
13
|
end
|
14
14
|
|
15
15
|
def on_def(node)
|
@@ -33,9 +33,7 @@ module Rubocop
|
|
33
33
|
end
|
34
34
|
|
35
35
|
if start_line == end_line && !(allow_empty? && empty_body)
|
36
|
-
|
37
|
-
node.loc.expression,
|
38
|
-
MSG)
|
36
|
+
convention(node, :expression)
|
39
37
|
end
|
40
38
|
end
|
41
39
|
end
|
@@ -14,7 +14,7 @@ module Rubocop
|
|
14
14
|
processed_source.tokens.each_cons(2) do |t1, t2|
|
15
15
|
if kind(t1) && t1.pos.line == t2.pos.line &&
|
16
16
|
t2.pos.column == t1.pos.column + offset(t1)
|
17
|
-
|
17
|
+
convention(nil, t1.pos, sprintf(MSG, kind(t1)))
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rubocop
|
4
|
+
module Cop
|
5
|
+
module Style
|
6
|
+
# Here we check if modifier keywords are preceded by a space.
|
7
|
+
class SpaceBeforeModifierKeyword < Cop
|
8
|
+
MSG = 'Put a space before the modifier keyword.'
|
9
|
+
|
10
|
+
def on_if(node)
|
11
|
+
if modifier?(node)
|
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
|
+
convention(node, left_of_kw) unless left_of_kw.is?(' ')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method :on_while, :on_if
|
20
|
+
alias_method :on_until, :on_if
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def modifier?(node)
|
25
|
+
node.loc.respond_to?(:end) && node.loc.end.nil? && !elsif?(node)
|
26
|
+
end
|
27
|
+
|
28
|
+
def elsif?(node)
|
29
|
+
node.loc.keyword.is?('elsif')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -4,7 +4,9 @@ module Rubocop
|
|
4
4
|
module Cop
|
5
5
|
module Style
|
6
6
|
# This cop looks for uses of Perl-style global variables.
|
7
|
-
class
|
7
|
+
class SpecialGlobalVars < Cop
|
8
|
+
MSG = 'Prefer %s over %s.'
|
9
|
+
|
8
10
|
PREFERRED_VARS = {
|
9
11
|
'$:' => '$LOAD_PATH',
|
10
12
|
'$"' => '$LOADED_FEATURES',
|
@@ -32,14 +34,21 @@ module Rubocop
|
|
32
34
|
|
33
35
|
def on_gvar(node)
|
34
36
|
global_var, = *node
|
35
|
-
global_var = global_var
|
36
37
|
|
37
|
-
if PREFERRED_VARS[global_var]
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
convention(node, :expression) if PREFERRED_VARS[global_var]
|
39
|
+
end
|
40
|
+
|
41
|
+
def message(node)
|
42
|
+
global_var, = *node
|
43
|
+
MSG.format(PREFERRED_VARS[global_var], global_var)
|
44
|
+
end
|
45
|
+
|
46
|
+
def autocorrect_action(node)
|
47
|
+
@corrections << lambda do |corrector|
|
48
|
+
global_var, = *node
|
49
|
+
|
50
|
+
corrector.replace(node.loc.expression,
|
51
|
+
PREFERRED_VARS[global_var])
|
43
52
|
end
|
44
53
|
end
|
45
54
|
end
|
@@ -19,8 +19,7 @@ module Rubocop
|
|
19
19
|
# "\\\\"
|
20
20
|
if node.loc.expression.source !~ /' | (?<! \\) \\{2}* \\ (?! \\)/x &&
|
21
21
|
node.loc.begin && node.loc.begin.is?('"')
|
22
|
-
|
23
|
-
do_autocorrect(node)
|
22
|
+
convention(node, :expression)
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
@@ -67,7 +67,7 @@ module Rubocop
|
|
67
67
|
case token.type
|
68
68
|
when :tPOW
|
69
69
|
if has_space?(token_before, token, token_after)
|
70
|
-
|
70
|
+
convention(nil, token.pos, MSG_DETECTED)
|
71
71
|
end
|
72
72
|
when *BINARY_OPERATORS
|
73
73
|
check_missing_space(token_before, token, token_after)
|
@@ -164,7 +164,7 @@ module Rubocop
|
|
164
164
|
def check_missing_space(token_before, token, token_after)
|
165
165
|
unless has_space?(token_before, token, token_after)
|
166
166
|
text = token.text.to_s + (token.type == :tOP_ASGN ? '=' : '')
|
167
|
-
|
167
|
+
convention(nil, token.pos, MSG_MISSING.format(text))
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
@@ -223,8 +223,8 @@ module Rubocop
|
|
223
223
|
|
224
224
|
def check(t1, t2, msg)
|
225
225
|
unless space_between?(t1, t2)
|
226
|
-
brace_token =
|
227
|
-
|
226
|
+
brace_token = t1.text == '{' ? t1 : t2
|
227
|
+
convention(nil, brace_token.pos, msg)
|
228
228
|
end
|
229
229
|
end
|
230
230
|
end
|
@@ -244,7 +244,7 @@ module Rubocop
|
|
244
244
|
range = Parser::Source::Range.new(processed_source.buffer,
|
245
245
|
t1.pos.end_pos,
|
246
246
|
t2.pos.begin_pos)
|
247
|
-
|
247
|
+
convention(nil, range, format(MSG, kind))
|
248
248
|
end
|
249
249
|
end
|
250
250
|
end
|
@@ -297,12 +297,13 @@ module Rubocop
|
|
297
297
|
# No offence if line break inside.
|
298
298
|
return if t1.pos.line < t2.pos.line
|
299
299
|
has_space = space_between?(t1, t2)
|
300
|
-
is_offence, word = if
|
300
|
+
is_offence, word = if cop_config['EnforcedStyleIsWithSpaces']
|
301
301
|
[!has_space, 'missing']
|
302
302
|
else
|
303
303
|
[has_space, 'detected']
|
304
304
|
end
|
305
|
-
|
305
|
+
brace_token = t1.text == '{' ? t1 : t2
|
306
|
+
convention(nil, brace_token.pos, sprintf(MSG, word)) if is_offence
|
306
307
|
end
|
307
308
|
end
|
308
309
|
|
@@ -319,7 +320,7 @@ module Rubocop
|
|
319
320
|
index = index_of_first_token(optarg)
|
320
321
|
arg, equals, value = processed_source.tokens[index, 3]
|
321
322
|
unless space_between?(arg, equals) && space_between?(equals, value)
|
322
|
-
|
323
|
+
convention(nil, equals.pos)
|
323
324
|
end
|
324
325
|
end
|
325
326
|
end
|