-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #605 from gyoshev/feature/no-trailing-whitespace-rule
New rule: no-trailing-whitespace
- Loading branch information
Showing
6 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# No Trailing Whitespace | ||
|
||
Rule `no-trailing-whitespace` will enforce that trailing whitespace is not allowed. | ||
|
||
## Examples | ||
|
||
When enabled, the following are disallowed (\s denotes spaces or tabs): | ||
|
||
```scss | ||
.foo {\s | ||
margin: 1.5rem; | ||
} | ||
|
||
.foo { | ||
margin: .5rem;\s | ||
} | ||
|
||
.foo { | ||
margin: .4rem; | ||
}\s | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
var helpers = require('../helpers'); | ||
|
||
module.exports = { | ||
'name': 'no-trailing-whitespace', | ||
'defaults': {}, | ||
'detect': function (ast, parser) { | ||
var result = []; | ||
var trailing = (/( |\t)+\n/); | ||
|
||
ast.traverseByType('space', function (space, i, parent) { | ||
var content = space.content; | ||
var nextIndex = i + 1; | ||
var next = parent.content[nextIndex]; | ||
|
||
while (next && (next.is('space') || next.is('declarationDelimeter'))) { | ||
content += next.content; | ||
nextIndex++; | ||
next = parent.content[nextIndex]; | ||
} | ||
|
||
if (trailing.test(content)) { | ||
result = helpers.addUnique(result, { | ||
'ruleId': parser.rule.name, | ||
'severity': parser.severity, | ||
'line': space.start.line, | ||
'column': space.start.column, | ||
'message': 'No trailing whitespace allowed' | ||
}); | ||
} | ||
}); | ||
|
||
return result; | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
var lint = require('./_lint'); | ||
|
||
////////////////////////////// | ||
// SCSS syntax tests | ||
////////////////////////////// | ||
describe('no trailing whitespace - scss', function () { | ||
var file = lint.file('no-trailing-whitespace.scss'); | ||
|
||
it('enforce', function (done) { | ||
lint.test(file, { | ||
'no-trailing-whitespace': 1 | ||
}, function (data) { | ||
lint.assert.equal(5, data.warningCount); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
////////////////////////////// | ||
// Sass syntax tests | ||
////////////////////////////// | ||
describe('no trailing whitespace - sass', function () { | ||
var file = lint.file('no-trailing-whitespace.sass'); | ||
|
||
it('enforce', function (done) { | ||
lint.test(file, { | ||
'no-trailing-whitespace': 1 | ||
}, function (data) { | ||
lint.assert.equal(5, data.warningCount); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
.foo | ||
margin: 1.5rem; | ||
|
||
// Two trailing spaces after selector | ||
.bar | ||
margin: 1.5rem; | ||
|
||
// Two trailing spaces after property | ||
.baz | ||
margin: 1.5rem; | ||
|
||
// Two trailing spaces between rules | ||
.qux | ||
margin: 1.5rem; | ||
|
||
|
||
// Trailing tab after selector | ||
.cat | ||
margin: 1.5rem; | ||
|
||
// Trailing tab after property | ||
.dog | ||
margin: 1.5rem; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
.foo { | ||
margin: 1.5rem; | ||
} | ||
|
||
// Two trailing spaces after selector | ||
.bar { | ||
margin: 1.5rem; | ||
} | ||
|
||
// Two trailing spaces after property | ||
.baz { | ||
margin: 1.5rem; | ||
} | ||
|
||
// Two trailing spaces after rule | ||
.qux { | ||
margin: 1.5rem; | ||
} | ||
|
||
// Trailing tab after selector | ||
.cat { | ||
margin: 1.5rem; | ||
} | ||
|
||
// Trailing tab after property | ||
.dog { | ||
margin: 1.5rem; | ||
} | ||
|