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
@@ -6,14 +6,14 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe EmptyLiteral do
|
9
|
-
|
9
|
+
subject(:cop) { described_class.new }
|
10
10
|
|
11
11
|
describe 'Empty Array' do
|
12
12
|
it 'registers an offence for Array.new()' do
|
13
13
|
inspect_source(cop,
|
14
14
|
['test = Array.new()'])
|
15
15
|
expect(cop.offences.size).to eq(1)
|
16
|
-
expect(cop.
|
16
|
+
expect(cop.messages)
|
17
17
|
.to eq([EmptyLiteral::ARR_MSG])
|
18
18
|
end
|
19
19
|
|
@@ -21,7 +21,7 @@ module Rubocop
|
|
21
21
|
inspect_source(cop,
|
22
22
|
['test = Array.new'])
|
23
23
|
expect(cop.offences.size).to eq(1)
|
24
|
-
expect(cop.
|
24
|
+
expect(cop.messages)
|
25
25
|
.to eq([EmptyLiteral::ARR_MSG])
|
26
26
|
end
|
27
27
|
|
@@ -42,7 +42,7 @@ module Rubocop
|
|
42
42
|
inspect_source(cop,
|
43
43
|
['test = Hash.new()'])
|
44
44
|
expect(cop.offences.size).to eq(1)
|
45
|
-
expect(cop.
|
45
|
+
expect(cop.messages)
|
46
46
|
.to eq([EmptyLiteral::HASH_MSG])
|
47
47
|
end
|
48
48
|
|
@@ -50,7 +50,7 @@ module Rubocop
|
|
50
50
|
inspect_source(cop,
|
51
51
|
['test = Hash.new'])
|
52
52
|
expect(cop.offences.size).to eq(1)
|
53
|
-
expect(cop.
|
53
|
+
expect(cop.messages)
|
54
54
|
.to eq([EmptyLiteral::HASH_MSG])
|
55
55
|
end
|
56
56
|
|
@@ -77,7 +77,7 @@ module Rubocop
|
|
77
77
|
inspect_source(cop,
|
78
78
|
['test = String.new()'])
|
79
79
|
expect(cop.offences.size).to eq(1)
|
80
|
-
expect(cop.
|
80
|
+
expect(cop.messages)
|
81
81
|
.to eq([EmptyLiteral::STR_MSG])
|
82
82
|
end
|
83
83
|
|
@@ -85,7 +85,7 @@ module Rubocop
|
|
85
85
|
inspect_source(cop,
|
86
86
|
['test = String.new'])
|
87
87
|
expect(cop.offences.size).to eq(1)
|
88
|
-
expect(cop.
|
88
|
+
expect(cop.messages)
|
89
89
|
.to eq([EmptyLiteral::STR_MSG])
|
90
90
|
end
|
91
91
|
|
@@ -6,12 +6,12 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe Encoding do
|
9
|
-
|
9
|
+
subject(:encoding) { Encoding.new }
|
10
10
|
|
11
11
|
it 'registers an offence when no encoding present', ruby: 1.9 do
|
12
12
|
inspect_source(encoding, ['def foo() end'])
|
13
13
|
|
14
|
-
expect(encoding.
|
14
|
+
expect(encoding.messages).to eq(
|
15
15
|
['Missing utf-8 encoding comment.'])
|
16
16
|
end
|
17
17
|
|
@@ -27,14 +27,14 @@ module Rubocop
|
|
27
27
|
'# encoding: utf-8',
|
28
28
|
'def foo() end'])
|
29
29
|
|
30
|
-
expect(encoding.
|
30
|
+
expect(encoding.messages).to be_empty
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'books an offence when encoding is in the wrong place', ruby: 1.9 do
|
34
34
|
inspect_source(encoding, ['def foo() end',
|
35
35
|
'# encoding: utf-8'])
|
36
36
|
|
37
|
-
expect(encoding.
|
37
|
+
expect(encoding.messages).to eq(
|
38
38
|
['Missing utf-8 encoding comment.'])
|
39
39
|
end
|
40
40
|
|
@@ -48,7 +48,13 @@ module Rubocop
|
|
48
48
|
inspect_source(encoding, ['# -*- encoding : utf-8 -*-',
|
49
49
|
'def foo() end'])
|
50
50
|
|
51
|
-
expect(encoding.
|
51
|
+
expect(encoding.messages).to be_empty
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'accepts vim-style encoding comments', ruby: 1.9 do
|
55
|
+
inspect_source(encoding, ['# vim:fileencoding=utf-8',
|
56
|
+
'def foo() end'])
|
57
|
+
expect(encoding.messages).to be_empty
|
52
58
|
end
|
53
59
|
end
|
54
60
|
end
|
@@ -6,18 +6,19 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe EndOfLine do
|
9
|
-
|
9
|
+
subject(:eol) { EndOfLine.new }
|
10
10
|
|
11
11
|
it 'registers an offence for CR+LF' do
|
12
12
|
pending 'Fails after upgdate to parser-2.0.0.pre3.'
|
13
13
|
inspect_source(eol, ["x=0\r", ''])
|
14
|
-
expect(eol.
|
14
|
+
expect(eol.messages).to eq(
|
15
15
|
['Carriage return character detected.'])
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'registers an offence for CR at end of file' do
|
19
|
+
pending
|
19
20
|
inspect_source(eol, ["x=0\r"])
|
20
|
-
expect(eol.
|
21
|
+
expect(eol.messages).to eq(
|
21
22
|
['Carriage return character detected.'])
|
22
23
|
end
|
23
24
|
end
|
@@ -6,13 +6,13 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe FavorJoin do
|
9
|
-
|
9
|
+
subject(:fj) { FavorJoin.new }
|
10
10
|
|
11
11
|
it 'registers an offence for an array followed by string' do
|
12
12
|
inspect_source(fj,
|
13
13
|
['%w(one two three) * ", "'])
|
14
14
|
expect(fj.offences.size).to eq(1)
|
15
|
-
expect(fj.
|
15
|
+
expect(fj.messages)
|
16
16
|
.to eq([FavorJoin::MSG])
|
17
17
|
end
|
18
18
|
|
@@ -6,9 +6,12 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe FavorModifier do
|
9
|
-
let(:if_unless) { IfUnlessModifier.new }
|
10
|
-
let(:while_until) { WhileUntilModifier.new }
|
11
|
-
|
9
|
+
let(:if_unless) { IfUnlessModifier.new(config) }
|
10
|
+
let(:while_until) { WhileUntilModifier.new(config) }
|
11
|
+
let(:config) do
|
12
|
+
hash = { 'LineLength' => { 'Max' => 79 } }
|
13
|
+
Rubocop::Config.new(hash)
|
14
|
+
end
|
12
15
|
|
13
16
|
it 'registers an offence for multiline if that fits on one line' do
|
14
17
|
# This if statement fits exactly on one line if written as a
|
@@ -21,7 +24,7 @@ module Rubocop
|
|
21
24
|
[" if #{condition}",
|
22
25
|
" #{body}",
|
23
26
|
' end'])
|
24
|
-
expect(if_unless.
|
27
|
+
expect(if_unless.messages).to eq(
|
25
28
|
['Favor modifier if/unless usage when you have a single-line' +
|
26
29
|
' body. Another good alternative is the usage of control flow' +
|
27
30
|
' &&/||.'])
|
@@ -55,9 +58,9 @@ module Rubocop
|
|
55
58
|
|
56
59
|
it 'registers an offence for multiline unless that fits on one line' do
|
57
60
|
inspect_source(if_unless, ['unless a',
|
58
|
-
|
59
|
-
|
60
|
-
expect(if_unless.
|
61
|
+
' b',
|
62
|
+
'end'])
|
63
|
+
expect(if_unless.messages).to eq(
|
61
64
|
['Favor modifier if/unless usage when you have a single-line' +
|
62
65
|
' body. Another good alternative is the usage of control flow' +
|
63
66
|
' &&/||.'])
|
@@ -74,7 +77,7 @@ module Rubocop
|
|
74
77
|
inspect_source(if_unless,
|
75
78
|
['if args.last.is_a? Hash then args.pop else ' +
|
76
79
|
'Hash.new end'])
|
77
|
-
expect(if_unless.
|
80
|
+
expect(if_unless.messages).to be_empty
|
78
81
|
end
|
79
82
|
|
80
83
|
it "accepts multiline unless that doesn't fit on one line" do
|
@@ -145,7 +148,7 @@ module Rubocop
|
|
145
148
|
inspect_source(cop, ["#{keyword} a",
|
146
149
|
' b',
|
147
150
|
'end'])
|
148
|
-
expect(cop.
|
151
|
+
expect(cop.messages).to eq(
|
149
152
|
['Favor modifier while/until usage when you have a single-line ' +
|
150
153
|
'body.'])
|
151
154
|
expect(cop.offences.map { |o| o.location.source }).to eq([keyword])
|
@@ -171,7 +174,7 @@ module Rubocop
|
|
171
174
|
" require 'simplecov'",
|
172
175
|
' SimpleCov.start',
|
173
176
|
'end'])
|
174
|
-
expect(cop.
|
177
|
+
expect(cop.messages).to be_empty
|
175
178
|
end
|
176
179
|
end
|
177
180
|
end
|
@@ -6,13 +6,13 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe FavorSprintf do
|
9
|
-
|
9
|
+
subject(:fs) { FavorSprintf.new }
|
10
10
|
|
11
11
|
it 'registers an offence for a string followed by something' do
|
12
12
|
inspect_source(fs,
|
13
13
|
['puts "%d" % 10'])
|
14
14
|
expect(fs.offences.size).to eq(1)
|
15
|
-
expect(fs.
|
15
|
+
expect(fs.messages)
|
16
16
|
.to eq([FavorSprintf::MSG])
|
17
17
|
end
|
18
18
|
|
@@ -20,7 +20,7 @@ module Rubocop
|
|
20
20
|
inspect_source(fs,
|
21
21
|
['puts x % [10, 11]'])
|
22
22
|
expect(fs.offences.size).to eq(1)
|
23
|
-
expect(fs.
|
23
|
+
expect(fs.messages)
|
24
24
|
.to eq([FavorSprintf::MSG])
|
25
25
|
end
|
26
26
|
|
@@ -44,7 +44,7 @@ module Rubocop
|
|
44
44
|
inspect_source(fs,
|
45
45
|
['puts "#{x * 5} %d #{@test}" % 10'])
|
46
46
|
expect(fs.offences.size).to eq(1)
|
47
|
-
expect(fs.
|
47
|
+
expect(fs.messages)
|
48
48
|
.to eq([FavorSprintf::MSG])
|
49
49
|
end
|
50
50
|
end
|
@@ -6,7 +6,7 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe FavorUntilOverNegatedWhile do
|
9
|
-
|
9
|
+
subject(:fav_until) { FavorUntilOverNegatedWhile.new }
|
10
10
|
|
11
11
|
it 'registers an offence for while with exclamation point condition' do
|
12
12
|
inspect_source(fav_until,
|
@@ -15,7 +15,7 @@ module Rubocop
|
|
15
15
|
'end',
|
16
16
|
'some_method while !a_condition',
|
17
17
|
])
|
18
|
-
expect(fav_until.
|
18
|
+
expect(fav_until.messages).to eq(
|
19
19
|
['Favor until over while for negative conditions.'] * 2)
|
20
20
|
end
|
21
21
|
|
@@ -25,7 +25,7 @@ module Rubocop
|
|
25
25
|
' some_method',
|
26
26
|
'end',
|
27
27
|
'some_method while not a_condition'])
|
28
|
-
expect(fav_until.
|
28
|
+
expect(fav_until.messages).to eq(
|
29
29
|
['Favor until over while for negative conditions.'] * 2)
|
30
30
|
expect(fav_until.offences.map(&:line)).to eq([1, 4])
|
31
31
|
end
|
@@ -39,7 +39,7 @@ module Rubocop
|
|
39
39
|
' some_method',
|
40
40
|
'end',
|
41
41
|
'some_method while not a_condition or other_cond'])
|
42
|
-
expect(fav_until.
|
42
|
+
expect(fav_until.messages).to be_empty
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
module Style
|
8
|
+
describe FinalNewline do
|
9
|
+
subject(:cop) { described_class.new }
|
10
|
+
|
11
|
+
it 'registers an offence for missing final newline' do
|
12
|
+
source = ['x = 0', 'top']
|
13
|
+
inspect_source(cop, source)
|
14
|
+
expect(cop.offences.size).to eq(1)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'accepts a final newline' do
|
18
|
+
source = ['x = 0', 'top', '']
|
19
|
+
inspect_source(cop, source)
|
20
|
+
expect(cop.offences).to be_empty
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -5,31 +5,27 @@ require 'spec_helper'
|
|
5
5
|
module Rubocop
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
|
-
describe
|
9
|
-
|
8
|
+
describe For do
|
9
|
+
subject(:cop) { described_class.new }
|
10
10
|
|
11
11
|
it 'registers an offence for for' do
|
12
|
-
inspect_source(
|
12
|
+
inspect_source(cop,
|
13
13
|
['def func',
|
14
14
|
' for n in [1, 2, 3] do',
|
15
15
|
' puts n',
|
16
16
|
' end',
|
17
17
|
'end'])
|
18
|
-
expect(
|
19
|
-
expect(af.offences.map(&:message))
|
20
|
-
.to eq([AvoidFor::MSG])
|
18
|
+
expect(cop.offences.size).to eq(1)
|
21
19
|
end
|
22
20
|
|
23
21
|
it 'does not register an offence for :for' do
|
24
|
-
inspect_source(
|
25
|
-
|
26
|
-
expect(af.offences).to be_empty
|
22
|
+
inspect_source(cop, ['[:for, :ala, :bala]'])
|
23
|
+
expect(cop.offences).to be_empty
|
27
24
|
end
|
28
25
|
|
29
26
|
it 'does not register an offence for def for' do
|
30
|
-
inspect_source(
|
31
|
-
|
32
|
-
expect(af.offences).to be_empty
|
27
|
+
inspect_source(cop, ['def for; end'])
|
28
|
+
expect(cop.offences).to be_empty
|
33
29
|
end
|
34
30
|
end
|
35
31
|
end
|
@@ -5,15 +5,25 @@ require 'spec_helper'
|
|
5
5
|
module Rubocop
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
|
-
describe
|
9
|
-
|
8
|
+
describe GlobalVars, :config do
|
9
|
+
cop_config = {
|
10
|
+
'AllowedVariables' => ['$allowed']
|
11
|
+
}
|
12
|
+
|
13
|
+
subject(:cop) { described_class.new(config) }
|
14
|
+
let(:cop_config) { cop_config }
|
10
15
|
|
11
16
|
it 'registers an offence for $custom' do
|
12
17
|
inspect_source(cop, ['puts $custom'])
|
13
18
|
expect(cop.offences.size).to eq(1)
|
14
19
|
end
|
15
20
|
|
16
|
-
|
21
|
+
it 'allows user whitelisted variables' do
|
22
|
+
inspect_source(cop, ['puts $allowed'])
|
23
|
+
expect(cop.offences).to be_empty
|
24
|
+
end
|
25
|
+
|
26
|
+
described_class::BUILT_IN_VARS.each do |var|
|
17
27
|
it "does not register an offence for built-in variable #{var}" do
|
18
28
|
inspect_source(cop, ["puts #{var}"])
|
19
29
|
expect(cop.offences).to be_empty
|
@@ -6,49 +6,60 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe HashSyntax do
|
9
|
-
|
9
|
+
subject(:hash_syntax) { HashSyntax.new }
|
10
10
|
|
11
11
|
it 'registers offence for hash rocket syntax when new is possible' do
|
12
12
|
inspect_source(hash_syntax, ['x = { :a => 0 }'])
|
13
|
-
expect(hash_syntax.
|
13
|
+
expect(hash_syntax.messages).to eq(
|
14
14
|
['Ruby 1.8 hash syntax detected'])
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'registers an offence for mixed syntax when new is possible' do
|
18
18
|
inspect_source(hash_syntax, ['x = { :a => 0, b: 1 }'])
|
19
|
-
expect(hash_syntax.
|
19
|
+
expect(hash_syntax.messages).to eq(
|
20
20
|
['Ruby 1.8 hash syntax detected'])
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'registers an offence for hash rockets in method calls' do
|
24
24
|
inspect_source(hash_syntax, ['func(3, :a => 0)'])
|
25
|
-
expect(hash_syntax.
|
25
|
+
expect(hash_syntax.messages).to eq(
|
26
26
|
['Ruby 1.8 hash syntax detected'])
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'accepts hash rockets when keys have different types' do
|
30
30
|
inspect_source(hash_syntax, ['x = { :a => 0, "b" => 1 }'])
|
31
|
-
expect(hash_syntax.
|
31
|
+
expect(hash_syntax.messages).to be_empty
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'accepts hash rockets when keys have whitespaces in them' do
|
35
35
|
inspect_source(hash_syntax, ['x = { :"t o" => 0 }'])
|
36
|
-
expect(hash_syntax.
|
36
|
+
expect(hash_syntax.messages).to be_empty
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'accepts hash rockets when keys have special symbols in them' do
|
40
40
|
inspect_source(hash_syntax, ['x = { :"\tab" => 1 }'])
|
41
|
-
expect(hash_syntax.
|
41
|
+
expect(hash_syntax.messages).to be_empty
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'accepts hash rockets when keys start with a digit' do
|
45
|
+
inspect_source(hash_syntax, ['x = { :"1" => 1 }'])
|
46
|
+
expect(hash_syntax.messages).to be_empty
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'registers offence when keys start with an uppercase letter' do
|
50
|
+
inspect_source(hash_syntax, ['x = { :A => 0 }'])
|
51
|
+
expect(hash_syntax.messages).to eq(
|
52
|
+
['Ruby 1.8 hash syntax detected'])
|
42
53
|
end
|
43
54
|
|
44
55
|
it 'accepts new syntax in a hash literal' do
|
45
56
|
inspect_source(hash_syntax, ['x = { a: 0, b: 1 }'])
|
46
|
-
expect(hash_syntax.
|
57
|
+
expect(hash_syntax.messages).to be_empty
|
47
58
|
end
|
48
59
|
|
49
60
|
it 'accepts new syntax in method calls' do
|
50
61
|
inspect_source(hash_syntax, ['func(3, a: 0)'])
|
51
|
-
expect(hash_syntax.
|
62
|
+
expect(hash_syntax.messages).to be_empty
|
52
63
|
end
|
53
64
|
end
|
54
65
|
end
|