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 ignoreAtRules to property-no-unknown #4965

Merged
merged 6 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: Add ignoreAtRules to property-no-unknown
  • Loading branch information
zbarnes committed Oct 6, 2020
commit a18034602f67efe1eb1476ec135ad8b7af2f67e4
21 changes: 21 additions & 0 deletions lib/rules/property-no-unknown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,27 @@ The following patterns are _not_ considered violations:
}
```

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

Skips checking properties of the given at-rules
Zacharias3690 marked this conversation as resolved.
Show resolved Hide resolved

Given:

```
["supports"]
```

The following patterns are _not_ considered violations:

<!-- prettier-ignore -->
```css
@supports(display: my-property) {
div {
display: my-property;
}
Zacharias3690 marked this conversation as resolved.
Show resolved Hide resolved
}
```

### `checkPrefixed: true | false` (default: `false`)

If `true`, this rule will check vendor-prefixed properties.
Expand Down
61 changes: 61 additions & 0 deletions lib/rules/property-no-unknown/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,64 @@ testRule({
},
],
});

testRule({
ruleName,
config: [true, { ignoreAtRules: ['media', '/^my-/'] }],

accept: [
{
code: 'a { @media { foo: 1 } }',
Zacharias3690 marked this conversation as resolved.
Show resolved Hide resolved
},
{
code: 'a { b { @media { foo: 1 }}}',
},
{
code: 'a { @my-at-rule { foo: 1 } }',
},
{
code: 'a { @my-other-at-rule { foo: 1 } }',
},
],

reject: [
{
code: 'a { @import { foo: 1; } }',
message: messages.rejected('foo'),
line: 1,
column: 15,
},
{
code: 'a { @my_at_rule { foo: 1; } }',
message: messages.rejected('foo'),
line: 1,
column: 19,
},
{
code: 'a { foo: 1; }',
message: messages.rejected('foo'),
line: 1,
column: 5,
},
],
});

testRule({
Zacharias3690 marked this conversation as resolved.
Show resolved Hide resolved
ruleName,
config: [true, { ignoreAtRules: [/^my-/] }],

accept: [
{
code: 'a { @my-at-rule foobar { foo: 1; } }',
},
],

reject: [
{
code: 'a { @my_at_rule foobar { foo: 1; } }',
message: messages.rejected('foo'),
line: 1,
column: 26,
},
],
});
13 changes: 10 additions & 3 deletions lib/rules/property-no-unknown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function rule(actual, options) {
ignoreProperties: [_.isString, _.isRegExp],
checkPrefixed: _.isBoolean,
ignoreSelectors: [_.isString, _.isRegExp],
ignoreAtRules: [_.isString, _.isRegExp],
},
optional: true,
},
Expand All @@ -44,7 +45,9 @@ function rule(actual, options) {

const shouldCheckPrefixed = _.get(options, 'checkPrefixed');

root.walkDecls((decl) => {
root.walkDecls(checkStatement);

function checkStatement(decl) {
const prop = decl.prop;

if (!isStandardSyntaxProperty(prop)) {
Expand All @@ -67,12 +70,16 @@ function rule(actual, options) {
return;
}

const { selector } = decl.parent;
const { selector, name } = decl.parent;
Zacharias3690 marked this conversation as resolved.
Show resolved Hide resolved

if (selector && optionsMatches(options, 'ignoreSelectors', selector)) {
return;
}

if (name && optionsMatches(options, 'ignoreAtRules', name)) {
Zacharias3690 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

if (allValidProperties.has(prop.toLowerCase())) {
return;
}
Expand All @@ -83,7 +90,7 @@ function rule(actual, options) {
result,
ruleName,
});
});
}
};
}

Expand Down