Skip to content

Commit

Permalink
852: Enhanced trailing semicolon to lint double semicolons
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanDDisch committed Sep 5, 2016
1 parent b7bcb3a commit 1ec22b1
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].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 @@ -53,6 +68,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(8, 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(4, 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 1ec22b1

Please sign in to comment.