rubocop 0.17.0 → 0.18.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/CHANGELOG.md +65 -42
- data/CONTRIBUTING.md +20 -3
- data/config/enabled.yml +10 -0
- data/lib/rubocop.rb +7 -0
- data/lib/rubocop/cop/cop.rb +4 -13
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +1 -1
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +1 -1
- data/lib/rubocop/cop/lint/loop.rb +1 -1
- data/lib/rubocop/cop/lint/require_parentheses.rb +72 -0
- data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -1
- data/lib/rubocop/cop/style/access_modifier_indentation.rb +3 -1
- data/lib/rubocop/cop/style/align_array.rb +1 -1
- data/lib/rubocop/cop/style/align_hash.rb +1 -1
- data/lib/rubocop/cop/style/align_parameters.rb +1 -1
- data/lib/rubocop/cop/style/def_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/line_end_concatenation.rb +53 -0
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +1 -1
- data/lib/rubocop/cop/style/proc.rb +6 -0
- data/lib/rubocop/cop/style/regexp_literal.rb +1 -1
- data/lib/rubocop/cop/style/space_after_method_name.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma.rb +7 -0
- data/lib/rubocop/cop/style/word_array.rb +27 -0
- data/lib/rubocop/cop/util.rb +1 -0
- data/lib/rubocop/formatter/simple_text_formatter.rb +6 -2
- data/lib/rubocop/options.rb +1 -1
- data/lib/rubocop/path_util.rb +22 -0
- data/lib/rubocop/rake_task.rb +17 -3
- data/lib/rubocop/version.rb +1 -1
- data/rubocop.gemspec +2 -2
- data/spec/project_spec.rb +93 -0
- data/spec/rubocop/cli_spec.rb +27 -22
- data/spec/rubocop/cop/cop_spec.rb +1 -1
- data/spec/rubocop/cop/lint/ambiguous_operator_spec.rb +2 -2
- data/spec/rubocop/cop/lint/ambiguous_regexp_literal_spec.rb +1 -1
- data/spec/rubocop/cop/lint/block_alignment_spec.rb +5 -5
- data/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +2 -2
- data/spec/rubocop/cop/lint/require_parentheses_spec.rb +82 -0
- data/spec/rubocop/cop/lint/rescue_exception_spec.rb +1 -1
- data/spec/rubocop/cop/lint/shadowing_outer_local_variable_spec.rb +9 -9
- data/spec/rubocop/cop/lint/useless_assignment_spec.rb +54 -54
- data/spec/rubocop/cop/lint/useless_setter_call_spec.rb +6 -6
- data/spec/rubocop/cop/style/access_modifier_indentation_spec.rb +49 -8
- data/spec/rubocop/cop/style/align_array_spec.rb +1 -1
- data/spec/rubocop/cop/style/align_hash_spec.rb +1 -1
- data/spec/rubocop/cop/style/align_parameters_spec.rb +2 -2
- data/spec/rubocop/cop/style/blocks_spec.rb +1 -1
- data/spec/rubocop/cop/style/case_indentation_spec.rb +1 -1
- data/spec/rubocop/cop/style/dot_position_spec.rb +1 -1
- data/spec/rubocop/cop/style/favor_unless_over_negated_if_spec.rb +2 -2
- data/spec/rubocop/cop/style/if_unless_modifier_spec.rb +3 -3
- data/spec/rubocop/cop/style/indentation_consistency_spec.rb +4 -4
- data/spec/rubocop/cop/style/indentation_width_spec.rb +3 -3
- data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +27 -0
- data/spec/rubocop/cop/style/multiline_block_chain_spec.rb +1 -1
- data/spec/rubocop/cop/style/proc_spec.rb +5 -0
- data/spec/rubocop/cop/style/regexp_literal_spec.rb +4 -4
- data/spec/rubocop/cop/style/string_literals_spec.rb +7 -7
- data/spec/rubocop/cop/style/trailing_comma_spec.rb +27 -6
- data/spec/rubocop/cop/style/unless_else_spec.rb +1 -1
- data/spec/rubocop/cop/style/variable_interpolation_spec.rb +2 -2
- data/spec/rubocop/cop/style/word_array_spec.rb +10 -0
- data/spec/rubocop/cop/variable_inspector/variable_table_spec.rb +4 -4
- data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +1 -1
- data/spec/rubocop/formatter/formatter_set_spec.rb +1 -1
- data/spec/rubocop/path_util_spec.rb +42 -0
- data/spec/spec_helper.rb +3 -1
- metadata +29 -8
@@ -55,7 +55,7 @@ describe Rubocop::Cop::Lint::UselessSetterCall do
|
|
55
55
|
expect(cop.offences).to be_empty
|
56
56
|
end
|
57
57
|
|
58
|
-
context 'when a lvar has an object passed as argument '
|
58
|
+
context 'when a lvar has an object passed as argument ' \
|
59
59
|
'at the end of the method' do
|
60
60
|
it 'accepts the lvar attr assignment' do
|
61
61
|
inspect_source(cop,
|
@@ -71,7 +71,7 @@ describe Rubocop::Cop::Lint::UselessSetterCall do
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
context 'when a lvar has an object passed as argument '
|
74
|
+
context 'when a lvar has an object passed as argument ' \
|
75
75
|
'by multiple-assignment at the end of the method' do
|
76
76
|
it 'accepts the lvar attr assignment' do
|
77
77
|
inspect_source(cop,
|
@@ -84,7 +84,7 @@ describe Rubocop::Cop::Lint::UselessSetterCall do
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
context 'when a lvar does not have any object passed as argument '
|
87
|
+
context 'when a lvar does not have any object passed as argument ' \
|
88
88
|
'with multiple-assignment at the end of the method' do
|
89
89
|
it 'registers an offence' do
|
90
90
|
inspect_source(cop,
|
@@ -97,7 +97,7 @@ describe Rubocop::Cop::Lint::UselessSetterCall do
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
context 'when a lvar possibly has an object passed as argument '
|
100
|
+
context 'when a lvar possibly has an object passed as argument ' \
|
101
101
|
'by logical-operator-assignment at the end of the method' do
|
102
102
|
it 'accepts the lvar attr assignment' do
|
103
103
|
inspect_source(cop,
|
@@ -111,7 +111,7 @@ describe Rubocop::Cop::Lint::UselessSetterCall do
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
-
context 'when a lvar does not have any object passed as argument '
|
114
|
+
context 'when a lvar does not have any object passed as argument ' \
|
115
115
|
'by binary-operator-assignment at the end of the method' do
|
116
116
|
it 'registers an offence' do
|
117
117
|
inspect_source(cop,
|
@@ -125,7 +125,7 @@ describe Rubocop::Cop::Lint::UselessSetterCall do
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
context 'when a lvar declared as an argument '
|
128
|
+
context 'when a lvar declared as an argument ' \
|
129
129
|
'is no longer the passed object at the end of the method' do
|
130
130
|
it 'registers an offence for the lvar attr assignment' do
|
131
131
|
inspect_source(cop,
|
@@ -5,7 +5,7 @@ require 'spec_helper'
|
|
5
5
|
describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
|
6
6
|
subject(:cop) { described_class.new(config) }
|
7
7
|
|
8
|
-
context 'when
|
8
|
+
context 'when EnforcedStyle is set to indent' do
|
9
9
|
let(:cop_config) { { 'EnforcedStyle' => 'indent' } }
|
10
10
|
|
11
11
|
it 'registers an offence for misaligned private' do
|
@@ -81,7 +81,7 @@ describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
|
|
81
81
|
.to eq(['Indent access modifiers like private.'])
|
82
82
|
end
|
83
83
|
|
84
|
-
it 'registers an offence for misaligned private in class '
|
84
|
+
it 'registers an offence for misaligned private in class ' \
|
85
85
|
'defined with Class.new' do
|
86
86
|
inspect_source(cop,
|
87
87
|
['Test = Class.new do',
|
@@ -95,7 +95,7 @@ describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
|
|
95
95
|
.to eq(['Indent access modifiers like private.'])
|
96
96
|
end
|
97
97
|
|
98
|
-
it 'registers an offence for misaligned private in module '
|
98
|
+
it 'registers an offence for misaligned private in module ' \
|
99
99
|
'defined with Module.new' do
|
100
100
|
inspect_source(cop,
|
101
101
|
['Test = Module.new do',
|
@@ -163,12 +163,30 @@ describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
|
|
163
163
|
expect(cop.messages)
|
164
164
|
.to eq(['Indent access modifiers like private.'])
|
165
165
|
end
|
166
|
+
|
167
|
+
it 'auto-corrects incorrectly indented access modifiers' do
|
168
|
+
corrected = autocorrect_source(cop, ['class Test',
|
169
|
+
'',
|
170
|
+
'public',
|
171
|
+
' private',
|
172
|
+
' protected',
|
173
|
+
'',
|
174
|
+
' def test; end',
|
175
|
+
'end'])
|
176
|
+
expect(corrected).to eq(['class Test',
|
177
|
+
'',
|
178
|
+
' public',
|
179
|
+
' private',
|
180
|
+
' protected',
|
181
|
+
'',
|
182
|
+
' def test; end',
|
183
|
+
'end'].join("\n"))
|
184
|
+
end
|
166
185
|
end
|
167
186
|
|
168
|
-
context 'when
|
187
|
+
context 'when EnforcedStyle is set to outdent' do
|
169
188
|
let(:cop_config) { { 'EnforcedStyle' => 'outdent' } }
|
170
189
|
let(:indent_msg) { 'Outdent access modifiers like private.' }
|
171
|
-
let(:blank_msg) { 'Keep a blank line before and after private.' }
|
172
190
|
|
173
191
|
it 'registers offence for private indented to method depth in a class' do
|
174
192
|
inspect_source(cop,
|
@@ -195,7 +213,7 @@ describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
|
|
195
213
|
expect(cop.messages).to eq([indent_msg])
|
196
214
|
end
|
197
215
|
|
198
|
-
it 'registers offence for private indented to method depth in singleton'
|
216
|
+
it 'registers offence for private indented to method depth in singleton' \
|
199
217
|
'class' do
|
200
218
|
inspect_source(cop,
|
201
219
|
['class << self',
|
@@ -208,7 +226,7 @@ describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
|
|
208
226
|
expect(cop.messages).to eq([indent_msg])
|
209
227
|
end
|
210
228
|
|
211
|
-
it 'registers offence for private indented to method depth in class '
|
229
|
+
it 'registers offence for private indented to method depth in class ' \
|
212
230
|
'defined with Class.new' do
|
213
231
|
inspect_source(cop,
|
214
232
|
['Test = Class.new do',
|
@@ -221,7 +239,7 @@ describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
|
|
221
239
|
expect(cop.messages).to eq([indent_msg])
|
222
240
|
end
|
223
241
|
|
224
|
-
it 'registers offence for private indented to method depth in module '
|
242
|
+
it 'registers offence for private indented to method depth in module ' \
|
225
243
|
'defined with Module.new' do
|
226
244
|
inspect_source(cop,
|
227
245
|
['Test = Module.new do',
|
@@ -274,5 +292,28 @@ describe Rubocop::Cop::Style::AccessModifierIndentation, :config do
|
|
274
292
|
expect(cop.offences.size).to eq(1)
|
275
293
|
expect(cop.messages).to eq([indent_msg])
|
276
294
|
end
|
295
|
+
|
296
|
+
it 'auto-corrects incorrectly indented access modifiers' do
|
297
|
+
corrected = autocorrect_source(cop, ['module M',
|
298
|
+
' class Test',
|
299
|
+
'',
|
300
|
+
'public',
|
301
|
+
' private',
|
302
|
+
' protected',
|
303
|
+
'',
|
304
|
+
' def test; end',
|
305
|
+
' end',
|
306
|
+
'end'])
|
307
|
+
expect(corrected).to eq(['module M',
|
308
|
+
' class Test',
|
309
|
+
'',
|
310
|
+
' public',
|
311
|
+
' private',
|
312
|
+
' protected',
|
313
|
+
'',
|
314
|
+
' def test; end',
|
315
|
+
' end',
|
316
|
+
'end'].join("\n"))
|
317
|
+
end
|
277
318
|
end
|
278
319
|
end
|
@@ -12,7 +12,7 @@ describe Rubocop::Cop::Style::AlignArray do
|
|
12
12
|
' c,',
|
13
13
|
' d',
|
14
14
|
']'])
|
15
|
-
expect(cop.messages).to eq(['Align the elements of an array '
|
15
|
+
expect(cop.messages).to eq(['Align the elements of an array ' \
|
16
16
|
'literal if they span more than ' +
|
17
17
|
'one line.'] * 2)
|
18
18
|
expect(cop.highlights).to eq(%w(b d))
|
@@ -34,7 +34,7 @@ describe Rubocop::Cop::Style::AlignHash, :config do
|
|
34
34
|
" 'ccc' => 2,",
|
35
35
|
" 'dddd' => 2",
|
36
36
|
'}'])
|
37
|
-
expect(cop.messages).to eq(['Align the elements of a hash '
|
37
|
+
expect(cop.messages).to eq(['Align the elements of a hash ' \
|
38
38
|
'literal if they span more than ' +
|
39
39
|
'one line.'] * 2)
|
40
40
|
expect(cop.highlights).to eq(['bb: 1',
|
@@ -53,7 +53,7 @@ describe Rubocop::Cop::Style::AlignParameters do
|
|
53
53
|
'func3(*a)'
|
54
54
|
])
|
55
55
|
expect(cop.offences.map(&:to_s))
|
56
|
-
.to eq(['C: 5: 6: Align the parameters of a method call if '
|
56
|
+
.to eq(['C: 5: 6: Align the parameters of a method call if ' \
|
57
57
|
'they span more than one line.'])
|
58
58
|
expect(cop.highlights).to eq(['*b'])
|
59
59
|
end
|
@@ -62,7 +62,7 @@ describe Rubocop::Cop::Style::AlignParameters do
|
|
62
62
|
inspect_source(cop, ['func1(a,',
|
63
63
|
' b,)'])
|
64
64
|
expect(cop.offences.map(&:to_s))
|
65
|
-
.to eq(['C: 2: 6: Align the parameters of a method call if '
|
65
|
+
.to eq(['C: 2: 6: Align the parameters of a method call if ' \
|
66
66
|
'they span more than one line.'])
|
67
67
|
expect(cop.highlights).to eq(['b'])
|
68
68
|
end
|
@@ -51,7 +51,7 @@ describe Rubocop::Cop::Style::Blocks do
|
|
51
51
|
expect(cop.offences).to be_empty
|
52
52
|
end
|
53
53
|
|
54
|
-
it 'registers an offence for braces if do-end would not change '
|
54
|
+
it 'registers an offence for braces if do-end would not change ' \
|
55
55
|
'the meaning' do
|
56
56
|
src = ['scope :foo, (lambda { |f|',
|
57
57
|
' where(condition: "value")',
|
@@ -190,7 +190,7 @@ describe Rubocop::Cop::Style::CaseIndentation do
|
|
190
190
|
expect(cop.offences).to be_empty
|
191
191
|
end
|
192
192
|
|
193
|
-
it "registers an offence for a when clause that's equally indented "
|
193
|
+
it "registers an offence for a when clause that's equally indented " \
|
194
194
|
'with case' do
|
195
195
|
source = ['y = case a',
|
196
196
|
' when 0 then break',
|
@@ -54,7 +54,7 @@ describe Rubocop::Cop::Style::DotPosition, :config do
|
|
54
54
|
inspect_source(cop, ['something',
|
55
55
|
' .method_name'])
|
56
56
|
expect(cop.messages)
|
57
|
-
.to eq(['Place the . on the previous line, together with the method '
|
57
|
+
.to eq(['Place the . on the previous line, together with the method ' \
|
58
58
|
'call receiver.'])
|
59
59
|
expect(cop.highlights).to eq(['.'])
|
60
60
|
expect(cop.config_to_allow_offences).to eq('Style' => 'leading')
|
@@ -13,7 +13,7 @@ describe Rubocop::Cop::Style::FavorUnlessOverNegatedIf do
|
|
13
13
|
'some_method if !a_condition'
|
14
14
|
])
|
15
15
|
expect(cop.messages).to eq(
|
16
|
-
['Favor unless (or control flow or) over if for negative '
|
16
|
+
['Favor unless (or control flow or) over if for negative ' \
|
17
17
|
'conditions.'] * 2)
|
18
18
|
end
|
19
19
|
|
@@ -24,7 +24,7 @@ describe Rubocop::Cop::Style::FavorUnlessOverNegatedIf do
|
|
24
24
|
'end',
|
25
25
|
'some_method if not a_condition'])
|
26
26
|
expect(cop.messages).to eq(
|
27
|
-
['Favor unless (or control flow or) over if for negative '
|
27
|
+
['Favor unless (or control flow or) over if for negative ' \
|
28
28
|
'conditions.'] * 2)
|
29
29
|
expect(cop.offences.map(&:line)).to eq([1, 4])
|
30
30
|
end
|
@@ -23,7 +23,7 @@ describe Rubocop::Cop::Style::IfUnlessModifier do
|
|
23
23
|
" #{body}",
|
24
24
|
' end'])
|
25
25
|
expect(cop.messages).to eq(
|
26
|
-
['Favor modifier if usage when you have a single-line'
|
26
|
+
['Favor modifier if usage when you have a single-line' \
|
27
27
|
' body. Another good alternative is the usage of control flow' +
|
28
28
|
' &&/||.'])
|
29
29
|
end
|
@@ -59,7 +59,7 @@ describe Rubocop::Cop::Style::IfUnlessModifier do
|
|
59
59
|
' b',
|
60
60
|
'end'])
|
61
61
|
expect(cop.messages).to eq(
|
62
|
-
['Favor modifier unless usage when you have a single-line'
|
62
|
+
['Favor modifier unless usage when you have a single-line' \
|
63
63
|
' body. Another good alternative is the usage of control flow' +
|
64
64
|
' &&/||.'])
|
65
65
|
end
|
@@ -73,7 +73,7 @@ describe Rubocop::Cop::Style::IfUnlessModifier do
|
|
73
73
|
|
74
74
|
it 'accepts if-else-end' do
|
75
75
|
inspect_source(cop,
|
76
|
-
['if args.last.is_a? Hash then args.pop else '
|
76
|
+
['if args.last.is_a? Hash then args.pop else ' \
|
77
77
|
'Hash.new end'])
|
78
78
|
expect(cop.messages).to be_empty
|
79
79
|
end
|
@@ -120,7 +120,7 @@ describe Rubocop::Cop::Style::IndentationConsistency do
|
|
120
120
|
expect(cop.offences).to be_empty
|
121
121
|
end
|
122
122
|
|
123
|
-
it 'accepts an if/else in assignment with end aligned with variable '
|
123
|
+
it 'accepts an if/else in assignment with end aligned with variable ' \
|
124
124
|
'and chaining after the end' do
|
125
125
|
inspect_source(cop,
|
126
126
|
['var = if a',
|
@@ -131,7 +131,7 @@ describe Rubocop::Cop::Style::IndentationConsistency do
|
|
131
131
|
expect(cop.offences).to be_empty
|
132
132
|
end
|
133
133
|
|
134
|
-
it 'accepts an if/else in assignment with end aligned with variable '
|
134
|
+
it 'accepts an if/else in assignment with end aligned with variable ' \
|
135
135
|
'and chaining with a block after the end' do
|
136
136
|
inspect_source(cop,
|
137
137
|
['var = if a',
|
@@ -160,7 +160,7 @@ describe Rubocop::Cop::Style::IndentationConsistency do
|
|
160
160
|
expect(cop.offences).to be_empty
|
161
161
|
end
|
162
162
|
|
163
|
-
it 'accepts an if/else in assignment on next line with end aligned '
|
163
|
+
it 'accepts an if/else in assignment on next line with end aligned ' \
|
164
164
|
'with if' do
|
165
165
|
inspect_source(cop,
|
166
166
|
['var =',
|
@@ -408,7 +408,7 @@ describe Rubocop::Cop::Style::IndentationConsistency do
|
|
408
408
|
expect(cop.offences).to be_empty
|
409
409
|
end
|
410
410
|
|
411
|
-
it 'registers an offence for bad indentation in def but not for '
|
411
|
+
it 'registers an offence for bad indentation in def but not for ' \
|
412
412
|
'outdented public, protected, and private' do
|
413
413
|
inspect_source(cop,
|
414
414
|
['class Test',
|
@@ -139,7 +139,7 @@ describe Rubocop::Cop::Style::IndentationWidth do
|
|
139
139
|
expect(cop.offences).to be_empty
|
140
140
|
end
|
141
141
|
|
142
|
-
it 'accepts an if/else in assignment with end aligned with variable '
|
142
|
+
it 'accepts an if/else in assignment with end aligned with variable ' \
|
143
143
|
'and chaining after the end' do
|
144
144
|
inspect_source(cop,
|
145
145
|
['var = if a',
|
@@ -150,7 +150,7 @@ describe Rubocop::Cop::Style::IndentationWidth do
|
|
150
150
|
expect(cop.offences).to be_empty
|
151
151
|
end
|
152
152
|
|
153
|
-
it 'accepts an if/else in assignment with end aligned with variable '
|
153
|
+
it 'accepts an if/else in assignment with end aligned with variable ' \
|
154
154
|
'and chaining with a block after the end' do
|
155
155
|
inspect_source(cop,
|
156
156
|
['var = if a',
|
@@ -179,7 +179,7 @@ describe Rubocop::Cop::Style::IndentationWidth do
|
|
179
179
|
expect(cop.offences).to be_empty
|
180
180
|
end
|
181
181
|
|
182
|
-
it 'accepts an if/else in assignment on next line with end aligned '
|
182
|
+
it 'accepts an if/else in assignment on next line with end aligned ' \
|
183
183
|
'with if' do
|
184
184
|
inspect_source(cop,
|
185
185
|
['var =',
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Rubocop::Cop::Style::LineEndConcatenation do
|
6
|
+
subject(:cop) { described_class.new }
|
7
|
+
|
8
|
+
it 'registers an offence for string concat at line end' do
|
9
|
+
inspect_source(cop,
|
10
|
+
['top = "test" +',
|
11
|
+
'"top"'])
|
12
|
+
expect(cop.offences.size).to eq(1)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'accepts string concat on the same line' do
|
16
|
+
inspect_source(cop,
|
17
|
+
['top = "test" + "top"'])
|
18
|
+
expect(cop.offences).to be_empty
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'autocorrects by replacing + with \\' do
|
22
|
+
corrected = autocorrect_source(cop,
|
23
|
+
['top = "test" +',
|
24
|
+
'"top"'])
|
25
|
+
expect(corrected).to eq ['top = "test" \\', '"top"'].join("\n")
|
26
|
+
end
|
27
|
+
end
|
@@ -38,7 +38,7 @@ describe Rubocop::Cop::Style::MultilineBlockChain do
|
|
38
38
|
expect(cop.highlights).to eq(['end.c', 'end.e'])
|
39
39
|
end
|
40
40
|
|
41
|
-
it 'registers an offence for a chain where the second block is '
|
41
|
+
it 'registers an offence for a chain where the second block is ' \
|
42
42
|
'single-line' do
|
43
43
|
inspect_source(cop, ['Thread.list.find_all { |t|',
|
44
44
|
' t.alive?',
|
@@ -19,4 +19,9 @@ describe Rubocop::Cop::Style::Proc do
|
|
19
19
|
inspect_source(cop, ['p = Proc.new'])
|
20
20
|
expect(cop.offences).to be_empty
|
21
21
|
end
|
22
|
+
|
23
|
+
it 'auto-corrects Proc.new to proc' do
|
24
|
+
corrected = autocorrect_source(cop, ['Proc.new { test }'])
|
25
|
+
expect(corrected).to eq 'proc { test }'
|
26
|
+
end
|
22
27
|
end
|
@@ -12,7 +12,7 @@ describe Rubocop::Cop::Style::RegexpLiteral, :config do
|
|
12
12
|
inspect_source(cop, ['x =~ /home\/\//',
|
13
13
|
'y =~ /etc\/top\//'])
|
14
14
|
expect(cop.messages)
|
15
|
-
.to eq(['Use %r for regular expressions matching more '
|
15
|
+
.to eq(['Use %r for regular expressions matching more ' \
|
16
16
|
"than 1 '/' character."] * 2)
|
17
17
|
expect(cop.config_to_allow_offences).to eq('MaxSlashes' => 2)
|
18
18
|
end
|
@@ -32,7 +32,7 @@ describe Rubocop::Cop::Style::RegexpLiteral, :config do
|
|
32
32
|
it 'registers an offence for one slash in regexp' do
|
33
33
|
inspect_source(cop, ['x =~ /home\//'])
|
34
34
|
expect(cop.messages)
|
35
|
-
.to eq(['Use %r for regular expressions matching more '
|
35
|
+
.to eq(['Use %r for regular expressions matching more ' \
|
36
36
|
"than 0 '/' characters."])
|
37
37
|
expect(cop.config_to_allow_offences).to eq('MaxSlashes' => 1)
|
38
38
|
end
|
@@ -45,7 +45,7 @@ describe Rubocop::Cop::Style::RegexpLiteral, :config do
|
|
45
45
|
it 'registers an offence for zero slashes in regexp' do
|
46
46
|
inspect_source(cop, ['y =~ %r(etc)'])
|
47
47
|
expect(cop.messages)
|
48
|
-
.to eq(['Use %r only for regular expressions matching more '
|
48
|
+
.to eq(['Use %r only for regular expressions matching more ' \
|
49
49
|
"than 0 '/' characters."])
|
50
50
|
expect(cop.config_to_allow_offences).to eq('MaxSlashes' => 1)
|
51
51
|
end
|
@@ -68,7 +68,7 @@ describe Rubocop::Cop::Style::RegexpLiteral, :config do
|
|
68
68
|
inspect_source(cop, ['x =~ %r(/home)',
|
69
69
|
'y =~ %r(etc)'])
|
70
70
|
expect(cop.messages)
|
71
|
-
.to eq(['Use %r only for regular expressions matching more '
|
71
|
+
.to eq(['Use %r only for regular expressions matching more ' \
|
72
72
|
"than 1 '/' character."] * 2)
|
73
73
|
expect(cop.config_to_allow_offences).to eq('MaxSlashes' => 2)
|
74
74
|
end
|
@@ -8,7 +8,7 @@ describe Rubocop::Cop::Style::StringLiterals, :config do
|
|
8
8
|
context 'configured with single quotes preferred' do
|
9
9
|
let(:cop_config) { { 'EnforcedStyle' => 'single_quotes' } }
|
10
10
|
|
11
|
-
it 'registers offence for double quotes when single quotes '
|
11
|
+
it 'registers offence for double quotes when single quotes ' \
|
12
12
|
'suffice' do
|
13
13
|
inspect_source(cop, ['s = "abc"',
|
14
14
|
'x = "a\\\\b"',
|
@@ -19,7 +19,7 @@ describe Rubocop::Cop::Style::StringLiterals, :config do
|
|
19
19
|
'"\\\\b"',
|
20
20
|
'"a\\\\"'])
|
21
21
|
expect(cop.messages)
|
22
|
-
.to eq(["Prefer single-quoted strings when you don't need "
|
22
|
+
.to eq(["Prefer single-quoted strings when you don't need " \
|
23
23
|
'string interpolation or special symbols.'] * 4)
|
24
24
|
expect(cop.config_to_allow_offences).to eq('EnforcedStyle' =>
|
25
25
|
'double_quotes')
|
@@ -29,7 +29,7 @@ describe Rubocop::Cop::Style::StringLiterals, :config do
|
|
29
29
|
inspect_source(cop, ['s = "abc"',
|
30
30
|
"x = 'abc'"])
|
31
31
|
expect(cop.messages)
|
32
|
-
.to eq(["Prefer single-quoted strings when you don't need "
|
32
|
+
.to eq(["Prefer single-quoted strings when you don't need " \
|
33
33
|
'string interpolation or special symbols.'])
|
34
34
|
expect(cop.config_to_allow_offences).to eq('Enabled' => false)
|
35
35
|
end
|
@@ -60,7 +60,7 @@ describe Rubocop::Cop::Style::StringLiterals, :config do
|
|
60
60
|
|
61
61
|
it 'accepts double quotes when they are needed' do
|
62
62
|
src = ['a = "\n"',
|
63
|
-
'b = "#{encode_severity}:'
|
63
|
+
'b = "#{encode_severity}:' \
|
64
64
|
'#{sprintf("%3d", line_number)}: #{m}"',
|
65
65
|
'c = "\'"',
|
66
66
|
'd = "#@test"',
|
@@ -124,12 +124,12 @@ describe Rubocop::Cop::Style::StringLiterals, :config do
|
|
124
124
|
context 'configured with double quotes preferred' do
|
125
125
|
let(:cop_config) { { 'EnforcedStyle' => 'double_quotes' } }
|
126
126
|
|
127
|
-
it 'registers offence for single quotes when double quotes would '
|
127
|
+
it 'registers offence for single quotes when double quotes would ' \
|
128
128
|
'be equivalent' do
|
129
129
|
inspect_source(cop, ["s = 'abc'"])
|
130
130
|
expect(cop.highlights).to eq(["'abc'"])
|
131
131
|
expect(cop.messages)
|
132
|
-
.to eq(['Prefer double-quoted strings unless you need '
|
132
|
+
.to eq(['Prefer double-quoted strings unless you need ' \
|
133
133
|
'single quotes to avoid extra backslashes for ' +
|
134
134
|
'escaping.'])
|
135
135
|
expect(cop.config_to_allow_offences).to eq('EnforcedStyle' =>
|
@@ -140,7 +140,7 @@ describe Rubocop::Cop::Style::StringLiterals, :config do
|
|
140
140
|
inspect_source(cop, ['s = "abc"',
|
141
141
|
"x = 'abc'"])
|
142
142
|
expect(cop.messages)
|
143
|
-
.to eq(['Prefer double-quoted strings unless you need '
|
143
|
+
.to eq(['Prefer double-quoted strings unless you need ' \
|
144
144
|
'single quotes to avoid extra backslashes for ' +
|
145
145
|
'escaping.'])
|
146
146
|
expect(cop.config_to_allow_offences).to eq('Enabled' => false)
|