From 56813ce2eaa33c6671f018d30793ea77ad78f997 Mon Sep 17 00:00:00 2001 From: jeddy3 Date: Fri, 30 Jun 2023 10:21:52 +0100 Subject: [PATCH 1/2] Fix function-url-quotes performance --- .changeset/tender-apes-count.md | 5 +++++ lib/rules/function-url-quotes/index.js | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 .changeset/tender-apes-count.md diff --git a/.changeset/tender-apes-count.md b/.changeset/tender-apes-count.md new file mode 100644 index 0000000000..e725efc37b --- /dev/null +++ b/.changeset/tender-apes-count.md @@ -0,0 +1,5 @@ +--- +"stylelint": patch +--- + +Fixed: `function-url-quotes` performance diff --git a/lib/rules/function-url-quotes/index.js b/lib/rules/function-url-quotes/index.js index b402ba7450..aef05e3852 100644 --- a/lib/rules/function-url-quotes/index.js +++ b/lib/rules/function-url-quotes/index.js @@ -57,6 +57,8 @@ const rule = (primary, secondaryOptions, context) => { * @param {import('postcss').Declaration} decl */ function checkDeclParams(decl) { + if (!/url\(/i.test(decl.value)) return; + if (!isStandardSyntaxDeclaration(decl)) return; const value = getDeclarationValue(decl); From a50a8ddf9ddb63b76c62b543e6b60c4e99d03c6e Mon Sep 17 00:00:00 2001 From: jeddy3 Date: Fri, 30 Jun 2023 11:41:27 +0100 Subject: [PATCH 2/2] Fix regex caching --- lib/rules/function-url-quotes/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/rules/function-url-quotes/index.js b/lib/rules/function-url-quotes/index.js index aef05e3852..efe959ea44 100644 --- a/lib/rules/function-url-quotes/index.js +++ b/lib/rules/function-url-quotes/index.js @@ -24,6 +24,8 @@ const meta = { fixable: true, }; +const URL_FUNC_REGEX = /url\(/i; + /** @type {import('stylelint').Rule} */ const rule = (primary, secondaryOptions, context) => { return (root, result) => { @@ -57,7 +59,7 @@ const rule = (primary, secondaryOptions, context) => { * @param {import('postcss').Declaration} decl */ function checkDeclParams(decl) { - if (!/url\(/i.test(decl.value)) return; + if (!URL_FUNC_REGEX.test(decl.value)) return; if (!isStandardSyntaxDeclaration(decl)) return;