Skip to content

Commit b45898d

Browse files
elstgavsds
authored andcommitted
Add at_least_one_space_or_newline option to SpaceAfterPropertyColon
1 parent f665f82 commit b45898d

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

lib/scss_lint/linter/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ The `style` option allows you to specify a different preferred style.
15191519

15201520
Configuration Option | Description
15211521
---------------------|---------------------------------------------------------
1522-
`style` | `one_space`, `no_space`, `at_least_one_space`, `one_space_or_newline`, or `aligned` (default **one_space**)
1522+
`style` | `one_space`, `no_space`, `one_space_or_newline`, `at_least_one_space`, `at_least_one_space_or_newline`, or `aligned` (default **one_space**)
15231523

15241524
## SpaceAfterPropertyName
15251525

lib/scss_lint/linter/space_after_property_colon.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def visit_prop(node)
2424
check_for_at_least_one_space(node, whitespace)
2525
when 'one_space_or_newline'
2626
check_for_one_space_or_newline(node, whitespace)
27+
when 'at_least_one_space_or_newline'
28+
check_for_at_least_one_space_or_newline(node, whitespace)
2729
end
2830

2931
yield # Continue linting children
@@ -52,6 +54,12 @@ def check_for_one_space_or_newline(node, whitespace)
5254
add_lint(node, 'Colon after property should be followed by one space or a newline')
5355
end
5456

57+
def check_for_at_least_one_space_or_newline(node, whitespace)
58+
return if [[' '], ["\n"]].include?(whitespace.uniq)
59+
return if whitespace[0] == "\n" && whitespace[1..-1].uniq == [' ']
60+
add_lint(node, 'Colon after property should be followed by at least one space or newline')
61+
end
62+
5563
def check_properties_alignment(rule_node)
5664
properties = rule_node.children.select { |node| node.is_a?(Sass::Tree::PropNode) }
5765

spec/scss_lint/linter/space_after_property_colon_spec.rb

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@
266266
it { should_not report_lint }
267267
end
268268

269+
context 'when the colon after a property is followed by multiple spaces' do
270+
let(:scss) { <<-SCSS }
271+
p {
272+
margin: bold;
273+
}
274+
SCSS
275+
276+
it { should report_lint line: 2 }
277+
end
278+
269279
context 'when the colon after a property is followed by a newline and spaces' do
270280
let(:scss) { <<-SCSS }
271281
p {
@@ -300,6 +310,93 @@
300310
end
301311
end
302312

313+
context 'when at least one space or newline is preferred' do
314+
let(:style) { 'at_least_one_space_or_newline' }
315+
316+
context 'when the colon after a property is not followed by space' do
317+
let(:scss) { <<-SCSS }
318+
p {
319+
margin:0;
320+
}
321+
SCSS
322+
323+
it { should report_lint line: 2 }
324+
end
325+
326+
context 'when the colon after a property is followed by a space' do
327+
let(:scss) { <<-SCSS }
328+
p {
329+
margin: 0;
330+
}
331+
SCSS
332+
333+
it { should_not report_lint }
334+
end
335+
336+
context 'when the colon after a property is surrounded by spaces' do
337+
let(:scss) { <<-SCSS }
338+
p {
339+
margin : bold;
340+
}
341+
SCSS
342+
343+
it { should_not report_lint }
344+
end
345+
346+
context 'when the colon after a property is followed by multiple spaces' do
347+
let(:scss) { <<-SCSS }
348+
p {
349+
margin: bold;
350+
}
351+
SCSS
352+
353+
it { should_not report_lint }
354+
end
355+
356+
context 'when the colon after a property is followed by multiple spaces and a tab' do
357+
let(:scss) { <<-SCSS }
358+
p {
359+
margin: \tbold;
360+
}
361+
SCSS
362+
363+
it { should report_lint line: 2 }
364+
end
365+
366+
context 'when the colon after a property is followed by a newline and spaces' do
367+
let(:scss) { <<-SCSS }
368+
p {
369+
background-image:
370+
url(https://something.crazy.long/with/paths?and=queries)
371+
}
372+
SCSS
373+
374+
it { should_not report_lint }
375+
end
376+
377+
context 'when the colon after a property is followed by a newline and no spaces' do
378+
let(:scss) { <<-SCSS }
379+
p {
380+
background-image:
381+
url(https://something.crazy.long/with/paths?and=queries)
382+
}
383+
SCSS
384+
385+
it { should_not report_lint }
386+
end
387+
388+
context 'when the colon after a property is followed by a space and then a newline' do
389+
let(:scss) { <<-SCSS }
390+
p {
391+
background-image:\s
392+
url(https://something.crazy.long/with/paths?and=queries)
393+
}
394+
SCSS
395+
396+
it { should report_lint line: 2 }
397+
end
398+
end
399+
303400
context 'when aligned property values are preferred' do
304401
let(:style) { 'aligned' }
305402

0 commit comments

Comments
 (0)