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,7 +6,7 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe MultilineIfThen do
|
9
|
-
|
9
|
+
subject(:mit) { MultilineIfThen.new }
|
10
10
|
|
11
11
|
# if
|
12
12
|
|
@@ -66,7 +66,7 @@ module Rubocop
|
|
66
66
|
it 'registers an offence for then in multiline unless' do
|
67
67
|
inspect_source(mit, ['unless cond then',
|
68
68
|
'end'])
|
69
|
-
expect(mit.
|
69
|
+
expect(mit.messages).to eq(
|
70
70
|
['Never use then for multi-line if/unless.'])
|
71
71
|
end
|
72
72
|
|
@@ -5,45 +5,35 @@ require 'spec_helper'
|
|
5
5
|
module Rubocop
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
|
-
describe NumericLiterals do
|
9
|
-
|
8
|
+
describe NumericLiterals, :config do
|
9
|
+
subject(:cop) { described_class.new(config) }
|
10
|
+
let(:cop_config) { { 'MinDigits' => 5 } }
|
10
11
|
|
11
12
|
it 'registers an offence for a long integer without underscores' do
|
12
|
-
inspect_source(
|
13
|
-
expect(
|
14
|
-
['Add underscores to large numeric literals to improve their ' +
|
15
|
-
'readability.'])
|
13
|
+
inspect_source(cop, ['a = 123456'])
|
14
|
+
expect(cop.offences.size).to eq(1)
|
16
15
|
end
|
17
16
|
|
18
|
-
it 'registers an offence for an integer with
|
19
|
-
inspect_source(
|
20
|
-
expect(
|
21
|
-
['Add underscores to large numeric literals to improve their ' +
|
22
|
-
'readability.'])
|
17
|
+
it 'registers an offence for an integer with misplaced' do
|
18
|
+
inspect_source(cop, ['a = 123_456_78_90_00'])
|
19
|
+
expect(cop.offences.size).to eq(1)
|
23
20
|
end
|
24
21
|
|
25
|
-
# it 'registers an offence for a long float without underscores' do
|
26
|
-
# inspect_source(num, ['a = 1.234567'])
|
27
|
-
# expect(num.offences.map(&:message)).to eq(
|
28
|
-
# ['Add underscores to large numeric literals to improve their ' +
|
29
|
-
# 'readability.'])
|
30
|
-
# end
|
31
|
-
|
32
22
|
it 'accepts long numbers with underscore' do
|
33
|
-
inspect_source(
|
34
|
-
'b =
|
35
|
-
expect(
|
23
|
+
inspect_source(cop, ['a = 123_456',
|
24
|
+
'b = 123_456.55'])
|
25
|
+
expect(cop.messages).to be_empty
|
36
26
|
end
|
37
27
|
|
38
28
|
it 'accepts a short integer without underscore' do
|
39
|
-
inspect_source(
|
40
|
-
expect(
|
29
|
+
inspect_source(cop, ['a = 123'])
|
30
|
+
expect(cop.messages).to be_empty
|
41
31
|
end
|
42
32
|
|
43
33
|
it 'accepts short numbers without underscore' do
|
44
|
-
inspect_source(
|
34
|
+
inspect_source(cop, ['a = 123',
|
45
35
|
'b = 123.456'])
|
46
|
-
expect(
|
36
|
+
expect(cop.messages).to be_empty
|
47
37
|
end
|
48
38
|
end
|
49
39
|
end
|
@@ -6,11 +6,11 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe OneLineConditional do
|
9
|
-
|
9
|
+
subject(:olc) { OneLineConditional.new }
|
10
10
|
|
11
11
|
it 'registers an offence for one line if/then/end' do
|
12
12
|
inspect_source(olc, ['if cond then run else dont end'])
|
13
|
-
expect(olc.
|
13
|
+
expect(olc.messages).to eq([olc.error_message])
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -6,7 +6,7 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe OpMethod do
|
9
|
-
|
9
|
+
subject(:om) { OpMethod.new }
|
10
10
|
|
11
11
|
it 'registers an offence for arg not named other' do
|
12
12
|
inspect_source(om,
|
@@ -14,7 +14,7 @@ module Rubocop
|
|
14
14
|
' another',
|
15
15
|
'end'])
|
16
16
|
expect(om.offences.size).to eq(1)
|
17
|
-
expect(om.
|
17
|
+
expect(om.messages)
|
18
18
|
.to eq([sprintf(OpMethod::MSG, '+')])
|
19
19
|
end
|
20
20
|
|
@@ -24,7 +24,7 @@ module Rubocop
|
|
24
24
|
' another',
|
25
25
|
'end'])
|
26
26
|
expect(om.offences.size).to eq(1)
|
27
|
-
expect(om.
|
27
|
+
expect(om.messages)
|
28
28
|
.to eq([sprintf(OpMethod::MSG, '+')])
|
29
29
|
end
|
30
30
|
|
@@ -5,10 +5,10 @@ require 'spec_helper'
|
|
5
5
|
module Rubocop
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
|
-
describe ParameterLists do
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
describe ParameterLists, :config do
|
9
|
+
subject(:list) { ParameterLists.new(config) }
|
10
|
+
let(:cop_config) do
|
11
|
+
{
|
12
12
|
'Max' => 4,
|
13
13
|
'CountKeywordArgs' => true
|
14
14
|
}
|
@@ -35,7 +35,7 @@ module Rubocop
|
|
35
35
|
end
|
36
36
|
|
37
37
|
context 'When CountKeywordArgs is false' do
|
38
|
-
before {
|
38
|
+
before { cop_config['CountKeywordArgs'] = false }
|
39
39
|
|
40
40
|
it 'it does not count keyword arguments', ruby: 2.0 do
|
41
41
|
inspect_source(list, ['def meth(a, b, c, d: 1, e: 2)',
|
@@ -5,11 +5,9 @@ require 'spec_helper'
|
|
5
5
|
module Rubocop
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
|
-
describe ParenthesesAroundCondition do
|
9
|
-
|
10
|
-
|
11
|
-
ParenthesesAroundCondition.config = { 'AllowSafeAssignment' => true }
|
12
|
-
end
|
8
|
+
describe ParenthesesAroundCondition, :config do
|
9
|
+
subject(:cop) { ParenthesesAroundCondition.new(config) }
|
10
|
+
let(:cop_config) { { 'AllowSafeAssignment' => true } }
|
13
11
|
|
14
12
|
it 'registers an offence for parentheses around condition' do
|
15
13
|
inspect_source(cop, ['if (x > 10)',
|
@@ -69,9 +67,7 @@ module Rubocop
|
|
69
67
|
end
|
70
68
|
|
71
69
|
context 'safe assignment is not allowed' do
|
72
|
-
|
73
|
-
ParenthesesAroundCondition.config['AllowSafeAssignment'] = false
|
74
|
-
end
|
70
|
+
let(:cop_config) { { 'AllowSafeAssignment' => false } }
|
75
71
|
|
76
72
|
it 'does not accepts = in condition surrounded with braces' do
|
77
73
|
inspect_source(cop,
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module Rubocop
|
6
|
+
module Cop
|
7
|
+
module Style
|
8
|
+
describe PerlBackrefs do
|
9
|
+
subject(:cop) { described_class.new }
|
10
|
+
|
11
|
+
it 'registers an offence for $1' do
|
12
|
+
inspect_source(cop, ['puts $1'])
|
13
|
+
expect(cop.offences.size).to eq(1)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'auto-corrects $1 to Regexp.last_match[1]' do
|
17
|
+
new_source = autocorrect_source(cop, '$1')
|
18
|
+
expect(new_source).to eq('Regexp.last_match[1]')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -6,10 +6,10 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe ReduceArguments do
|
9
|
-
|
9
|
+
subject(:cop) { described_class.new }
|
10
10
|
|
11
11
|
it 'find wrong argument names in calls with different syntax' do
|
12
|
-
inspect_source(
|
12
|
+
inspect_source(cop,
|
13
13
|
['def m',
|
14
14
|
' [0, 1].reduce { |c, d| c + d }',
|
15
15
|
' [0, 1].reduce{ |c, d| c + d }',
|
@@ -18,13 +18,12 @@ module Rubocop
|
|
18
18
|
' [0, 1].reduce (5) { |c, d| c + d }',
|
19
19
|
' [0, 1].reduce(5) { |c, d| c + d }',
|
20
20
|
'end'])
|
21
|
-
expect(
|
22
|
-
expect(
|
23
|
-
.map(&:line).sort).to eq((2..7).to_a)
|
21
|
+
expect(cop.offences.size).to eq(6)
|
22
|
+
expect(cop.offences.map(&:line).sort).to eq((2..7).to_a)
|
24
23
|
end
|
25
24
|
|
26
25
|
it 'allows calls with proper argument names' do
|
27
|
-
inspect_source(
|
26
|
+
inspect_source(cop,
|
28
27
|
['def m',
|
29
28
|
' [0, 1].reduce { |a, e| a + e }',
|
30
29
|
' [0, 1].reduce{ |a, e| a + e }',
|
@@ -33,25 +32,33 @@ module Rubocop
|
|
33
32
|
' [0, 1].reduce (5) { |a, e| a + e }',
|
34
33
|
' [0, 1].reduce(5) { |a, e| a + e }',
|
35
34
|
'end'])
|
36
|
-
expect(
|
35
|
+
expect(cop.offences).to be_empty
|
37
36
|
end
|
38
37
|
|
39
38
|
it 'ignores do..end blocks' do
|
40
|
-
inspect_source(
|
39
|
+
inspect_source(cop,
|
41
40
|
['def m',
|
42
41
|
' [0, 1].reduce do |c, d|',
|
43
42
|
' c + d',
|
44
43
|
' end',
|
45
44
|
'end'])
|
46
|
-
expect(
|
45
|
+
expect(cop.offences).to be_empty
|
47
46
|
end
|
48
47
|
|
49
48
|
it 'ignores :reduce symbols' do
|
50
|
-
inspect_source(
|
49
|
+
inspect_source(cop,
|
51
50
|
['def m',
|
52
51
|
' call_method(:reduce) { |a, b| a + b}',
|
53
52
|
'end'])
|
54
|
-
expect(
|
53
|
+
expect(cop.offences).to be_empty
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'does not report when destructuring is used' do
|
57
|
+
inspect_source(cop,
|
58
|
+
['def m',
|
59
|
+
' test.reduce { |a, (id, _)| a + id}',
|
60
|
+
'end'])
|
61
|
+
expect(cop.offences).to be_empty
|
55
62
|
end
|
56
63
|
end
|
57
64
|
end
|
@@ -6,7 +6,7 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe RedundantReturn do
|
9
|
-
|
9
|
+
subject(:cop) { described_class.new }
|
10
10
|
|
11
11
|
it 'reports an offence for def with only a return' do
|
12
12
|
src = ['def func',
|
@@ -58,6 +58,21 @@ module Rubocop
|
|
58
58
|
inspect_source(cop, src)
|
59
59
|
expect(cop.offences).to be_empty
|
60
60
|
end
|
61
|
+
|
62
|
+
it 'auto-corrects by removing redundant returns' do
|
63
|
+
src = ['def func',
|
64
|
+
' one',
|
65
|
+
' two',
|
66
|
+
' return something',
|
67
|
+
'end'].join("\n")
|
68
|
+
result_src = ['def func',
|
69
|
+
' one',
|
70
|
+
' two',
|
71
|
+
' something',
|
72
|
+
'end'].join("\n")
|
73
|
+
new_source = autocorrect_source(cop, src)
|
74
|
+
expect(new_source).to eq(result_src)
|
75
|
+
end
|
61
76
|
end
|
62
77
|
end
|
63
78
|
end
|
@@ -6,7 +6,7 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe RedundantSelf do
|
9
|
-
|
9
|
+
subject(:cop) { RedundantSelf.new }
|
10
10
|
|
11
11
|
it 'reports an offence a self receiver on an rvalue' do
|
12
12
|
src = ['a = self.b']
|
@@ -104,6 +104,11 @@ module Rubocop
|
|
104
104
|
inspect_source(cop, src)
|
105
105
|
expect(cop.offences).to be_empty
|
106
106
|
end
|
107
|
+
|
108
|
+
it 'auto-corrects by removing redundant self' do
|
109
|
+
new_source = autocorrect_source(cop, ['self.x'])
|
110
|
+
expect(new_source).to eq('x')
|
111
|
+
end
|
107
112
|
end
|
108
113
|
end
|
109
114
|
end
|
@@ -5,16 +5,16 @@ require 'spec_helper'
|
|
5
5
|
module Rubocop
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
|
-
describe RegexpLiteral do
|
9
|
-
|
10
|
-
|
8
|
+
describe RegexpLiteral, :config do
|
9
|
+
subject(:rl) { RegexpLiteral.new(config) }
|
10
|
+
let(:cop_config) { { 'MaxSlashes' => 1 } }
|
11
11
|
|
12
12
|
context 'when a regexp uses // delimiters' do
|
13
13
|
context 'when MaxSlashes is 1' do
|
14
14
|
it 'registers an offence for two slashes in regexp' do
|
15
15
|
inspect_source(rl, ['x =~ /home\/\//',
|
16
16
|
'y =~ /etc\/top\//'])
|
17
|
-
expect(rl.
|
17
|
+
expect(rl.messages)
|
18
18
|
.to eq(['Use %r for regular expressions matching more ' +
|
19
19
|
"than 1 '/' character."] * 2)
|
20
20
|
end
|
@@ -29,11 +29,11 @@ module Rubocop
|
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'when MaxSlashes is 0' do
|
32
|
-
|
32
|
+
let(:cop_config) { { 'MaxSlashes' => 0 } }
|
33
33
|
|
34
34
|
it 'registers an offence for one slash in regexp' do
|
35
35
|
inspect_source(rl, ['x =~ /home\//'])
|
36
|
-
expect(rl.
|
36
|
+
expect(rl.messages)
|
37
37
|
.to eq(['Use %r for regular expressions matching more ' +
|
38
38
|
"than 0 '/' characters."])
|
39
39
|
end
|
@@ -42,6 +42,18 @@ module Rubocop
|
|
42
42
|
inspect_source(rl, ['z =~ /a/'])
|
43
43
|
expect(rl.offences).to be_empty
|
44
44
|
end
|
45
|
+
|
46
|
+
it 'registers an offence for zero slashes in regexp' do
|
47
|
+
inspect_source(rl, ['y =~ %r(etc)'])
|
48
|
+
expect(rl.messages)
|
49
|
+
.to eq(['Use %r only for regular expressions matching more ' +
|
50
|
+
"than 0 '/' characters."])
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'accepts regexp with one slash' do
|
54
|
+
inspect_source(rl, ['x =~ %r(/home)'])
|
55
|
+
expect(rl.offences).to be_empty
|
56
|
+
end
|
45
57
|
end
|
46
58
|
end
|
47
59
|
|
@@ -50,7 +62,7 @@ module Rubocop
|
|
50
62
|
it 'registers an offence for zero or one slash in regexp' do
|
51
63
|
inspect_source(rl, ['x =~ %r(/home)',
|
52
64
|
'y =~ %r(etc)'])
|
53
|
-
expect(rl.
|
65
|
+
expect(rl.messages)
|
54
66
|
.to eq(['Use %r only for regular expressions matching more ' +
|
55
67
|
"than 1 '/' character."] * 2)
|
56
68
|
end
|
@@ -61,22 +73,6 @@ module Rubocop
|
|
61
73
|
expect(rl.offences).to be_empty
|
62
74
|
end
|
63
75
|
end
|
64
|
-
|
65
|
-
context 'when MaxSlashes is 0' do
|
66
|
-
before { RegexpLiteral.config = { 'MaxSlashes' => 0 } }
|
67
|
-
|
68
|
-
it 'registers an offence for zero slashes in regexp' do
|
69
|
-
inspect_source(rl, ['y =~ %r(etc)'])
|
70
|
-
expect(rl.offences.map(&:message))
|
71
|
-
.to eq(['Use %r only for regular expressions matching more ' +
|
72
|
-
"than 0 '/' characters."])
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'accepts regexp with one slash' do
|
76
|
-
inspect_source(rl, ['x =~ %r(/home)'])
|
77
|
-
expect(rl.offences).to be_empty
|
78
|
-
end
|
79
|
-
end
|
80
76
|
end
|
81
77
|
end
|
82
78
|
end
|
@@ -6,13 +6,13 @@ module Rubocop
|
|
6
6
|
module Cop
|
7
7
|
module Style
|
8
8
|
describe RescueModifier do
|
9
|
-
|
9
|
+
subject(:rm) { RescueModifier.new }
|
10
10
|
|
11
11
|
it 'registers an offence for modifier rescue' do
|
12
12
|
inspect_source(rm,
|
13
13
|
['method rescue handle'])
|
14
14
|
expect(rm.offences.size).to eq(1)
|
15
|
-
expect(rm.
|
15
|
+
expect(rm.messages)
|
16
16
|
.to eq([RescueModifier::MSG])
|
17
17
|
end
|
18
18
|
|
@@ -20,7 +20,7 @@ module Rubocop
|
|
20
20
|
inspect_source(rm,
|
21
21
|
['method1 or method2 rescue handle'])
|
22
22
|
expect(rm.offences.size).to eq(1)
|
23
|
-
expect(rm.
|
23
|
+
expect(rm.messages)
|
24
24
|
.to eq([RescueModifier::MSG])
|
25
25
|
end
|
26
26
|
|