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 support for vendor prefixes in property-(dis)allowed-list #6025

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rules/property-allowed-list/README.md
Expand Up @@ -13,7 +13,7 @@ This rule ignores variables (`$sass`, `@less`, `--custom-property`).

## Options

`array|string|regex`: `["array", "of", "unprefixed", /properties/, "regex"]|"property"|"/regex/"|/regex/`
`array|string|regex`: `["array", "of", /properties/, "regex"]|"property"|"/regex/"|/regex/`

If a string is surrounded with `"/"` (e.g. `"/^background/"`), it is interpreted as a regular expression. This allows, for example, easy targeting of shorthands: `/^background/` will match `background`, `background-size`, `background-color`, etc.

Expand Down
36 changes: 36 additions & 0 deletions lib/rules/property-allowed-list/__tests__/index.js
Expand Up @@ -166,3 +166,39 @@ testRule({
},
],
});

testRule({
ruleName,

config: ['-webkit-text-stroke'],

accept: [
{
code: 'a { -webkit-text-stroke: 2px red; }',
},
],

reject: [
{
code: 'a { text-stroke: 2px red; }',
message: messages.rejected('text-stroke'),
line: 1,
column: 5,
},
],
});

testRule({
ruleName,

config: ['text-stroke'],

accept: [
{
code: 'a { -webkit-text-stroke: 2px red; }',
},
{
code: 'a { text-stroke: 2px red; }',
},
],
});
3 changes: 2 additions & 1 deletion lib/rules/property-allowed-list/index.js
Expand Up @@ -42,7 +42,8 @@ const rule = (primary) => {
return;
}

if (matchesStringOrRegExp(vendor.unprefixed(prop), primary)) {
// either the prefix or unprefixed version is in the list
if (matchesStringOrRegExp([prop, vendor.unprefixed(prop)], primary)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/property-disallowed-list/README.md
Expand Up @@ -11,7 +11,7 @@ a { text-rendering: optimizeLegibility; }

## Options

`array|string|regex`: `["array", "of", "unprefixed", /properties/, "regex"]|"property"|"/regex/"|/regex/`
`array|string|regex`: `["array", "of", /properties/, "regex"]|"property"|"/regex/"|/regex/`

If a string is surrounded with `"/"` (e.g. `"/^background/"`), it is interpreted as a regular expression. This allows, for example, easy targeting of shorthands: `/^background/` will match `background`, `background-size`, `background-color`, etc.

Expand Down
42 changes: 42 additions & 0 deletions lib/rules/property-disallowed-list/__tests__/index.js
Expand Up @@ -157,3 +157,45 @@ testRule({
},
],
});

testRule({
ruleName,

config: ['-webkit-text-stroke'],

accept: [
{
code: 'a { text-stroke: 2px red; }',
},
],

reject: [
{
code: 'a { -webkit-text-stroke: 2px red; }',
message: messages.rejected('-webkit-text-stroke'),
line: 1,
column: 5,
},
],
});

testRule({
ruleName,

config: ['text-stroke'],

reject: [
{
code: 'a { -webkit-text-stroke: 2px red; }',
message: messages.rejected('-webkit-text-stroke'),
line: 1,
column: 5,
},
{
code: 'a { text-stroke: 2px red; }',
message: messages.rejected('text-stroke'),
line: 1,
column: 5,
},
],
});
3 changes: 2 additions & 1 deletion lib/rules/property-disallowed-list/index.js
Expand Up @@ -42,7 +42,8 @@ const rule = (primary) => {
return;
}

if (!matchesStringOrRegExp(vendor.unprefixed(prop), primary)) {
// either the prefix or unprefixed version is in the list
if (!matchesStringOrRegExp([prop, vendor.unprefixed(prop)], primary)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/matchesStringOrRegExp.js
Expand Up @@ -8,7 +8,7 @@
* Any strings starting and ending with `/` are interpreted
* as regular expressions.
*
* @param {string} input
* @param {string | Array<string>} input
* @param {string | RegExp | Array<string | RegExp>} comparison
*
* @returns {false | {match: string, pattern: (string | RegExp), substring: string}}
Expand Down