Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:sasstools/sass-lint into feature…
Browse files Browse the repository at this point in the history
…/shorthand-values
  • Loading branch information
DanPurdy committed Sep 13, 2015
2 parents 5635a3b + 87e94ab commit cf631e8
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/rules/no-trailing-zero.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# No Trailing Zero

Rule `no-trailing-zero` will enforce that trailing zeros are not allowed.

## Examples

When enabled, the following are disallowed:

```scss
.foo {
margin: 1.500rem;
}

.foo {
margin: .500rem;
}

.foo {
margin: 0.2500rem;
}
```
1 change: 1 addition & 0 deletions lib/config/sass-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ rules:
no-important: 1
no-invalid-hex: 1
no-qualifying-elements: 1
no-trailing-zero: 1
no-url-protocols: 1
no-vendor-prefixes: 1
no-warn: 1
Expand Down
30 changes: 30 additions & 0 deletions lib/rules/no-trailing-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

var helpers = require('../helpers');

var trailingZeroRegex = /^(\d+\.|\.)+(\d*?[1-9])0+$/;

module.exports = {
'name': 'no-trailing-zero',
'defaults': {
'include': false
},
'detect': function (ast, parser) {
var result = [];

ast.traverseByType('number', function (num) {

if (num.content.match(trailingZeroRegex)) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': num.start.line,
'column': num.start.column,
'message': 'Don\'t include trailing zeros on numbers',
'severity': parser.severity
});
}
});

return result;
}
};
16 changes: 16 additions & 0 deletions tests/rules/no-trailing-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

var lint = require('./_lint');

var file = lint.file('no-trailing-zero.scss');

describe('no trailing zero', function () {
it('enforce', function (done) {
lint.test(file, {
'trailing-zero': 1
}, function (data) {
lint.assert.equal(3, data.warningCount);
done();
});
});
});
27 changes: 27 additions & 0 deletions tests/sass/no-trailing-zero.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.foo {
margin: 1.5rem;
}

.foo {
margin: 1.500rem;
}

.foo {
margin: .5rem;
}

.foo {
margin: .500rem;
}

.foo {
margin: 0.25rem;
}

.foo {
margin: 0.2500rem;
}

.foo {
margin: 0;
}

0 comments on commit cf631e8

Please sign in to comment.