Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore maps and lists in color-named #2182

Merged
merged 1 commit into from
Dec 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 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, blue: #00f);",
description: "ignore non-standard list and map syntax",
} ],

reject: [ {
Expand Down Expand Up @@ -93,6 +96,11 @@ testRule(rule, {
message: messages.rejected("white"),
line: 1,
column: 24,
}, {
code: "a { background: color(green); }",
message: messages.rejected("green"),
line: 1,
column: 23,
} ],
})

Expand Down Expand Up @@ -255,6 +263,11 @@ testRule(rule, {
message: messages.expected("black", "rgb(0,0,0)"),
line: 1,
column: 23,
}, {
code: "a { color: color(#000 a(50%)) }",
message: messages.expected("black", "#000"),
line: 1,
column: 18,
} ],
})

Expand Down Expand Up @@ -300,6 +313,8 @@ testRule(rule, {
code: "a { color: map-get($colour, blue(60%)); }",
}, {
code: "a { color: map-get($colour, blue); }",
}, {
code: "a { background: color(blue); }",
} ],

reject: [ {
Expand Down
5 changes: 5 additions & 0 deletions lib/rules/color-named/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const _ = require("lodash")
const declarationValueIndex = require("../../utils/declarationValueIndex")
const isStandardSyntaxFunction = require("../../utils/isStandardSyntaxFunction")
const isStandardSyntaxValue = require("../../utils/isStandardSyntaxValue")
const keywordSets = require("../../reference/keywordSets")
const namedColorData = require("../../reference/namedColorData")
Expand Down Expand Up @@ -70,6 +71,10 @@ const rule = function (expectation, options) {
return false
}

if (!isStandardSyntaxFunction(node)) {
return false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use just return

Copy link
Contributor Author

@mmase mmase Dec 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't appear to work. I don't know a ton about postcss-value-parser, but returning undefined on only a value would work. However, since we are making an assertion on a node, you need to return false for it to skip the values within that node. Otherwise, I would group it with the isStandardSyntaxValue check below this.

}

if (!isStandardSyntaxValue(value)) {
return
}
Expand Down