Skip to content

Commit

Permalink
Merge pull request sasstools#106 from bgriffith/hotfix/space-before-c…
Browse files Browse the repository at this point in the history
…olon

Fix Space Before Colon and paren issue
  • Loading branch information
DanPurdy committed Sep 5, 2015
2 parents f80caac + ec5a125 commit 552737b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 25 deletions.
44 changes: 23 additions & 21 deletions lib/rules/space-before-colon.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,31 @@ module.exports = {
'detect': function (ast, parser) {
var result = [];

ast.traverseByType('propertyDelimiter', function (delimiter, i, parent) {
var previous = parent.content[i - 1];
ast.traverseByTypes(['propertyDelimiter', 'operator'], function (delimiter, i, parent) {
if (delimiter.content === ':') {
var previous = parent.content[i - 1];

if (previous.is('space')) {
if (!parser.options.include) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': previous.start.line,
'column': previous.start.column,
'message': 'No space allowed before `:`',
'severity': parser.severity
});
if (previous.is('space')) {
if (!parser.options.include) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': previous.start.line,
'column': previous.start.column,
'message': 'No space allowed before `:`',
'severity': parser.severity
});
}
}
}
else {
if (parser.options.include) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': delimiter.start.line,
'column': delimiter.start.column - 1,
'message': 'Space expected before `:`',
'severity': parser.severity
});
else {
if (parser.options.include) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': delimiter.start.line,
'column': delimiter.start.column - 1,
'message': 'Space expected before `:`',
'severity': parser.severity
});
}
}
}
});
Expand Down
25 changes: 23 additions & 2 deletions tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,9 @@ describe('rule', function () {
//////////////////////////////
// Space Before Colon
//////////////////////////////
it('space before colon', function (done) {

// Default
it('space before colon - [include: false]', function (done) {
lintFile('space-before-colon.scss', {
'options': {
'merge-default-rules': false
Expand All @@ -525,7 +527,26 @@ describe('rule', function () {
'space-before-colon': 1
}
}, function (data) {
assert.equal(1, data.warningCount);
assert.equal(3, data.warningCount);
done();
});
});

it('space before colon - [include: true]', function (done) {
lintFile('space-before-colon.scss', {
'options': {
'merge-default-rules': false
},
'rules': {
'space-before-colon': [
1,
{
'include': true
}
]
}
}, function (data) {
assert.equal(4, data.warningCount);
done();
});
});
Expand Down
16 changes: 14 additions & 2 deletions tests/sass/space-before-colon.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
.foo {
content: 'bar';
content : 'bar';
content :'foo';
}

.bar {
content:'bar';
}

.baz {
@media (max-width :50em) and (orientation:landscape) {
content: 'baz';
}
}

$qux: 'qux';
$norf :'norf';

0 comments on commit 552737b

Please sign in to comment.