Skip to content

Commit f6d5055

Browse files
authored
Refactor to commonize regex patterns (#8272)
1 parent a80cdf6 commit f6d5055

File tree

53 files changed

+181
-74
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+181
-74
lines changed

lib/rules/at-rule-descriptor-no-unknown/index.cjs

Lines changed: 2 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/rules/at-rule-descriptor-no-unknown/index.mjs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import { lexer } from 'css-tree';
22

3+
import { atRuleRegexes } from '../../utils/regexes.mjs';
34
import isStandardSyntaxAtRule from '../../utils/isStandardSyntaxAtRule.mjs';
45
import isStandardSyntaxDeclaration from '../../utils/isStandardSyntaxDeclaration.mjs';
5-
import { nestingSupportedAtKeywords } from '../../reference/atKeywords.mjs';
66
import report from '../../utils/report.mjs';
77
import ruleMessages from '../../utils/ruleMessages.mjs';
88
import validateOptions from '../../utils/validateOptions.mjs';
99

10-
const UNSUPPORTED_NESTING_REGEX = new RegExp(
11-
`^((?!${[...nestingSupportedAtKeywords.values()].join('|')}).)*$`,
12-
'i',
13-
);
14-
1510
const ruleName = 'at-rule-descriptor-no-unknown';
1611

1712
const messages = ruleMessages(ruleName, {
@@ -32,7 +27,7 @@ const rule = (primary) => {
3227
return;
3328
}
3429

35-
root.walkAtRules(UNSUPPORTED_NESTING_REGEX, (atRule) => {
30+
root.walkAtRules(atRuleRegexes.unsupportedNesting, (atRule) => {
3631
if (!isStandardSyntaxAtRule(atRule)) return;
3732

3833
atRule.walkDecls((decl) => {

lib/rules/at-rule-descriptor-value-no-unknown/index.cjs

Lines changed: 2 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/rules/at-rule-descriptor-value-no-unknown/index.mjs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import { lexer } from 'css-tree';
22

3+
import { atRuleRegexes } from '../../utils/regexes.mjs';
34
import { declarationValueIndex } from '../../utils/nodeFieldIndices.mjs';
45
import isStandardSyntaxAtRule from '../../utils/isStandardSyntaxAtRule.mjs';
56
import isStandardSyntaxDeclaration from '../../utils/isStandardSyntaxDeclaration.mjs';
6-
import { nestingSupportedAtKeywords } from '../../reference/atKeywords.mjs';
77
import report from '../../utils/report.mjs';
88
import ruleMessages from '../../utils/ruleMessages.mjs';
99
import validateOptions from '../../utils/validateOptions.mjs';
1010

11-
const UNSUPPORTED_NESTING_REGEX = new RegExp(
12-
`^((?!${[...nestingSupportedAtKeywords.values()].join('|')}).)*$`,
13-
'i',
14-
);
15-
1611
const ruleName = 'at-rule-descriptor-value-no-unknown';
1712

1813
const messages = ruleMessages(ruleName, {
@@ -33,7 +28,7 @@ const rule = (primary) => {
3328
return;
3429
}
3530

36-
root.walkAtRules(UNSUPPORTED_NESTING_REGEX, (atRule) => {
31+
root.walkAtRules(atRuleRegexes.unsupportedNesting, (atRule) => {
3732
if (!isStandardSyntaxAtRule(atRule)) return;
3833

3934
atRule.walkDecls((decl) => {

lib/rules/custom-property-no-missing-var-function/index.cjs

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/rules/custom-property-no-missing-var-function/index.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import valueParser from 'postcss-value-parser';
22

3+
import { atRuleRegexes } from '../../utils/regexes.mjs';
34
import { declarationValueIndex } from '../../utils/nodeFieldIndices.mjs';
45
import isVarFunction from '../../utils/isVarFunction.mjs';
56
import report from '../../utils/report.mjs';
@@ -50,7 +51,7 @@ const rule = (primary) => {
5051
/** @type {Set<string>} */
5152
const knownCustomProperties = new Set();
5253

53-
root.walkAtRules(/^property$/i, ({ params }) => {
54+
root.walkAtRules(atRuleRegexes.property, ({ params }) => {
5455
knownCustomProperties.add(params);
5556
});
5657

lib/rules/declaration-property-value-no-unknown/index.cjs

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/rules/declaration-property-value-no-unknown/index.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { find, fork, parse, string } from 'css-tree';
22

33
import { isRegExp, isString } from '../../utils/validateTypes.mjs';
4+
import { atRuleRegexes } from '../../utils/regexes.mjs';
45
import { declarationValueIndex } from '../../utils/nodeFieldIndices.mjs';
56
import { isDeclaration } from '../../utils/typeGuards.mjs';
67

@@ -85,7 +86,7 @@ const rule = (primary, secondaryOptions) => {
8586
/** @type {Map<string, string>} */
8687
const typedCustomPropertyNames = new Map();
8788

88-
root.walkAtRules(/^property$/i, (atRule) => {
89+
root.walkAtRules(atRuleRegexes.property, (atRule) => {
8990
const propName = atRule.params.trim();
9091

9192
if (!propName || !atRule.nodes || !isCustomProperty(propName)) return;

lib/rules/import-notation/index.cjs

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/rules/import-notation/index.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import valueParser from 'postcss-value-parser';
22

33
import { atRuleParamIndex } from '../../utils/nodeFieldIndices.mjs';
4+
import { atRuleRegexes } from '../../utils/regexes.mjs';
45
import getAtRuleParams from '../../utils/getAtRuleParams.mjs';
56
import report from '../../utils/report.mjs';
67
import ruleMessages from '../../utils/ruleMessages.mjs';
@@ -41,7 +42,7 @@ const rule = (primary) => {
4142

4243
if (!validOptions) return;
4344

44-
root.walkAtRules(/^import$/i, checkAtRuleImportParams);
45+
root.walkAtRules(atRuleRegexes.import, checkAtRuleImportParams);
4546

4647
/** @param {AtRule} atRule */
4748
function checkAtRuleImportParams(atRule) {

0 commit comments

Comments
 (0)