rubocop 0.28.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -11,7 +11,7 @@ describe RuboCop::Cop::Style::RegexpLiteral, :config do
|
|
11
11
|
let(:cop_config) { { 'MaxSlashes' => -1 } }
|
12
12
|
|
13
13
|
it 'fails' do
|
14
|
-
expect { inspect_source(cop,
|
14
|
+
expect { inspect_source(cop, 'x =~ /home/') }
|
15
15
|
.to raise_error(RuntimeError)
|
16
16
|
end
|
17
17
|
end
|
@@ -20,26 +20,26 @@ describe RuboCop::Cop::Style::RegexpLiteral, :config do
|
|
20
20
|
let(:cop_config) { { 'MaxSlashes' => 0 } }
|
21
21
|
|
22
22
|
it 'registers an offense for one slash in // regexp' do
|
23
|
-
inspect_source(cop,
|
23
|
+
inspect_source(cop, 'x =~ /home\//')
|
24
24
|
expect(cop.messages)
|
25
25
|
.to eq(['Use %r for regular expressions matching more ' \
|
26
26
|
"than 0 '/' characters."])
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'accepts zero slashes in // regexp' do
|
30
|
-
inspect_source(cop,
|
30
|
+
inspect_source(cop, 'z =~ /a/')
|
31
31
|
expect(cop.offenses).to be_empty
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'registers an offense for zero slashes in %r regexp' do
|
35
|
-
inspect_source(cop,
|
35
|
+
inspect_source(cop, 'y =~ %r(etc)')
|
36
36
|
expect(cop.messages)
|
37
37
|
.to eq(['Use %r only for regular expressions matching more ' \
|
38
38
|
"than 0 '/' characters."])
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'accepts %r regexp with one slash' do
|
42
|
-
inspect_source(cop,
|
42
|
+
inspect_source(cop, 'x =~ %r(/home)')
|
43
43
|
expect(cop.offenses).to be_empty
|
44
44
|
end
|
45
45
|
|
@@ -47,17 +47,17 @@ describe RuboCop::Cop::Style::RegexpLiteral, :config do
|
|
47
47
|
subject(:cop) { described_class.new(config, auto_gen_config: true) }
|
48
48
|
|
49
49
|
it 'sets MaxSlashes: 1 for one slash in // regexp' do
|
50
|
-
inspect_source(cop,
|
50
|
+
inspect_source(cop, 'x =~ /home\//')
|
51
51
|
expect(cop.config_to_allow_offenses).to eq('MaxSlashes' => 1)
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'disables the cop for zero slashes in %r regexp' do
|
55
|
-
inspect_source(cop,
|
55
|
+
inspect_source(cop, 'y =~ %r(etc)')
|
56
56
|
expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'generates nothing if there are no offenses' do
|
60
|
-
inspect_source(cop,
|
60
|
+
inspect_source(cop, 'x =~ %r(/home)')
|
61
61
|
expect(cop.config_to_allow_offenses).to eq(nil)
|
62
62
|
end
|
63
63
|
end
|
@@ -100,7 +100,7 @@ describe RuboCop::Cop::Style::RegexpLiteral, :config do
|
|
100
100
|
end
|
101
101
|
|
102
102
|
it 'ignores slashes do not belong // regexp' do
|
103
|
-
inspect_source(cop,
|
103
|
+
inspect_source(cop, 'x =~ /\s{#{x[/\s+/].length}}/')
|
104
104
|
expect(cop.offenses).to be_empty
|
105
105
|
end
|
106
106
|
|
@@ -7,7 +7,7 @@ describe RuboCop::Cop::Style::RescueModifier do
|
|
7
7
|
|
8
8
|
it 'registers an offense for modifier rescue' do
|
9
9
|
inspect_source(cop,
|
10
|
-
|
10
|
+
'method rescue handle')
|
11
11
|
expect(cop.offenses.size).to eq(1)
|
12
12
|
expect(cop.messages)
|
13
13
|
.to eq(['Avoid using `rescue` in its modifier form.'])
|
@@ -15,7 +15,7 @@ describe RuboCop::Cop::Style::RescueModifier do
|
|
15
15
|
|
16
16
|
it 'handles more complex expression with modifier rescue' do
|
17
17
|
inspect_source(cop,
|
18
|
-
|
18
|
+
'method1 or method2 rescue handle')
|
19
19
|
expect(cop.offenses.size).to eq(1)
|
20
20
|
expect(cop.messages)
|
21
21
|
.to eq(['Avoid using `rescue` in its modifier form.'])
|
@@ -8,7 +8,7 @@ describe RuboCop::Cop::Style::SelfAssignment do
|
|
8
8
|
[:+, :-, :*, :**, :/, :|, :&].product(['x', '@x', '@@x']).each do |op, var|
|
9
9
|
it "registers an offense for non-shorthand assignment #{op} and #{var}" do
|
10
10
|
inspect_source(cop,
|
11
|
-
|
11
|
+
"#{var} = #{var} #{op} y")
|
12
12
|
expect(cop.offenses.size).to eq(1)
|
13
13
|
expect(cop.messages)
|
14
14
|
.to eq(["Use self-assignment shorthand `#{op}=`."])
|
@@ -16,17 +16,20 @@ describe RuboCop::Cop::Style::SelfAssignment do
|
|
16
16
|
|
17
17
|
it "accepts shorthand assignment for #{op} and #{var}" do
|
18
18
|
inspect_source(cop,
|
19
|
-
|
20
|
-
expect(cop.offenses
|
21
|
-
|
22
|
-
|
19
|
+
"#{var} #{op}= y")
|
20
|
+
expect(cop.offenses).to be_empty
|
21
|
+
end
|
22
|
+
|
23
|
+
it "auto-corrects a non-shorthand assignment #{op} and #{var}" do
|
24
|
+
new_source = autocorrect_source(cop, "#{var} = #{var} #{op} y")
|
25
|
+
expect(new_source).to eq("#{var} #{op}= y")
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
26
29
|
['||', '&&'].product(['x', '@x', '@@x']).each do |op, var|
|
27
30
|
it "registers an offense for non-shorthand assignment #{op} and #{var}" do
|
28
31
|
inspect_source(cop,
|
29
|
-
|
32
|
+
"#{var} = #{var} #{op} y")
|
30
33
|
expect(cop.offenses.size).to eq(1)
|
31
34
|
expect(cop.messages)
|
32
35
|
.to eq(["Use self-assignment shorthand `#{op}=`."])
|
@@ -34,10 +37,13 @@ describe RuboCop::Cop::Style::SelfAssignment do
|
|
34
37
|
|
35
38
|
it "accepts shorthand assignment for #{op} and #{var}" do
|
36
39
|
inspect_source(cop,
|
37
|
-
|
38
|
-
expect(cop.offenses
|
39
|
-
|
40
|
-
|
40
|
+
"#{var} #{op}= y")
|
41
|
+
expect(cop.offenses).to be_empty
|
42
|
+
end
|
43
|
+
|
44
|
+
it "auto-corrects a non-shorthand assignment #{op} and #{var}" do
|
45
|
+
new_source = autocorrect_source(cop, "#{var} = #{var} #{op} y")
|
46
|
+
expect(new_source).to eq("#{var} #{op}= y")
|
41
47
|
end
|
42
48
|
end
|
43
49
|
end
|
@@ -8,31 +8,31 @@ describe RuboCop::Cop::Style::Semicolon, :config do
|
|
8
8
|
|
9
9
|
it 'registers an offense for a single expression' do
|
10
10
|
inspect_source(cop,
|
11
|
-
|
11
|
+
'puts "this is a test";')
|
12
12
|
expect(cop.offenses.size).to eq(1)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'registers an offense for several expressions' do
|
16
16
|
inspect_source(cop,
|
17
|
-
|
17
|
+
'puts "this is a test"; puts "So is this"')
|
18
18
|
expect(cop.offenses.size).to eq(1)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'registers an offense for one line method with two statements' do
|
22
22
|
inspect_source(cop,
|
23
|
-
|
23
|
+
'def foo(a) x(1); y(2); z(3); end')
|
24
24
|
expect(cop.offenses.size).to eq(1)
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'accepts semicolon before end if so configured' do
|
28
28
|
inspect_source(cop,
|
29
|
-
|
29
|
+
'def foo(a) z(3); end')
|
30
30
|
expect(cop.offenses).to be_empty
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'accepts semicolon after params if so configured' do
|
34
34
|
inspect_source(cop,
|
35
|
-
|
35
|
+
'def foo(a); z(3) end')
|
36
36
|
expect(cop.offenses).to be_empty
|
37
37
|
end
|
38
38
|
|
@@ -65,13 +65,13 @@ describe RuboCop::Cop::Style::Semicolon, :config do
|
|
65
65
|
|
66
66
|
it 'accepts one line empty module definitions' do
|
67
67
|
inspect_source(cop,
|
68
|
-
|
68
|
+
'module Foo; end')
|
69
69
|
expect(cop.offenses).to be_empty
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'registers an offense for semicolon at the end no matter what' do
|
73
73
|
inspect_source(cop,
|
74
|
-
|
74
|
+
'module Foo; end;')
|
75
75
|
expect(cop.offenses.size).to eq(1)
|
76
76
|
end
|
77
77
|
|
@@ -101,13 +101,13 @@ describe RuboCop::Cop::Style::Semicolon, :config do
|
|
101
101
|
|
102
102
|
it 'accepts several expressions' do
|
103
103
|
inspect_source(cop,
|
104
|
-
|
104
|
+
'puts "this is a test"; puts "So is this"')
|
105
105
|
expect(cop.offenses).to be_empty
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'accepts one line method with two statements' do
|
109
109
|
inspect_source(cop,
|
110
|
-
|
110
|
+
'def foo(a) x(1); y(2); z(3); end')
|
111
111
|
expect(cop.offenses).to be_empty
|
112
112
|
end
|
113
113
|
end
|
@@ -44,13 +44,13 @@ describe RuboCop::Cop::Style::SingleLineBlockParams, :config do
|
|
44
44
|
|
45
45
|
it 'allows an unused parameter to have a leading underscore' do
|
46
46
|
inspect_source(cop,
|
47
|
-
|
47
|
+
'File.foreach(filename).reduce(0) { |a, _e| a + 1 }')
|
48
48
|
expect(cop.offenses).to be_empty
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'finds incorrectly named parameters with leading underscores' do
|
52
52
|
inspect_source(cop,
|
53
|
-
|
53
|
+
'File.foreach(filename).reduce(0) { |_x, _y| }')
|
54
54
|
expect(cop.messages).to eq(['Name `reduce` block params `|a, e|`.'])
|
55
55
|
end
|
56
56
|
|
@@ -56,7 +56,7 @@ describe RuboCop::Cop::Style::SingleSpaceBeforeFirstArg do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'accepts a method call with space after the left parenthesis' do
|
59
|
-
inspect_source(cop,
|
59
|
+
inspect_source(cop, 'something( x )')
|
60
60
|
expect(cop.offenses).to be_empty
|
61
61
|
end
|
62
62
|
end
|
@@ -8,23 +8,23 @@ describe RuboCop::Cop::Style::SpaceAfterColon do
|
|
8
8
|
it 'registers an offense for colon without space after it' do
|
9
9
|
# TODO: There is double reporting of the last colon (also from
|
10
10
|
# SpaceAroundOperators).
|
11
|
-
inspect_source(cop,
|
11
|
+
inspect_source(cop, 'x = w ? {a:3}:4')
|
12
12
|
expect(cop.messages).to eq(['Space missing after colon.'] * 2)
|
13
13
|
expect(cop.highlights).to eq([':'] * 2)
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'accepts colons in symbols' do
|
17
|
-
inspect_source(cop,
|
17
|
+
inspect_source(cop, 'x = :a')
|
18
18
|
expect(cop.messages).to be_empty
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'accepts colon in ternary followed by space' do
|
22
|
-
inspect_source(cop,
|
22
|
+
inspect_source(cop, 'x = w ? a : b')
|
23
23
|
expect(cop.messages).to be_empty
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'accepts hash rockets' do
|
27
|
-
inspect_source(cop,
|
27
|
+
inspect_source(cop, 'x = {"a"=>1}')
|
28
28
|
expect(cop.messages).to be_empty
|
29
29
|
end
|
30
30
|
|
@@ -44,7 +44,7 @@ describe RuboCop::Cop::Style::SpaceAfterColon do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'accepts colons in strings' do
|
47
|
-
inspect_source(cop,
|
47
|
+
inspect_source(cop, "str << ':'")
|
48
48
|
expect(cop.messages).to be_empty
|
49
49
|
end
|
50
50
|
|
@@ -6,19 +6,19 @@ describe RuboCop::Cop::Style::SpaceAfterComma do
|
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
8
|
it 'registers an offense for block argument commas without space' do
|
9
|
-
inspect_source(cop,
|
9
|
+
inspect_source(cop, 'each { |s,t| }')
|
10
10
|
expect(cop.messages).to eq(
|
11
11
|
['Space missing after comma.'])
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'registers an offense for array index commas without space' do
|
15
|
-
inspect_source(cop,
|
15
|
+
inspect_source(cop, 'formats[0,1]')
|
16
16
|
expect(cop.messages).to eq(
|
17
17
|
['Space missing after comma.'])
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'registers an offense for method call arg commas without space' do
|
21
|
-
inspect_source(cop,
|
21
|
+
inspect_source(cop, 'a(1,2)')
|
22
22
|
expect(cop.messages).to eq(
|
23
23
|
['Space missing after comma.'])
|
24
24
|
end
|
@@ -7,23 +7,23 @@ describe RuboCop::Cop::Style::SpaceAfterControlKeyword do
|
|
7
7
|
|
8
8
|
it 'registers an offense for normal if' do
|
9
9
|
inspect_source(cop,
|
10
|
-
|
10
|
+
'if(test) then result end')
|
11
11
|
expect(cop.offenses.size).to eq(1)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'registers an offense for modifier unless' do
|
15
|
-
inspect_source(cop,
|
15
|
+
inspect_source(cop, 'action unless(test)')
|
16
16
|
|
17
17
|
expect(cop.offenses.size).to eq(1)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'does not get confused by keywords' do
|
21
|
-
inspect_source(cop,
|
21
|
+
inspect_source(cop, '[:if, :unless].action')
|
22
22
|
expect(cop.offenses).to be_empty
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'does not get confused by the ternary operator' do
|
26
|
-
inspect_source(cop,
|
26
|
+
inspect_source(cop, 'a ? b : c')
|
27
27
|
expect(cop.offenses).to be_empty
|
28
28
|
end
|
29
29
|
|
@@ -6,12 +6,12 @@ describe RuboCop::Cop::Style::SpaceAfterNot do
|
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
8
|
it 'reports an offense for space after !' do
|
9
|
-
inspect_source(cop,
|
9
|
+
inspect_source(cop, '! something')
|
10
10
|
expect(cop.offenses.size).to eq(1)
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'accepts no space after !' do
|
14
|
-
inspect_source(cop,
|
14
|
+
inspect_source(cop, '!something')
|
15
15
|
expect(cop.offenses).to be_empty
|
16
16
|
end
|
17
17
|
|
@@ -6,13 +6,13 @@ describe RuboCop::Cop::Style::SpaceAfterSemicolon do
|
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
8
|
it 'registers an offense for semicolon without space after it' do
|
9
|
-
inspect_source(cop,
|
9
|
+
inspect_source(cop, 'x = 1;y = 2')
|
10
10
|
expect(cop.messages).to eq(
|
11
11
|
['Space missing after semicolon.'])
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'does not crash if semicolon is the last character of the file' do
|
15
|
-
inspect_source(cop,
|
15
|
+
inspect_source(cop, 'x = 1;')
|
16
16
|
expect(cop.messages).to be_empty
|
17
17
|
end
|
18
18
|
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe RuboCop::Cop::Style::SpaceAroundBlockParameters, :config do
|
6
|
+
subject(:cop) { described_class.new(config) }
|
7
|
+
|
8
|
+
shared_examples 'common behavior' do
|
9
|
+
it 'accepts an empty block' do
|
10
|
+
inspect_source(cop, '{}.each {}')
|
11
|
+
expect(cop.offenses).to be_empty
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when EnforcedStyleInsidePipes is no_space' do
|
16
|
+
let(:cop_config) { { 'EnforcedStyleInsidePipes' => 'no_space' } }
|
17
|
+
|
18
|
+
include_examples 'common behavior'
|
19
|
+
|
20
|
+
it 'accepts a block with spaces in the right places' do
|
21
|
+
inspect_source(cop, '{}.each { |x, y| puts x }')
|
22
|
+
expect(cop.offenses).to be_empty
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'accepts a block with parameters but no body' do
|
26
|
+
inspect_source(cop, '{}.each { |x, y| }')
|
27
|
+
expect(cop.offenses).to be_empty
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'accepts a block parameter without preceding space' do
|
31
|
+
# This is checked by Style/SpaceAfterComma.
|
32
|
+
inspect_source(cop, '{}.each { |x,y| puts x }')
|
33
|
+
expect(cop.offenses).to be_empty
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'registers an offense for space before first parameter' do
|
37
|
+
inspect_source(cop, '{}.each { | x| puts x }')
|
38
|
+
expect(cop.messages)
|
39
|
+
.to eq(['Space before first block parameter detected.'])
|
40
|
+
expect(cop.highlights).to eq([' '])
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'registers an offense for space after last parameter' do
|
44
|
+
inspect_source(cop, '{}.each { |x, y | puts x }')
|
45
|
+
expect(cop.messages).to eq(['Space after last block parameter detected.'])
|
46
|
+
expect(cop.highlights).to eq([' '])
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'registers an offense for no space after closing pipe' do
|
50
|
+
inspect_source(cop, '{}.each { |x, y|puts x }')
|
51
|
+
expect(cop.messages).to eq(['Space after closing `|` missing.'])
|
52
|
+
expect(cop.highlights).to eq(['|'])
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'accepts line break after closing pipe' do
|
56
|
+
inspect_source(cop, ['{}.each do |x, y|',
|
57
|
+
' puts x',
|
58
|
+
'end'])
|
59
|
+
expect(cop.offenses).to be_empty
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'registers an offense for multiple spaces before parameter' do
|
63
|
+
inspect_source(cop, '{}.each { |x, y| puts x }')
|
64
|
+
expect(cop.messages)
|
65
|
+
.to eq(['Extra space before block parameter detected.'])
|
66
|
+
expect(cop.highlights).to eq([' '])
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'auto-corrects offenses' do
|
70
|
+
new_source = autocorrect_source(cop,
|
71
|
+
'{}.each { | x=5, (y,*z) |puts x }')
|
72
|
+
expect(new_source).to eq('{}.each { |x=5, (y,*z)| puts x }')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when EnforcedStyleInsidePipes is space' do
|
77
|
+
let(:cop_config) { { 'EnforcedStyleInsidePipes' => 'space' } }
|
78
|
+
|
79
|
+
include_examples 'common behavior'
|
80
|
+
|
81
|
+
it 'accepts a block with spaces in the right places' do
|
82
|
+
inspect_source(cop, '{}.each { | x, y | puts x }')
|
83
|
+
expect(cop.offenses).to be_empty
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'accepts a block with parameters but no body' do
|
87
|
+
inspect_source(cop, '{}.each { | x, y | }')
|
88
|
+
expect(cop.offenses).to be_empty
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'accepts a block parameter without preceding space' do
|
92
|
+
# This is checked by Style/SpaceAfterComma.
|
93
|
+
inspect_source(cop, '{}.each { | x,y | puts x }')
|
94
|
+
expect(cop.offenses).to be_empty
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'registers an offense for no space before first parameter' do
|
98
|
+
inspect_source(cop, '{}.each { |x | puts x }')
|
99
|
+
expect(cop.messages)
|
100
|
+
.to eq(['Space before first block parameter missing.'])
|
101
|
+
expect(cop.highlights).to eq(['x'])
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'registers an offense for no space after last parameter' do
|
105
|
+
inspect_source(cop, '{}.each { | x, y| puts x }')
|
106
|
+
expect(cop.messages).to eq(['Space after last block parameter missing.'])
|
107
|
+
expect(cop.highlights).to eq(['y'])
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'registers an offense for extra space before first parameter' do
|
111
|
+
inspect_source(cop, '{}.each { | x | puts x }')
|
112
|
+
expect(cop.messages)
|
113
|
+
.to eq(['Extra space before first block parameter detected.'])
|
114
|
+
expect(cop.highlights).to eq([' '])
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'registers an offense for no space after last parameter' do
|
118
|
+
inspect_source(cop, '{}.each { | x, y | puts x }')
|
119
|
+
expect(cop.messages)
|
120
|
+
.to eq(['Extra space after last block parameter detected.'])
|
121
|
+
expect(cop.highlights).to eq([' '])
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'registers an offense for no space after closing pipe' do
|
125
|
+
inspect_source(cop, '{}.each { | x, y |puts x }')
|
126
|
+
expect(cop.messages).to eq(['Space after closing `|` missing.'])
|
127
|
+
expect(cop.highlights).to eq(['|'])
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'accepts line break after closing pipe' do
|
131
|
+
inspect_source(cop, ['{}.each do | x, y |',
|
132
|
+
' puts x',
|
133
|
+
'end'])
|
134
|
+
expect(cop.offenses).to be_empty
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'registers an offense for multiple spaces before parameter' do
|
138
|
+
inspect_source(cop, '{}.each { | x, y | puts x }')
|
139
|
+
expect(cop.messages)
|
140
|
+
.to eq(['Extra space before block parameter detected.'])
|
141
|
+
expect(cop.highlights).to eq([' '])
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'auto-corrects offenses' do
|
145
|
+
new_source = autocorrect_source(cop,
|
146
|
+
'{}.each { | x=5, (y,*z)|puts x }')
|
147
|
+
expect(new_source).to eq('{}.each { | x=5, (y,*z) | puts x }')
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|