Skip to content

Commit

Permalink
Ignore function nodes in color-named
Browse files Browse the repository at this point in the history
  • Loading branch information
mmase committed Dec 12, 2016
1 parent bf60e46 commit d7567e2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rules/color-named/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ testRule(rule, {
}, {
code: "a { font: 10px/14px Brown, sans-serif; }",
description: "ignore font family names that are colors",
}, {
code: "colors: (white: #fff);",
description: "ignore color names in non-standard syntax",
} ],

reject: [ {
Expand Down
12 changes: 12 additions & 0 deletions lib/rules/color-named/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const rule = function (expectation, options) {
const namedColors = Object.keys(namedColorData)

root.walkDecls(decl => {
const functionNodes = []

if (propertySets.acceptCustomIdents.has(decl.prop)) {
return
}
Expand All @@ -63,6 +65,16 @@ const rule = function (expectation, options) {
type = node.type,
sourceIndex = node.sourceIndex

if (type === "function") {
node.nodes.forEach((node) => {
functionNodes.push(node.sourceIndex)
})
}

if (functionNodes.indexOf(sourceIndex) > -1) {
return
}

if (
optionsMatches(options, "ignore", "inside-function")
&& type === "function"
Expand Down

0 comments on commit d7567e2

Please sign in to comment.