diff --git a/lib/rules/at-rule-allowed-list/__tests__/index.js b/lib/rules/at-rule-allowed-list/__tests__/index.js index 63f4c77d77..9eb959e2c3 100644 --- a/lib/rules/at-rule-allowed-list/__tests__/index.js +++ b/lib/rules/at-rule-allowed-list/__tests__/index.js @@ -80,7 +80,7 @@ testRule({ ruleName, skipBasicChecks: true, - config: ['keyframes'], + config: 'keyframes', accept: [ { diff --git a/lib/rules/at-rule-allowed-list/index.js b/lib/rules/at-rule-allowed-list/index.js index 87c661e080..963a675055 100644 --- a/lib/rules/at-rule-allowed-list/index.js +++ b/lib/rules/at-rule-allowed-list/index.js @@ -17,14 +17,11 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/at-rule-allowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { - // To allow for just a string as a parameter (not only arrays of strings) - const primaryValues = [primary].flat(); - return (root, result) => { const validOptions = validateOptions(result, ruleName, { - actual: primaryValues, + actual: primary, possible: [isString], }); @@ -32,8 +29,7 @@ const rule = (primary) => { return; } - /** @type {string[]} */ - const atRuleNames = primaryValues; + const primaryValues = [primary].flat(); root.walkAtRules((atRule) => { const name = atRule.name; @@ -42,7 +38,7 @@ const rule = (primary) => { return; } - if (atRuleNames.includes(vendor.unprefixed(name).toLowerCase())) { + if (primaryValues.includes(vendor.unprefixed(name).toLowerCase())) { return; } diff --git a/lib/rules/at-rule-disallowed-list/__tests__/index.js b/lib/rules/at-rule-disallowed-list/__tests__/index.js index 174550d71a..d2f325ee4e 100644 --- a/lib/rules/at-rule-disallowed-list/__tests__/index.js +++ b/lib/rules/at-rule-disallowed-list/__tests__/index.js @@ -91,7 +91,7 @@ testRule({ testRule({ ruleName, - config: ['keyframes'], + config: 'keyframes', accept: [ { diff --git a/lib/rules/at-rule-disallowed-list/index.js b/lib/rules/at-rule-disallowed-list/index.js index 6d1e4db2b7..0722de0e50 100644 --- a/lib/rules/at-rule-disallowed-list/index.js +++ b/lib/rules/at-rule-disallowed-list/index.js @@ -17,14 +17,11 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/at-rule-disallowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { - // To allow for just a string as a parameter (not only arrays of strings) - const primaryValues = [primary].flat(); - return (root, result) => { const validOptions = validateOptions(result, ruleName, { - actual: primaryValues, + actual: primary, possible: [isString], }); @@ -32,8 +29,7 @@ const rule = (primary) => { return; } - /** @type {string[]} */ - const atRuleNames = primaryValues; + const primaryValues = [primary].flat(); root.walkAtRules((atRule) => { const name = atRule.name; @@ -42,7 +38,7 @@ const rule = (primary) => { return; } - if (!atRuleNames.includes(vendor.unprefixed(name).toLowerCase())) { + if (!primaryValues.includes(vendor.unprefixed(name).toLowerCase())) { return; } diff --git a/lib/rules/comment-word-disallowed-list/README.md b/lib/rules/comment-word-disallowed-list/README.md index e218e2caf4..a68f598fce 100644 --- a/lib/rules/comment-word-disallowed-list/README.md +++ b/lib/rules/comment-word-disallowed-list/README.md @@ -13,7 +13,7 @@ Specify a list of disallowed words within comments. ## Options -`array|string|regexp`: `["array", "of", "words", /or/, "/regex/"]|"word"|"/regex/"` +`array|string|regexp`: `["array", "of", "words", /or/, "/regex/"]|"word"|"/regex/"|/regex/` If a string is surrounded with `"/"` (e.g. `"/^TODO:/"`), it is interpreted as a regular expression. diff --git a/lib/rules/comment-word-disallowed-list/__tests__/index.js b/lib/rules/comment-word-disallowed-list/__tests__/index.js index eaa57b41b6..9fd5394a88 100644 --- a/lib/rules/comment-word-disallowed-list/__tests__/index.js +++ b/lib/rules/comment-word-disallowed-list/__tests__/index.js @@ -4,7 +4,7 @@ const { messages, ruleName } = require('..'); testRule({ ruleName, - config: ['bad-word'], + config: 'bad-word', accept: [ { @@ -219,7 +219,7 @@ testRule({ testRule({ ruleName, customSyntax: 'postcss-scss', - config: [['/^TODO:/', 'bad-word']], + config: ['/^TODO:/', 'bad-word'], accept: [ { diff --git a/lib/rules/comment-word-disallowed-list/index.js b/lib/rules/comment-word-disallowed-list/index.js index 4a8de7dc7c..2c1c2b8c10 100644 --- a/lib/rules/comment-word-disallowed-list/index.js +++ b/lib/rules/comment-word-disallowed-list/index.js @@ -17,7 +17,7 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/comment-word-disallowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/function-allowed-list/README.md b/lib/rules/function-allowed-list/README.md index 26d0bf74cf..0efd629e28 100644 --- a/lib/rules/function-allowed-list/README.md +++ b/lib/rules/function-allowed-list/README.md @@ -11,14 +11,14 @@ a { transform: scale(1); } ## Options -`array|string`: `["array", "of", "unprefixed", /functions/ or "regex"]|"function"|"/regex/"` +`array|string|regex`: `["array", "of", "unprefixed", /functions/, "/regex/"]|"function"|"/regex/"|/regex/` If a string is surrounded with `"/"` (e.g. `"/^rgb/"`), it is interpreted as a regular expression. Given: ```json -["scale", "rgba", "linear-gradient"] +["scale", "rgba", "/linear-gradient/"] ``` The following patterns are considered problems: diff --git a/lib/rules/function-allowed-list/__tests__/index.js b/lib/rules/function-allowed-list/__tests__/index.js index f7c188598f..806a60a49f 100644 --- a/lib/rules/function-allowed-list/__tests__/index.js +++ b/lib/rules/function-allowed-list/__tests__/index.js @@ -135,7 +135,7 @@ testRule({ testRule({ ruleName, - config: ['/rgb/'], + config: '/rgb/', accept: [ { diff --git a/lib/rules/function-allowed-list/index.js b/lib/rules/function-allowed-list/index.js index 6efb2b8baf..7b34fd4ee2 100644 --- a/lib/rules/function-allowed-list/index.js +++ b/lib/rules/function-allowed-list/index.js @@ -20,13 +20,11 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/function-allowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { - const list = [primary].flat(); - return (root, result) => { const validOptions = validateOptions(result, ruleName, { - actual: list, + actual: primary, possible: [isString, isRegExp], }); @@ -46,7 +44,7 @@ const rule = (primary) => { return; } - if (matchesStringOrRegExp(vendor.unprefixed(node.value), list)) { + if (matchesStringOrRegExp(vendor.unprefixed(node.value), primary)) { return; } diff --git a/lib/rules/function-disallowed-list/README.md b/lib/rules/function-disallowed-list/README.md index 4cbb55872f..5b577eda82 100644 --- a/lib/rules/function-disallowed-list/README.md +++ b/lib/rules/function-disallowed-list/README.md @@ -11,7 +11,7 @@ a { transform: scale(1); } ## Options -`array|string`: `["array", "of", "unprefixed", /functions/ or "regex"]|"function"|"/regex/"` +`array|string|regex`: `["array", "of", "unprefixed", /functions/, "regex"]|"function"|"/regex/"|/regex/` If a string is surrounded with `"/"` (e.g. `"/^rgb/"`), it is interpreted as a regular expression. diff --git a/lib/rules/function-disallowed-list/__tests__/index.js b/lib/rules/function-disallowed-list/__tests__/index.js index 583d756e86..f878f511f0 100644 --- a/lib/rules/function-disallowed-list/__tests__/index.js +++ b/lib/rules/function-disallowed-list/__tests__/index.js @@ -102,7 +102,7 @@ testRule({ testRule({ ruleName, - config: ['/rgb/'], + config: '/rgb/', accept: [ { diff --git a/lib/rules/function-disallowed-list/index.js b/lib/rules/function-disallowed-list/index.js index b2331820e6..1ee81ed9f2 100644 --- a/lib/rules/function-disallowed-list/index.js +++ b/lib/rules/function-disallowed-list/index.js @@ -20,7 +20,7 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/function-disallowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/function-url-scheme-allowed-list/README.md b/lib/rules/function-url-scheme-allowed-list/README.md index 86d8801a93..2e89691e92 100644 --- a/lib/rules/function-url-scheme-allowed-list/README.md +++ b/lib/rules/function-url-scheme-allowed-list/README.md @@ -18,7 +18,7 @@ This rule ignores: ## Options -`array|string|regex`: `["array", "of", /schemes/ or "/regex/"]|"scheme"|/regex/` +`array|string|regex`: `["array", "of", /schemes/, "/regex/"]|"scheme"|"/regex/"|/regex/` Given: diff --git a/lib/rules/function-url-scheme-allowed-list/__tests__/index.js b/lib/rules/function-url-scheme-allowed-list/__tests__/index.js index e637888b59..b1d433c775 100644 --- a/lib/rules/function-url-scheme-allowed-list/__tests__/index.js +++ b/lib/rules/function-url-scheme-allowed-list/__tests__/index.js @@ -158,7 +158,7 @@ testRule({ testRule({ ruleName, - config: [[]], + config: [], accept: [ { @@ -193,7 +193,7 @@ testRule({ testRule({ ruleName, - config: [''], + config: '', accept: [ { @@ -228,7 +228,6 @@ testRule({ testRule({ ruleName, - // primaryOptionArray config: ['uri', 'file', 'https'], accept: [ @@ -250,7 +249,7 @@ testRule({ testRule({ ruleName, - config: [['/^http/']], + config: ['/^http/'], accept: [ { @@ -283,7 +282,7 @@ testRule({ testRule({ ruleName, - config: [[/^http/]], + config: [/^http/], accept: [ { diff --git a/lib/rules/function-url-scheme-allowed-list/index.js b/lib/rules/function-url-scheme-allowed-list/index.js index dbd1dfc72a..3214b780f9 100644 --- a/lib/rules/function-url-scheme-allowed-list/index.js +++ b/lib/rules/function-url-scheme-allowed-list/index.js @@ -19,7 +19,7 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/function-url-scheme-allowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/function-url-scheme-disallowed-list/README.md b/lib/rules/function-url-scheme-disallowed-list/README.md index fcb18b4aa4..0f79a7d960 100644 --- a/lib/rules/function-url-scheme-disallowed-list/README.md +++ b/lib/rules/function-url-scheme-disallowed-list/README.md @@ -18,7 +18,7 @@ This rule ignores: ## Options -`array|string|regex`: `["array", "of", /schemes/ or "/regex/"]|"scheme"|/regex/` +`array|string|regex`: `["array", "of", /schemes/, "/regex/"]|"scheme"|"/regex/"|/regex/` Given: diff --git a/lib/rules/function-url-scheme-disallowed-list/__tests__/index.js b/lib/rules/function-url-scheme-disallowed-list/__tests__/index.js index 3c568e65a0..4844ab11d2 100644 --- a/lib/rules/function-url-scheme-disallowed-list/__tests__/index.js +++ b/lib/rules/function-url-scheme-disallowed-list/__tests__/index.js @@ -4,7 +4,7 @@ const { messages, ruleName } = require('..'); testRule({ ruleName, - config: [[]], + config: [], accept: [ { @@ -15,7 +15,7 @@ testRule({ testRule({ ruleName, - config: [''], + config: '', accept: [ { @@ -184,7 +184,7 @@ testRule({ testRule({ ruleName, - config: [['/^http/']], + config: ['/^http/'], accept: [ { @@ -220,7 +220,7 @@ testRule({ testRule({ ruleName, - config: [[/^http/]], + config: [/^http/], accept: [ { diff --git a/lib/rules/function-url-scheme-disallowed-list/index.js b/lib/rules/function-url-scheme-disallowed-list/index.js index 59d5b4bb42..50a97c6915 100644 --- a/lib/rules/function-url-scheme-disallowed-list/index.js +++ b/lib/rules/function-url-scheme-disallowed-list/index.js @@ -19,7 +19,7 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/function-url-scheme-disallowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/media-feature-name-allowed-list/README.md b/lib/rules/media-feature-name-allowed-list/README.md index 0efd5fc808..528618216f 100644 --- a/lib/rules/media-feature-name-allowed-list/README.md +++ b/lib/rules/media-feature-name-allowed-list/README.md @@ -11,7 +11,7 @@ Specify a list of allowed media feature names. ## Options -`array|string|regex`: `["array", "of", "unprefixed", /media-features/ or "regex"]|"media-feature"|/regex/` +`array|string|regex`: `["array", "of", "unprefixed", /media-features/, "regex"]|"media-feature"|"/regex/"|/regex/` Given: diff --git a/lib/rules/media-feature-name-allowed-list/__tests__/index.js b/lib/rules/media-feature-name-allowed-list/__tests__/index.js index d874706594..f1f186933e 100644 --- a/lib/rules/media-feature-name-allowed-list/__tests__/index.js +++ b/lib/rules/media-feature-name-allowed-list/__tests__/index.js @@ -101,7 +101,7 @@ testRule({ testRule({ ruleName, - config: [/^my-/], + config: /^my-/, accept: [ { diff --git a/lib/rules/media-feature-name-allowed-list/index.js b/lib/rules/media-feature-name-allowed-list/index.js index 345708371c..ab992bdbe3 100644 --- a/lib/rules/media-feature-name-allowed-list/index.js +++ b/lib/rules/media-feature-name-allowed-list/index.js @@ -22,7 +22,7 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/media-feature-name-allowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/media-feature-name-disallowed-list/README.md b/lib/rules/media-feature-name-disallowed-list/README.md index b2a1ee623b..7256cca72d 100644 --- a/lib/rules/media-feature-name-disallowed-list/README.md +++ b/lib/rules/media-feature-name-disallowed-list/README.md @@ -11,7 +11,7 @@ Specify a list of disallowed media feature names. ## Options -`array|string|regex`: `["array", "of", "unprefixed", /media-features/ or "regex"]|"media-feature"|/regex/` +`array|string|regex`: `["array", "of", "unprefixed", /media-features/, "regex"]|"media-feature"|"/regex/"|/regex/` Given: diff --git a/lib/rules/media-feature-name-disallowed-list/__tests__/index.js b/lib/rules/media-feature-name-disallowed-list/__tests__/index.js index 734ae2c4ef..6c169831e0 100644 --- a/lib/rules/media-feature-name-disallowed-list/__tests__/index.js +++ b/lib/rules/media-feature-name-disallowed-list/__tests__/index.js @@ -99,7 +99,7 @@ testRule({ testRule({ ruleName, - config: [/^my-/], + config: /^my-/, accept: [ { diff --git a/lib/rules/media-feature-name-disallowed-list/index.js b/lib/rules/media-feature-name-disallowed-list/index.js index 5c3bb69ed7..df96afbf85 100644 --- a/lib/rules/media-feature-name-disallowed-list/index.js +++ b/lib/rules/media-feature-name-disallowed-list/index.js @@ -22,7 +22,7 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/media-feature-name-disallowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/property-allowed-list/README.md b/lib/rules/property-allowed-list/README.md index b39cd7b79e..d1e7846503 100644 --- a/lib/rules/property-allowed-list/README.md +++ b/lib/rules/property-allowed-list/README.md @@ -13,7 +13,7 @@ This rule ignores variables (`$sass`, `@less`, `--custom-property`). ## Options -`array|string`: `["array", "of", "unprefixed", /properties/ or "regex"]|"property"|"/regex/"`|/regex/ +`array|string|regex`: `["array", "of", "unprefixed", /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. diff --git a/lib/rules/property-allowed-list/__tests__/index.js b/lib/rules/property-allowed-list/__tests__/index.js index b868f89b5a..68c5ce8182 100644 --- a/lib/rules/property-allowed-list/__tests__/index.js +++ b/lib/rules/property-allowed-list/__tests__/index.js @@ -20,7 +20,7 @@ testRule({ testRule({ ruleName, - config: [[]], + config: [], reject: [ { @@ -95,7 +95,7 @@ testRule({ testRule({ ruleName, - config: [['/^background/']], + config: '/^background/', accept: [ { @@ -131,7 +131,7 @@ testRule({ testRule({ ruleName, - config: [[/^background/]], + config: /^background/, accept: [ { diff --git a/lib/rules/property-allowed-list/index.js b/lib/rules/property-allowed-list/index.js index 4312dcf339..3cd1a2d764 100644 --- a/lib/rules/property-allowed-list/index.js +++ b/lib/rules/property-allowed-list/index.js @@ -19,7 +19,7 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/property-allowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/property-disallowed-list/README.md b/lib/rules/property-disallowed-list/README.md index 9119a62cf0..e438c61834 100644 --- a/lib/rules/property-disallowed-list/README.md +++ b/lib/rules/property-disallowed-list/README.md @@ -11,7 +11,7 @@ a { text-rendering: optimizeLegibility; } ## Options -`array|string`: `["array", "of", "unprefixed", /properties/ or "regex"]|"property"|"/regex/"`|/regex/ +`array|string|regex`: `["array", "of", "unprefixed", /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. diff --git a/lib/rules/property-disallowed-list/__tests__/index.js b/lib/rules/property-disallowed-list/__tests__/index.js index ff6a065fd7..644bf8e620 100644 --- a/lib/rules/property-disallowed-list/__tests__/index.js +++ b/lib/rules/property-disallowed-list/__tests__/index.js @@ -17,7 +17,7 @@ testRule({ testRule({ ruleName, - config: [[]], + config: [], accept: [ { @@ -77,7 +77,7 @@ testRule({ testRule({ ruleName, - config: [['/^background/']], + config: '/^background/', accept: [ { @@ -122,7 +122,7 @@ testRule({ testRule({ ruleName, - config: [[/^background/]], + config: /^background/, accept: [ { diff --git a/lib/rules/property-disallowed-list/index.js b/lib/rules/property-disallowed-list/index.js index 39dd76a260..f4c9e5fe89 100644 --- a/lib/rules/property-disallowed-list/index.js +++ b/lib/rules/property-disallowed-list/index.js @@ -19,7 +19,7 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/property-disallowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/selector-attribute-name-disallowed-list/README.md b/lib/rules/selector-attribute-name-disallowed-list/README.md index 79d9078339..11f5098453 100644 --- a/lib/rules/selector-attribute-name-disallowed-list/README.md +++ b/lib/rules/selector-attribute-name-disallowed-list/README.md @@ -11,7 +11,7 @@ Specify a list of disallowed attribute names. ## Options -`array|string|regex`: `["array", "of", /names/ or "regex"]|"name"|/regex/` +`array|string|regex`: `["array", "of", /names/, "regex"]|"name"|"/regex/"|/regex/` Given: diff --git a/lib/rules/selector-attribute-name-disallowed-list/__tests__/index.js b/lib/rules/selector-attribute-name-disallowed-list/__tests__/index.js index 903abac35c..cdf63cadf0 100644 --- a/lib/rules/selector-attribute-name-disallowed-list/__tests__/index.js +++ b/lib/rules/selector-attribute-name-disallowed-list/__tests__/index.js @@ -67,3 +67,21 @@ testRule({ }, ], }); + +testRule({ + ruleName, + config: /^data-/, + + accept: [ + { + code: 'a[title] { }', + }, + ], + + reject: [ + { + code: 'a[data-foo="bar"] { }', + message: messages.rejected('data-foo'), + }, + ], +}); diff --git a/lib/rules/selector-attribute-name-disallowed-list/index.js b/lib/rules/selector-attribute-name-disallowed-list/index.js index 8b2c4d0619..93c9fb9ee2 100644 --- a/lib/rules/selector-attribute-name-disallowed-list/index.js +++ b/lib/rules/selector-attribute-name-disallowed-list/index.js @@ -18,13 +18,11 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/selector-attribute-name-disallowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { - const list = [primary].flat(); - return (root, result) => { const validOptions = validateOptions(result, ruleName, { - actual: list, + actual: primary, possible: [isString, isRegExp], }); @@ -45,7 +43,7 @@ const rule = (primary) => { selectorTree.walkAttributes((attributeNode) => { const attributeName = attributeNode.qualifiedAttribute; - if (!matchesStringOrRegExp(attributeName, list)) { + if (!matchesStringOrRegExp(attributeName, primary)) { return; } diff --git a/lib/rules/selector-attribute-operator-allowed-list/__tests__/index.js b/lib/rules/selector-attribute-operator-allowed-list/__tests__/index.js index 4e34462d57..14329002f7 100644 --- a/lib/rules/selector-attribute-operator-allowed-list/__tests__/index.js +++ b/lib/rules/selector-attribute-operator-allowed-list/__tests__/index.js @@ -78,7 +78,7 @@ testRule({ testRule({ ruleName, - config: ['='], + config: '=', accept: [ { diff --git a/lib/rules/selector-attribute-operator-allowed-list/index.js b/lib/rules/selector-attribute-operator-allowed-list/index.js index 7b5761c9ed..9944b74b4d 100644 --- a/lib/rules/selector-attribute-operator-allowed-list/index.js +++ b/lib/rules/selector-attribute-operator-allowed-list/index.js @@ -17,13 +17,11 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/selector-attribute-operator-allowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { - const list = [primary].flat(); - return (root, result) => { const validOptions = validateOptions(result, ruleName, { - actual: list, + actual: primary, possible: [isString], }); @@ -31,6 +29,8 @@ const rule = (primary) => { return; } + const primaryValues = [primary].flat(); + root.walkRules((ruleNode) => { if (!isStandardSyntaxRule(ruleNode)) { return; @@ -44,7 +44,7 @@ const rule = (primary) => { selectorTree.walkAttributes((attributeNode) => { const operator = attributeNode.operator; - if (!operator || (operator && list.includes(operator))) { + if (!operator || (operator && primaryValues.includes(operator))) { return; } diff --git a/lib/rules/selector-attribute-operator-disallowed-list/__tests__/index.js b/lib/rules/selector-attribute-operator-disallowed-list/__tests__/index.js index c97dea3e70..ce6036e55a 100644 --- a/lib/rules/selector-attribute-operator-disallowed-list/__tests__/index.js +++ b/lib/rules/selector-attribute-operator-disallowed-list/__tests__/index.js @@ -72,7 +72,7 @@ testRule({ testRule({ ruleName, - config: ['*='], + config: '*=', accept: [ { diff --git a/lib/rules/selector-attribute-operator-disallowed-list/index.js b/lib/rules/selector-attribute-operator-disallowed-list/index.js index b2adcf288e..9a25580bcd 100644 --- a/lib/rules/selector-attribute-operator-disallowed-list/index.js +++ b/lib/rules/selector-attribute-operator-disallowed-list/index.js @@ -17,13 +17,11 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/selector-attribute-operator-disallowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { - const list = [primary].flat(); - return (root, result) => { const validOptions = validateOptions(result, ruleName, { - actual: list, + actual: primary, possible: [isString], }); @@ -31,6 +29,8 @@ const rule = (primary) => { return; } + const primaryValues = [primary].flat(); + root.walkRules((ruleNode) => { if (!isStandardSyntaxRule(ruleNode)) { return; @@ -44,7 +44,7 @@ const rule = (primary) => { selectorTree.walkAttributes((attributeNode) => { const operator = attributeNode.operator; - if (!operator || (operator && !list.includes(operator))) { + if (!operator || (operator && !primaryValues.includes(operator))) { return; } diff --git a/lib/rules/selector-combinator-allowed-list/__tests__/index.js b/lib/rules/selector-combinator-allowed-list/__tests__/index.js index 2d07cd78c9..ed872dbcc0 100644 --- a/lib/rules/selector-combinator-allowed-list/__tests__/index.js +++ b/lib/rules/selector-combinator-allowed-list/__tests__/index.js @@ -58,7 +58,7 @@ testRule({ testRule({ ruleName, - config: ['~'], + config: '~', skipBasicChecks: true, accept: [ diff --git a/lib/rules/selector-combinator-allowed-list/index.js b/lib/rules/selector-combinator-allowed-list/index.js index ece5053cea..b2ded9cd31 100644 --- a/lib/rules/selector-combinator-allowed-list/index.js +++ b/lib/rules/selector-combinator-allowed-list/index.js @@ -18,7 +18,7 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/selector-combinator-allowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/selector-combinator-disallowed-list/__tests__/index.js b/lib/rules/selector-combinator-disallowed-list/__tests__/index.js index ad3c6e56dd..cb0353d698 100644 --- a/lib/rules/selector-combinator-disallowed-list/__tests__/index.js +++ b/lib/rules/selector-combinator-disallowed-list/__tests__/index.js @@ -64,3 +64,21 @@ testRule({ }, ], }); + +testRule({ + ruleName, + config: '>', + + accept: [ + { + code: 'a {}', + }, + ], + + reject: [ + { + code: 'a > b {}', + message: messages.rejected('>'), + }, + ], +}); diff --git a/lib/rules/selector-combinator-disallowed-list/index.js b/lib/rules/selector-combinator-disallowed-list/index.js index a02a20f371..3e19b65e8a 100644 --- a/lib/rules/selector-combinator-disallowed-list/index.js +++ b/lib/rules/selector-combinator-disallowed-list/index.js @@ -18,7 +18,7 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/selector-combinator-disallowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/selector-disallowed-list/README.md b/lib/rules/selector-disallowed-list/README.md index d328e3dbff..ba430d5060 100644 --- a/lib/rules/selector-disallowed-list/README.md +++ b/lib/rules/selector-disallowed-list/README.md @@ -11,7 +11,7 @@ Specify a list of disallowed selectors. ## Options -`array|string|regexp`: `["array", "of", "selectors", /or/, "/regex/"]|"selector"|"/regex/"` +`array|string|regexp`: `["array", "of", "selectors", /or/, "/regex/"]|"selector"|"/regex/"|/regex/` If a string is surrounded with `"/"` (e.g. `"/\.foo/"`), it is interpreted as a regular expression. diff --git a/lib/rules/selector-disallowed-list/__tests__/index.js b/lib/rules/selector-disallowed-list/__tests__/index.js index c78f6830aa..11282ef2a4 100644 --- a/lib/rules/selector-disallowed-list/__tests__/index.js +++ b/lib/rules/selector-disallowed-list/__tests__/index.js @@ -60,7 +60,7 @@ testRule({ testRule({ ruleName, - config: [/\.foo[^>]*>.*\.bar/], + config: /\.foo[^>]*>.*\.bar/, accept: [ { diff --git a/lib/rules/selector-disallowed-list/index.js b/lib/rules/selector-disallowed-list/index.js index bd64407730..b075b2800d 100644 --- a/lib/rules/selector-disallowed-list/index.js +++ b/lib/rules/selector-disallowed-list/index.js @@ -17,13 +17,11 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/selector-disallowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { - const list = [primary].flat(); - return (root, result) => { const validOptions = validateOptions(result, ruleName, { - actual: list, + actual: primary, possible: [isString, isRegExp], }); @@ -38,7 +36,7 @@ const rule = (primary) => { const selector = ruleNode.selector; - if (!matchesStringOrRegExp(selector, list)) { + if (!matchesStringOrRegExp(selector, primary)) { return; } diff --git a/lib/rules/selector-pseudo-class-allowed-list/README.md b/lib/rules/selector-pseudo-class-allowed-list/README.md index 908116b66c..cb5a3bdc19 100644 --- a/lib/rules/selector-pseudo-class-allowed-list/README.md +++ b/lib/rules/selector-pseudo-class-allowed-list/README.md @@ -13,7 +13,7 @@ This rule ignores selectors that use variable interpolation e.g. `:#{$variable} ## Options -`array|string|regex`: `["array", "of", "unprefixed", /pseudo-classes/ or "/regex/"]|"pseudo-class"|/regex/` +`array|string|regex`: `["array", "of", "unprefixed", /pseudo-classes/, "/regex/"]|"pseudo-class"|"/regex/"|/regex/` If a string is surrounded with `"/"` (e.g. `"/^nth-/"`), it is interpreted as a regular expression. This allows, for example, easy targeting of shorthands: `/^nth-/` will match `nth-child`, `nth-last-child`, `nth-of-type`, etc. diff --git a/lib/rules/selector-pseudo-class-allowed-list/__tests__/index.js b/lib/rules/selector-pseudo-class-allowed-list/__tests__/index.js index 995058d411..a659f7e259 100644 --- a/lib/rules/selector-pseudo-class-allowed-list/__tests__/index.js +++ b/lib/rules/selector-pseudo-class-allowed-list/__tests__/index.js @@ -107,7 +107,7 @@ testRule({ testRule({ ruleName, - config: [['/^nth/']], + config: '/^nth/', skipBasicChecks: true, accept: [ @@ -134,7 +134,7 @@ testRule({ testRule({ ruleName, - config: [[/^nth/]], + config: /^nth/, skipBasicChecks: true, accept: [ diff --git a/lib/rules/selector-pseudo-class-allowed-list/index.js b/lib/rules/selector-pseudo-class-allowed-list/index.js index a7685cbfd1..23f4d1cbb8 100644 --- a/lib/rules/selector-pseudo-class-allowed-list/index.js +++ b/lib/rules/selector-pseudo-class-allowed-list/index.js @@ -19,7 +19,7 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/selector-pseudo-class-allowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/selector-pseudo-class-disallowed-list/README.md b/lib/rules/selector-pseudo-class-disallowed-list/README.md index 01142df60a..c3945579df 100644 --- a/lib/rules/selector-pseudo-class-disallowed-list/README.md +++ b/lib/rules/selector-pseudo-class-disallowed-list/README.md @@ -13,7 +13,7 @@ This rule ignores selectors that use variable interpolation e.g. `:#{$variable} ## Options -`array|string|regex`: `["array", "of", "unprefixed", /pseudo-classes/ or "/regex/"]|"pseudo-class"|/regex/` +`array|string|regex`: `["array", "of", "unprefixed", /pseudo-classes/, "/regex/"]|"pseudo-class"|"/regex/"|/regex/` If a string is surrounded with `"/"` (e.g. `"/^nth-/"`), it is interpreted as a regular expression. This allows, for example, easy targeting of shorthands: `/^nth-/` will match `nth-child`, `nth-last-child`, `nth-of-type`, etc. diff --git a/lib/rules/selector-pseudo-class-disallowed-list/__tests__/index.js b/lib/rules/selector-pseudo-class-disallowed-list/__tests__/index.js index b067a84f1b..bb860e7186 100644 --- a/lib/rules/selector-pseudo-class-disallowed-list/__tests__/index.js +++ b/lib/rules/selector-pseudo-class-disallowed-list/__tests__/index.js @@ -98,7 +98,7 @@ testRule({ testRule({ ruleName, - config: [['/^last/']], + config: '/^last/', skipBasicChecks: true, accept: [ @@ -131,7 +131,7 @@ testRule({ testRule({ ruleName, - config: [[/^last/]], + config: /^last/, skipBasicChecks: true, accept: [ @@ -152,7 +152,7 @@ testRule({ testRule({ ruleName, - config: [[/(not|matches|has)/]], + config: [/(not|matches|has)/], skipBasicChecks: true, accept: [ diff --git a/lib/rules/selector-pseudo-class-disallowed-list/index.js b/lib/rules/selector-pseudo-class-disallowed-list/index.js index 85a13141ae..994547b83d 100644 --- a/lib/rules/selector-pseudo-class-disallowed-list/index.js +++ b/lib/rules/selector-pseudo-class-disallowed-list/index.js @@ -19,7 +19,7 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/selector-pseudo-class-disallowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/selector-pseudo-element-allowed-list/README.md b/lib/rules/selector-pseudo-element-allowed-list/README.md index 84630f6c64..34c166ed68 100644 --- a/lib/rules/selector-pseudo-element-allowed-list/README.md +++ b/lib/rules/selector-pseudo-element-allowed-list/README.md @@ -16,7 +16,7 @@ This rule ignores: ## Options -`array|string|regex`: `["array", "of", "unprefixed", "pseudo-elements" or "regex"]|"pseudo-element"|/regex/` +`array|string|regex`: `["array", "of", "unprefixed", /pseudo-elements/, "/regex/"]|"pseudo-element"|"/regex/"|/regex/` Given: diff --git a/lib/rules/selector-pseudo-element-allowed-list/index.js b/lib/rules/selector-pseudo-element-allowed-list/index.js index c3ac82850f..7221e87360 100644 --- a/lib/rules/selector-pseudo-element-allowed-list/index.js +++ b/lib/rules/selector-pseudo-element-allowed-list/index.js @@ -19,7 +19,7 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/selector-pseudo-element-allowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/selector-pseudo-element-disallowed-list/README.md b/lib/rules/selector-pseudo-element-disallowed-list/README.md index c4dde13422..b38f2e56b7 100644 --- a/lib/rules/selector-pseudo-element-disallowed-list/README.md +++ b/lib/rules/selector-pseudo-element-disallowed-list/README.md @@ -16,7 +16,7 @@ This rule ignores: ## Options -`array|string|regex`: `["array", "of", "unprefixed", "pseudo-elements" or "regex"]|"pseudo-element"|/regex/` +`array|string|regex`: `["array", "of", "unprefixed", /pseudo-elements/, "/regex/"]|"pseudo-element"|"/regex/"|/regex/` Given: diff --git a/lib/rules/selector-pseudo-element-disallowed-list/__tests__/index.js b/lib/rules/selector-pseudo-element-disallowed-list/__tests__/index.js index 92c0b32a1b..192b3f7db3 100644 --- a/lib/rules/selector-pseudo-element-disallowed-list/__tests__/index.js +++ b/lib/rules/selector-pseudo-element-disallowed-list/__tests__/index.js @@ -85,7 +85,7 @@ testRule({ testRule({ ruleName, - config: ['before'], + config: 'before', skipBasicChecks: true, customSyntax: 'postcss-scss', diff --git a/lib/rules/selector-pseudo-element-disallowed-list/index.js b/lib/rules/selector-pseudo-element-disallowed-list/index.js index 1bf3da8942..a2b8afaa62 100644 --- a/lib/rules/selector-pseudo-element-disallowed-list/index.js +++ b/lib/rules/selector-pseudo-element-disallowed-list/index.js @@ -19,7 +19,7 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/selector-pseudo-element-disallowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule>} */ const rule = (primary) => { return (root, result) => { const validOptions = validateOptions(result, ruleName, { diff --git a/lib/rules/unit-allowed-list/index.js b/lib/rules/unit-allowed-list/index.js index d5416d48b3..4161962746 100644 --- a/lib/rules/unit-allowed-list/index.js +++ b/lib/rules/unit-allowed-list/index.js @@ -21,16 +21,14 @@ const meta = { url: 'https://stylelint.io/user-guide/rules/list/unit-allowed-list', }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { - const list = [primary].flat(); - return (root, result) => { const validOptions = validateOptions( result, ruleName, { - actual: list, + actual: primary, possible: [isString], }, { @@ -47,6 +45,8 @@ const rule = (primary, secondaryOptions) => { return; } + const primaryValues = [primary].flat(); + /** * @template {import('postcss').AtRule | import('postcss').Declaration} T * @param {T} node @@ -74,7 +74,7 @@ const rule = (primary, secondaryOptions) => { const unit = getUnitFromValueNode(valueNode); - if (!unit || (unit && list.includes(unit.toLowerCase()))) { + if (!unit || (unit && primaryValues.includes(unit.toLowerCase()))) { return; } diff --git a/lib/rules/unit-disallowed-list/index.js b/lib/rules/unit-disallowed-list/index.js index 1e81e77b4c..e02489445d 100644 --- a/lib/rules/unit-disallowed-list/index.js +++ b/lib/rules/unit-disallowed-list/index.js @@ -37,16 +37,14 @@ const getMediaFeatureName = (mediaFeatureNode) => { return match ? match[1] : undefined; }; -/** @type {import('stylelint').Rule} */ +/** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions) => { - const list = [primary].flat(); - return (root, result) => { const validOptions = validateOptions( result, ruleName, { - actual: list, + actual: primary, possible: [isString], }, { @@ -63,6 +61,8 @@ const rule = (primary, secondaryOptions) => { return; } + const primaryValues = [primary].flat(); + /** * @param {import('postcss').Node} node * @param {number} nodeIndex @@ -75,7 +75,7 @@ const rule = (primary, secondaryOptions) => { const unit = getUnitFromValueNode(valueNode); // There is not unit or it is not configured as a problem - if (!unit || (unit && !list.includes(unit.toLowerCase()))) { + if (!unit || (unit && !primaryValues.includes(unit.toLowerCase()))) { return; } diff --git a/lib/utils/containsString.js b/lib/utils/containsString.js index 4ef1f3fd61..34db7d899f 100644 --- a/lib/utils/containsString.js +++ b/lib/utils/containsString.js @@ -11,9 +11,9 @@ const { isString } = require('./validateTypes'); * Any strings starting and ending with `/` are ignored. Use the * matchesStringOrRegExp() util to match regexes. * + * @template {unknown} T * @param {string} input - * @param {string | string[]} comparison - * + * @param {T | T[]} comparison * @returns {ReturnValue} */ module.exports = function containsString(input, comparison) { @@ -33,10 +33,8 @@ module.exports = function containsString(input, comparison) { }; /** - * * @param {string} value - * @param {string} comparison - * + * @param {unknown} comparison * @returns {ReturnValue} */ function testAgainstString(value, comparison) {