From d8f2d9c44bd2cd2fb8084d03326698c4d9f0370d Mon Sep 17 00:00:00 2001 From: kimulaco <11986753+kimulaco@users.noreply.github.com> Date: Mon, 12 Sep 2022 03:27:13 +0900 Subject: [PATCH] Fix false positives for interpolation and shorthand in `font-family-name-quotes` (#6335) --- .changeset/famous-cobras-clean.md | 5 +++ .../__tests__/index.js | 31 +++++++++++++++++++ lib/rules/font-family-name-quotes/index.js | 8 ++--- 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 .changeset/famous-cobras-clean.md diff --git a/.changeset/famous-cobras-clean.md b/.changeset/famous-cobras-clean.md new file mode 100644 index 0000000000..bb52239a8c --- /dev/null +++ b/.changeset/famous-cobras-clean.md @@ -0,0 +1,5 @@ +--- +"stylelint": patch +--- + +Fixed: `font-family-name-quotes` false positives for interpolation and shorthand diff --git a/lib/rules/font-family-name-quotes/__tests__/index.js b/lib/rules/font-family-name-quotes/__tests__/index.js index 190e8a77ae..648fa45e13 100644 --- a/lib/rules/font-family-name-quotes/__tests__/index.js +++ b/lib/rules/font-family-name-quotes/__tests__/index.js @@ -25,6 +25,13 @@ const variablePositiveTests = [ }, ]; +const scssPositiveTests = [ + { + code: 'a { font: #{customFunc($some-length)} "Times", "Arial"; }', + description: 'ignores Sass function with interpolation', + }, +]; + testRule({ ruleName, config: ['always-unless-keyword'], @@ -203,6 +210,14 @@ testRule({ ], }); +testRule({ + ruleName, + customSyntax: 'postcss-scss', + config: ['always-unless-keyword'], + + accept: [...scssPositiveTests], +}); + testRule({ ruleName, config: ['always-where-recommended'], @@ -378,6 +393,14 @@ testRule({ ], }); +testRule({ + ruleName, + customSyntax: 'postcss-scss', + config: ['always-where-recommended'], + + accept: [...scssPositiveTests], +}); + testRule({ ruleName, config: ['always-where-required'], @@ -503,6 +526,14 @@ testRule({ ], }); +testRule({ + ruleName, + customSyntax: 'postcss-scss', + config: ['always-where-required'], + + accept: [...scssPositiveTests], +}); + testRule({ ruleName, config: ['always-unless-keyword'], diff --git a/lib/rules/font-family-name-quotes/index.js b/lib/rules/font-family-name-quotes/index.js index d54f49bbc1..0e0bf8980e 100644 --- a/lib/rules/font-family-name-quotes/index.js +++ b/lib/rules/font-family-name-quotes/index.js @@ -141,6 +141,10 @@ const rule = (primary, _secondary, context) => { } root.walkDecls(/^font(-family)?$/i, (decl) => { + if (!isStandardSyntaxValue(decl.value)) { + return; + } + let fontFamilyNodes = makeMutableFontFamilies(findFontFamily(decl.value), decl); if (fontFamilyNodes.length === 0) { @@ -159,10 +163,6 @@ const rule = (primary, _secondary, context) => { function checkFamilyName(fontFamilyNode, decl) { const { name: family, rawName: rawFamily, hasQuotes } = fontFamilyNode; - if (!isStandardSyntaxValue(rawFamily)) { - return; - } - if (isVariable(rawFamily)) { return; }