rubocop 0.28.0 → 0.29.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubocop might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +7 -7
- data/.travis.yml +4 -0
- data/CHANGELOG.md +59 -0
- data/README.md +62 -28
- data/config/default.yml +31 -0
- data/config/disabled.yml +1 -1
- data/config/enabled.yml +17 -0
- data/lib/rubocop.rb +4 -0
- data/lib/rubocop/cli.rb +1 -1
- data/lib/rubocop/config.rb +12 -8
- data/lib/rubocop/config_loader.rb +20 -10
- data/lib/rubocop/cop/cop.rb +13 -7
- data/lib/rubocop/cop/corrector.rb +10 -10
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +6 -1
- data/lib/rubocop/cop/lint/block_alignment.rb +9 -2
- data/lib/rubocop/cop/lint/debugger.rb +13 -1
- data/lib/rubocop/cop/lint/duplicate_methods.rb +104 -0
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/require_parentheses.rb +3 -3
- data/lib/rubocop/cop/mixin/access_modifier_node.rb +27 -0
- data/lib/rubocop/cop/mixin/on_normal_if_unless.rb +0 -4
- data/lib/rubocop/cop/rails/delegate.rb +4 -5
- data/lib/rubocop/cop/rails/read_write_attribute.rb +33 -0
- data/lib/rubocop/cop/style/access_modifier_indentation.rb +0 -7
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +4 -2
- data/lib/rubocop/cop/style/class_methods.rb +25 -9
- data/lib/rubocop/cop/style/empty_lines_around_access_modifier.rb +7 -1
- data/lib/rubocop/cop/style/empty_literal.rb +25 -10
- data/lib/rubocop/cop/style/even_odd.rb +32 -14
- data/lib/rubocop/cop/style/first_parameter_indentation.rb +106 -0
- data/lib/rubocop/cop/style/format_string.rb +2 -2
- data/lib/rubocop/cop/style/global_vars.rb +1 -5
- data/lib/rubocop/cop/style/hash_syntax.rb +0 -4
- data/lib/rubocop/cop/style/indentation_consistency.rb +5 -5
- data/lib/rubocop/cop/style/indentation_width.rb +13 -14
- data/lib/rubocop/cop/style/lambda.rb +48 -2
- data/lib/rubocop/cop/style/line_end_concatenation.rb +43 -47
- data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +3 -3
- data/lib/rubocop/cop/style/module_function.rb +3 -3
- data/lib/rubocop/cop/style/multiline_block_layout.rb +65 -17
- data/lib/rubocop/cop/style/multiline_operation_indentation.rb +2 -1
- data/lib/rubocop/cop/style/perl_backrefs.rb +2 -2
- data/lib/rubocop/cop/style/redundant_exception.rb +12 -0
- data/lib/rubocop/cop/style/self_assignment.rb +27 -0
- data/lib/rubocop/cop/style/semicolon.rb +2 -1
- data/lib/rubocop/cop/style/space_around_block_parameters.rb +92 -0
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +0 -8
- data/lib/rubocop/cop/style/struct_inheritance.rb +42 -0
- data/lib/rubocop/cop/style/trivial_accessors.rb +10 -4
- data/lib/rubocop/cop/util.rb +32 -7
- data/lib/rubocop/formatter/simple_text_formatter.rb +0 -15
- data/lib/rubocop/options.rb +28 -41
- data/lib/rubocop/processed_source.rb +6 -0
- data/lib/rubocop/rake_task.rb +6 -3
- data/lib/rubocop/runner.rb +55 -15
- data/lib/rubocop/version.rb +1 -1
- data/relnotes/v0.29.0.md +116 -0
- data/rubocop.gemspec +3 -3
- data/spec/rubocop/cli_spec.rb +329 -25
- data/spec/rubocop/config_loader_spec.rb +20 -0
- data/spec/rubocop/cop/lint/assignment_in_condition_spec.rb +27 -3
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +3 -4
- data/spec/rubocop/cop/lint/condition_position_spec.rb +1 -1
- data/spec/rubocop/cop/lint/debugger_spec.rb +20 -7
- data/spec/rubocop/cop/lint/duplicate_methods_spec.rb +189 -0
- data/spec/rubocop/cop/lint/empty_interpolation_spec.rb +1 -1
- data/spec/rubocop/cop/lint/end_in_method_spec.rb +1 -1
- data/spec/rubocop/cop/lint/eval_spec.rb +4 -4
- data/spec/rubocop/cop/lint/literal_in_condition_spec.rb +18 -0
- data/spec/rubocop/cop/lint/literal_in_interpolation_spec.rb +2 -2
- data/spec/rubocop/cop/lint/loop_spec.rb +4 -4
- data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +7 -7
- data/spec/rubocop/cop/lint/space_before_first_arg_spec.rb +5 -4
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +3 -9
- data/spec/rubocop/cop/lint/useless_comparison_spec.rb +1 -1
- data/spec/rubocop/cop/lint/void_spec.rb +1 -1
- data/spec/rubocop/cop/metrics/abc_size_spec.rb +10 -0
- data/spec/rubocop/cop/metrics/line_length_spec.rb +2 -2
- data/spec/rubocop/cop/metrics/parameter_lists_spec.rb +2 -2
- data/spec/rubocop/cop/rails/action_filter_spec.rb +6 -12
- data/spec/rubocop/cop/rails/default_scope_spec.rb +5 -5
- data/spec/rubocop/cop/rails/delegate_spec.rb +8 -0
- data/spec/rubocop/cop/rails/has_and_belongs_to_many_spec.rb +1 -1
- data/spec/rubocop/cop/rails/read_write_attribute_spec.rb +119 -8
- data/spec/rubocop/cop/rails/scope_args_spec.rb +3 -3
- data/spec/rubocop/cop/rails/validation_spec.rb +3 -3
- data/spec/rubocop/cop/style/alias_spec.rb +5 -5
- data/spec/rubocop/cop/style/align_hash_spec.rb +1 -1
- data/spec/rubocop/cop/style/align_parameters_spec.rb +8 -8
- data/spec/rubocop/cop/style/and_or_spec.rb +15 -30
- data/spec/rubocop/cop/style/array_join_spec.rb +4 -4
- data/spec/rubocop/cop/style/ascii_comments_spec.rb +1 -2
- data/spec/rubocop/cop/style/ascii_identifiers_spec.rb +2 -2
- 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_end_newline_spec.rb +1 -1
- data/spec/rubocop/cop/style/blocks_spec.rb +2 -2
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +38 -33
- data/spec/rubocop/cop/style/case_equality_spec.rb +1 -1
- data/spec/rubocop/cop/style/character_literal_spec.rb +4 -4
- data/spec/rubocop/cop/style/class_and_module_children_spec.rb +4 -2
- data/spec/rubocop/cop/style/class_methods_spec.rb +12 -0
- data/spec/rubocop/cop/style/class_vars_spec.rb +2 -2
- data/spec/rubocop/cop/style/collection_methods_spec.rb +4 -4
- data/spec/rubocop/cop/style/colon_method_call_spec.rb +8 -8
- data/spec/rubocop/cop/style/comment_annotation_spec.rb +10 -10
- data/spec/rubocop/cop/style/constant_name_spec.rb +7 -7
- data/spec/rubocop/cop/style/def_with_parentheses_spec.rb +1 -1
- data/spec/rubocop/cop/style/deprecated_hash_methods_spec.rb +4 -4
- data/spec/rubocop/cop/style/dot_position_spec.rb +8 -6
- data/spec/rubocop/cop/style/each_with_object_spec.rb +2 -2
- data/spec/rubocop/cop/style/else_alignment_spec.rb +2 -4
- data/spec/rubocop/cop/style/empty_lines_around_access_modifier_spec.rb +78 -0
- data/spec/rubocop/cop/style/empty_lines_around_class_body_spec.rb +60 -0
- data/spec/rubocop/cop/style/empty_lines_spec.rb +3 -3
- data/spec/rubocop/cop/style/empty_literal_spec.rb +29 -12
- data/spec/rubocop/cop/style/encoding_spec.rb +3 -3
- data/spec/rubocop/cop/style/end_block_spec.rb +1 -1
- data/spec/rubocop/cop/style/end_of_line_spec.rb +2 -2
- data/spec/rubocop/cop/style/even_odd_spec.rb +109 -20
- data/spec/rubocop/cop/style/extra_spacing_spec.rb +3 -3
- data/spec/rubocop/cop/style/first_parameter_indentation_spec.rb +293 -0
- data/spec/rubocop/cop/style/for_spec.rb +2 -2
- data/spec/rubocop/cop/style/format_string_spec.rb +45 -21
- data/spec/rubocop/cop/style/global_vars_spec.rb +4 -4
- data/spec/rubocop/cop/style/guard_clause_spec.rb +17 -0
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +15 -15
- data/spec/rubocop/cop/{metrics → style}/if_unless_modifier_spec.rb +2 -2
- data/spec/rubocop/cop/style/if_with_semicolon_spec.rb +2 -2
- data/spec/rubocop/cop/style/indent_array_spec.rb +3 -6
- data/spec/rubocop/cop/style/indent_hash_spec.rb +4 -4
- data/spec/rubocop/cop/style/indentation_consistency_spec.rb +1 -2
- data/spec/rubocop/cop/style/indentation_width_spec.rb +1 -2
- data/spec/rubocop/cop/style/infinite_loop_spec.rb +1 -1
- data/spec/rubocop/cop/style/lambda_call_spec.rb +4 -4
- data/spec/rubocop/cop/style/lambda_spec.rb +37 -2
- data/spec/rubocop/cop/style/leading_comment_space_spec.rb +7 -12
- data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +41 -1
- data/spec/rubocop/cop/style/method_call_parentheses_spec.rb +4 -4
- data/spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb +3 -3
- data/spec/rubocop/cop/style/method_name_spec.rb +1 -1
- data/spec/rubocop/cop/style/multiline_block_layout_spec.rb +61 -0
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +1 -3
- data/spec/rubocop/cop/style/multiline_operation_indentation_spec.rb +8 -0
- data/spec/rubocop/cop/style/multiline_ternary_operator_spec.rb +1 -1
- data/spec/rubocop/cop/style/nested_ternary_operator_spec.rb +1 -1
- data/spec/rubocop/cop/style/next_spec.rb +16 -0
- data/spec/rubocop/cop/style/numeric_literals_spec.rb +5 -5
- data/spec/rubocop/cop/style/one_line_conditional_spec.rb +1 -1
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +22 -4
- data/spec/rubocop/cop/style/percent_literal_delimiters_spec.rb +31 -31
- data/spec/rubocop/cop/style/percent_q_literals_spec.rb +12 -12
- data/spec/rubocop/cop/style/perl_backrefs_spec.rb +3 -3
- data/spec/rubocop/cop/style/proc_spec.rb +3 -3
- data/spec/rubocop/cop/style/raise_args_spec.rb +9 -9
- data/spec/rubocop/cop/style/redundant_begin_spec.rb +1 -1
- data/spec/rubocop/cop/style/redundant_exception_spec.rb +36 -4
- data/spec/rubocop/cop/style/redundant_self_spec.rb +89 -45
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +9 -9
- data/spec/rubocop/cop/style/rescue_modifier_spec.rb +2 -2
- data/spec/rubocop/cop/style/self_assignment_spec.rb +16 -10
- data/spec/rubocop/cop/style/semicolon_spec.rb +9 -9
- data/spec/rubocop/cop/style/single_line_block_params_spec.rb +2 -2
- data/spec/rubocop/cop/style/single_space_before_first_arg_spec.rb +1 -1
- data/spec/rubocop/cop/style/space_after_colon_spec.rb +5 -5
- data/spec/rubocop/cop/style/space_after_comma_spec.rb +3 -3
- data/spec/rubocop/cop/style/space_after_control_keyword_spec.rb +4 -4
- data/spec/rubocop/cop/style/space_after_not_spec.rb +2 -2
- data/spec/rubocop/cop/style/space_after_semicolon_spec.rb +2 -2
- data/spec/rubocop/cop/style/space_around_block_parameters_spec.rb +150 -0
- data/spec/rubocop/cop/style/space_around_equals_in_parameter_default_spec.rb +18 -9
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +24 -21
- data/spec/rubocop/cop/style/space_before_block_braces_spec.rb +4 -4
- data/spec/rubocop/cop/style/space_before_comma_spec.rb +4 -4
- data/spec/rubocop/cop/style/space_before_comment_spec.rb +3 -3
- data/spec/rubocop/cop/style/space_before_semicolon_spec.rb +2 -2
- data/spec/rubocop/cop/style/space_inside_block_braces_spec.rb +33 -24
- data/spec/rubocop/cop/style/space_inside_brackets_spec.rb +2 -2
- data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +9 -9
- data/spec/rubocop/cop/style/space_inside_parens_spec.rb +1 -1
- data/spec/rubocop/cop/style/special_global_vars_spec.rb +6 -6
- data/spec/rubocop/cop/style/string_literals_in_interpolation_spec.rb +3 -3
- data/spec/rubocop/cop/style/string_literals_spec.rb +16 -16
- data/spec/rubocop/cop/style/struct_inheritance_spec.rb +44 -0
- data/spec/rubocop/cop/style/symbol_array_spec.rb +9 -9
- data/spec/rubocop/cop/style/symbol_proc_spec.rb +12 -12
- data/spec/rubocop/cop/style/tab_spec.rb +4 -4
- data/spec/rubocop/cop/style/trailing_blank_lines_spec.rb +2 -2
- data/spec/rubocop/cop/style/trailing_whitespace_spec.rb +2 -2
- data/spec/rubocop/cop/style/trivial_accessors_spec.rb +16 -0
- data/spec/rubocop/cop/style/unneeded_capital_w_spec.rb +11 -22
- data/spec/rubocop/cop/style/variable_interpolation_spec.rb +7 -7
- data/spec/rubocop/cop/style/while_until_do_spec.rb +2 -2
- data/spec/rubocop/cop/{metrics → style}/while_until_modifier_spec.rb +2 -2
- data/spec/rubocop/cop/style/word_array_spec.rb +11 -11
- data/spec/rubocop/cop/util_spec.rb +51 -0
- data/spec/rubocop/cop/variable_force/reference_spec.rb +19 -0
- data/spec/rubocop/cop/variable_force/variable_table_spec.rb +7 -0
- data/spec/rubocop/formatter/disabled_lines_formatter_spec.rb +7 -8
- data/spec/rubocop/formatter/text_util_spec.rb +55 -0
- data/spec/rubocop/options_spec.rb +26 -20
- data/spec/rubocop/rake_task_spec.rb +122 -0
- data/spec/rubocop/runner_spec.rb +37 -2
- data/spec/rubocop/token_spec.rb +5 -1
- data/spec/spec_helper.rb +5 -2
- data/spec/support/cop_helper.rb +3 -0
- data/spec/support/cops/class_must_be_a_module_cop.rb +19 -0
- data/spec/support/cops/module_must_be_a_class_cop.rb +19 -0
- data/spec/support/custom_matchers.rb +1 -1
- metadata +35 -12
@@ -7,12 +7,12 @@ describe RuboCop::Cop::Style::PercentQLiterals, :config do
|
|
7
7
|
|
8
8
|
shared_examples 'accepts quote characters' do
|
9
9
|
it 'accepts single quotes' do
|
10
|
-
inspect_source(cop,
|
10
|
+
inspect_source(cop, "'hi'")
|
11
11
|
expect(cop.offenses).to be_empty
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'accepts double quotes' do
|
15
|
-
inspect_source(cop,
|
15
|
+
inspect_source(cop, '"hi"')
|
16
16
|
expect(cop.offenses).to be_empty
|
17
17
|
end
|
18
18
|
end
|
@@ -20,12 +20,12 @@ describe RuboCop::Cop::Style::PercentQLiterals, :config do
|
|
20
20
|
shared_examples 'accepts any q string with backslash t' do
|
21
21
|
context 'with special characters' do
|
22
22
|
it 'accepts %q' do
|
23
|
-
inspect_source(cop,
|
23
|
+
inspect_source(cop, '%q(\t)')
|
24
24
|
expect(cop.offenses).to be_empty
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'accepts %Q' do
|
28
|
-
inspect_source(cop,
|
28
|
+
inspect_source(cop, '%Q(\t)')
|
29
29
|
expect(cop.offenses).to be_empty
|
30
30
|
end
|
31
31
|
end
|
@@ -36,12 +36,12 @@ describe RuboCop::Cop::Style::PercentQLiterals, :config do
|
|
36
36
|
|
37
37
|
context 'without interpolation' do
|
38
38
|
it 'accepts %q' do
|
39
|
-
inspect_source(cop,
|
39
|
+
inspect_source(cop, '%q(hi)')
|
40
40
|
expect(cop.offenses).to be_empty
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'registers offense for %Q' do
|
44
|
-
inspect_source(cop,
|
44
|
+
inspect_source(cop, '%Q(hi)')
|
45
45
|
expect(cop.messages)
|
46
46
|
.to eq(['Do not use `%Q` unless interpolation is needed. Use `%q`.'])
|
47
47
|
expect(cop.highlights).to eq(['%Q('])
|
@@ -58,13 +58,13 @@ describe RuboCop::Cop::Style::PercentQLiterals, :config do
|
|
58
58
|
|
59
59
|
context 'with interpolation' do
|
60
60
|
it 'accepts %Q' do
|
61
|
-
inspect_source(cop,
|
61
|
+
inspect_source(cop, '%Q(#{1 + 2})')
|
62
62
|
expect(cop.offenses).to be_empty
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'accepts %q' do
|
66
66
|
# This is most probably a mistake, but not this cop's responsibility.
|
67
|
-
inspect_source(cop,
|
67
|
+
inspect_source(cop, '%q(#{1 + 2})')
|
68
68
|
expect(cop.offenses).to be_empty
|
69
69
|
end
|
70
70
|
|
@@ -77,13 +77,13 @@ describe RuboCop::Cop::Style::PercentQLiterals, :config do
|
|
77
77
|
|
78
78
|
context 'without interpolation' do
|
79
79
|
it 'registers offense for %q' do
|
80
|
-
inspect_source(cop,
|
80
|
+
inspect_source(cop, '%q(hi)')
|
81
81
|
expect(cop.messages).to eq(['Use `%Q` instead of `%q`.'])
|
82
82
|
expect(cop.highlights).to eq(['%q('])
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'accepts %Q' do
|
86
|
-
inspect_source(cop,
|
86
|
+
inspect_source(cop, '%Q(hi)')
|
87
87
|
expect(cop.offenses).to be_empty
|
88
88
|
end
|
89
89
|
|
@@ -98,7 +98,7 @@ describe RuboCop::Cop::Style::PercentQLiterals, :config do
|
|
98
98
|
|
99
99
|
context 'with interpolation' do
|
100
100
|
it 'accepts %Q' do
|
101
|
-
inspect_source(cop,
|
101
|
+
inspect_source(cop, '%Q(#{1 + 2})')
|
102
102
|
expect(cop.offenses).to be_empty
|
103
103
|
end
|
104
104
|
|
@@ -106,7 +106,7 @@ describe RuboCop::Cop::Style::PercentQLiterals, :config do
|
|
106
106
|
# It's strange if interpolation syntax appears inside a static string,
|
107
107
|
# but we can't be sure if it's a mistake or not. Changing it to %Q
|
108
108
|
# would alter semantics, so we leave it as it is.
|
109
|
-
inspect_source(cop,
|
109
|
+
inspect_source(cop, '%q(#{1 + 2})')
|
110
110
|
expect(cop.offenses).to be_empty
|
111
111
|
end
|
112
112
|
|
@@ -6,17 +6,17 @@ describe RuboCop::Cop::Style::PerlBackrefs do
|
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
8
|
it 'registers an offense for $1' do
|
9
|
-
inspect_source(cop,
|
9
|
+
inspect_source(cop, 'puts $1')
|
10
10
|
expect(cop.offenses.size).to eq(1)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'auto-corrects $1 to Regexp.last_match[1]' do
|
14
14
|
new_source = autocorrect_source(cop, '$1')
|
15
|
-
expect(new_source).to eq('Regexp.last_match
|
15
|
+
expect(new_source).to eq('Regexp.last_match(1)')
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'auto-corrects #$1 to #{Regexp.last_match[1]}' do
|
19
19
|
new_source = autocorrect_source(cop, '"#$1"')
|
20
|
-
expect(new_source).to eq('"#{Regexp.last_match
|
20
|
+
expect(new_source).to eq('"#{Regexp.last_match(1)}"')
|
21
21
|
end
|
22
22
|
end
|
@@ -6,17 +6,17 @@ describe RuboCop::Cop::Style::Proc do
|
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
8
|
it 'registers an offense for a Proc.new call' do
|
9
|
-
inspect_source(cop,
|
9
|
+
inspect_source(cop, 'f = Proc.new { |x| puts x }')
|
10
10
|
expect(cop.offenses.size).to eq(1)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'accepts the proc method' do
|
14
|
-
inspect_source(cop,
|
14
|
+
inspect_source(cop, 'f = proc { |x| puts x }')
|
15
15
|
expect(cop.offenses).to be_empty
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'accepts the Proc.new call outside of block' do
|
19
|
-
inspect_source(cop,
|
19
|
+
inspect_source(cop, 'p = Proc.new')
|
20
20
|
expect(cop.offenses).to be_empty
|
21
21
|
end
|
22
22
|
|
@@ -9,7 +9,7 @@ describe RuboCop::Cop::Style::RaiseArgs, :config do
|
|
9
9
|
let(:cop_config) { { 'EnforcedStyle' => 'compact' } }
|
10
10
|
|
11
11
|
it 'reports an offense for a raise with 2 args' do
|
12
|
-
inspect_source(cop,
|
12
|
+
inspect_source(cop, 'raise RuntimeError, msg')
|
13
13
|
expect(cop.offenses.size).to eq(1)
|
14
14
|
expect(cop.config_to_allow_offenses).to eq('EnforcedStyle' => 'exploded')
|
15
15
|
end
|
@@ -27,17 +27,17 @@ describe RuboCop::Cop::Style::RaiseArgs, :config do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'reports an offense for a raise with 3 args' do
|
30
|
-
inspect_source(cop,
|
30
|
+
inspect_source(cop, 'raise RuntimeError, msg, caller')
|
31
31
|
expect(cop.offenses.size).to eq(1)
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'accepts a raise with msg argument' do
|
35
|
-
inspect_source(cop,
|
35
|
+
inspect_source(cop, 'raise msg')
|
36
36
|
expect(cop.offenses).to be_empty
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'accepts a raise with an exception argument' do
|
40
|
-
inspect_source(cop,
|
40
|
+
inspect_source(cop, 'raise Ex.new(msg)')
|
41
41
|
expect(cop.offenses).to be_empty
|
42
42
|
end
|
43
43
|
end
|
@@ -46,7 +46,7 @@ describe RuboCop::Cop::Style::RaiseArgs, :config do
|
|
46
46
|
let(:cop_config) { { 'EnforcedStyle' => 'exploded' } }
|
47
47
|
|
48
48
|
it 'reports an offense for a raise with exception object' do
|
49
|
-
inspect_source(cop,
|
49
|
+
inspect_source(cop, 'raise Ex.new(msg)')
|
50
50
|
expect(cop.offenses.size).to eq(1)
|
51
51
|
expect(cop.messages)
|
52
52
|
.to eq(['Provide an exception class and message ' \
|
@@ -65,22 +65,22 @@ describe RuboCop::Cop::Style::RaiseArgs, :config do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'accepts exception constructor with more than 1 argument' do
|
68
|
-
inspect_source(cop,
|
68
|
+
inspect_source(cop, 'raise RuntimeError.new(a1, a2, a3)')
|
69
69
|
expect(cop.offenses).to be_empty
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'accepts a raise with 3 args' do
|
73
|
-
inspect_source(cop,
|
73
|
+
inspect_source(cop, 'raise RuntimeError, msg, caller')
|
74
74
|
expect(cop.offenses).to be_empty
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'accepts a raise with 2 args' do
|
78
|
-
inspect_source(cop,
|
78
|
+
inspect_source(cop, 'raise RuntimeError, msg')
|
79
79
|
expect(cop.offenses).to be_empty
|
80
80
|
end
|
81
81
|
|
82
82
|
it 'accepts a raise with msg argument' do
|
83
|
-
inspect_source(cop,
|
83
|
+
inspect_source(cop, 'raise msg')
|
84
84
|
expect(cop.offenses).to be_empty
|
85
85
|
end
|
86
86
|
end
|
@@ -6,7 +6,7 @@ describe RuboCop::Cop::Style::RedundantBegin do
|
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
8
|
it 'reports an offense for single line def with redundant begin block' do
|
9
|
-
src =
|
9
|
+
src = ' def func; begin; x; y; rescue; z end end'
|
10
10
|
inspect_source(cop, src)
|
11
11
|
expect(cop.offenses.size).to eq(1)
|
12
12
|
end
|
@@ -6,22 +6,54 @@ describe RuboCop::Cop::Style::RedundantException do
|
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
8
|
it 'reports an offense for a raise with RuntimeError' do
|
9
|
-
inspect_source(cop,
|
9
|
+
inspect_source(cop, 'raise RuntimeError, msg')
|
10
10
|
expect(cop.offenses.size).to eq(1)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'reports an offense for a fail with RuntimeError' do
|
14
|
-
inspect_source(cop,
|
14
|
+
inspect_source(cop, 'fail RuntimeError, msg')
|
15
15
|
expect(cop.offenses.size).to eq(1)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'accepts a raise with RuntimeError if it does not have 2 args' do
|
19
|
-
inspect_source(cop,
|
19
|
+
inspect_source(cop, 'raise RuntimeError, msg, caller')
|
20
20
|
expect(cop.offenses).to be_empty
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'accepts a fail with RuntimeError if it does not have 2 args' do
|
24
|
-
inspect_source(cop,
|
24
|
+
inspect_source(cop, 'fail RuntimeError, msg, caller')
|
25
25
|
expect(cop.offenses).to be_empty
|
26
26
|
end
|
27
|
+
|
28
|
+
it 'auto-corrects a raise by removing RuntimeError' do
|
29
|
+
src = 'raise RuntimeError, msg'
|
30
|
+
result_src = 'raise msg'
|
31
|
+
new_src = autocorrect_source(cop, src)
|
32
|
+
expect(new_src).to eq(result_src)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'auto-corrects a fil by removing RuntimeError' do
|
36
|
+
src = 'fail RuntimeError, msg'
|
37
|
+
result_src = 'fail msg'
|
38
|
+
new_src = autocorrect_source(cop, src)
|
39
|
+
expect(new_src).to eq(result_src)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'does not modify raise w/ RuntimeError if it does not have 2 args' do
|
43
|
+
src = 'raise runtimeError, msg, caller'
|
44
|
+
new_src = autocorrect_source(cop, src)
|
45
|
+
expect(new_src).to eq(src)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'does not modify fail w/ RuntimeError if it does not have 2 args' do
|
49
|
+
src = 'fail RuntimeError, msg, caller'
|
50
|
+
new_src = autocorrect_source(cop, src)
|
51
|
+
expect(new_src).to eq(src)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'does not modify rescue w/ non redundant error' do
|
55
|
+
src = 'fail OtherError, msg'
|
56
|
+
new_src = autocorrect_source(cop, src)
|
57
|
+
expect(new_src).to eq(src)
|
58
|
+
end
|
27
59
|
end
|
@@ -6,43 +6,43 @@ describe RuboCop::Cop::Style::RedundantSelf do
|
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
8
|
it 'reports an offense a self receiver on an rvalue' do
|
9
|
-
src =
|
9
|
+
src = 'a = self.b'
|
10
10
|
inspect_source(cop, src)
|
11
11
|
expect(cop.offenses.size).to eq(1)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'accepts a self receiver on an lvalue of an assignment' do
|
15
|
-
src =
|
15
|
+
src = 'self.a = b'
|
16
16
|
inspect_source(cop, src)
|
17
17
|
expect(cop.offenses).to be_empty
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'accepts a self receiver on an lvalue of an or-assignment' do
|
21
|
-
src =
|
21
|
+
src = 'self.logger ||= Rails.logger'
|
22
22
|
inspect_source(cop, src)
|
23
23
|
expect(cop.offenses).to be_empty
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'accepts a self receiver on an lvalue of an and-assignment' do
|
27
|
-
src =
|
27
|
+
src = 'self.flag &&= value'
|
28
28
|
inspect_source(cop, src)
|
29
29
|
expect(cop.offenses).to be_empty
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'accepts a self receiver on an lvalue of a plus-assignment' do
|
33
|
-
src =
|
33
|
+
src = 'self.sum += 10'
|
34
34
|
inspect_source(cop, src)
|
35
35
|
expect(cop.offenses).to be_empty
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'accepts a self receiver with the square bracket operator' do
|
39
|
-
src =
|
39
|
+
src = 'self[a]'
|
40
40
|
inspect_source(cop, src)
|
41
41
|
expect(cop.offenses).to be_empty
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'accepts a self receiver with the double less-than operator' do
|
45
|
-
src =
|
45
|
+
src = 'self << a'
|
46
46
|
inspect_source(cop, src)
|
47
47
|
expect(cop.offenses).to be_empty
|
48
48
|
end
|
@@ -89,54 +89,98 @@ describe RuboCop::Cop::Style::RedundantSelf do
|
|
89
89
|
expect(cop.offenses).to be_empty
|
90
90
|
end
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
92
|
+
describe 'instance methods' do
|
93
|
+
it 'accepts a self receiver used to distinguish from blockarg' do
|
94
|
+
src = ['def requested_specs(&groups)',
|
95
|
+
' some_method(self.groups)',
|
96
|
+
'end'
|
97
|
+
]
|
98
|
+
inspect_source(cop, src)
|
99
|
+
expect(cop.offenses).to be_empty
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'accepts a self receiver used to distinguish from argument' do
|
103
|
+
src = ['def requested_specs(groups)',
|
104
|
+
' some_method(self.groups)',
|
105
|
+
'end'
|
106
|
+
]
|
107
|
+
inspect_source(cop, src)
|
108
|
+
expect(cop.offenses).to be_empty
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'accepts a self receiver used to distinguish from argument' do
|
112
|
+
src = ['def requested_specs(final = true)',
|
113
|
+
' something if self.final != final',
|
114
|
+
'end'
|
115
|
+
]
|
116
|
+
inspect_source(cop, src)
|
117
|
+
expect(cop.offenses).to be_empty
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'accepts a self receiver used to distinguish from local variable' do
|
121
|
+
src = ['def requested_specs',
|
122
|
+
' @requested_specs ||= begin',
|
123
|
+
' groups = self.groups - Bundler.settings.without',
|
124
|
+
' groups.map! { |g| g.to_sym }',
|
125
|
+
' specs_for(groups)',
|
126
|
+
' end',
|
127
|
+
'end'
|
128
|
+
]
|
129
|
+
inspect_source(cop, src)
|
130
|
+
expect(cop.offenses).to be_empty
|
131
|
+
end
|
108
132
|
end
|
109
133
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
134
|
+
describe 'class methods' do
|
135
|
+
it 'accepts a self receiver used to distinguish from blockarg' do
|
136
|
+
src = ['def self.requested_specs(&groups)',
|
137
|
+
' some_method(self.groups)',
|
138
|
+
'end'
|
139
|
+
]
|
140
|
+
inspect_source(cop, src)
|
141
|
+
expect(cop.offenses).to be_empty
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'accepts a self receiver used to distinguish from argument' do
|
145
|
+
src = ['def self.requested_specs(groups)',
|
146
|
+
' some_method(self.groups)',
|
147
|
+
'end'
|
148
|
+
]
|
149
|
+
inspect_source(cop, src)
|
150
|
+
expect(cop.offenses).to be_empty
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'accepts a self receiver used to distinguish from argument' do
|
154
|
+
src = ['def self.requested_specs(final = true)',
|
155
|
+
' something if self.final != final',
|
156
|
+
'end'
|
157
|
+
]
|
158
|
+
inspect_source(cop, src)
|
159
|
+
expect(cop.offenses).to be_empty
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'accepts a self receiver used to distinguish from local variable' do
|
163
|
+
src = ['def self.requested_specs',
|
164
|
+
' @requested_specs ||= begin',
|
165
|
+
' groups = self.groups - Bundler.settings.without',
|
166
|
+
' groups.map! { |g| g.to_sym }',
|
167
|
+
' specs_for(groups)',
|
168
|
+
' end',
|
169
|
+
'end'
|
170
|
+
]
|
171
|
+
inspect_source(cop, src)
|
172
|
+
expect(cop.offenses).to be_empty
|
173
|
+
end
|
130
174
|
end
|
131
175
|
|
132
176
|
it 'accepts a self receiver used to distinguish from constant' do
|
133
|
-
src =
|
177
|
+
src = 'self.Foo'
|
134
178
|
inspect_source(cop, src)
|
135
179
|
expect(cop.offenses).to be_empty
|
136
180
|
end
|
137
181
|
|
138
182
|
it 'auto-corrects by removing redundant self' do
|
139
|
-
new_source = autocorrect_source(cop,
|
183
|
+
new_source = autocorrect_source(cop, 'self.x')
|
140
184
|
expect(new_source).to eq('x')
|
141
185
|
end
|
142
186
|
end
|