Skip to content

Commit

Permalink
Merge pull request #1107 from sasstools/feature_lint-double-semi-colons
Browse files Browse the repository at this point in the history
Feature lint double semi colons
  • Loading branch information
DanPurdy committed Aug 27, 2017
2 parents 2c4f63e + 09f4c43 commit 93d1f5c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
16 changes: 16 additions & 0 deletions lib/rules/trailing-semicolon.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ module.exports = {
'detect': function (ast, parser) {
var result = [];

var hasDoubleSemiColon = function (tree) {

tree.traverseByType('declarationDelimiter', function (node, index, parent) {
if (parent.content[index + 1] && parent.content[index + 1].is('declarationDelimiter')) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'severity': parser.severity,
'line': parent.content[index + 1].start.line,
'column': parent.content[index + 1].start.column,
'message': 'No double semicolons allowed'
});
}
});
};

if (ast.syntax !== 'sass') {
ast.traverseByType('block', function (block) {
var last,
Expand Down Expand Up @@ -57,6 +72,7 @@ module.exports = {
}
}
}
hasDoubleSemiColon(parent);
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions tests/rules/trailing-semicolon.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('trailing semicolon - scss', function () {
lint.test(file, {
'trailing-semicolon': 1
}, function (data) {
lint.assert.equal(5, data.warningCount);
lint.assert.equal(9, data.warningCount);
done();
});
});
Expand All @@ -26,7 +26,7 @@ describe('trailing semicolon - scss', function () {
}
]
}, function (data) {
lint.assert.equal(1, data.warningCount);
lint.assert.equal(5, data.warningCount);
done();
});
});
Expand Down
7 changes: 4 additions & 3 deletions tests/sass/trailing-semicolon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
}

.bar {
content: 'qux';
content: 'qux';;
padding: 0

.qux {
float: left;;
content: 'waldo'
}
}
Expand All @@ -21,7 +22,7 @@

.baz {
font: {
family: 'Arial';
family: 'Arial';;
weight: bold;
size: 2rem
}
Expand All @@ -30,7 +31,7 @@
.norf {
border: {
top: {
color: red;
color: red;;

left: {
radius: 5px
Expand Down

0 comments on commit 93d1f5c

Please sign in to comment.