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
@@ -56,12 +56,12 @@ describe RuboCop::Cop::Style::SpaceInsideBrackets do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'accepts square brackets called with method call syntax' do
|
59
|
-
inspect_source(cop,
|
59
|
+
inspect_source(cop, 'subject.[](0)')
|
60
60
|
expect(cop.messages).to be_empty
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'only reports a single space once' do
|
64
|
-
inspect_source(cop,
|
64
|
+
inspect_source(cop, '[ ]')
|
65
65
|
expect(cop.messages).to eq(
|
66
66
|
['Space inside square brackets detected.'])
|
67
67
|
end
|
@@ -10,12 +10,12 @@ describe RuboCop::Cop::Style::SpaceInsideHashLiteralBraces, :config do
|
|
10
10
|
let(:cop_config) { { 'EnforcedStyleForEmptyBraces' => 'no_space' } }
|
11
11
|
|
12
12
|
it 'accepts empty braces with no space inside' do
|
13
|
-
inspect_source(cop,
|
13
|
+
inspect_source(cop, 'h = {}')
|
14
14
|
expect(cop.messages).to be_empty
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'registers an offense for empty braces with space inside' do
|
18
|
-
inspect_source(cop,
|
18
|
+
inspect_source(cop, 'h = { }')
|
19
19
|
expect(cop.messages)
|
20
20
|
.to eq(['Space inside empty hash literal braces detected.'])
|
21
21
|
expect(cop.highlights).to eq([' '])
|
@@ -31,12 +31,12 @@ describe RuboCop::Cop::Style::SpaceInsideHashLiteralBraces, :config do
|
|
31
31
|
let(:cop_config) { { 'EnforcedStyleForEmptyBraces' => 'space' } }
|
32
32
|
|
33
33
|
it 'accepts empty braces with space inside' do
|
34
|
-
inspect_source(cop,
|
34
|
+
inspect_source(cop, 'h = { }')
|
35
35
|
expect(cop.messages).to be_empty
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'registers an offense for empty braces with no space inside' do
|
39
|
-
inspect_source(cop,
|
39
|
+
inspect_source(cop, 'h = {}')
|
40
40
|
expect(cop.messages)
|
41
41
|
.to eq(['Space inside empty hash literal braces missing.'])
|
42
42
|
expect(cop.highlights).to eq(['{'])
|
@@ -62,7 +62,7 @@ describe RuboCop::Cop::Style::SpaceInsideHashLiteralBraces, :config do
|
|
62
62
|
|
63
63
|
it 'registers an offense for correct + opposite' do
|
64
64
|
inspect_source(cop,
|
65
|
-
|
65
|
+
'h = { a: 1}')
|
66
66
|
expect(cop.messages).to eq(['Space inside } missing.'])
|
67
67
|
expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
|
68
68
|
end
|
@@ -79,7 +79,7 @@ describe RuboCop::Cop::Style::SpaceInsideHashLiteralBraces, :config do
|
|
79
79
|
|
80
80
|
it 'registers an offense for hashes with spaces' do
|
81
81
|
inspect_source(cop,
|
82
|
-
|
82
|
+
'h = { a: 1, b: 2 }')
|
83
83
|
expect(cop.messages).to eq(['Space inside { detected.',
|
84
84
|
'Space inside } detected.'])
|
85
85
|
expect(cop.highlights).to eq([' ', ' '])
|
@@ -88,7 +88,7 @@ describe RuboCop::Cop::Style::SpaceInsideHashLiteralBraces, :config do
|
|
88
88
|
|
89
89
|
it 'registers an offense for opposite + correct' do
|
90
90
|
inspect_source(cop,
|
91
|
-
|
91
|
+
'h = {a: 1 }')
|
92
92
|
expect(cop.messages).to eq(['Space inside } detected.'])
|
93
93
|
expect(cop.config_to_allow_offenses).to eq('Enabled' => false)
|
94
94
|
end
|
@@ -134,14 +134,14 @@ describe RuboCop::Cop::Style::SpaceInsideHashLiteralBraces, :config do
|
|
134
134
|
end
|
135
135
|
|
136
136
|
it 'accepts hash literals with no braces' do
|
137
|
-
inspect_source(cop,
|
137
|
+
inspect_source(cop, 'x(a: b.c)')
|
138
138
|
expect(cop.offenses).to be_empty
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'can handle interpolation in a braceless hash literal' do
|
142
142
|
# A tricky special case where the closing brace of the
|
143
143
|
# interpolation risks getting confused for a hash literal brace.
|
144
|
-
inspect_source(cop,
|
144
|
+
inspect_source(cop, 'f(get: "#{x}")')
|
145
145
|
expect(cop.offenses).to be_empty
|
146
146
|
end
|
147
147
|
end
|
@@ -6,28 +6,28 @@ describe RuboCop::Cop::Style::SpecialGlobalVars do
|
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
8
|
it 'registers an offense for $:' do
|
9
|
-
inspect_source(cop,
|
9
|
+
inspect_source(cop, 'puts $:')
|
10
10
|
expect(cop.offenses.size).to eq(1)
|
11
11
|
expect(cop.messages)
|
12
12
|
.to eq(['Prefer `$LOAD_PATH` over `$:`.'])
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'registers an offense for $"' do
|
16
|
-
inspect_source(cop,
|
16
|
+
inspect_source(cop, 'puts $"')
|
17
17
|
expect(cop.offenses.size).to eq(1)
|
18
18
|
expect(cop.messages)
|
19
19
|
.to eq(['Prefer `$LOADED_FEATURES` over `$"`.'])
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'registers an offense for $0' do
|
23
|
-
inspect_source(cop,
|
23
|
+
inspect_source(cop, 'puts $0')
|
24
24
|
expect(cop.offenses.size).to eq(1)
|
25
25
|
expect(cop.messages)
|
26
26
|
.to eq(['Prefer `$PROGRAM_NAME` over `$0`.'])
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'registers an offense for $$' do
|
30
|
-
inspect_source(cop,
|
30
|
+
inspect_source(cop, 'puts $$')
|
31
31
|
expect(cop.offenses.size).to eq(1)
|
32
32
|
expect(cop.messages)
|
33
33
|
.to eq(['Prefer `$PROCESS_ID` or `$PID` from the English ' \
|
@@ -35,13 +35,13 @@ describe RuboCop::Cop::Style::SpecialGlobalVars do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'is clear about variables from the English library vs those not' do
|
38
|
-
inspect_source(cop,
|
38
|
+
inspect_source(cop, 'puts $*')
|
39
39
|
expect(cop.messages)
|
40
40
|
.to eq(['Prefer `$ARGV` from the English library, or `ARGV` over `$*`.'])
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'does not register an offense for backrefs like $1' do
|
44
|
-
inspect_source(cop,
|
44
|
+
inspect_source(cop, 'puts $1')
|
45
45
|
expect(cop.offenses).to be_empty
|
46
46
|
end
|
47
47
|
|
@@ -9,7 +9,7 @@ describe RuboCop::Cop::Style::StringLiteralsInInterpolation, :config do
|
|
9
9
|
let(:cop_config) { { 'EnforcedStyle' => 'single_quotes' } }
|
10
10
|
|
11
11
|
it 'registers an offense for double quotes within embedded expression' do
|
12
|
-
src =
|
12
|
+
src = '"#{"A"}"'
|
13
13
|
inspect_source(cop, src)
|
14
14
|
expect(cop.messages)
|
15
15
|
.to eq(['Prefer single-quoted strings inside interpolations.'])
|
@@ -26,7 +26,7 @@ describe RuboCop::Cop::Style::StringLiteralsInInterpolation, :config do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'accepts double quotes on a static string' do
|
29
|
-
src =
|
29
|
+
src = '"A"'
|
30
30
|
inspect_source(cop, src)
|
31
31
|
expect(cop.offenses).to be_empty
|
32
32
|
end
|
@@ -92,7 +92,7 @@ describe RuboCop::Cop::Style::StringLiteralsInInterpolation, :config do
|
|
92
92
|
let(:cop_config) { { 'EnforcedStyle' => 'other' } }
|
93
93
|
|
94
94
|
it 'fails' do
|
95
|
-
expect { inspect_source(cop,
|
95
|
+
expect { inspect_source(cop, 'a = "#{"b"}"') }
|
96
96
|
.to raise_error(RuntimeError)
|
97
97
|
end
|
98
98
|
end
|
@@ -35,22 +35,22 @@ describe RuboCop::Cop::Style::StringLiterals, :config do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'accepts single quotes' do
|
38
|
-
inspect_source(cop,
|
38
|
+
inspect_source(cop, "a = 'x'")
|
39
39
|
expect(cop.offenses).to be_empty
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'accepts single quotes in interpolation' do
|
43
|
-
inspect_source(cop,
|
43
|
+
inspect_source(cop, %q("hello#{hash['there']}"))
|
44
44
|
expect(cop.offenses).to be_empty
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'accepts %q and %Q quotes' do
|
48
|
-
inspect_source(cop,
|
48
|
+
inspect_source(cop, 'a = %q(x) + %Q[x]')
|
49
49
|
expect(cop.offenses).to be_empty
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'accepts % quotes' do
|
53
|
-
inspect_source(cop,
|
53
|
+
inspect_source(cop, 'a = %(x)')
|
54
54
|
expect(cop.offenses).to be_empty
|
55
55
|
end
|
56
56
|
|
@@ -77,7 +77,7 @@ describe RuboCop::Cop::Style::StringLiterals, :config do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'accepts double quotes at the start of regexp literals' do
|
80
|
-
inspect_source(cop,
|
80
|
+
inspect_source(cop, 's = /"((?:[^\\"]|\\.)*)"/')
|
81
81
|
expect(cop.offenses).to be_empty
|
82
82
|
end
|
83
83
|
|
@@ -91,17 +91,17 @@ describe RuboCop::Cop::Style::StringLiterals, :config do
|
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'accepts " in a %w' do
|
94
|
-
inspect_source(cop,
|
94
|
+
inspect_source(cop, '%w(")')
|
95
95
|
expect(cop.offenses).to be_empty
|
96
96
|
end
|
97
97
|
|
98
98
|
it 'accepts \\\\\n in a string' do # this would be: "\\\n"
|
99
|
-
inspect_source(cop,
|
99
|
+
inspect_source(cop, '"foo \\\\\n bar"')
|
100
100
|
expect(cop.offenses).to be_empty
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'accepts double quotes in interpolation' do
|
104
|
-
src =
|
104
|
+
src = '"#{"A"}"'
|
105
105
|
inspect_source(cop, src)
|
106
106
|
expect(cop.offenses).to be_empty
|
107
107
|
end
|
@@ -137,7 +137,7 @@ describe RuboCop::Cop::Style::StringLiterals, :config do
|
|
137
137
|
|
138
138
|
it 'registers offense for single quotes when double quotes would ' \
|
139
139
|
'be equivalent' do
|
140
|
-
inspect_source(cop,
|
140
|
+
inspect_source(cop, "s = 'abc'")
|
141
141
|
expect(cop.highlights).to eq(["'abc'"])
|
142
142
|
expect(cop.messages)
|
143
143
|
.to eq(['Prefer double-quoted strings unless you need ' \
|
@@ -158,22 +158,22 @@ describe RuboCop::Cop::Style::StringLiterals, :config do
|
|
158
158
|
end
|
159
159
|
|
160
160
|
it 'accepts double quotes' do
|
161
|
-
inspect_source(cop,
|
161
|
+
inspect_source(cop, 'a = "x"')
|
162
162
|
expect(cop.offenses).to be_empty
|
163
163
|
end
|
164
164
|
|
165
165
|
it 'accepts single quotes in interpolation' do
|
166
|
-
inspect_source(cop,
|
166
|
+
inspect_source(cop, %q("hello#{hash['there']}"))
|
167
167
|
expect(cop.offenses).to be_empty
|
168
168
|
end
|
169
169
|
|
170
170
|
it 'accepts %q and %Q quotes' do
|
171
|
-
inspect_source(cop,
|
171
|
+
inspect_source(cop, 'a = %q(x) + %Q[x]')
|
172
172
|
expect(cop.offenses).to be_empty
|
173
173
|
end
|
174
174
|
|
175
175
|
it 'accepts % quotes' do
|
176
|
-
inspect_source(cop,
|
176
|
+
inspect_source(cop, 'a = %(x)')
|
177
177
|
expect(cop.offenses).to be_empty
|
178
178
|
end
|
179
179
|
|
@@ -194,12 +194,12 @@ describe RuboCop::Cop::Style::StringLiterals, :config do
|
|
194
194
|
end
|
195
195
|
|
196
196
|
it 'accepts single quotes at the start of regexp literals' do
|
197
|
-
inspect_source(cop,
|
197
|
+
inspect_source(cop, "s = /'((?:[^\\']|\\.)*)'/")
|
198
198
|
expect(cop.offenses).to be_empty
|
199
199
|
end
|
200
200
|
|
201
201
|
it "accepts ' in a %w" do
|
202
|
-
inspect_source(cop,
|
202
|
+
inspect_source(cop, "%w(')")
|
203
203
|
expect(cop.offenses).to be_empty
|
204
204
|
end
|
205
205
|
|
@@ -221,7 +221,7 @@ describe RuboCop::Cop::Style::StringLiterals, :config do
|
|
221
221
|
let(:cop_config) { { 'EnforcedStyle' => 'other' } }
|
222
222
|
|
223
223
|
it 'fails' do
|
224
|
-
expect { inspect_source(cop,
|
224
|
+
expect { inspect_source(cop, 'a = "b"') }
|
225
225
|
.to raise_error(RuntimeError)
|
226
226
|
end
|
227
227
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe RuboCop::Cop::Style::StructInheritance do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offense when extending instance of Struct' do
|
9
|
+
inspect_source(cop,
|
10
|
+
['class Person < Struct.new(:first_name, :last_name)',
|
11
|
+
'end'
|
12
|
+
])
|
13
|
+
expect(cop.offenses.size).to eq(1)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'registers an offense when extending instance of Struct' do
|
17
|
+
inspect_source(cop,
|
18
|
+
['class Person < Struct.new(:first_name, :last_name) do end',
|
19
|
+
'end'
|
20
|
+
])
|
21
|
+
expect(cop.offenses).to be_empty
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'accepts plain class' do
|
25
|
+
inspect_source(cop,
|
26
|
+
['class Person',
|
27
|
+
'end'
|
28
|
+
])
|
29
|
+
expect(cop.offenses).to be_empty
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'accepts extending DelegateClass' do
|
33
|
+
inspect_source(cop,
|
34
|
+
['class Person < DelegateClass(Animal)',
|
35
|
+
'end'
|
36
|
+
])
|
37
|
+
expect(cop.offenses).to be_empty
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'accepts assignment to Struct.new' do
|
41
|
+
inspect_source(cop, 'Person = Struct.new(:first_name, :last_name)')
|
42
|
+
expect(cop.offenses).to be_empty
|
43
|
+
end
|
44
|
+
end
|
@@ -5,33 +5,33 @@ require 'spec_helper'
|
|
5
5
|
describe RuboCop::Cop::Style::SymbolArray do
|
6
6
|
subject(:cop) { described_class.new }
|
7
7
|
|
8
|
-
it 'registers an offense for arrays of symbols', ruby: 2
|
8
|
+
it 'registers an offense for arrays of symbols', ruby: 2 do
|
9
9
|
inspect_source(cop,
|
10
|
-
|
10
|
+
'[:one, :two, :three]')
|
11
11
|
expect(cop.offenses.size).to eq(1)
|
12
12
|
end
|
13
13
|
|
14
|
-
it 'does not reg an offense for array with non-syms', ruby: 2
|
14
|
+
it 'does not reg an offense for array with non-syms', ruby: 2 do
|
15
15
|
inspect_source(cop,
|
16
|
-
|
16
|
+
'[:one, :two, "three"]')
|
17
17
|
expect(cop.offenses).to be_empty
|
18
18
|
end
|
19
19
|
|
20
|
-
it 'does not reg an offense for array starting with %i', ruby: 2
|
20
|
+
it 'does not reg an offense for array starting with %i', ruby: 2 do
|
21
21
|
inspect_source(cop,
|
22
|
-
|
22
|
+
'%i(one two three)')
|
23
23
|
expect(cop.offenses).to be_empty
|
24
24
|
end
|
25
25
|
|
26
|
-
it 'does not reg an offense for array with one element', ruby: 2
|
26
|
+
it 'does not reg an offense for array with one element', ruby: 2 do
|
27
27
|
inspect_source(cop,
|
28
|
-
|
28
|
+
'[:three]')
|
29
29
|
expect(cop.offenses).to be_empty
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'does nothing on Ruby 1.9', ruby: 1.9 do
|
33
33
|
inspect_source(cop,
|
34
|
-
|
34
|
+
'[:one, :two, :three]')
|
35
35
|
expect(cop.offenses).to be_empty
|
36
36
|
end
|
37
37
|
end
|
@@ -16,68 +16,68 @@ describe RuboCop::Cop::Style::SymbolProc, :config do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'registers an offense for a block when method in body is unary -/=' do
|
19
|
-
inspect_source(cop,
|
19
|
+
inspect_source(cop, 'something.map { |x| -x }')
|
20
20
|
expect(cop.offenses.size).to eq(1)
|
21
21
|
expect(cop.messages)
|
22
22
|
.to eq(['Pass `&:-@` as an argument to `map` instead of a block.'])
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'accepts method receiving another argument beside the block' do
|
26
|
-
inspect_source(cop,
|
26
|
+
inspect_source(cop, 'File.open(file) { |f| f.readlines }')
|
27
27
|
|
28
28
|
expect(cop.offenses).to be_empty
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'accepts block with more than 1 arguments' do
|
32
|
-
inspect_source(cop,
|
32
|
+
inspect_source(cop, 'something { |x, y| x.method }')
|
33
33
|
|
34
34
|
expect(cop.offenses).to be_empty
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'accepts lambda with 1 argument' do
|
38
|
-
inspect_source(cop,
|
38
|
+
inspect_source(cop, '->(x) { x.method }')
|
39
39
|
|
40
40
|
expect(cop.offenses).to be_empty
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'accepts proc with 1 argument' do
|
44
|
-
inspect_source(cop,
|
44
|
+
inspect_source(cop, 'proc { |x| x.method }')
|
45
45
|
|
46
46
|
expect(cop.offenses).to be_empty
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'accepts Proc.new with 1 argument' do
|
50
|
-
inspect_source(cop,
|
50
|
+
inspect_source(cop, 'Proc.new { |x| x.method }')
|
51
51
|
|
52
52
|
expect(cop.offenses).to be_empty
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'accepts ignored method' do
|
56
|
-
inspect_source(cop,
|
56
|
+
inspect_source(cop, 'respond_to { |format| format.xml }')
|
57
57
|
|
58
58
|
expect(cop.offenses).to be_empty
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'accepts block with no arguments' do
|
62
|
-
inspect_source(cop,
|
62
|
+
inspect_source(cop, 'something { x.method }')
|
63
63
|
|
64
64
|
expect(cop.offenses).to be_empty
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'accepts empty block body' do
|
68
|
-
inspect_source(cop,
|
68
|
+
inspect_source(cop, 'something { |x| }')
|
69
69
|
|
70
70
|
expect(cop.offenses).to be_empty
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'accepts block with more than 1 expression in body' do
|
74
|
-
inspect_source(cop,
|
74
|
+
inspect_source(cop, 'something { |x| x.method; something_else }')
|
75
75
|
|
76
76
|
expect(cop.offenses).to be_empty
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'accepts block when method in body is not called on block arg' do
|
80
|
-
inspect_source(cop,
|
80
|
+
inspect_source(cop, 'something { |x| y.method }')
|
81
81
|
|
82
82
|
expect(cop.offenses).to be_empty
|
83
83
|
end
|
@@ -94,7 +94,7 @@ describe RuboCop::Cop::Style::SymbolProc, :config do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'does not crash with a bare method call' do
|
97
|
-
run = -> { inspect_source(cop,
|
97
|
+
run = -> { inspect_source(cop, 'coll.map { |s| bare_method }') }
|
98
98
|
expect(&run).not_to raise_error
|
99
99
|
end
|
100
100
|
end
|