Skip to content

Commit 9d1ffa8

Browse files
committed
Merge pull request sasstools#359 from bgriffith/hotfix/fix-property-nesting
Hotfix master - Fix trailing-semicolon issue with nested properties
2 parents 46f4099 + 14e39e5 commit 9d1ffa8

File tree

3 files changed

+76
-28
lines changed

3 files changed

+76
-28
lines changed

lib/rules/trailing-semicolon.js

+31-25
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,44 @@ module.exports = {
2323
}
2424

2525
block.forEach('declaration', function (item, i, parent) {
26-
if (helpers.isEqual(last, item)) {
27-
next = parent.content[i + 1];
28-
29-
if (next.type === 'declarationDelimiter') {
30-
if (!parser.options.include) {
31-
result = helpers.addUnique(result, {
32-
'ruleId': parser.rule.name,
33-
'severity': parser.severity,
34-
'line': item.end.line,
35-
'column': item.end.column,
36-
'message': 'No trailing semicolons allowed'
37-
});
38-
}
39-
}
40-
else {
41-
if (parser.options.include) {
42-
result = helpers.addUnique(result, {
43-
'ruleId': parser.rule.name,
44-
'severity': parser.severity,
45-
'line': item.last('value').start.line,
46-
'column': item.last('value').start.column,
47-
'message': 'Trailing semicolons required'
48-
});
26+
if (item.contains('value')) {
27+
var valueNode = item.last('value').content[0];
28+
29+
if (!valueNode.is('block')) {
30+
if (helpers.isEqual(last, item)) {
31+
if (parent.content[i + 1]) {
32+
next = parent.content[i + 1];
33+
34+
if (next.is('declarationDelimiter')) {
35+
if (!parser.options.include) {
36+
result = helpers.addUnique(result, {
37+
'ruleId': parser.rule.name,
38+
'severity': parser.severity,
39+
'line': item.end.line,
40+
'column': item.end.column,
41+
'message': 'No trailing semicolons allowed'
42+
});
43+
}
44+
}
45+
else {
46+
if (parser.options.include) {
47+
result = helpers.addUnique(result, {
48+
'ruleId': parser.rule.name,
49+
'severity': parser.severity,
50+
'line': item.last('value').start.line,
51+
'column': item.last('value').start.column,
52+
'message': 'Trailing semicolons required'
53+
});
54+
}
55+
}
56+
}
4957
}
5058
}
5159
}
52-
5360
});
5461
});
5562
}
5663

57-
5864
return result;
5965
}
6066
};

tests/rules/trailing-semicolon.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,21 @@ describe('trailing semicolon - scss', function () {
1212
lint.test(file, {
1313
'trailing-semicolon': 1
1414
}, function (data) {
15-
lint.assert.equal(2, data.warningCount);
15+
lint.assert.equal(5, data.warningCount);
16+
done();
17+
});
18+
});
19+
20+
it('[include: false]', function (done) {
21+
lint.test(file, {
22+
'trailing-semicolon': [
23+
1,
24+
{
25+
'include': false
26+
}
27+
]
28+
}, function (data) {
29+
lint.assert.equal(1, data.warningCount);
1630
done();
1731
});
1832
});

tests/sass/trailing-semicolon.scss

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
11
.foo {
2-
content: 'bar';
2+
content: 'bar'
33
}
44

55
.bar {
66
content: 'qux';
7-
content: 'baz', 'fail'
7+
padding: 0
88

99
.qux {
1010
content: 'waldo'
1111
}
1212
}
13+
14+
.qux {
15+
font: {
16+
family: 'Arial';
17+
weight: bold;
18+
size: 2rem;
19+
}
20+
}
21+
22+
.baz {
23+
font: {
24+
family: 'Arial';
25+
weight: bold;
26+
size: 2rem
27+
}
28+
}
29+
30+
.norf {
31+
border: {
32+
top: {
33+
color: red;
34+
35+
left: {
36+
radius: 5px
37+
}
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)