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

Add ignoreFunctions: [] to unit-no-unkown #3736

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions lib/rules/unit-no-unknown/README.md
Expand Up @@ -83,3 +83,43 @@ a {
width: 10my-other-unit;
}
```

### `ignoreFunctions: ["/regex/", "string"]`

Given:

```js
["image-set", "/^my-/", "/^YOUR-/i"]
```

The following patterns are *not* considered violations:

```css
a {
background-image: image-set(
'/images/some-image-1x.jpg' 1x,
'/images/some-image-2x.jpg' 2x,
'/images/some-image-3x.jpg' 3x
);
}
```

```css
a {
background-image: my-image-set(
'/images/some-image-1x.jpg' 1x,
'/images/some-image-2x.jpg' 2x,
'/images/some-image-3x.jpg' 3x
);
}
```

```css
a {
background-image: YOUR-image-set(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
background-image: YOUR-image-set(
background-image: YoUr-image-set(

'/images/some-image-1x.jpg' 1x,
'/images/some-image-2x.jpg' 2x,
'/images/some-image-3x.jpg' 3x
);
}
```
27 changes: 27 additions & 0 deletions lib/rules/unit-no-unknown/__tests__/index.js
Expand Up @@ -472,3 +472,30 @@ testRule(rule, {
}
]
});

testRule(rule, {
ruleName,
config: [true, { ignoreFunctions: ["image-set", "/^my-/", "/^YOUR-/i"] }],

accept: [
{
code:
"a { background-image: image-set('/images/some-image-1x.jpg' 1x,'/images/some-image-2x.jpg' 2x,'/images/some-image-3x.jpg' 3x,); }"
},
{
code:
"a { background-image: my-image-set('/images/some-image-1x.jpg' 1x,'/images/some-image-2x.jpg' 2x,'/images/some-image-3x.jpg' 3x,); }"
},
{
code:
"a { background-image: YOUR-image-set('/images/some-image-1x.jpg' 1x,'/images/some-image-2x.jpg' 2x,'/images/some-image-3x.jpg' 3x,); }"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"a { background-image: YOUR-image-set('/images/some-image-1x.jpg' 1x,'/images/some-image-2x.jpg' 2x,'/images/some-image-3x.jpg' 3x,); }"
"a { background-image: YoUr-image-set('/images/some-image-1x.jpg' 1x,'/images/some-image-2x.jpg' 2x,'/images/some-image-3x.jpg' 3x,); }"

}
],

reject: [
{
code: "a { margin: calc(10pixels + 1pixels); }",
message: messages.rejected("pixels")
}
]
});
11 changes: 9 additions & 2 deletions lib/rules/unit-no-unknown/index.js
Expand Up @@ -26,7 +26,8 @@ const rule = function(actual, options) {
{
actual: options,
possible: {
ignoreUnits: [_.isString]
ignoreUnits: [_.isString],
ignoreFunctions: [_.isString]
},
optional: true
}
Expand All @@ -42,9 +43,15 @@ const rule = function(actual, options) {
value = value.replace(/\*/g, ",");
valueParser(value).walk(function(valueNode) {
// Ignore wrong units within `url` function
// and within functions listed in the `ignoreFunctions` option
if (
valueNode.type === "function" &&
valueNode.value.toLowerCase() === "url"
(valueNode.value.toLowerCase() === "url" ||
optionsMatches(
options,
"ignoreFunctions",
valueNode.value.toLowerCase()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
valueNode.value.toLowerCase()
valueNode.value

I don't think we want to lowercase this as it makes the case insensitivity flag (i) redundant.

))
) {
return false;
}
Expand Down