forked from sasstools/sass-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
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 sasstools#144 from DanPurdy/feature/vendor-prefix
Add rule: no-vendor-prefix
- Loading branch information
Showing
5 changed files
with
270 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,97 @@ | ||
# No Vendor Prefixes | ||
|
||
Rule `no-vendor-prefixes` will enforce that vendor prefixes are not allowed to be used. | ||
|
||
List of prefixes affected by default: | ||
* webkit | ||
* moz | ||
* ms | ||
|
||
## Options | ||
|
||
* `additional-identifiers`: `[array of additional prefixes to check for]` (defaults to empty array `[]`) | ||
* `excluded-identifiers`: `[array of prefixes to exclude checking for]` (defaults to empty array `[]`) | ||
|
||
## Examples | ||
|
||
When enabled, the following are disallowed: | ||
|
||
```scss | ||
@-webkit-keyframes anim { | ||
0% { opacity: 0; } | ||
} | ||
|
||
.ms-block { | ||
-ms-hyphenate-limit-lines: no-limit; | ||
} | ||
|
||
::-moz-placeholder { | ||
content: ''; | ||
} | ||
|
||
.foo { | ||
-webkit-transition: none; | ||
} | ||
|
||
.bar { | ||
position: -moz-sticky; | ||
} | ||
``` | ||
|
||
When `additional-identifiers` contains a custom prefix value of `test` as show below | ||
|
||
```yaml | ||
no-vendor-prefix: | ||
- 1 | ||
- | ||
'additional-identifiers': | ||
- 'khtml' | ||
``` | ||
|
||
The following would now also be disallowed | ||
|
||
```scss | ||
.baz { | ||
position: -khtml-sticky; | ||
} | ||
``` | ||
|
||
When `excluded-identifiers` contains currently disallowed prefix values such as `webkit` and `moz` as show below | ||
|
||
```yaml | ||
no-vendor-prefix: | ||
- 1 | ||
- | ||
'excluded-identifiers': | ||
- 'webkit' | ||
- 'moz' | ||
``` | ||
|
||
The following would now be allowed | ||
|
||
```scss | ||
@-webkit-keyframes anim { | ||
0% { opacity: 0; } | ||
} | ||
|
||
::-moz-placeholder { | ||
content: ''; | ||
} | ||
|
||
.foo { | ||
-webkit-transition: none; | ||
} | ||
|
||
.bar { | ||
position: -moz-sticky; | ||
} | ||
``` | ||
|
||
While the following would remain disallowed | ||
|
||
```scss | ||
|
||
.ms-block { | ||
-ms-hyphenate-limit-lines: no-limit; | ||
} | ||
``` |
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,61 @@ | ||
'use strict'; | ||
|
||
var helpers = require('../helpers'); | ||
|
||
var prefixes = ['webkit', 'moz', 'ms']; | ||
|
||
var handleExcludes = function (excludes) { | ||
excludes.forEach(function (item) { | ||
var index = prefixes.indexOf(item); | ||
|
||
if (index > -1) { | ||
prefixes.splice(index, 1); | ||
} | ||
}); | ||
}; | ||
|
||
var handleIncludes = function (includes) { | ||
includes.forEach(function (item) { | ||
if (prefixes.indexOf(item) === -1) { | ||
prefixes.push(item); | ||
} | ||
}); | ||
}; | ||
|
||
var precompileRegEx = function (includes, excludes) { | ||
|
||
if (includes.length) { | ||
handleIncludes(includes); | ||
} | ||
|
||
if (excludes.length) { | ||
handleExcludes(excludes); | ||
} | ||
|
||
return new RegExp('-(' + prefixes.join('|') + ')-'); | ||
}; | ||
|
||
module.exports = { | ||
'name': 'no-vendor-prefixes', | ||
'defaults': { | ||
'additional-identifiers': [], | ||
'excluded-identifiers': [] | ||
}, | ||
'detect': function (ast, parser) { | ||
var result = [], | ||
statement = precompileRegEx(parser.options['additional-identifiers'], parser.options['excluded-identifiers']); | ||
|
||
ast.traverseByType('ident', function (value) { | ||
if (statement.test(value.content)) { | ||
result = helpers.addUnique(result, { | ||
'ruleId': parser.rule.name, | ||
'line': value.start.line, | ||
'column': value.start.column, | ||
'message': 'Vendor prefixes should not be used', | ||
'severity': parser.severity | ||
}); | ||
} | ||
}); | ||
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,88 @@ | ||
'use strict'; | ||
|
||
var lint = require('./_lint'); | ||
|
||
var file = lint.file('no-vendor-prefixes.scss'); | ||
|
||
describe('no vendor prefix', function () { | ||
it('enforce', function (done) { | ||
lint.test(file, { | ||
'no-vendor-prefixes': 1 | ||
}, function (data) { | ||
lint.assert.equal(5, data.warningCount); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('[excluded-identifiers: webkit]', function (done) { | ||
lint.test(file, { | ||
'no-vendor-prefixes': [ | ||
1, | ||
{ | ||
'excluded-identifiers': | ||
[ | ||
'webkit' | ||
] | ||
} | ||
] | ||
}, function (data) { | ||
lint.assert.equal(3, data.warningCount); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('[excluded-identifiers: webkit, moz]', function (done) { | ||
lint.test(file, { | ||
'no-vendor-prefixes': [ | ||
1, | ||
{ | ||
'excluded-identifiers': | ||
[ | ||
'webkit', | ||
'moz' | ||
] | ||
} | ||
] | ||
}, function (data) { | ||
lint.assert.equal(1, data.warningCount); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('[included-identifiers: khtml]', function (done) { | ||
lint.test(file, { | ||
'no-vendor-prefixes': [ | ||
1, | ||
{ | ||
'additional-identifiers': | ||
[ | ||
'khtml' | ||
] | ||
} | ||
] | ||
}, function (data) { | ||
lint.assert.equal(2, data.warningCount); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('[included-identifiers: khtml, webkit, moz]', function (done) { | ||
lint.test(file, { | ||
'no-vendor-prefixes': [ | ||
1, | ||
{ | ||
'excluded-identifiers': [], | ||
'additional-identifiers': | ||
[ | ||
'khtml', | ||
'webkit', | ||
'moz' | ||
] | ||
} | ||
] | ||
}, function (data) { | ||
lint.assert.equal(6, 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,23 @@ | ||
@-webkit-keyframes anim { | ||
0% { opacity: 0; } | ||
} | ||
|
||
::-moz-placeholder { | ||
color: red; | ||
} | ||
|
||
.foo { | ||
-webkit-transition: none; | ||
} | ||
|
||
.bar { | ||
position: -moz-sticky; | ||
} | ||
|
||
.baz { | ||
position: -khtml-sticky; | ||
} | ||
|
||
.ms-block { | ||
-ms-hyphenate-limit-lines: no-limit; | ||
} |