From c0522ad8c10d68bd108ab89b4ca13c848d95ae4a Mon Sep 17 00:00:00 2001 From: Dan Purdy Date: Wed, 9 Sep 2015 00:41:28 +0100 Subject: [PATCH 1/8] :white_check_mark: Add no-vendor-prefix tests #34 --- lib/config/sass-lint.yml | 1 + tests/rules/no-vendor-prefix.js | 87 ++++++++++++++++++++++++++++++++ tests/sass/no-vendor-prefix.scss | 23 +++++++++ 3 files changed, 111 insertions(+) create mode 100644 tests/rules/no-vendor-prefix.js create mode 100644 tests/sass/no-vendor-prefix.scss diff --git a/lib/config/sass-lint.yml b/lib/config/sass-lint.yml index 55df4deb..e9187caf 100644 --- a/lib/config/sass-lint.yml +++ b/lib/config/sass-lint.yml @@ -27,6 +27,7 @@ rules: no-color-keywords: 1 no-invalid-hex: 1 no-css-comments: 1 + no-vendor-prefix: 1 # Style Guide border-zero: 1 diff --git a/tests/rules/no-vendor-prefix.js b/tests/rules/no-vendor-prefix.js new file mode 100644 index 00000000..ed931822 --- /dev/null +++ b/tests/rules/no-vendor-prefix.js @@ -0,0 +1,87 @@ +'use strict'; + +var lint = require('./_lint'); + +var file = lint.file('no-vendor-prefix.scss'); + +describe('no vendor prefix', function () { + it('enforce', function (done) { + lint.test(file, { + 'no-vendor-prefix': 1 + }, function (data) { + lint.assert.equal(5, data.warningCount); + done(); + }); + }); + + it('[excluded-identifiers: webkit]', function (done) { + lint.test(file, { + 'no-vendor-prefix': [ + 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-prefix': [ + 1, + { + 'excluded-identifiers': + [ + 'webkit', + 'moz' + ] + } + ] + }, function (data) { + lint.assert.equal(1, data.warningCount); + done(); + }); + }); + + it('[included-identifiers: prefix]', function (done) { + lint.test(file, { + 'no-vendor-prefix': [ + 1, + { + 'additional-identifiers': + [ + 'prefix' + ] + } + ] + }, function (data) { + lint.assert.equal(2, data.warningCount); + done(); + }); + }); + + it('[included-identifiers: prefix, webkit, moz]', function (done) { + lint.test(file, { + 'no-vendor-prefix': [ + 1, + { + 'additional-identifiers': + [ + 'prefix', + 'webkit', + 'moz' + ] + } + ] + }, function (data) { + lint.assert.equal(6, data.warningCount); + done(); + }); + }); +}); diff --git a/tests/sass/no-vendor-prefix.scss b/tests/sass/no-vendor-prefix.scss new file mode 100644 index 00000000..1057a606 --- /dev/null +++ b/tests/sass/no-vendor-prefix.scss @@ -0,0 +1,23 @@ +@-webkit-keyframes anim { + 0% { opacity: 0; } +} + +::-moz-placeholder { + color: red; +} + +.foo { + -webkit-transition: none; +} + +.bar { + position: -moz-sticky; +} + +.baz { + position: -prefix-sticky; +} + +.ms-block { + -ms-hyphenate-limit-lines: no-limit; +} From b32e92e0eb18c6b46c83cb249026a52477d4ab98 Mon Sep 17 00:00:00 2001 From: Dan Purdy Date: Wed, 9 Sep 2015 00:42:02 +0100 Subject: [PATCH 2/8] :memo: Add no-vendor-prefix docs #34 --- docs/rules/no-vendor-prefix.md | 97 ++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 docs/rules/no-vendor-prefix.md diff --git a/docs/rules/no-vendor-prefix.md b/docs/rules/no-vendor-prefix.md new file mode 100644 index 00000000..42ad6c97 --- /dev/null +++ b/docs/rules/no-vendor-prefix.md @@ -0,0 +1,97 @@ +# No Vendor Prefix + +Rule `no-vendor-prefix` 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': + - 'test' +``` + +The following would now also be disallowed + +```scss +.baz { + position: -test-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; +} +``` From 2f96de5a7e09eb398c072f831e2e08da372154c5 Mon Sep 17 00:00:00 2001 From: Dan Purdy Date: Wed, 9 Sep 2015 00:42:41 +0100 Subject: [PATCH 3/8] :mag: Add no-vendor-prefix rule #34 --- lib/rules/no-vendor-prefix.js | 61 +++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 lib/rules/no-vendor-prefix.js diff --git a/lib/rules/no-vendor-prefix.js b/lib/rules/no-vendor-prefix.js new file mode 100644 index 00000000..629e7a88 --- /dev/null +++ b/lib/rules/no-vendor-prefix.js @@ -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 (excludes.length) { + handleExcludes(excludes); + } + + if (includes.length) { + handleIncludes(includes); + } + + return new RegExp('-(' + prefixes.join('|') + ')-'); +}; + +module.exports = { + 'name': 'no-vendor-prefix', + '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': 'Hexadecimal values must be a valid format', + 'severity': parser.severity + }); + } + }); + return result; + } +}; From 93d9ac7cbe2cbfa993ade66ff1ad6b358370515f Mon Sep 17 00:00:00 2001 From: Dan Purdy Date: Wed, 9 Sep 2015 00:49:54 +0100 Subject: [PATCH 4/8] :art: Update to correct warning message for new rule --- lib/rules/no-vendor-prefix.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rules/no-vendor-prefix.js b/lib/rules/no-vendor-prefix.js index 629e7a88..86031c88 100644 --- a/lib/rules/no-vendor-prefix.js +++ b/lib/rules/no-vendor-prefix.js @@ -51,7 +51,7 @@ module.exports = { 'ruleId': parser.rule.name, 'line': value.start.line, 'column': value.start.column, - 'message': 'Hexadecimal values must be a valid format', + 'message': 'Vendor prefixes should not be used', 'severity': parser.severity }); } From 38fa3cb0699b9c50916b5561bc4843b4e78f4ce3 Mon Sep 17 00:00:00 2001 From: Dan Purdy Date: Wed, 9 Sep 2015 00:53:30 +0100 Subject: [PATCH 5/8] :art: Update tests and docs to use valid alternative prefix --- docs/rules/no-vendor-prefix.md | 4 ++-- tests/rules/no-vendor-prefix.js | 4 ++-- tests/sass/no-vendor-prefix.scss | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/rules/no-vendor-prefix.md b/docs/rules/no-vendor-prefix.md index 42ad6c97..3782756f 100644 --- a/docs/rules/no-vendor-prefix.md +++ b/docs/rules/no-vendor-prefix.md @@ -45,14 +45,14 @@ no-vendor-prefix: - 1 - 'additional-identifiers': - - 'test' + - 'khtml' ``` The following would now also be disallowed ```scss .baz { - position: -test-sticky; + position: -khtml-sticky; } ``` diff --git a/tests/rules/no-vendor-prefix.js b/tests/rules/no-vendor-prefix.js index ed931822..6d23cb6e 100644 --- a/tests/rules/no-vendor-prefix.js +++ b/tests/rules/no-vendor-prefix.js @@ -56,7 +56,7 @@ describe('no vendor prefix', function () { { 'additional-identifiers': [ - 'prefix' + 'khtml' ] } ] @@ -73,7 +73,7 @@ describe('no vendor prefix', function () { { 'additional-identifiers': [ - 'prefix', + 'khtml', 'webkit', 'moz' ] diff --git a/tests/sass/no-vendor-prefix.scss b/tests/sass/no-vendor-prefix.scss index 1057a606..af061dbf 100644 --- a/tests/sass/no-vendor-prefix.scss +++ b/tests/sass/no-vendor-prefix.scss @@ -15,7 +15,7 @@ } .baz { - position: -prefix-sticky; + position: -khtml-sticky; } .ms-block { From 3bf980e78280416f7de2a9f4c1d0db056f46b57b Mon Sep 17 00:00:00 2001 From: Dan Purdy Date: Wed, 9 Sep 2015 01:00:20 +0100 Subject: [PATCH 6/8] :art: Update function order and add test default fix --- lib/rules/no-vendor-prefix.js | 8 ++++---- tests/rules/no-vendor-prefix.js | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/rules/no-vendor-prefix.js b/lib/rules/no-vendor-prefix.js index 86031c88..d64172b5 100644 --- a/lib/rules/no-vendor-prefix.js +++ b/lib/rules/no-vendor-prefix.js @@ -24,14 +24,14 @@ var handleIncludes = function (includes) { var precompileRegEx = function (includes, excludes) { - if (excludes.length) { - handleExcludes(excludes); - } - if (includes.length) { handleIncludes(includes); } + if (excludes.length) { + handleExcludes(excludes); + } + return new RegExp('-(' + prefixes.join('|') + ')-'); }; diff --git a/tests/rules/no-vendor-prefix.js b/tests/rules/no-vendor-prefix.js index 6d23cb6e..19f7e67c 100644 --- a/tests/rules/no-vendor-prefix.js +++ b/tests/rules/no-vendor-prefix.js @@ -71,6 +71,7 @@ describe('no vendor prefix', function () { 'no-vendor-prefix': [ 1, { + 'excluded-identifiers': [], 'additional-identifiers': [ 'khtml', From 6803925280ca96d09007bc95a28d0fa1eb17ae76 Mon Sep 17 00:00:00 2001 From: Dan Purdy Date: Wed, 9 Sep 2015 01:02:15 +0100 Subject: [PATCH 7/8] :art: Improve test naming --- tests/rules/no-vendor-prefix.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/rules/no-vendor-prefix.js b/tests/rules/no-vendor-prefix.js index 19f7e67c..52e1fa7d 100644 --- a/tests/rules/no-vendor-prefix.js +++ b/tests/rules/no-vendor-prefix.js @@ -49,7 +49,7 @@ describe('no vendor prefix', function () { }); }); - it('[included-identifiers: prefix]', function (done) { + it('[included-identifiers: khtml]', function (done) { lint.test(file, { 'no-vendor-prefix': [ 1, @@ -66,7 +66,7 @@ describe('no vendor prefix', function () { }); }); - it('[included-identifiers: prefix, webkit, moz]', function (done) { + it('[included-identifiers: khtml, webkit, moz]', function (done) { lint.test(file, { 'no-vendor-prefix': [ 1, From 8e2996e28e36ebe9bd034e1a91a8c197636574b7 Mon Sep 17 00:00:00 2001 From: Dan Purdy Date: Wed, 9 Sep 2015 15:56:14 +0100 Subject: [PATCH 8/8] :art: Rename rule to vendor prefixes --- .../{no-vendor-prefix.md => no-vendor-prefixes.md} | 4 ++-- lib/config/sass-lint.yml | 2 +- .../{no-vendor-prefix.js => no-vendor-prefixes.js} | 2 +- .../{no-vendor-prefix.js => no-vendor-prefixes.js} | 12 ++++++------ ...no-vendor-prefix.scss => no-vendor-prefixes.scss} | 0 5 files changed, 10 insertions(+), 10 deletions(-) rename docs/rules/{no-vendor-prefix.md => no-vendor-prefixes.md} (92%) rename lib/rules/{no-vendor-prefix.js => no-vendor-prefixes.js} (97%) rename tests/rules/{no-vendor-prefix.js => no-vendor-prefixes.js} (88%) rename tests/sass/{no-vendor-prefix.scss => no-vendor-prefixes.scss} (100%) diff --git a/docs/rules/no-vendor-prefix.md b/docs/rules/no-vendor-prefixes.md similarity index 92% rename from docs/rules/no-vendor-prefix.md rename to docs/rules/no-vendor-prefixes.md index 3782756f..cc8a9e85 100644 --- a/docs/rules/no-vendor-prefix.md +++ b/docs/rules/no-vendor-prefixes.md @@ -1,6 +1,6 @@ -# No Vendor Prefix +# No Vendor Prefixes -Rule `no-vendor-prefix` will enforce that vendor prefixes are not allowed to be used. +Rule `no-vendor-prefixes` will enforce that vendor prefixes are not allowed to be used. List of prefixes affected by default: * webkit diff --git a/lib/config/sass-lint.yml b/lib/config/sass-lint.yml index 6d6b0cff..2b2684b5 100644 --- a/lib/config/sass-lint.yml +++ b/lib/config/sass-lint.yml @@ -28,7 +28,7 @@ rules: no-invalid-hex: 1 no-css-comments: 1 no-color-literals: 1 - no-vendor-prefix: 1 + no-vendor-prefixes: 1 # Style Guide border-zero: 1 diff --git a/lib/rules/no-vendor-prefix.js b/lib/rules/no-vendor-prefixes.js similarity index 97% rename from lib/rules/no-vendor-prefix.js rename to lib/rules/no-vendor-prefixes.js index d64172b5..115121c4 100644 --- a/lib/rules/no-vendor-prefix.js +++ b/lib/rules/no-vendor-prefixes.js @@ -36,7 +36,7 @@ var precompileRegEx = function (includes, excludes) { }; module.exports = { - 'name': 'no-vendor-prefix', + 'name': 'no-vendor-prefixes', 'defaults': { 'additional-identifiers': [], 'excluded-identifiers': [] diff --git a/tests/rules/no-vendor-prefix.js b/tests/rules/no-vendor-prefixes.js similarity index 88% rename from tests/rules/no-vendor-prefix.js rename to tests/rules/no-vendor-prefixes.js index 52e1fa7d..50f81071 100644 --- a/tests/rules/no-vendor-prefix.js +++ b/tests/rules/no-vendor-prefixes.js @@ -2,12 +2,12 @@ var lint = require('./_lint'); -var file = lint.file('no-vendor-prefix.scss'); +var file = lint.file('no-vendor-prefixes.scss'); describe('no vendor prefix', function () { it('enforce', function (done) { lint.test(file, { - 'no-vendor-prefix': 1 + 'no-vendor-prefixes': 1 }, function (data) { lint.assert.equal(5, data.warningCount); done(); @@ -16,7 +16,7 @@ describe('no vendor prefix', function () { it('[excluded-identifiers: webkit]', function (done) { lint.test(file, { - 'no-vendor-prefix': [ + 'no-vendor-prefixes': [ 1, { 'excluded-identifiers': @@ -33,7 +33,7 @@ describe('no vendor prefix', function () { it('[excluded-identifiers: webkit, moz]', function (done) { lint.test(file, { - 'no-vendor-prefix': [ + 'no-vendor-prefixes': [ 1, { 'excluded-identifiers': @@ -51,7 +51,7 @@ describe('no vendor prefix', function () { it('[included-identifiers: khtml]', function (done) { lint.test(file, { - 'no-vendor-prefix': [ + 'no-vendor-prefixes': [ 1, { 'additional-identifiers': @@ -68,7 +68,7 @@ describe('no vendor prefix', function () { it('[included-identifiers: khtml, webkit, moz]', function (done) { lint.test(file, { - 'no-vendor-prefix': [ + 'no-vendor-prefixes': [ 1, { 'excluded-identifiers': [], diff --git a/tests/sass/no-vendor-prefix.scss b/tests/sass/no-vendor-prefixes.scss similarity index 100% rename from tests/sass/no-vendor-prefix.scss rename to tests/sass/no-vendor-prefixes.scss