tailor 1.3.1 → 1.4.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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Gemfile.lock +27 -25
- data/History.md +36 -0
- data/README.md +10 -4
- data/Rakefile +6 -6
- data/features/support/env.rb +2 -2
- data/features/support/legacy/bad_ternary_colon_spacing.rb +1 -1
- data/features/support/legacy/long_file_with_indentation.rb +2 -2
- data/features/support/world.rb +1 -1
- data/features/valid_ruby.feature +1 -1
- data/lib/tailor/cli/options.rb +19 -1
- data/lib/tailor/configuration.rb +2 -2
- data/lib/tailor/configuration/style.rb +6 -0
- data/lib/tailor/lexed_line.rb +2 -2
- data/lib/tailor/lexer/lexer_constants.rb +1 -0
- data/lib/tailor/lexer/token.rb +2 -2
- data/lib/tailor/logger.rb +2 -2
- data/lib/tailor/rake_task.rb +2 -2
- data/lib/tailor/ruler.rb +0 -1
- data/lib/tailor/rulers/allow_camel_case_methods_ruler.rb +0 -1
- data/lib/tailor/rulers/allow_conditional_parentheses.rb +65 -0
- data/lib/tailor/rulers/allow_unnecessary_double_quotes_ruler.rb +61 -0
- data/lib/tailor/rulers/allow_unnecessary_interpolation_ruler.rb +87 -0
- data/lib/tailor/rulers/indentation_spaces_ruler.rb +40 -50
- data/lib/tailor/rulers/indentation_spaces_ruler/argument_alignment.rb +63 -0
- data/lib/tailor/rulers/indentation_spaces_ruler/ast_xml.rb +89 -0
- data/lib/tailor/rulers/indentation_spaces_ruler/indentation_manager.rb +2 -14
- data/lib/tailor/rulers/indentation_spaces_ruler/line_continuations.rb +58 -0
- data/lib/tailor/rulers/max_code_lines_in_class_ruler.rb +3 -3
- data/lib/tailor/rulers/max_code_lines_in_method_ruler.rb +3 -3
- data/lib/tailor/rulers/spaces_after_comma_ruler.rb +3 -3
- data/lib/tailor/rulers/spaces_after_conditional_ruler.rb +3 -3
- data/lib/tailor/rulers/spaces_after_lbrace_ruler.rb +3 -3
- data/lib/tailor/rulers/spaces_after_lbracket_ruler.rb +3 -3
- data/lib/tailor/rulers/spaces_after_lparen_ruler.rb +3 -3
- data/lib/tailor/rulers/spaces_before_comma_ruler.rb +3 -3
- data/lib/tailor/rulers/spaces_before_rbrace_ruler.rb +2 -2
- data/lib/tailor/rulers/spaces_in_empty_braces_ruler.rb +2 -2
- data/lib/tailor/tailorrc.erb +28 -0
- data/lib/tailor/version.rb +1 -1
- data/spec/functional/conditional_parentheses_spec.rb +325 -0
- data/spec/functional/conditional_spacing_spec.rb +66 -42
- data/spec/functional/configuration_spec.rb +1 -1
- data/spec/functional/horizontal_spacing/braces_spec.rb +10 -9
- data/spec/functional/horizontal_spacing/hard_tabs_spec.rb +4 -4
- data/spec/functional/horizontal_spacing_spec.rb +5 -5
- data/spec/functional/indentation_spacing/argument_alignment_spec.rb +511 -0
- data/spec/functional/indentation_spacing/line_continuations_spec.rb +181 -0
- data/spec/functional/indentation_spacing_spec.rb +17 -0
- data/spec/functional/string_interpolation_spec.rb +117 -0
- data/spec/functional/string_quoting_spec.rb +97 -0
- data/spec/functional/vertical_spacing/class_length_spec.rb +1 -1
- data/spec/spec_helper.rb +8 -2
- data/spec/support/argument_alignment_cases.rb +93 -0
- data/spec/support/bad_indentation_cases.rb +20 -20
- data/spec/support/conditional_parentheses_cases.rb +60 -0
- data/spec/support/good_indentation_cases.rb +31 -31
- data/spec/support/horizontal_spacing_cases.rb +1 -1
- data/spec/support/line_indentation_cases.rb +71 -0
- data/spec/support/string_interpolation_cases.rb +45 -0
- data/spec/support/string_quoting_cases.rb +25 -0
- data/spec/unit/tailor/configuration/file_set_spec.rb +3 -3
- data/spec/unit/tailor/configuration/style_spec.rb +24 -21
- data/spec/unit/tailor/configuration_spec.rb +4 -1
- data/spec/unit/tailor/formatter_spec.rb +10 -10
- data/spec/unit/tailor/reporter_spec.rb +0 -1
- data/spec/unit/tailor/rulers/indentation_spaces_ruler/indentation_manager_spec.rb +0 -11
- data/spec/unit/tailor/rulers/indentation_spaces_ruler_spec.rb +1 -1
- data/spec/unit/tailor/version_spec.rb +1 -1
- data/tailor.gemspec +1 -0
- metadata +72 -33
- data/.infinity_test +0 -4
data/lib/tailor/version.rb
CHANGED
@@ -0,0 +1,325 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../support/conditional_parentheses_cases'
|
3
|
+
require 'tailor/critic'
|
4
|
+
require 'tailor/configuration/style'
|
5
|
+
|
6
|
+
describe 'Conditional parentheses' do
|
7
|
+
|
8
|
+
def file_name
|
9
|
+
self.class.description
|
10
|
+
end
|
11
|
+
|
12
|
+
def contents
|
13
|
+
CONDITIONAL_PARENTHESES[file_name] || begin
|
14
|
+
raise "Example not found: #{file_name}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
before do
|
19
|
+
Tailor::Logger.stub(:log)
|
20
|
+
FakeFS.activate!
|
21
|
+
FileUtils.touch file_name
|
22
|
+
File.open(file_name, 'w') { |f| f.write contents }
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:critic) { Tailor::Critic.new }
|
26
|
+
|
27
|
+
let(:style) do
|
28
|
+
style = Tailor::Configuration::Style.new
|
29
|
+
style.trailing_newlines 0, level: :off
|
30
|
+
style.allow_invalid_ruby true, level: :off
|
31
|
+
|
32
|
+
style
|
33
|
+
end
|
34
|
+
|
35
|
+
context :no_parentheses do
|
36
|
+
it 'does not warn' do
|
37
|
+
critic.check_file(file_name, style.to_hash)
|
38
|
+
expect(critic.problems[file_name]).to be_empty
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'does not warn when parentheses are allowed' do
|
42
|
+
style.allow_conditional_parentheses true, level: :warn
|
43
|
+
critic.check_file(file_name, style.to_hash)
|
44
|
+
expect(critic.problems[file_name]).to be_empty
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'does not warn when parentheses are disabled' do
|
48
|
+
style.allow_conditional_parentheses false, level: :off
|
49
|
+
critic.check_file(file_name, style.to_hash)
|
50
|
+
expect(critic.problems[file_name]).to be_empty
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context :with_parentheses do
|
55
|
+
it 'warns' do
|
56
|
+
critic.check_file(file_name, style.to_hash)
|
57
|
+
expect(critic.problems[file_name]).to eql [{
|
58
|
+
type: 'conditional_parentheses',
|
59
|
+
line: 1,
|
60
|
+
column: 4,
|
61
|
+
message: 'Parentheses around conditional expression at column 4.',
|
62
|
+
level: :warn
|
63
|
+
}]
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'does not warn when parentheses are allowed' do
|
67
|
+
style.allow_conditional_parentheses true, level: :warn
|
68
|
+
critic.check_file(file_name, style.to_hash)
|
69
|
+
expect(critic.problems[file_name]).to be_empty
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'does not warn when parentheses are disabled' do
|
73
|
+
style.allow_conditional_parentheses false, level: :off
|
74
|
+
critic.check_file(file_name, style.to_hash)
|
75
|
+
expect(critic.problems[file_name]).to be_empty
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context :with_parentheses_no_space do
|
80
|
+
it 'warns' do
|
81
|
+
critic.check_file(file_name, style.to_hash)
|
82
|
+
|
83
|
+
expect(critic.problems[file_name].select do |p|
|
84
|
+
p[:type] == 'conditional_parentheses'
|
85
|
+
end).to eql [{
|
86
|
+
type: 'conditional_parentheses',
|
87
|
+
line: 1,
|
88
|
+
column: 3,
|
89
|
+
message: 'Parentheses around conditional expression at column 3.',
|
90
|
+
level: :warn
|
91
|
+
}]
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'does not warn when parentheses are allowed' do
|
95
|
+
style.allow_conditional_parentheses true, level: :warn
|
96
|
+
critic.check_file(file_name, style.to_hash)
|
97
|
+
expect(critic.problems[file_name].select do |p|
|
98
|
+
p[:type] == 'conditional_parentheses'
|
99
|
+
end).to be_empty
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'does not warn when parentheses are disabled' do
|
103
|
+
style.allow_conditional_parentheses false, level: :off
|
104
|
+
critic.check_file(file_name, style.to_hash)
|
105
|
+
|
106
|
+
expect(critic.problems[file_name].select do |p|
|
107
|
+
p[:type] == 'conditional_parentheses'
|
108
|
+
end).to be_empty
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context :method_call do
|
113
|
+
it 'does not warn' do
|
114
|
+
critic.check_file(file_name, style.to_hash)
|
115
|
+
expect(critic.problems[file_name]).to be_empty
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'does not warn when parentheses are allowed' do
|
119
|
+
style.allow_conditional_parentheses true, level: :warn
|
120
|
+
critic.check_file(file_name, style.to_hash)
|
121
|
+
expect(critic.problems[file_name]).to be_empty
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'does not warn when parentheses are disabled' do
|
125
|
+
style.allow_conditional_parentheses false, level: :off
|
126
|
+
critic.check_file(file_name, style.to_hash)
|
127
|
+
expect(critic.problems[file_name]).to be_empty
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context :indented_method_call do
|
132
|
+
it 'does not warn' do
|
133
|
+
critic.check_file(file_name, style.to_hash)
|
134
|
+
expect(critic.problems[file_name]).to be_empty
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'does not warn when parentheses are allowed' do
|
138
|
+
style.allow_conditional_parentheses true, level: :warn
|
139
|
+
critic.check_file(file_name, style.to_hash)
|
140
|
+
expect(critic.problems[file_name]).to be_empty
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'does not warn when parentheses are disabled' do
|
144
|
+
style.allow_conditional_parentheses false, level: :off
|
145
|
+
critic.check_file(file_name, style.to_hash)
|
146
|
+
expect(critic.problems[file_name]).to be_empty
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context :method_call_on_parens do
|
151
|
+
it 'does not warn' do
|
152
|
+
critic.check_file(file_name, style.to_hash)
|
153
|
+
expect(critic.problems[file_name]).to be_empty
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'does not warn when parentheses are allowed' do
|
157
|
+
style.allow_conditional_parentheses true, level: :warn
|
158
|
+
critic.check_file(file_name, style.to_hash)
|
159
|
+
expect(critic.problems[file_name]).to be_empty
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'does not warn when parentheses are disabled' do
|
163
|
+
style.allow_conditional_parentheses false, level: :off
|
164
|
+
critic.check_file(file_name, style.to_hash)
|
165
|
+
expect(critic.problems[file_name]).to be_empty
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context :double_parens do
|
170
|
+
it 'warns by default' do
|
171
|
+
critic.check_file(file_name, style.to_hash)
|
172
|
+
expect(critic.problems[file_name]).to eql [{
|
173
|
+
type: 'conditional_parentheses',
|
174
|
+
line: 1,
|
175
|
+
column: 4,
|
176
|
+
message: 'Parentheses around conditional expression at column 4.',
|
177
|
+
level: :warn
|
178
|
+
}]
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'does not warn when parentheses are allowed' do
|
182
|
+
style.allow_conditional_parentheses true, level: :warn
|
183
|
+
critic.check_file(file_name, style.to_hash)
|
184
|
+
expect(critic.problems[file_name]).to be_empty
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'does not warn when parentheses are disabled' do
|
188
|
+
style.allow_conditional_parentheses false, level: :off
|
189
|
+
critic.check_file(file_name, style.to_hash)
|
190
|
+
expect(critic.problems[file_name]).to be_empty
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
context :unless_no_parentheses do
|
195
|
+
it 'does not warn' do
|
196
|
+
critic.check_file(file_name, style.to_hash)
|
197
|
+
expect(critic.problems[file_name]).to be_empty
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'does not warn when parentheses are allowed' do
|
201
|
+
style.allow_conditional_parentheses true, level: :warn
|
202
|
+
critic.check_file(file_name, style.to_hash)
|
203
|
+
expect(critic.problems[file_name]).to be_empty
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'does not warn when parentheses are disabled' do
|
207
|
+
style.allow_conditional_parentheses false, level: :off
|
208
|
+
critic.check_file(file_name, style.to_hash)
|
209
|
+
expect(critic.problems[file_name]).to be_empty
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context :unless_with_parentheses do
|
214
|
+
it 'warns on parentheses' do
|
215
|
+
critic.check_file(file_name, style.to_hash)
|
216
|
+
expect(critic.problems[file_name]).to eql [{
|
217
|
+
type: 'conditional_parentheses',
|
218
|
+
line: 1,
|
219
|
+
column: 8,
|
220
|
+
message: 'Parentheses around conditional expression at column 8.',
|
221
|
+
level: :warn
|
222
|
+
}]
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'does not warn when parentheses are allowed' do
|
226
|
+
style.allow_conditional_parentheses true, level: :warn
|
227
|
+
critic.check_file(file_name, style.to_hash)
|
228
|
+
expect(critic.problems[file_name]).to be_empty
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'does not warn when parentheses are disabled' do
|
232
|
+
style.allow_conditional_parentheses false, level: :off
|
233
|
+
critic.check_file(file_name, style.to_hash)
|
234
|
+
expect(critic.problems[file_name]).to be_empty
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
context :case_no_parentheses do
|
239
|
+
it 'does not warn' do
|
240
|
+
critic.check_file(file_name, style.to_hash)
|
241
|
+
expect(critic.problems[file_name]).to be_empty
|
242
|
+
end
|
243
|
+
|
244
|
+
it 'does not warn when parentheses are allowed' do
|
245
|
+
style.allow_conditional_parentheses true, level: :warn
|
246
|
+
critic.check_file(file_name, style.to_hash)
|
247
|
+
expect(critic.problems[file_name]).to be_empty
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'does not warn when parentheses are disabled' do
|
251
|
+
style.allow_conditional_parentheses false, level: :off
|
252
|
+
critic.check_file(file_name, style.to_hash)
|
253
|
+
expect(critic.problems[file_name]).to be_empty
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
context :case_with_parentheses do
|
258
|
+
it 'warns on parentheses' do
|
259
|
+
critic.check_file(file_name, style.to_hash)
|
260
|
+
expect(critic.problems[file_name]).to eql [{
|
261
|
+
type: 'conditional_parentheses',
|
262
|
+
line: 1,
|
263
|
+
column: 6,
|
264
|
+
message: 'Parentheses around conditional expression at column 6.',
|
265
|
+
level: :warn
|
266
|
+
}]
|
267
|
+
end
|
268
|
+
|
269
|
+
it 'does not warn when parentheses are allowed' do
|
270
|
+
style.allow_conditional_parentheses true, level: :warn
|
271
|
+
critic.check_file(file_name, style.to_hash)
|
272
|
+
expect(critic.problems[file_name]).to be_empty
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'does not warn when parentheses are disabled' do
|
276
|
+
style.allow_conditional_parentheses false, level: :off
|
277
|
+
critic.check_file(file_name, style.to_hash)
|
278
|
+
expect(critic.problems[file_name]).to be_empty
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
context :while_no_parentheses do
|
283
|
+
it 'does not warn' do
|
284
|
+
critic.check_file(file_name, style.to_hash)
|
285
|
+
expect(critic.problems[file_name]).to be_empty
|
286
|
+
end
|
287
|
+
|
288
|
+
it 'does not warn when parentheses are allowed' do
|
289
|
+
style.allow_conditional_parentheses true, level: :warn
|
290
|
+
critic.check_file(file_name, style.to_hash)
|
291
|
+
expect(critic.problems[file_name]).to be_empty
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'does not warn when parentheses are disabled' do
|
295
|
+
style.allow_conditional_parentheses false, level: :off
|
296
|
+
critic.check_file(file_name, style.to_hash)
|
297
|
+
expect(critic.problems[file_name]).to be_empty
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
context :while_with_parentheses do
|
302
|
+
it 'warns on parentheses' do
|
303
|
+
critic.check_file(file_name, style.to_hash)
|
304
|
+
expect(critic.problems[file_name]).to eql [{
|
305
|
+
type: 'conditional_parentheses',
|
306
|
+
line: 1,
|
307
|
+
column: 7,
|
308
|
+
message: 'Parentheses around conditional expression at column 7.',
|
309
|
+
level: :warn
|
310
|
+
}]
|
311
|
+
end
|
312
|
+
|
313
|
+
it 'does not warn when parentheses are allowed' do
|
314
|
+
style.allow_conditional_parentheses true, level: :warn
|
315
|
+
critic.check_file(file_name, style.to_hash)
|
316
|
+
expect(critic.problems[file_name]).to be_empty
|
317
|
+
end
|
318
|
+
|
319
|
+
it 'does not warn when parentheses are disabled' do
|
320
|
+
style.allow_conditional_parentheses false, level: :off
|
321
|
+
critic.check_file(file_name, style.to_hash)
|
322
|
+
expect(critic.problems[file_name]).to be_empty
|
323
|
+
end
|
324
|
+
end
|
325
|
+
end
|
@@ -34,55 +34,67 @@ describe 'Conditional spacing' do
|
|
34
34
|
context :no_space_after_if do
|
35
35
|
it 'warns when there is no space after an if statement' do
|
36
36
|
critic.check_file(file_name, style.to_hash)
|
37
|
-
expect(critic.problems[file_name]
|
38
|
-
:type
|
39
|
-
|
40
|
-
:
|
41
|
-
:
|
42
|
-
:
|
37
|
+
expect(critic.problems[file_name].reject do |p|
|
38
|
+
p[:type] == 'conditional_parentheses'
|
39
|
+
end).to eql [{
|
40
|
+
type: 'spaces_after_conditional',
|
41
|
+
line: 1,
|
42
|
+
column: 0,
|
43
|
+
message: '0 spaces after conditional at column 0, expected 1.',
|
44
|
+
level: :error
|
43
45
|
}]
|
44
46
|
end
|
45
47
|
|
46
48
|
it 'warns with the correct number of expected spaces' do
|
47
49
|
style.spaces_after_conditional 2, level: :error
|
48
50
|
critic.check_file(file_name, style.to_hash)
|
49
|
-
expect(critic.problems[file_name]
|
50
|
-
:type
|
51
|
-
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
51
|
+
expect(critic.problems[file_name].reject do |p|
|
52
|
+
p[:type] == 'conditional_parentheses'
|
53
|
+
end).to eql [{
|
54
|
+
type: 'spaces_after_conditional',
|
55
|
+
line: 1,
|
56
|
+
column: 0,
|
57
|
+
message: '0 spaces after conditional at column 0, expected 2.',
|
58
|
+
level: :error
|
55
59
|
}]
|
56
60
|
end
|
57
61
|
|
58
62
|
it 'does not warn if spaces are set to zero' do
|
59
63
|
style.spaces_after_conditional 0, level: :error
|
60
64
|
critic.check_file(file_name, style.to_hash)
|
61
|
-
expect(critic.problems[file_name]
|
65
|
+
expect(critic.problems[file_name].reject do |p|
|
66
|
+
p[:type] == 'conditional_parentheses'
|
67
|
+
end).to be_empty
|
62
68
|
end
|
63
69
|
|
64
70
|
it 'does not warn if spaces are disabled' do
|
65
71
|
style.spaces_after_conditional 2, level: :off
|
66
72
|
critic.check_file(file_name, style.to_hash)
|
67
|
-
expect(critic.problems[file_name]
|
73
|
+
expect(critic.problems[file_name].reject do |p|
|
74
|
+
p[:type] == 'conditional_parentheses'
|
75
|
+
end).to be_empty
|
68
76
|
end
|
69
77
|
end
|
70
78
|
|
71
79
|
context :space_after_if do
|
72
80
|
it 'does not warn when there is a space after the if' do
|
73
81
|
critic.check_file(file_name, style.to_hash)
|
74
|
-
expect(critic.problems[file_name]
|
82
|
+
expect(critic.problems[file_name].reject do |p|
|
83
|
+
p[:type] == 'conditional_parentheses'
|
84
|
+
end).to be_empty
|
75
85
|
end
|
76
86
|
|
77
87
|
it 'warns if spaces has been set to zero' do
|
78
88
|
style.spaces_after_conditional 0, level: :error
|
79
89
|
critic.check_file(file_name, style.to_hash)
|
80
|
-
expect(critic.problems[file_name]
|
81
|
-
:type
|
82
|
-
|
83
|
-
:
|
84
|
-
:
|
85
|
-
:
|
90
|
+
expect(critic.problems[file_name].reject do |p|
|
91
|
+
p[:type] == 'conditional_parentheses'
|
92
|
+
end).to eql [{
|
93
|
+
type: 'spaces_after_conditional',
|
94
|
+
line: 1,
|
95
|
+
column: 0,
|
96
|
+
message: '1 spaces after conditional at column 0, expected 0.',
|
97
|
+
level: :error
|
86
98
|
}]
|
87
99
|
end
|
88
100
|
end
|
@@ -90,19 +102,23 @@ describe 'Conditional spacing' do
|
|
90
102
|
context :no_parens do
|
91
103
|
it 'never warns' do
|
92
104
|
critic.check_file(file_name, style.to_hash)
|
93
|
-
expect(critic.problems[file_name]
|
105
|
+
expect(critic.problems[file_name].reject do |p|
|
106
|
+
p[:type] == 'conditional_parentheses'
|
107
|
+
end).to be_empty
|
94
108
|
end
|
95
109
|
end
|
96
110
|
|
97
111
|
context :nested_parens do
|
98
112
|
it 'warns when there is no space after an if statement' do
|
99
113
|
critic.check_file(file_name, style.to_hash)
|
100
|
-
expect(critic.problems[file_name]
|
101
|
-
:type
|
102
|
-
|
103
|
-
:
|
104
|
-
:
|
105
|
-
:
|
114
|
+
expect(critic.problems[file_name].reject do |p|
|
115
|
+
p[:type] == 'conditional_parentheses'
|
116
|
+
end).to eql [{
|
117
|
+
type: 'spaces_after_conditional',
|
118
|
+
line: 1,
|
119
|
+
column: 0,
|
120
|
+
message: '0 spaces after conditional at column 0, expected 1.',
|
121
|
+
level: :error
|
106
122
|
}]
|
107
123
|
end
|
108
124
|
end
|
@@ -110,12 +126,14 @@ describe 'Conditional spacing' do
|
|
110
126
|
context :no_space_after_unless do
|
111
127
|
it 'warns when there is no space after an unless statement' do
|
112
128
|
critic.check_file(file_name, style.to_hash)
|
113
|
-
expect(critic.problems[file_name]
|
114
|
-
:type
|
115
|
-
|
116
|
-
:
|
117
|
-
:
|
118
|
-
:
|
129
|
+
expect(critic.problems[file_name].reject do |p|
|
130
|
+
p[:type] == 'conditional_parentheses'
|
131
|
+
end).to eql [{
|
132
|
+
type: 'spaces_after_conditional',
|
133
|
+
line: 1,
|
134
|
+
column: 0,
|
135
|
+
message: '0 spaces after conditional at column 0, expected 1.',
|
136
|
+
level: :error
|
119
137
|
}]
|
120
138
|
end
|
121
139
|
end
|
@@ -123,19 +141,23 @@ describe 'Conditional spacing' do
|
|
123
141
|
context :space_after_unless do
|
124
142
|
it 'does not warn when there is space after an unless statement' do
|
125
143
|
critic.check_file(file_name, style.to_hash)
|
126
|
-
expect(critic.problems[file_name]
|
144
|
+
expect(critic.problems[file_name].reject do |p|
|
145
|
+
p[:type] == 'conditional_parentheses'
|
146
|
+
end).to be_empty
|
127
147
|
end
|
128
148
|
end
|
129
149
|
|
130
150
|
context :no_space_after_case do
|
131
151
|
it 'warns when there is no space after a case statement' do
|
132
152
|
critic.check_file(file_name, style.to_hash)
|
133
|
-
expect(critic.problems[file_name]
|
134
|
-
:type
|
135
|
-
|
136
|
-
:
|
137
|
-
:
|
138
|
-
:
|
153
|
+
expect(critic.problems[file_name].reject do |p|
|
154
|
+
p[:type] == 'conditional_parentheses'
|
155
|
+
end).to eql [{
|
156
|
+
type: 'spaces_after_conditional',
|
157
|
+
line: 1,
|
158
|
+
column: 5,
|
159
|
+
message: '0 spaces after conditional at column 5, expected 1.',
|
160
|
+
level: :error
|
139
161
|
}]
|
140
162
|
end
|
141
163
|
end
|
@@ -143,7 +165,9 @@ describe 'Conditional spacing' do
|
|
143
165
|
context :space_after_case do
|
144
166
|
it 'does not warn when there is space after a case statement' do
|
145
167
|
critic.check_file(file_name, style.to_hash)
|
146
|
-
expect(critic.problems[file_name]
|
168
|
+
expect(critic.problems[file_name].reject do |p|
|
169
|
+
p[:type] == 'conditional_parentheses'
|
170
|
+
end).to be_empty
|
147
171
|
end
|
148
172
|
end
|
149
173
|
end
|