From e31abb6230815c3f49f97b322cb968526fa5ba10 Mon Sep 17 00:00:00 2001 From: Dan Purdy Date: Thu, 31 Aug 2017 00:08:56 +0100 Subject: [PATCH 1/2] Check for custom properties in no-color-keywords --- lib/rules/no-color-keywords.js | 2 +- tests/sass/no-color-keywords.sass | 2 ++ tests/sass/no-color-keywords.scss | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/rules/no-color-keywords.js b/lib/rules/no-color-keywords.js index dcf21d1b..31518ce4 100644 --- a/lib/rules/no-color-keywords.js +++ b/lib/rules/no-color-keywords.js @@ -16,7 +16,7 @@ var cssColors = yaml.safeLoad(fs.readFileSync(path.join(__dirname, '../../data', */ var checkValidParentType = function (node) { if (node) { - return node.type === 'function' || node.type === 'variable'; + return node.type === 'function' || node.type === 'variable' || node.type === 'customProperty'; } return false; diff --git a/tests/sass/no-color-keywords.sass b/tests/sass/no-color-keywords.sass index a619da9f..127727b1 100644 --- a/tests/sass/no-color-keywords.sass +++ b/tests/sass/no-color-keywords.sass @@ -31,3 +31,5 @@ $other: rgba($blue, 0.3) // Issue #717 - rule trips over Sass color function names $colors: ( 'red': red($color), 'green': green($color), 'blue': blue($color) ) + +$badge-bg: var(--red) diff --git a/tests/sass/no-color-keywords.scss b/tests/sass/no-color-keywords.scss index 3bcea3d7..4aac84b4 100644 --- a/tests/sass/no-color-keywords.scss +++ b/tests/sass/no-color-keywords.scss @@ -42,3 +42,5 @@ $colors: ( 'green': green($color), 'blue': blue($color) ); + +$badge-bg: var(--red); From 9ee433045e40dc1c23958af80d8e7ec8f797c879 Mon Sep 17 00:00:00 2001 From: Dan Purdy Date: Thu, 31 Aug 2017 00:19:36 +0100 Subject: [PATCH 2/2] Tidy up no-color-keywords logic --- lib/rules/no-color-keywords.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/rules/no-color-keywords.js b/lib/rules/no-color-keywords.js index 31518ce4..face6db9 100644 --- a/lib/rules/no-color-keywords.js +++ b/lib/rules/no-color-keywords.js @@ -15,11 +15,11 @@ var cssColors = yaml.safeLoad(fs.readFileSync(path.join(__dirname, '../../data', * @returns {boolean} Whether the node is a valid type or not */ var checkValidParentType = function (node) { - if (node) { - return node.type === 'function' || node.type === 'variable' || node.type === 'customProperty'; + if (node && (node.is('function') || node.is('variable') || node.is('customProperty'))) { + return false; } - return false; + return true; }; module.exports = { @@ -30,7 +30,7 @@ module.exports = { ast.traverseByType('value', function (node) { node.traverse(function (elem, i, parent) { - if (elem.type === 'ident' && !checkValidParentType(parent)) { + if (elem.type === 'ident' && checkValidParentType(parent)) { var index = cssColors.indexOf(elem.content.toLowerCase()); if (index !== -1) {