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
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 3ab0d432e91c72639b48734e66c1e4ce045ea0d8
|
4
|
-
data.tar.gz: cd33ef19aa06a05bb32a2f882ec8ea128a0d8e8a
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 56e469c18ad41f08a3b33c0e13d8632cdf6d92c1281bd7012077beb759bceefe8429da0f1f670accf44dfc08841ec366807cf0d3d50ce1827b1a5689a6333a77
|
7
|
-
data.tar.gz: 773e23dbd3e938afe4ee156c6c0c7afd3b8589c1a8e896b24b119086865200d3c4dcc87cdc9453b0f0a6eb5076f3aaa5e6b89a5da3794de67bea258b138dc6c9
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Rubocop
|
4
|
-
module Cop
|
5
|
-
module Lint
|
6
|
-
# This cop looks for unused local variables in each scope.
|
7
|
-
# Actually this is a mimic of the warning
|
8
|
-
# "assigned but unused variable - foo" from `ruby -cw`.
|
9
|
-
class UnusedLocalVariable < Cop
|
10
|
-
include VariableInspector
|
11
|
-
|
12
|
-
MSG = 'Assigned but unused variable - %s'
|
13
|
-
TYPES_TO_ACCEPT_UNUSED =
|
14
|
-
(ARGUMENT_DECLARATION_TYPES - [:shadowarg]).freeze
|
15
|
-
|
16
|
-
def investigate(processed_source)
|
17
|
-
inspect_variables(processed_source.ast)
|
18
|
-
end
|
19
|
-
|
20
|
-
def after_leaving_scope(scope)
|
21
|
-
scope.variable_entries.each_value do |entry|
|
22
|
-
next if entry.used?
|
23
|
-
next if TYPES_TO_ACCEPT_UNUSED.include?(entry.node.type)
|
24
|
-
next if entry.name.to_s.start_with?('_')
|
25
|
-
message = sprintf(MSG, entry.name)
|
26
|
-
add_offence(:warning, entry.node.loc.expression, message)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,19 +0,0 @@
|
|
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 AvoidPerlBackrefs < Cop
|
9
|
-
def on_nth_ref(node)
|
10
|
-
backref, = *node
|
11
|
-
|
12
|
-
add_offence(:convention,
|
13
|
-
node.loc.expression,
|
14
|
-
"Prefer the use of MatchData over $#{backref}.")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,588 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
module Rubocop
|
6
|
-
module Cop
|
7
|
-
module Lint
|
8
|
-
describe UnusedLocalVariable do
|
9
|
-
subject(:cop) { UnusedLocalVariable.new }
|
10
|
-
|
11
|
-
context 'when a variable is assigned and unreferenced in a method' do
|
12
|
-
let(:source) do
|
13
|
-
[
|
14
|
-
'class SomeClass',
|
15
|
-
' foo = 1',
|
16
|
-
' puts foo',
|
17
|
-
' def some_method',
|
18
|
-
' foo = 2',
|
19
|
-
' bar = 3',
|
20
|
-
' puts bar',
|
21
|
-
' end',
|
22
|
-
'end'
|
23
|
-
]
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'registers an offence' do
|
27
|
-
inspect_source(cop, source)
|
28
|
-
expect(cop.offences.size).to eq(1)
|
29
|
-
expect(cop.offences.first.message)
|
30
|
-
.to include('unused variable - foo')
|
31
|
-
expect(cop.offences.first.line).to eq(5)
|
32
|
-
end
|
33
|
-
|
34
|
-
include_examples 'mimics MRI 2.0'
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'when a variable is assigned and unreferenced ' +
|
38
|
-
'in a singleton method defined with self keyword' do
|
39
|
-
let(:source) do
|
40
|
-
[
|
41
|
-
'class SomeClass',
|
42
|
-
' foo = 1',
|
43
|
-
' puts foo',
|
44
|
-
' def self.some_method',
|
45
|
-
' foo = 2',
|
46
|
-
' bar = 3',
|
47
|
-
' puts bar',
|
48
|
-
' end',
|
49
|
-
'end'
|
50
|
-
]
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'registers an offence' do
|
54
|
-
inspect_source(cop, source)
|
55
|
-
expect(cop.offences.size).to eq(1)
|
56
|
-
expect(cop.offences.first.message)
|
57
|
-
.to include('unused variable - foo')
|
58
|
-
expect(cop.offences.first.line).to eq(5)
|
59
|
-
end
|
60
|
-
|
61
|
-
include_examples 'mimics MRI 2.0'
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'when a variable is assigned and unreferenced ' +
|
65
|
-
'in a singleton method defined with variable name' do
|
66
|
-
let(:source) do
|
67
|
-
[
|
68
|
-
'1.times do',
|
69
|
-
' foo = 1',
|
70
|
-
' puts foo',
|
71
|
-
' instance = Object.new',
|
72
|
-
' def instance.some_method',
|
73
|
-
' foo = 2',
|
74
|
-
' bar = 3',
|
75
|
-
' puts bar',
|
76
|
-
' end',
|
77
|
-
'end'
|
78
|
-
]
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'registers an offence' do
|
82
|
-
inspect_source(cop, source)
|
83
|
-
expect(cop.offences.size).to eq(1)
|
84
|
-
expect(cop.offences.first.message)
|
85
|
-
.to include('unused variable - foo')
|
86
|
-
expect(cop.offences.first.line).to eq(6)
|
87
|
-
end
|
88
|
-
|
89
|
-
include_examples 'mimics MRI 2.0'
|
90
|
-
end
|
91
|
-
|
92
|
-
context 'when a variable is assigned and unreferenced in a class' do
|
93
|
-
let(:source) do
|
94
|
-
[
|
95
|
-
'1.times do',
|
96
|
-
' foo = 1',
|
97
|
-
' puts foo',
|
98
|
-
' class SomeClass',
|
99
|
-
' foo = 2',
|
100
|
-
' bar = 3',
|
101
|
-
' puts bar',
|
102
|
-
' end',
|
103
|
-
'end'
|
104
|
-
]
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'registers an offence' do
|
108
|
-
inspect_source(cop, source)
|
109
|
-
expect(cop.offences.size).to eq(1)
|
110
|
-
expect(cop.offences.first.message)
|
111
|
-
.to include('unused variable - foo')
|
112
|
-
expect(cop.offences.first.line).to eq(5)
|
113
|
-
end
|
114
|
-
|
115
|
-
include_examples 'mimics MRI 2.0'
|
116
|
-
end
|
117
|
-
|
118
|
-
context 'when a variable is assigned and unreferenced ' +
|
119
|
-
'in a singleton class' do
|
120
|
-
let(:source) do
|
121
|
-
[
|
122
|
-
'1.times do',
|
123
|
-
' foo = 1',
|
124
|
-
' puts foo',
|
125
|
-
' instance = Object.new',
|
126
|
-
' class << instance',
|
127
|
-
' foo = 2',
|
128
|
-
' bar = 3',
|
129
|
-
' puts bar',
|
130
|
-
' end',
|
131
|
-
'end'
|
132
|
-
]
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'registers an offence' do
|
136
|
-
inspect_source(cop, source)
|
137
|
-
expect(cop.offences.size).to eq(1)
|
138
|
-
expect(cop.offences.first.message)
|
139
|
-
.to include('unused variable - foo')
|
140
|
-
expect(cop.offences.first.line).to eq(6)
|
141
|
-
end
|
142
|
-
|
143
|
-
include_examples 'mimics MRI 2.0'
|
144
|
-
end
|
145
|
-
|
146
|
-
context 'when a variable is assigned and unreferenced in a module' do
|
147
|
-
let(:source) do
|
148
|
-
[
|
149
|
-
'1.times do',
|
150
|
-
' foo = 1',
|
151
|
-
' puts foo',
|
152
|
-
' module SomeModule',
|
153
|
-
' foo = 2',
|
154
|
-
' bar = 3',
|
155
|
-
' puts bar',
|
156
|
-
' end',
|
157
|
-
'end'
|
158
|
-
]
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'registers an offence' do
|
162
|
-
inspect_source(cop, source)
|
163
|
-
expect(cop.offences.size).to eq(1)
|
164
|
-
expect(cop.offences.first.message)
|
165
|
-
.to include('unused variable - foo')
|
166
|
-
expect(cop.offences.first.line).to eq(5)
|
167
|
-
end
|
168
|
-
|
169
|
-
include_examples 'mimics MRI 2.0'
|
170
|
-
end
|
171
|
-
|
172
|
-
context 'when a variable is assigned and unreferenced in top level' do
|
173
|
-
let(:source) do
|
174
|
-
[
|
175
|
-
'foo = 1',
|
176
|
-
'bar = 2',
|
177
|
-
'puts bar'
|
178
|
-
]
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'registers an offence' do
|
182
|
-
inspect_source(cop, source)
|
183
|
-
expect(cop.offences.size).to eq(1)
|
184
|
-
expect(cop.offences.first.message)
|
185
|
-
.to include('unused variable - foo')
|
186
|
-
expect(cop.offences.first.line).to eq(1)
|
187
|
-
end
|
188
|
-
|
189
|
-
include_examples 'mimics MRI 2.0'
|
190
|
-
end
|
191
|
-
|
192
|
-
context 'when a variable is assigned multiple times ' +
|
193
|
-
'but unreferenced' do
|
194
|
-
let(:source) do
|
195
|
-
[
|
196
|
-
'def some_method',
|
197
|
-
' foo = 1',
|
198
|
-
' bar = 2',
|
199
|
-
' foo = 3',
|
200
|
-
' puts bar',
|
201
|
-
'end'
|
202
|
-
]
|
203
|
-
end
|
204
|
-
|
205
|
-
include_examples 'accepts'
|
206
|
-
include_examples 'mimics MRI 2.0'
|
207
|
-
end
|
208
|
-
|
209
|
-
context 'when an unreferenced variable is reassigned in a block' do
|
210
|
-
let(:source) do
|
211
|
-
[
|
212
|
-
'def some_method',
|
213
|
-
' foo = 1',
|
214
|
-
' 1.times do',
|
215
|
-
' foo = 2',
|
216
|
-
' end',
|
217
|
-
'end'
|
218
|
-
]
|
219
|
-
end
|
220
|
-
|
221
|
-
include_examples 'accepts'
|
222
|
-
include_examples 'mimics MRI 2.0'
|
223
|
-
end
|
224
|
-
|
225
|
-
context 'when a referenced variable in reassigned in a block' do
|
226
|
-
let(:source) do
|
227
|
-
[
|
228
|
-
'def some_method',
|
229
|
-
' foo = 1',
|
230
|
-
' puts foo',
|
231
|
-
' 1.times do',
|
232
|
-
' foo = 2',
|
233
|
-
' end',
|
234
|
-
'end'
|
235
|
-
]
|
236
|
-
end
|
237
|
-
|
238
|
-
include_examples 'accepts'
|
239
|
-
include_examples 'mimics MRI 2.0'
|
240
|
-
end
|
241
|
-
|
242
|
-
context 'when a block local variable is declared but not assigned' do
|
243
|
-
let(:source) do
|
244
|
-
[
|
245
|
-
'1.times do |i; foo|',
|
246
|
-
'end'
|
247
|
-
]
|
248
|
-
end
|
249
|
-
|
250
|
-
it 'registers an offence' do
|
251
|
-
inspect_source(cop, source)
|
252
|
-
expect(cop.offences.size).to eq(1)
|
253
|
-
expect(cop.offences.first.message)
|
254
|
-
.to include('unused variable - foo')
|
255
|
-
expect(cop.offences.first.line).to eq(1)
|
256
|
-
end
|
257
|
-
|
258
|
-
include_examples 'mimics MRI 2.0'
|
259
|
-
end
|
260
|
-
|
261
|
-
context 'when a block local variable is assigned and unreferenced' do
|
262
|
-
let(:source) do
|
263
|
-
[
|
264
|
-
'1.times do |i; foo|',
|
265
|
-
' foo = 2',
|
266
|
-
'end'
|
267
|
-
]
|
268
|
-
end
|
269
|
-
|
270
|
-
include_examples 'accepts'
|
271
|
-
include_examples 'mimics MRI 2.0'
|
272
|
-
end
|
273
|
-
|
274
|
-
context 'when a variable is assigned in loop body ' +
|
275
|
-
'and referenced in post while condition' do
|
276
|
-
let(:source) do
|
277
|
-
[
|
278
|
-
'begin',
|
279
|
-
' if foo',
|
280
|
-
' foo += 1',
|
281
|
-
' else',
|
282
|
-
' foo = 1',
|
283
|
-
' end',
|
284
|
-
'end while foo < 10'
|
285
|
-
]
|
286
|
-
end
|
287
|
-
|
288
|
-
include_examples 'accepts'
|
289
|
-
include_examples 'mimics MRI 2.0'
|
290
|
-
end
|
291
|
-
|
292
|
-
context 'when a variable is assigned in loop body ' +
|
293
|
-
'and referenced in post until condition' do
|
294
|
-
let(:source) do
|
295
|
-
[
|
296
|
-
'begin',
|
297
|
-
' if foo',
|
298
|
-
' foo += 1',
|
299
|
-
' else',
|
300
|
-
' foo = 1',
|
301
|
-
' end',
|
302
|
-
'end until foo > 10'
|
303
|
-
]
|
304
|
-
end
|
305
|
-
|
306
|
-
include_examples 'accepts'
|
307
|
-
include_examples 'mimics MRI 2.0'
|
308
|
-
end
|
309
|
-
|
310
|
-
context 'when a named capture is unreferenced in top level' do
|
311
|
-
let(:source) do
|
312
|
-
[
|
313
|
-
"/(?<foo>\w+)/ =~ 'FOO'",
|
314
|
-
]
|
315
|
-
end
|
316
|
-
|
317
|
-
it 'registers an offence' do
|
318
|
-
inspect_source(cop, source)
|
319
|
-
expect(cop.offences.size).to eq(1)
|
320
|
-
expect(cop.offences.first.message)
|
321
|
-
.to include('unused variable - foo')
|
322
|
-
expect(cop.offences.first.line).to eq(1)
|
323
|
-
end
|
324
|
-
|
325
|
-
include_examples 'mimics MRI 2.0'
|
326
|
-
end
|
327
|
-
|
328
|
-
context 'when a named capture is unreferenced ' +
|
329
|
-
'in other than top level' do
|
330
|
-
let(:source) do
|
331
|
-
[
|
332
|
-
'def some_method',
|
333
|
-
" /(?<foo>\w+)/ =~ 'FOO'",
|
334
|
-
'end'
|
335
|
-
]
|
336
|
-
end
|
337
|
-
|
338
|
-
it 'registers an offence' do
|
339
|
-
inspect_source(cop, source)
|
340
|
-
expect(cop.offences.size).to eq(1)
|
341
|
-
expect(cop.offences.first.message)
|
342
|
-
.to include('unused variable - foo')
|
343
|
-
expect(cop.offences.first.line).to eq(2)
|
344
|
-
end
|
345
|
-
|
346
|
-
# MRI 2.0 accepts this case, but I have no idea why it does so
|
347
|
-
# and there's no convincing reason to conform to this behavior,
|
348
|
-
# so RuboCop does not mimic MRI in this case.
|
349
|
-
end
|
350
|
-
|
351
|
-
context 'when a named capture is referenced' do
|
352
|
-
let(:source) do
|
353
|
-
[
|
354
|
-
'def some_method',
|
355
|
-
" /(?<foo>\w+)/ =~ 'bar'",
|
356
|
-
' puts foo',
|
357
|
-
'end'
|
358
|
-
]
|
359
|
-
end
|
360
|
-
|
361
|
-
include_examples 'accepts'
|
362
|
-
include_examples 'mimics MRI 2.0'
|
363
|
-
end
|
364
|
-
|
365
|
-
context 'when a variable is assigned in begin ' +
|
366
|
-
'and referenced outside' do
|
367
|
-
let(:source) do
|
368
|
-
[
|
369
|
-
'def some_method',
|
370
|
-
' begin',
|
371
|
-
' foo = 1',
|
372
|
-
' end',
|
373
|
-
' puts foo',
|
374
|
-
'end'
|
375
|
-
]
|
376
|
-
end
|
377
|
-
|
378
|
-
include_examples 'accepts'
|
379
|
-
include_examples 'mimics MRI 2.0'
|
380
|
-
end
|
381
|
-
|
382
|
-
context 'when a variable is shadowed by a block argument ' +
|
383
|
-
'and unreferenced' do
|
384
|
-
let(:source) do
|
385
|
-
[
|
386
|
-
'def some_method',
|
387
|
-
' foo = 1',
|
388
|
-
' 1.times do |foo|',
|
389
|
-
' puts foo',
|
390
|
-
' end',
|
391
|
-
'end'
|
392
|
-
]
|
393
|
-
end
|
394
|
-
|
395
|
-
it 'registers an offence' do
|
396
|
-
inspect_source(cop, source)
|
397
|
-
expect(cop.offences.size).to eq(1)
|
398
|
-
expect(cop.offences.first.message)
|
399
|
-
.to include('unused variable - foo')
|
400
|
-
expect(cop.offences.first.line).to eq(2)
|
401
|
-
end
|
402
|
-
|
403
|
-
include_examples 'mimics MRI 2.0', 'unused variable'
|
404
|
-
end
|
405
|
-
|
406
|
-
context 'when a variable is not used and the name starts with _' do
|
407
|
-
let(:source) do
|
408
|
-
[
|
409
|
-
'def some_method',
|
410
|
-
' _foo = 1',
|
411
|
-
' bar = 2',
|
412
|
-
' puts bar',
|
413
|
-
'end'
|
414
|
-
]
|
415
|
-
end
|
416
|
-
|
417
|
-
include_examples 'accepts'
|
418
|
-
include_examples 'mimics MRI 2.0'
|
419
|
-
end
|
420
|
-
|
421
|
-
context 'when a method argument is not used' do
|
422
|
-
let(:source) do
|
423
|
-
[
|
424
|
-
'def some_method(arg)',
|
425
|
-
'end'
|
426
|
-
]
|
427
|
-
end
|
428
|
-
|
429
|
-
include_examples 'accepts'
|
430
|
-
include_examples 'mimics MRI 2.0'
|
431
|
-
end
|
432
|
-
|
433
|
-
context 'when an optional method argument is not used' do
|
434
|
-
let(:source) do
|
435
|
-
[
|
436
|
-
'def some_method(arg = nil)',
|
437
|
-
'end'
|
438
|
-
]
|
439
|
-
end
|
440
|
-
|
441
|
-
include_examples 'accepts'
|
442
|
-
include_examples 'mimics MRI 2.0'
|
443
|
-
end
|
444
|
-
|
445
|
-
context 'when a block method argument is not used' do
|
446
|
-
let(:source) do
|
447
|
-
[
|
448
|
-
'def some_method(&block)',
|
449
|
-
'end'
|
450
|
-
]
|
451
|
-
end
|
452
|
-
|
453
|
-
include_examples 'accepts'
|
454
|
-
include_examples 'mimics MRI 2.0'
|
455
|
-
end
|
456
|
-
|
457
|
-
context 'when a splat method argument is not used' do
|
458
|
-
let(:source) do
|
459
|
-
[
|
460
|
-
'def some_method(*args)',
|
461
|
-
'end'
|
462
|
-
]
|
463
|
-
end
|
464
|
-
|
465
|
-
include_examples 'accepts'
|
466
|
-
include_examples 'mimics MRI 2.0'
|
467
|
-
end
|
468
|
-
|
469
|
-
context 'when a optional keyword method argument is not used' do
|
470
|
-
let(:source) do
|
471
|
-
[
|
472
|
-
'def some_method(name: value)',
|
473
|
-
'end'
|
474
|
-
]
|
475
|
-
end
|
476
|
-
|
477
|
-
include_examples 'accepts'
|
478
|
-
include_examples 'mimics MRI 2.0'
|
479
|
-
end
|
480
|
-
|
481
|
-
context 'when a keyword splat method argument is used' do
|
482
|
-
let(:source) do
|
483
|
-
[
|
484
|
-
'def some_method(name: value, **rest_keywords)',
|
485
|
-
' p rest_keywords',
|
486
|
-
'end'
|
487
|
-
]
|
488
|
-
end
|
489
|
-
|
490
|
-
include_examples 'accepts'
|
491
|
-
include_examples 'mimics MRI 2.0'
|
492
|
-
end
|
493
|
-
|
494
|
-
context 'when a keyword splat method argument is not used' do
|
495
|
-
let(:source) do
|
496
|
-
[
|
497
|
-
'def some_method(name: value, **rest_keywords)',
|
498
|
-
'end'
|
499
|
-
]
|
500
|
-
end
|
501
|
-
|
502
|
-
include_examples 'accepts'
|
503
|
-
include_examples 'mimics MRI 2.0'
|
504
|
-
end
|
505
|
-
|
506
|
-
context 'when a block argument is not used' do
|
507
|
-
let(:source) do
|
508
|
-
[
|
509
|
-
'1.times do |i|',
|
510
|
-
'end'
|
511
|
-
]
|
512
|
-
end
|
513
|
-
|
514
|
-
include_examples 'accepts'
|
515
|
-
include_examples 'mimics MRI 2.0'
|
516
|
-
end
|
517
|
-
|
518
|
-
context 'when there is only one AST node and it is unused variable' do
|
519
|
-
let(:source) do
|
520
|
-
[
|
521
|
-
'foo = 1'
|
522
|
-
]
|
523
|
-
end
|
524
|
-
|
525
|
-
it 'registers an offence' do
|
526
|
-
inspect_source(cop, source)
|
527
|
-
expect(cop.offences.size).to eq(1)
|
528
|
-
expect(cop.offences.first.message)
|
529
|
-
.to include('unused variable - foo')
|
530
|
-
expect(cop.offences.first.line).to eq(1)
|
531
|
-
end
|
532
|
-
|
533
|
-
include_examples 'mimics MRI 2.0'
|
534
|
-
end
|
535
|
-
|
536
|
-
context 'when a variable is assigned ' +
|
537
|
-
'while being passed to a method taking block' do
|
538
|
-
|
539
|
-
context 'and the variable is used' do
|
540
|
-
let(:source) do
|
541
|
-
[
|
542
|
-
'some_method(foo = 1) do',
|
543
|
-
'end',
|
544
|
-
'puts foo'
|
545
|
-
]
|
546
|
-
end
|
547
|
-
|
548
|
-
include_examples 'accepts'
|
549
|
-
include_examples 'mimics MRI 2.0'
|
550
|
-
end
|
551
|
-
|
552
|
-
context 'and the variable is not used' do
|
553
|
-
let(:source) do
|
554
|
-
[
|
555
|
-
'some_method(foo = 1) do',
|
556
|
-
'end'
|
557
|
-
]
|
558
|
-
end
|
559
|
-
|
560
|
-
it 'registers an offence' do
|
561
|
-
inspect_source(cop, source)
|
562
|
-
expect(cop.offences.size).to eq(1)
|
563
|
-
expect(cop.offences.first.message)
|
564
|
-
.to include('unused variable - foo')
|
565
|
-
expect(cop.offences.first.line).to eq(1)
|
566
|
-
end
|
567
|
-
|
568
|
-
include_examples 'mimics MRI 2.0'
|
569
|
-
end
|
570
|
-
end
|
571
|
-
|
572
|
-
context 'when a variabled is assigned ' +
|
573
|
-
'and passed to a method followed by method taking block' do
|
574
|
-
let(:source) do
|
575
|
-
[
|
576
|
-
"pattern = '*.rb'",
|
577
|
-
'Dir.glob(pattern).map do |path|',
|
578
|
-
'end'
|
579
|
-
]
|
580
|
-
end
|
581
|
-
|
582
|
-
include_examples 'accepts'
|
583
|
-
include_examples 'mimics MRI 2.0'
|
584
|
-
end
|
585
|
-
end
|
586
|
-
end
|
587
|
-
end
|
588
|
-
end
|