rubocop 0.16.0 → 0.17.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/.gitignore +1 -0
- data/.travis.yml +3 -1
- data/CHANGELOG.md +44 -0
- data/CONTRIBUTING.md +40 -8
- data/Gemfile +6 -0
- data/README.md +65 -20
- data/Rakefile +0 -1
- data/config/default.yml +15 -3
- data/config/enabled.yml +143 -109
- data/lib/rubocop.rb +45 -26
- data/lib/rubocop/cli.rb +26 -27
- data/lib/rubocop/config.rb +0 -1
- data/lib/rubocop/config_loader.rb +16 -23
- data/lib/rubocop/cop/commissioner.rb +2 -7
- data/lib/rubocop/cop/cop.rb +24 -51
- data/lib/rubocop/cop/ignored_node.rb +31 -0
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +50 -0
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +36 -0
- data/lib/rubocop/cop/lint/assignment_in_condition.rb +3 -11
- data/lib/rubocop/cop/lint/block_alignment.rb +6 -20
- data/lib/rubocop/cop/lint/condition_position.rb +52 -0
- data/lib/rubocop/cop/lint/else_layout.rb +57 -0
- data/lib/rubocop/cop/lint/end_alignment.rb +33 -8
- data/lib/rubocop/cop/lint/invalid_character_literal.rb +37 -0
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +2 -4
- data/lib/rubocop/cop/lint/syntax.rb +6 -12
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +25 -0
- data/lib/rubocop/cop/mixin/array_syntax.rb +20 -0
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +76 -0
- data/lib/rubocop/cop/mixin/check_assignment.rb +26 -0
- data/lib/rubocop/cop/{check_methods.rb → mixin/check_methods.rb} +0 -0
- data/lib/rubocop/cop/mixin/code_length.rb +33 -0
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +53 -0
- data/lib/rubocop/cop/mixin/configurable_max.rb +19 -0
- data/lib/rubocop/cop/mixin/configurable_naming.rb +45 -0
- data/lib/rubocop/cop/{style → mixin}/if_node.rb +0 -0
- data/lib/rubocop/cop/mixin/if_then_else.rb +23 -0
- data/lib/rubocop/cop/mixin/negative_conditional.rb +24 -0
- data/lib/rubocop/cop/mixin/parser_diagnostic.rb +34 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +19 -0
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +32 -0
- data/lib/rubocop/cop/mixin/space_inside.rb +31 -0
- data/lib/rubocop/cop/mixin/statement_modifier.rb +59 -0
- data/lib/rubocop/cop/mixin/string_help.rb +32 -0
- data/lib/rubocop/cop/mixin/surrounding_space.rb +42 -0
- data/lib/rubocop/cop/rails/default_scope.rb +3 -1
- data/lib/rubocop/cop/style/accessor_method_name.rb +4 -12
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +16 -1
- data/lib/rubocop/cop/style/case_indentation.rb +33 -16
- data/lib/rubocop/cop/style/character_literal.rb +10 -0
- data/lib/rubocop/cop/style/dot_position.rb +23 -6
- data/lib/rubocop/cop/style/empty_lines_around_body.rb +5 -5
- data/lib/rubocop/cop/style/favor_unless_over_negated_if.rb +1 -32
- data/lib/rubocop/cop/style/favor_until_over_negated_while.rb +20 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +5 -1
- data/lib/rubocop/cop/style/if_unless_modifier.rb +34 -0
- data/lib/rubocop/cop/style/if_with_semicolon.rb +1 -1
- data/lib/rubocop/cop/style/indentation_consistency.rb +51 -0
- data/lib/rubocop/cop/style/indentation_width.rb +0 -26
- data/lib/rubocop/cop/style/lambda_call.rb +12 -5
- data/lib/rubocop/cop/style/method_def_parentheses.rb +29 -11
- data/lib/rubocop/cop/style/multiline_if_then.rb +4 -9
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +22 -0
- data/lib/rubocop/cop/style/{ternary_operator.rb → nested_ternary_operator.rb} +0 -15
- data/lib/rubocop/cop/style/numeric_literals.rb +30 -2
- data/lib/rubocop/cop/style/one_line_conditional.rb +2 -1
- data/lib/rubocop/cop/style/parameter_lists.rb +7 -3
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +9 -11
- data/lib/rubocop/cop/style/predicate_name.rb +4 -12
- data/lib/rubocop/cop/style/raise_args.rb +19 -11
- data/lib/rubocop/cop/style/regexp_literal.rb +19 -6
- data/lib/rubocop/cop/style/space_after_colon.rb +36 -0
- data/lib/rubocop/cop/style/space_after_comma.rb +16 -0
- data/lib/rubocop/cop/style/space_after_semicolon.rb +16 -0
- data/lib/rubocop/cop/style/space_around_block_braces.rb +38 -38
- data/lib/rubocop/cop/style/space_around_operators.rb +1 -2
- data/lib/rubocop/cop/style/space_inside_hash_literal_braces.rb +6 -2
- data/lib/rubocop/cop/style/string_literals.rb +5 -5
- data/lib/rubocop/cop/style/trailing_comma.rb +94 -0
- data/lib/rubocop/cop/style/unless_else.rb +2 -2
- data/lib/rubocop/cop/style/while_until_modifier.rb +32 -0
- data/lib/rubocop/cop/style/word_array.rb +9 -1
- data/lib/rubocop/cop/util.rb +14 -0
- data/lib/rubocop/cop/variable_inspector.rb +11 -6
- data/lib/rubocop/cop/variable_inspector/scope.rb +4 -3
- data/lib/rubocop/file_inspector.rb +22 -6
- data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
- data/lib/rubocop/formatter/colorizable.rb +37 -0
- data/lib/rubocop/formatter/disabled_config_formatter.rb +27 -6
- data/lib/rubocop/formatter/progress_formatter.rb +1 -1
- data/lib/rubocop/formatter/simple_text_formatter.rb +9 -5
- data/lib/rubocop/options.rb +19 -4
- data/lib/rubocop/target_finder.rb +4 -0
- data/lib/rubocop/version.rb +1 -1
- data/rubocop-todo.yml +10 -2
- data/rubocop.gemspec +3 -2
- data/spec/project_spec.rb +12 -7
- data/spec/rubocop/cli_spec.rb +262 -99
- data/spec/rubocop/config_loader_spec.rb +5 -5
- data/spec/rubocop/config_spec.rb +3 -3
- data/spec/rubocop/config_store_spec.rb +12 -11
- data/spec/rubocop/cop/commissioner_spec.rb +21 -5
- data/spec/rubocop/cop/cop_spec.rb +1 -1
- data/spec/rubocop/cop/lint/ambiguous_operator_spec.rb +113 -0
- data/spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb +35 -0
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +2 -2
- data/spec/rubocop/cop/lint/condition_position_spec.rb +49 -0
- data/spec/rubocop/cop/lint/else_layout_spec.rb +65 -0
- data/spec/rubocop/cop/lint/end_alignment_spec.rb +41 -1
- data/spec/rubocop/cop/lint/invalid_character_literal_spec.rb +33 -0
- data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +3 -3
- data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +12 -12
- data/spec/rubocop/cop/lint/syntax_spec.rb +2 -2
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +72 -54
- data/spec/rubocop/cop/lint/useless_else_without_rescue_spec.rb +48 -0
- data/spec/rubocop/cop/offence_spec.rb +1 -1
- data/spec/rubocop/cop/rails/default_scope_spec.rb +6 -0
- data/spec/rubocop/cop/rails/output_spec.rb +2 -1
- data/spec/rubocop/cop/style/align_hash_spec.rb +9 -9
- data/spec/rubocop/cop/style/align_parameters_spec.rb +1 -1
- data/spec/rubocop/cop/style/braces_around_hash_parameters_spec.rb +5 -0
- data/spec/rubocop/cop/style/case_indentation_spec.rb +53 -2
- data/spec/rubocop/cop/style/class_and_module_camel_case_spec.rb +3 -3
- data/spec/rubocop/cop/style/documentation_spec.rb +0 -1
- data/spec/rubocop/cop/style/dot_position_spec.rb +18 -3
- data/spec/rubocop/cop/style/empty_line_between_defs_spec.rb +4 -4
- data/spec/rubocop/cop/style/empty_lines_around_body_spec.rb +13 -0
- 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 +1 -1
- data/spec/rubocop/cop/style/hash_syntax_spec.rb +5 -0
- data/spec/rubocop/cop/style/{favor_modifier_spec.rb → if_unless_modifier_spec.rb} +4 -111
- data/spec/rubocop/cop/style/indentation_consistency_spec.rb +490 -0
- data/spec/rubocop/cop/style/indentation_width_spec.rb +19 -91
- data/spec/rubocop/cop/style/lambda_call_spec.rb +18 -0
- data/spec/rubocop/cop/style/method_called_on_do_end_block_spec.rb +2 -2
- data/spec/rubocop/cop/style/method_def_parentheses_spec.rb +35 -1
- data/spec/rubocop/cop/style/method_length_spec.rb +1 -0
- data/spec/rubocop/cop/style/method_name_spec.rb +27 -5
- data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +4 -4
- data/spec/rubocop/cop/style/multiline_if_then_spec.rb +2 -2
- data/spec/rubocop/cop/style/multiline_ternary_operator_spec.rb +18 -0
- data/spec/rubocop/cop/style/{ternary_operator_spec.rb → nested_ternary_operator_spec.rb} +0 -15
- data/spec/rubocop/cop/style/numeric_literals_spec.rb +18 -1
- data/spec/rubocop/cop/style/one_line_conditional_spec.rb +2 -1
- data/spec/rubocop/cop/style/parameter_lists_spec.rb +1 -0
- data/spec/rubocop/cop/style/parentheses_around_condition_spec.rb +13 -4
- data/spec/rubocop/cop/style/raise_args_spec.rb +22 -0
- data/spec/rubocop/cop/style/redundant_self_spec.rb +4 -4
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +4 -0
- data/spec/rubocop/cop/style/space_after_colon_spec.rb +12 -4
- data/spec/rubocop/cop/style/space_after_method_name_spec.rb +2 -2
- data/spec/rubocop/cop/style/space_around_block_braces_spec.rb +30 -1
- data/spec/rubocop/cop/style/{space_around_equals_in_default_parameter_spec.rb → space_around_equals_in_parameter_default_spec.rb} +0 -0
- data/spec/rubocop/cop/style/space_around_operators_spec.rb +2 -1
- data/spec/rubocop/cop/style/space_inside_hash_literal_braces_spec.rb +20 -3
- data/spec/rubocop/cop/style/string_literals_spec.rb +33 -0
- data/spec/rubocop/cop/style/trailing_comma_spec.rb +200 -0
- data/spec/rubocop/cop/style/variable_name_spec.rb +27 -3
- data/spec/rubocop/cop/style/while_until_modifier_spec.rb +75 -0
- data/spec/rubocop/cop/style/word_array_spec.rb +1 -0
- data/spec/rubocop/cop/team_spec.rb +1 -1
- data/spec/rubocop/cop/variable_inspector/scope_spec.rb +3 -4
- data/spec/rubocop/file_inspector_spec.rb +1 -1
- data/spec/rubocop/formatter/base_formatter_spec.rb +12 -11
- data/spec/rubocop/formatter/colorizable_spec.rb +107 -0
- data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +2 -0
- data/spec/rubocop/formatter/formatter_set_spec.rb +1 -1
- data/spec/rubocop/formatter/json_formatter_spec.rb +4 -3
- data/spec/rubocop/formatter/progress_formatter_spec.rb +2 -2
- data/spec/rubocop/options_spec.rb +3 -1
- data/spec/rubocop/target_finder_spec.rb +13 -11
- data/spec/spec_helper.rb +5 -1
- data/spec/support/shared_examples.rb +2 -2
- data/spec/support/statement_modifier_helper.rb +41 -0
- metadata +88 -30
- data/lib/rubocop/cop/check_assignment.rb +0 -43
- data/lib/rubocop/cop/style/array_syntax.rb +0 -22
- data/lib/rubocop/cop/style/autocorrect_alignment.rb +0 -78
- data/lib/rubocop/cop/style/code_length.rb +0 -35
- data/lib/rubocop/cop/style/configurable_enforced_style.rb +0 -51
- data/lib/rubocop/cop/style/configurable_max.rb +0 -17
- data/lib/rubocop/cop/style/configurable_naming.rb +0 -41
- data/lib/rubocop/cop/style/favor_modifier.rb +0 -118
- data/lib/rubocop/cop/style/if_then_else.rb +0 -27
- data/lib/rubocop/cop/style/space_after_comma_etc.rb +0 -73
- data/lib/rubocop/cop/style/space_inside.rb +0 -33
- data/lib/rubocop/cop/style/string_help.rb +0 -30
- data/lib/rubocop/cop/style/surrounding_space.rb +0 -44
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Lint::UselessElseWithoutRescue do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
before do
|
9
|
+
inspect_source(cop, source)
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'with `else` without `rescue`' do
|
13
|
+
let(:source) do
|
14
|
+
[
|
15
|
+
'begin',
|
16
|
+
' do_something',
|
17
|
+
'else',
|
18
|
+
' handle_unknown_errors',
|
19
|
+
'end'
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'registers an offence' do
|
24
|
+
expect(cop.offences.size).to eq(1)
|
25
|
+
expect(cop.offences.first.message)
|
26
|
+
.to eq('Else without rescue is useless')
|
27
|
+
expect(cop.highlights).to eq(['else'])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'with `else` with `rescue`' do
|
32
|
+
let(:source) do
|
33
|
+
[
|
34
|
+
'begin',
|
35
|
+
' do_something',
|
36
|
+
'rescue ArgumentError',
|
37
|
+
' handle_argument_error',
|
38
|
+
'else',
|
39
|
+
' handle_unknown_errors',
|
40
|
+
'end'
|
41
|
+
]
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'accepts' do
|
45
|
+
expect(cop.offences).to be_empty
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -119,7 +119,7 @@ describe Rubocop::Cop::Offence do
|
|
119
119
|
|
120
120
|
[{ cop: 'B' }, { cop: 'A' }, 1],
|
121
121
|
[{ line: 6, cop: 'A' }, { line: 5, cop: 'B' }, 1],
|
122
|
-
[{ col: 6, cop: 'A' }, { col: 5, cop: 'B' }, 1]
|
122
|
+
[{ col: 6, cop: 'A' }, { col: 5, cop: 'B' }, 1]
|
123
123
|
].each do |one, other, expectation|
|
124
124
|
context "when receiver has #{one} and other has #{other}" do
|
125
125
|
it "returns #{expectation}" do
|
@@ -23,6 +23,12 @@ describe Rubocop::Cop::Rails::DefaultScope do
|
|
23
23
|
expect(cop.offences.size).to eq(1)
|
24
24
|
end
|
25
25
|
|
26
|
+
it 'registers an offence for non blocks' do
|
27
|
+
inspect_source(cop,
|
28
|
+
['default_scope order: "position"'])
|
29
|
+
expect(cop.offences.size).to eq(1)
|
30
|
+
end
|
31
|
+
|
26
32
|
it 'accepts a block arg' do
|
27
33
|
inspect_source(cop,
|
28
34
|
['default_scope { something }'])
|
@@ -33,7 +33,8 @@ describe Rubocop::Cop::Rails::Output, :config do
|
|
33
33
|
it 'should ignore certain files' do
|
34
34
|
source = ['print 1']
|
35
35
|
processed_source = parse_source(source)
|
36
|
-
processed_source.buffer
|
36
|
+
allow(processed_source.buffer)
|
37
|
+
.to receive(:name).and_return('/var/lib/test.rake')
|
37
38
|
_investigate(cop, processed_source)
|
38
39
|
expect(cop.offences).to be_empty
|
39
40
|
end
|
@@ -58,7 +58,7 @@ describe Rubocop::Cop::Style::AlignHash, :config do
|
|
58
58
|
" 'a' => 0,",
|
59
59
|
" 'bbb' => 1",
|
60
60
|
'}'])
|
61
|
-
expect(cop.offences).to
|
61
|
+
expect(cop.offences.size).to eq(1)
|
62
62
|
expect(cop.highlights).to eq(["'bbb' => 1"])
|
63
63
|
end
|
64
64
|
|
@@ -66,13 +66,13 @@ describe Rubocop::Cop::Style::AlignHash, :config do
|
|
66
66
|
it 'registers an offence for misaligned hash keys' do
|
67
67
|
inspect_source(cop, ['func(a: 0,',
|
68
68
|
' b: 1)'])
|
69
|
-
expect(cop.offences).to
|
69
|
+
expect(cop.offences.size).to eq(1)
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'registers an offence for right alignment of keys' do
|
73
73
|
inspect_source(cop, ['func(a: 0,',
|
74
74
|
' bbb: 1)'])
|
75
|
-
expect(cop.offences).to
|
75
|
+
expect(cop.offences.size).to eq(1)
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'accepts aligned hash keys' do
|
@@ -93,7 +93,7 @@ describe Rubocop::Cop::Style::AlignHash, :config do
|
|
93
93
|
' ccc: 2 }',
|
94
94
|
'hash2 = { :a => 0,',
|
95
95
|
' :bb => 1,',
|
96
|
-
' :ccc =>2 }'
|
96
|
+
' :ccc =>2 }'
|
97
97
|
])
|
98
98
|
expect(new_source).to eq(['hash1 = { a: 0,',
|
99
99
|
' bb: 1,',
|
@@ -126,7 +126,7 @@ describe Rubocop::Cop::Style::AlignHash, :config do
|
|
126
126
|
'hash2 = {',
|
127
127
|
' a: 0,',
|
128
128
|
' bbb: 1',
|
129
|
-
'}'
|
129
|
+
'}'
|
130
130
|
])
|
131
131
|
expect(cop.offences).to be_empty
|
132
132
|
end
|
@@ -144,7 +144,7 @@ describe Rubocop::Cop::Style::AlignHash, :config do
|
|
144
144
|
'hash2 = {',
|
145
145
|
' a: 0,',
|
146
146
|
' bbb:1',
|
147
|
-
'}'
|
147
|
+
'}'
|
148
148
|
])
|
149
149
|
expect(cop.highlights).to eq(["'a' => 0",
|
150
150
|
'bbb:1'])
|
@@ -155,7 +155,7 @@ describe Rubocop::Cop::Style::AlignHash, :config do
|
|
155
155
|
" 'a' => 0,",
|
156
156
|
" 'bbb' => 1",
|
157
157
|
'}'])
|
158
|
-
expect(cop.offences).to
|
158
|
+
expect(cop.offences.size).to eq(1)
|
159
159
|
end
|
160
160
|
|
161
161
|
it 'auto-corrects alignment' do
|
@@ -234,7 +234,7 @@ describe Rubocop::Cop::Style::AlignHash, :config do
|
|
234
234
|
" 'a' => 0,",
|
235
235
|
" 'bbb' => 1",
|
236
236
|
'}'])
|
237
|
-
expect(cop.offences).to
|
237
|
+
expect(cop.offences.size).to eq(1)
|
238
238
|
end
|
239
239
|
|
240
240
|
it 'registers an offence for misaligned hash rockets' do
|
@@ -242,7 +242,7 @@ describe Rubocop::Cop::Style::AlignHash, :config do
|
|
242
242
|
" 'a' => 0,",
|
243
243
|
" 'bbb' => 1",
|
244
244
|
'}'])
|
245
|
-
expect(cop.offences).to
|
245
|
+
expect(cop.offences.size).to eq(1)
|
246
246
|
end
|
247
247
|
|
248
248
|
include_examples 'not on separate lines'
|
@@ -159,6 +159,11 @@ describe Rubocop::Cop::Style::BracesAroundHashParameters, :config do
|
|
159
159
|
corrected = autocorrect_source(cop, ['where({ x: 1, foo: "bar" })'])
|
160
160
|
expect(corrected).to eq 'where( x: 1, foo: "bar" )'
|
161
161
|
end
|
162
|
+
|
163
|
+
it 'one hash parameter with braces and a trailing comma' do
|
164
|
+
corrected = autocorrect_source(cop, ['where({ x: 1, y: 2, })'])
|
165
|
+
expect(corrected).to eq 'where( x: 1, y: 2 )'
|
166
|
+
end
|
162
167
|
end
|
163
168
|
end
|
164
169
|
|
@@ -2,8 +2,13 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Rubocop::Cop::Style::CaseIndentation
|
5
|
+
describe Rubocop::Cop::Style::CaseIndentation do
|
6
6
|
subject(:cop) { described_class.new(config) }
|
7
|
+
let(:config) do
|
8
|
+
merged = Rubocop::ConfigLoader
|
9
|
+
.default_configuration['CaseIndentation'].merge(cop_config)
|
10
|
+
Rubocop::Config.new('CaseIndentation' => merged)
|
11
|
+
end
|
7
12
|
|
8
13
|
context 'with IndentWhenRelativeTo: case' do
|
9
14
|
context 'with IndentOneStep: false' do
|
@@ -23,6 +28,19 @@ describe Rubocop::Cop::Style::CaseIndentation, :config do
|
|
23
28
|
expect(cop.offences).to be_empty
|
24
29
|
end
|
25
30
|
|
31
|
+
it 'registers on offence for an assignment indented as end' do
|
32
|
+
source = ['output = case variable',
|
33
|
+
"when 'value1'",
|
34
|
+
" 'output1'",
|
35
|
+
'else',
|
36
|
+
" 'output2'",
|
37
|
+
'end']
|
38
|
+
inspect_source(cop, source)
|
39
|
+
expect(cop.messages).to eq(['Indent when as deep as case.'])
|
40
|
+
expect(cop.config_to_allow_offences).to eq('IndentWhenRelativeTo' =>
|
41
|
+
'end')
|
42
|
+
end
|
43
|
+
|
26
44
|
it 'registers on offence for an assignment indented some other way' do
|
27
45
|
source = ['output = case variable',
|
28
46
|
" when 'value1'",
|
@@ -32,6 +50,25 @@ describe Rubocop::Cop::Style::CaseIndentation, :config do
|
|
32
50
|
'end']
|
33
51
|
inspect_source(cop, source)
|
34
52
|
expect(cop.messages).to eq(['Indent when as deep as case.'])
|
53
|
+
expect(cop.config_to_allow_offences).to eq('Enabled' => false)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'registers on offence for correct + opposite' do
|
57
|
+
source = ['output = case variable',
|
58
|
+
" when 'value1'",
|
59
|
+
" 'output1'",
|
60
|
+
' else',
|
61
|
+
" 'output2'",
|
62
|
+
' end',
|
63
|
+
'output = case variable',
|
64
|
+
"when 'value1'",
|
65
|
+
" 'output1'",
|
66
|
+
'else',
|
67
|
+
" 'output2'",
|
68
|
+
'end']
|
69
|
+
inspect_source(cop, source)
|
70
|
+
expect(cop.messages).to eq(['Indent when as deep as case.'])
|
71
|
+
expect(cop.config_to_allow_offences).to eq('Enabled' => false)
|
35
72
|
end
|
36
73
|
end
|
37
74
|
|
@@ -222,7 +259,7 @@ describe Rubocop::Cop::Style::CaseIndentation, :config do
|
|
222
259
|
expect(cop.offences).to be_empty
|
223
260
|
end
|
224
261
|
|
225
|
-
it 'registers on offence for an assignment indented
|
262
|
+
it 'registers on offence for an assignment indented as case' do
|
226
263
|
source = ['output = case variable',
|
227
264
|
" when 'value1'",
|
228
265
|
" 'output1'",
|
@@ -231,6 +268,20 @@ describe Rubocop::Cop::Style::CaseIndentation, :config do
|
|
231
268
|
' end']
|
232
269
|
inspect_source(cop, source)
|
233
270
|
expect(cop.messages).to eq(['Indent when one step more than end.'])
|
271
|
+
expect(cop.config_to_allow_offences).to eq('IndentWhenRelativeTo' =>
|
272
|
+
'case')
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'registers on offence for an assignment indented some other way' do
|
276
|
+
source = ['output = case variable',
|
277
|
+
" when 'value1'",
|
278
|
+
" 'output1'",
|
279
|
+
' else',
|
280
|
+
" 'output2'",
|
281
|
+
' end']
|
282
|
+
inspect_source(cop, source)
|
283
|
+
expect(cop.messages).to eq(['Indent when one step more than end.'])
|
284
|
+
expect(cop.config_to_allow_offences).to eq('Enabled' => false)
|
234
285
|
end
|
235
286
|
end
|
236
287
|
end
|
@@ -11,7 +11,7 @@ describe Rubocop::Cop::Style::ClassAndModuleCamelCase do
|
|
11
11
|
'end',
|
12
12
|
'',
|
13
13
|
'module My_Module',
|
14
|
-
'end'
|
14
|
+
'end'
|
15
15
|
])
|
16
16
|
expect(cop.offences.size).to eq(2)
|
17
17
|
end
|
@@ -22,7 +22,7 @@ describe Rubocop::Cop::Style::ClassAndModuleCamelCase do
|
|
22
22
|
'end',
|
23
23
|
'',
|
24
24
|
'module My_Module::Ala',
|
25
|
-
'end'
|
25
|
+
'end'
|
26
26
|
])
|
27
27
|
expect(cop.offences.size).to eq(2)
|
28
28
|
end
|
@@ -33,7 +33,7 @@ describe Rubocop::Cop::Style::ClassAndModuleCamelCase do
|
|
33
33
|
'end',
|
34
34
|
'',
|
35
35
|
'module Mine',
|
36
|
-
'end'
|
36
|
+
'end'
|
37
37
|
])
|
38
38
|
expect(cop.offences).to be_empty
|
39
39
|
end
|
@@ -6,12 +6,23 @@ describe Rubocop::Cop::Style::DotPosition, :config do
|
|
6
6
|
subject(:cop) { described_class.new(config) }
|
7
7
|
|
8
8
|
context 'Leading dots style' do
|
9
|
-
let(:cop_config) { { 'Style' => '
|
9
|
+
let(:cop_config) { { 'Style' => 'leading' } }
|
10
10
|
|
11
11
|
it 'registers an offence for trailing dot in multi-line call' do
|
12
12
|
inspect_source(cop, ['something.',
|
13
13
|
' method_name'])
|
14
14
|
expect(cop.offences.size).to eq(1)
|
15
|
+
expect(cop.highlights).to eq(['.'])
|
16
|
+
expect(cop.config_to_allow_offences).to eq('Style' => 'trailing')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'registers an offence for correct + opposite' do
|
20
|
+
inspect_source(cop, ['something',
|
21
|
+
' .method_name',
|
22
|
+
'something.',
|
23
|
+
' method_name'])
|
24
|
+
expect(cop.offences.size).to eq(1)
|
25
|
+
expect(cop.config_to_allow_offences).to eq('Enabled' => false)
|
15
26
|
end
|
16
27
|
|
17
28
|
it 'accepts leading do in multi-line method call' do
|
@@ -37,12 +48,16 @@ describe Rubocop::Cop::Style::DotPosition, :config do
|
|
37
48
|
end
|
38
49
|
|
39
50
|
context 'Trailing dots style' do
|
40
|
-
let(:cop_config) { { 'Style' => '
|
51
|
+
let(:cop_config) { { 'Style' => 'trailing' } }
|
41
52
|
|
42
53
|
it 'registers an offence for leading dot in multi-line call' do
|
43
54
|
inspect_source(cop, ['something',
|
44
55
|
' .method_name'])
|
45
|
-
expect(cop.
|
56
|
+
expect(cop.messages)
|
57
|
+
.to eq(['Place the . on the previous line, together with the method ' +
|
58
|
+
'call receiver.'])
|
59
|
+
expect(cop.highlights).to eq(['.'])
|
60
|
+
expect(cop.config_to_allow_offences).to eq('Style' => 'leading')
|
46
61
|
end
|
47
62
|
|
48
63
|
it 'accepts trailing dot in multi-line method call' do
|
@@ -65,7 +65,7 @@ describe Rubocop::Cop::Style::EmptyLineBetweenDefs, :config do
|
|
65
65
|
' # calculates size',
|
66
66
|
' def n',
|
67
67
|
' end',
|
68
|
-
'end'
|
68
|
+
'end'
|
69
69
|
]
|
70
70
|
inspect_source(cop, source)
|
71
71
|
expect(cop.offences).to be_empty
|
@@ -77,7 +77,7 @@ describe Rubocop::Cop::Style::EmptyLineBetweenDefs, :config do
|
|
77
77
|
' #',
|
78
78
|
' def html_escape(s)',
|
79
79
|
' end',
|
80
|
-
'end'
|
80
|
+
'end'
|
81
81
|
]
|
82
82
|
inspect_source(cop, source)
|
83
83
|
expect(cop.messages).to be_empty
|
@@ -89,7 +89,7 @@ describe Rubocop::Cop::Style::EmptyLineBetweenDefs, :config do
|
|
89
89
|
' def initialize(attrs)',
|
90
90
|
' end',
|
91
91
|
' end',
|
92
|
-
'end'
|
92
|
+
'end'
|
93
93
|
]
|
94
94
|
inspect_source(cop, source)
|
95
95
|
expect(cop.messages).to be_empty
|
@@ -99,7 +99,7 @@ describe Rubocop::Cop::Style::EmptyLineBetweenDefs, :config do
|
|
99
99
|
source = ['def a; end',
|
100
100
|
'def b; end']
|
101
101
|
inspect_source(cop, source)
|
102
|
-
expect(cop.offences).to
|
102
|
+
expect(cop.offences.size).to eq(1)
|
103
103
|
end
|
104
104
|
|
105
105
|
context 'when AllowAdjacentOneLineDefs is enabled' do
|
@@ -14,6 +14,19 @@ describe Rubocop::Cop::Style::EmptyLinesAroundBody do
|
|
14
14
|
expect(cop.offences.size).to eq(1)
|
15
15
|
end
|
16
16
|
|
17
|
+
# The cop only registers an offence if the extra line is completely emtpy. If
|
18
|
+
# there is trailing whitespace, then that must be dealt with first. Having
|
19
|
+
# two cops registering offence for the line with only spaces would cause
|
20
|
+
# havoc in auto-correction.
|
21
|
+
it 'accepts method body starting with a line with spaces' do
|
22
|
+
inspect_source(cop,
|
23
|
+
['def some_method',
|
24
|
+
' ',
|
25
|
+
' do_something',
|
26
|
+
'end'])
|
27
|
+
expect(cop.offences).to be_empty
|
28
|
+
end
|
29
|
+
|
17
30
|
it 'autocorrects method body starting with a blank' do
|
18
31
|
corrected = autocorrect_source(cop,
|
19
32
|
['def some_method',
|
@@ -10,7 +10,7 @@ describe Rubocop::Cop::Style::FavorUnlessOverNegatedIf do
|
|
10
10
|
['if !a_condition',
|
11
11
|
' some_method',
|
12
12
|
'end',
|
13
|
-
'some_method if !a_condition'
|
13
|
+
'some_method if !a_condition'
|
14
14
|
])
|
15
15
|
expect(cop.messages).to eq(
|
16
16
|
['Favor unless (or control flow or) over if for negative ' +
|
@@ -10,7 +10,7 @@ describe Rubocop::Cop::Style::FavorUntilOverNegatedWhile do
|
|
10
10
|
['while !a_condition',
|
11
11
|
' some_method',
|
12
12
|
'end',
|
13
|
-
'some_method while !a_condition'
|
13
|
+
'some_method while !a_condition'
|
14
14
|
])
|
15
15
|
expect(cop.messages).to eq(
|
16
16
|
['Favor until over while for negative conditions.'] * 2)
|
@@ -17,11 +17,14 @@ describe Rubocop::Cop::Style::HashSyntax, :config do
|
|
17
17
|
it 'registers offence for hash rocket syntax when new is possible' do
|
18
18
|
inspect_source(cop, ['x = { :a => 0 }'])
|
19
19
|
expect(cop.messages).to eq(['Use the new Ruby 1.9 hash syntax.'])
|
20
|
+
expect(cop.config_to_allow_offences)
|
21
|
+
.to eq('EnforcedStyle' => 'hash_rockets')
|
20
22
|
end
|
21
23
|
|
22
24
|
it 'registers an offence for mixed syntax when new is possible' do
|
23
25
|
inspect_source(cop, ['x = { :a => 0, b: 1 }'])
|
24
26
|
expect(cop.messages).to eq(['Use the new Ruby 1.9 hash syntax.'])
|
27
|
+
expect(cop.config_to_allow_offences).to eq('Enabled' => false)
|
25
28
|
end
|
26
29
|
|
27
30
|
it 'registers an offence for hash rockets in method calls' do
|
@@ -96,11 +99,13 @@ describe Rubocop::Cop::Style::HashSyntax, :config do
|
|
96
99
|
it 'registers offence for Ruby 1.9 style' do
|
97
100
|
inspect_source(cop, ['x = { a: 0 }'])
|
98
101
|
expect(cop.messages).to eq(['Always use hash rockets in hashes.'])
|
102
|
+
expect(cop.config_to_allow_offences).to eq('EnforcedStyle' => 'ruby19')
|
99
103
|
end
|
100
104
|
|
101
105
|
it 'registers an offence for mixed syntax' do
|
102
106
|
inspect_source(cop, ['x = { :a => 0, b: 1 }'])
|
103
107
|
expect(cop.messages).to eq(['Always use hash rockets in hashes.'])
|
108
|
+
expect(cop.config_to_allow_offences).to eq('Enabled' => false)
|
104
109
|
end
|
105
110
|
|
106
111
|
it 'registers an offence for 1.9 style in method calls' do
|