rubocop 0.16.0 → 0.17.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/.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,200 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::TrailingComma, :config do
|
6
|
+
subject(:cop) { described_class.new(config) }
|
7
|
+
let(:cop_config) { { 'EnforcedStyleForMultiline' => 'no_comma' } }
|
8
|
+
|
9
|
+
context 'with single line list of values' do
|
10
|
+
it 'registers an offence for trailing comma in an Array literal' do
|
11
|
+
inspect_source(cop, 'VALUES = [1001, 2020, 3333, ]')
|
12
|
+
expect(cop.messages)
|
13
|
+
.to eq(['Avoid comma after the last item of an array.'])
|
14
|
+
expect(cop.highlights).to eq([','])
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'registers an offence for trailing comma in a Hash literal' do
|
18
|
+
inspect_source(cop, 'MAP = { a: 1001, b: 2020, c: 3333, }')
|
19
|
+
expect(cop.messages)
|
20
|
+
.to eq(['Avoid comma after the last item of a hash.'])
|
21
|
+
expect(cop.highlights).to eq([','])
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'registers an offence for trailing comma in a method call' do
|
25
|
+
inspect_source(cop, 'some_method(a, b, c, )')
|
26
|
+
expect(cop.messages)
|
27
|
+
.to eq(['Avoid comma after the last parameter of a method call.'])
|
28
|
+
expect(cop.highlights).to eq([','])
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'registers an offence for trailing comma in a method call with hash' +
|
32
|
+
' parameters at the end' do
|
33
|
+
inspect_source(cop, 'some_method(a, b, c: 0, d: 1, )')
|
34
|
+
expect(cop.messages)
|
35
|
+
.to eq(['Avoid comma after the last parameter of a method call.'])
|
36
|
+
expect(cop.highlights).to eq([','])
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'accepts Array literal without trailing comma' do
|
40
|
+
inspect_source(cop, 'VALUES = [1001, 2020, 3333]')
|
41
|
+
expect(cop.offences).to be_empty
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'accepts empty Array literal' do
|
45
|
+
inspect_source(cop, 'VALUES = []')
|
46
|
+
expect(cop.offences).to be_empty
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'accepts rescue clause' do
|
50
|
+
# The list of rescued classes is an array.
|
51
|
+
inspect_source(cop, ['begin',
|
52
|
+
' do_something',
|
53
|
+
'rescue RuntimeError',
|
54
|
+
'end'])
|
55
|
+
expect(cop.offences).to be_empty
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'accepts Hash literal without trailing comma' do
|
59
|
+
inspect_source(cop, 'MAP = { a: 1001, b: 2020, c: 3333 }')
|
60
|
+
expect(cop.offences).to be_empty
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'accepts empty Hash literal' do
|
64
|
+
inspect_source(cop, 'MAP = {}')
|
65
|
+
expect(cop.offences).to be_empty
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'accepts method call without trailing comma' do
|
69
|
+
inspect_source(cop, 'some_method(a, b, c)')
|
70
|
+
expect(cop.offences).to be_empty
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'accepts method call without parameters' do
|
74
|
+
inspect_source(cop, 'some_method')
|
75
|
+
expect(cop.offences).to be_empty
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'with multi-line list of values' do
|
80
|
+
context 'when EnforcedStyleForMultiline is no_comma' do
|
81
|
+
it 'registers an offence for trailing comma in an Array literal' do
|
82
|
+
inspect_source(cop, ['VALUES = [',
|
83
|
+
' 1001,',
|
84
|
+
' 2020,',
|
85
|
+
' 3333,',
|
86
|
+
' ]'])
|
87
|
+
expect(cop.highlights).to eq([','])
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'registers an offence for trailing comma in a Hash literal' do
|
91
|
+
inspect_source(cop, ['MAP = { a: 1001,',
|
92
|
+
' b: 2020,',
|
93
|
+
' c: 3333,',
|
94
|
+
' }'])
|
95
|
+
expect(cop.highlights).to eq([','])
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'registers an offence for trailing comma in a method call with ' +
|
99
|
+
'hash parameters at the end' do
|
100
|
+
inspect_source(cop, ['some_method(',
|
101
|
+
' a,',
|
102
|
+
' b,',
|
103
|
+
' c: 0,',
|
104
|
+
' d: 1,)'])
|
105
|
+
expect(cop.highlights).to eq([','])
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'accepts an Array literal with no trailing comma' do
|
109
|
+
inspect_source(cop, ['VALUES = [ 1001,',
|
110
|
+
' 2020,',
|
111
|
+
' 3333 ]'])
|
112
|
+
expect(cop.offences).to be_empty
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'accepts a Hash literal with no trailing comma' do
|
116
|
+
inspect_source(cop, ['MAP = {',
|
117
|
+
' a: 1001,',
|
118
|
+
' b: 2020,',
|
119
|
+
' c: 3333',
|
120
|
+
' }'])
|
121
|
+
expect(cop.offences).to be_empty
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'accepts a method call with ' +
|
125
|
+
'hash parameters at the end and no trailing comma' do
|
126
|
+
inspect_source(cop, ['some_method(a,',
|
127
|
+
' b,',
|
128
|
+
' c: 0,',
|
129
|
+
' d: 1',
|
130
|
+
' )'])
|
131
|
+
expect(cop.offences).to be_empty
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'when EnforcedStyleForMultiline is comma' do
|
136
|
+
let(:cop_config) { { 'EnforcedStyleForMultiline' => 'comma' } }
|
137
|
+
|
138
|
+
it 'registers an offence for no trailing comma in an Array literal' do
|
139
|
+
inspect_source(cop, ['VALUES = [',
|
140
|
+
' 1001,',
|
141
|
+
' 2020,',
|
142
|
+
' 3333]'])
|
143
|
+
expect(cop.messages)
|
144
|
+
.to eq(['Put a comma after the last item of a multiline array.'])
|
145
|
+
expect(cop.highlights).to eq(['3333'])
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'registers an offence for no trailing comma in a Hash literal' do
|
149
|
+
inspect_source(cop, ['MAP = { a: 1001,',
|
150
|
+
' b: 2020,',
|
151
|
+
' c: 3333 }'])
|
152
|
+
expect(cop.messages)
|
153
|
+
.to eq(['Put a comma after the last item of a multiline hash.'])
|
154
|
+
expect(cop.highlights).to eq(['c: 3333'])
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'registers an offence for no trailing comma in a method call with' +
|
158
|
+
' hash parameters at the end' do
|
159
|
+
inspect_source(cop, ['some_method(',
|
160
|
+
' a,',
|
161
|
+
' b,',
|
162
|
+
' c: 0,',
|
163
|
+
' d: 1',
|
164
|
+
' )'])
|
165
|
+
expect(cop.messages)
|
166
|
+
.to eq(['Put a comma after the last parameter of a multiline ' +
|
167
|
+
'method call.'])
|
168
|
+
expect(cop.highlights).to eq(['d: 1'])
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'accepts trailing comma in an Array literal' do
|
172
|
+
inspect_source(cop, ['VALUES = [1001,',
|
173
|
+
' 2020,',
|
174
|
+
' 3333,',
|
175
|
+
' ]'])
|
176
|
+
expect(cop.offences).to be_empty
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'accepts trailing comma in a Hash literal' do
|
180
|
+
inspect_source(cop, ['MAP = {',
|
181
|
+
' a: 1001,',
|
182
|
+
' b: 2020,',
|
183
|
+
' c: 3333,',
|
184
|
+
' }'])
|
185
|
+
expect(cop.offences).to be_empty
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'accepts trailing comma in a method call with hash' +
|
189
|
+
' parameters at the end' do
|
190
|
+
inspect_source(cop, ['some_method(',
|
191
|
+
' a,',
|
192
|
+
' b,',
|
193
|
+
' c: 0,',
|
194
|
+
' d: 1,',
|
195
|
+
' )'])
|
196
|
+
expect(cop.offences).to be_empty
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
@@ -32,19 +32,28 @@ describe Rubocop::Cop::Style::VariableName, :config do
|
|
32
32
|
|
33
33
|
it 'registers an offence for camel case in local variable name' do
|
34
34
|
inspect_source(cop, 'myLocal = 1')
|
35
|
-
expect(cop.offences).to
|
35
|
+
expect(cop.offences.size).to eq(1)
|
36
36
|
expect(cop.highlights).to eq(['myLocal'])
|
37
|
+
expect(cop.config_to_allow_offences).to eq('EnforcedStyle' =>
|
38
|
+
'camelCase')
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'registers an offence for correct + opposite' do
|
42
|
+
inspect_source(cop, ['my_local = 1',
|
43
|
+
'myLocal = 1'])
|
44
|
+
expect(cop.highlights).to eq(['myLocal'])
|
45
|
+
expect(cop.config_to_allow_offences).to eq('Enabled' => false)
|
37
46
|
end
|
38
47
|
|
39
48
|
it 'registers an offence for camel case in instance variable name' do
|
40
49
|
inspect_source(cop, '@myAttribute = 3')
|
41
|
-
expect(cop.offences).to
|
50
|
+
expect(cop.offences.size).to eq(1)
|
42
51
|
expect(cop.highlights).to eq(['@myAttribute'])
|
43
52
|
end
|
44
53
|
|
45
54
|
it 'registers an offence for camel case in setter name' do
|
46
55
|
inspect_source(cop, 'self.mySetter = 2')
|
47
|
-
expect(cop.offences).to
|
56
|
+
expect(cop.offences.size).to eq(1)
|
48
57
|
expect(cop.highlights).to eq(['mySetter'])
|
49
58
|
end
|
50
59
|
|
@@ -54,6 +63,21 @@ describe Rubocop::Cop::Style::VariableName, :config do
|
|
54
63
|
context 'when configured for camelCase' do
|
55
64
|
let(:cop_config) { { 'EnforcedStyle' => 'camelCase' } }
|
56
65
|
|
66
|
+
it 'registers an offence for snake case in local variable name' do
|
67
|
+
inspect_source(cop, 'my_local = 1')
|
68
|
+
expect(cop.offences.size).to eq(1)
|
69
|
+
expect(cop.highlights).to eq(['my_local'])
|
70
|
+
expect(cop.config_to_allow_offences).to eq('EnforcedStyle' =>
|
71
|
+
'snake_case')
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'registers an offence for opposite + correct' do
|
75
|
+
inspect_source(cop, ['my_local = 1',
|
76
|
+
'myLocal = 1'])
|
77
|
+
expect(cop.highlights).to eq(['my_local'])
|
78
|
+
expect(cop.config_to_allow_offences).to eq('Enabled' => false)
|
79
|
+
end
|
80
|
+
|
57
81
|
it 'accepts camel case in local variable name' do
|
58
82
|
inspect_source(cop, 'myLocal = 1')
|
59
83
|
expect(cop.offences).to be_empty
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::WhileUntilModifier do
|
6
|
+
include StatementModifierHelper
|
7
|
+
|
8
|
+
subject(:cop) { described_class.new(config) }
|
9
|
+
let(:config) do
|
10
|
+
hash = { 'LineLength' => { 'Max' => 79 } }
|
11
|
+
Rubocop::Config.new(hash)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "accepts multiline unless that doesn't fit on one line" do
|
15
|
+
check_too_long(cop, 'unless')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'accepts multiline unless whose body is more than one line' do
|
19
|
+
check_short_multiline(cop, 'unless')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'registers an offence for multiline while that fits on one line' do
|
23
|
+
check_really_short(cop, 'while')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "accepts multiline while that doesn't fit on one line" do
|
27
|
+
check_too_long(cop, 'while')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'accepts multiline while whose body is more than one line' do
|
31
|
+
check_short_multiline(cop, 'while')
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'accepts oneline while when condition has local variable assignment' do
|
35
|
+
inspect_source(cop, ['lines = %w{first second third}',
|
36
|
+
'while (line = lines.shift)',
|
37
|
+
' puts line',
|
38
|
+
'end'])
|
39
|
+
expect(cop.offences).to be_empty
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'registers an offence for oneline while when assignment is in body' do
|
43
|
+
inspect_source(cop, ['while true',
|
44
|
+
' x = 0',
|
45
|
+
'end'])
|
46
|
+
expect(cop.offences.size).to eq(1)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'registers an offence for multiline until that fits on one line' do
|
50
|
+
check_really_short(cop, 'until')
|
51
|
+
end
|
52
|
+
|
53
|
+
it "accepts multiline until that doesn't fit on one line" do
|
54
|
+
check_too_long(cop, 'until')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'accepts multiline until whose body is more than one line' do
|
58
|
+
check_short_multiline(cop, 'until')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'accepts an empty condition' do
|
62
|
+
check_empty(cop, 'while')
|
63
|
+
check_empty(cop, 'until')
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'accepts modifier while' do
|
67
|
+
inspect_source(cop, ['ala while bala'])
|
68
|
+
expect(cop.offences).to be_empty
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'accepts modifier until' do
|
72
|
+
inspect_source(cop, ['ala until bala'])
|
73
|
+
expect(cop.offences).to be_empty
|
74
|
+
end
|
75
|
+
end
|
@@ -10,6 +10,7 @@ describe Rubocop::Cop::Style::WordArray, :config do
|
|
10
10
|
inspect_source(cop,
|
11
11
|
["['one', 'two', 'three']"])
|
12
12
|
expect(cop.offences.size).to eq(1)
|
13
|
+
expect(cop.config_to_allow_offences).to eq('MinSize' => 3)
|
13
14
|
end
|
14
15
|
|
15
16
|
it 'registers an offence for arrays of double quoted strings' do
|
@@ -82,7 +82,7 @@ describe Rubocop::Cop::Team do
|
|
82
82
|
let(:cop_names) { offences.map(&:cop_name) }
|
83
83
|
|
84
84
|
it 'returns Parser warning offences' do
|
85
|
-
expect(cop_names).to include('
|
85
|
+
expect(cop_names).to include('AmbiguousOperator')
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'returns offences from cops' do
|
@@ -23,8 +23,8 @@ describe Rubocop::Cop::VariableInspector::Scope do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
let(:ast) do
|
26
|
-
|
27
|
-
|
26
|
+
ast = Rubocop::SourceParser.parse(source).ast
|
27
|
+
Rubocop::Cop::VariableInspector.wrap_with_top_level_node(ast)
|
28
28
|
end
|
29
29
|
|
30
30
|
let(:scope_node_type) { :def }
|
@@ -172,12 +172,11 @@ describe Rubocop::Cop::VariableInspector::Scope do
|
|
172
172
|
context 'when the scope is top level' do
|
173
173
|
let(:source) do
|
174
174
|
<<-END
|
175
|
-
foo = 1
|
176
175
|
this_is_target
|
177
176
|
END
|
178
177
|
end
|
179
178
|
|
180
|
-
let(:scope_node_type) { :
|
179
|
+
let(:scope_node_type) { :top_level }
|
181
180
|
|
182
181
|
include_examples 'returns the body node'
|
183
182
|
end
|
@@ -30,7 +30,7 @@ module Rubocop
|
|
30
30
|
'# encoding: utf-8'
|
31
31
|
])
|
32
32
|
|
33
|
-
SimpleTextFormatter.
|
33
|
+
allow(SimpleTextFormatter).to receive(:new).and_return(formatter)
|
34
34
|
$stdout = StringIO.new
|
35
35
|
end
|
36
36
|
|
@@ -76,7 +76,7 @@ module Rubocop
|
|
76
76
|
'no_offence.rb'
|
77
77
|
].map { |path| File.expand_path(path) }.sort
|
78
78
|
|
79
|
-
formatter.
|
79
|
+
expect(formatter).to receive(method_name) do |all_files|
|
80
80
|
expect(all_files.sort).to eq(expected_paths)
|
81
81
|
end
|
82
82
|
|
@@ -85,7 +85,7 @@ module Rubocop
|
|
85
85
|
|
86
86
|
describe 'the passed files paths' do
|
87
87
|
it 'is frozen' do
|
88
|
-
formatter.
|
88
|
+
expect(formatter).to receive(method_name) do |all_files|
|
89
89
|
all_files.each do |path|
|
90
90
|
expect(path).to be_frozen
|
91
91
|
end
|
@@ -115,11 +115,11 @@ module Rubocop
|
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
|
-
cli.
|
118
|
+
allow(cli).to receive(:wants_to_quit?) do
|
119
119
|
formatter.processed_file_count == 2
|
120
120
|
end
|
121
121
|
|
122
|
-
formatter.
|
122
|
+
expect(formatter).to receive(:finished) do |processed_files|
|
123
123
|
expect(processed_files.size).to eq(2)
|
124
124
|
end
|
125
125
|
|
@@ -130,13 +130,13 @@ module Rubocop
|
|
130
130
|
|
131
131
|
shared_examples 'receives a file path' do |method_name|
|
132
132
|
it 'receives a file path' do
|
133
|
-
formatter.
|
133
|
+
expect(formatter).to receive(method_name)
|
134
134
|
.with(File.expand_path('1_offence.rb'), anything)
|
135
135
|
|
136
|
-
formatter.
|
136
|
+
expect(formatter).to receive(method_name)
|
137
137
|
.with(File.expand_path('4_offences.rb'), anything)
|
138
138
|
|
139
|
-
formatter.
|
139
|
+
expect(formatter).to receive(method_name)
|
140
140
|
.with(File.expand_path('no_offence.rb'), anything)
|
141
141
|
|
142
142
|
run
|
@@ -144,7 +144,8 @@ module Rubocop
|
|
144
144
|
|
145
145
|
describe 'the passed path' do
|
146
146
|
it 'is frozen' do
|
147
|
-
formatter
|
147
|
+
expect(formatter)
|
148
|
+
.to receive(method_name).exactly(3).times do |path|
|
148
149
|
expect(path).to be_frozen
|
149
150
|
end
|
150
151
|
run
|
@@ -156,7 +157,7 @@ module Rubocop
|
|
156
157
|
include_examples 'receives a file path', :file_started
|
157
158
|
|
158
159
|
it 'receives file specific information hash' do
|
159
|
-
formatter.
|
160
|
+
expect(formatter).to receive(:file_started)
|
160
161
|
.with(anything, an_instance_of(Hash)).exactly(3).times
|
161
162
|
run
|
162
163
|
end
|
@@ -166,7 +167,7 @@ module Rubocop
|
|
166
167
|
include_examples 'receives a file path', :file_finished
|
167
168
|
|
168
169
|
it 'receives an array of detected offences for the file' do
|
169
|
-
formatter.
|
170
|
+
expect(formatter).to receive(:file_finished)
|
170
171
|
.exactly(3).times do |file, offences|
|
171
172
|
case File.basename(file)
|
172
173
|
when '1_offence.rb'
|