Skip to content

Commit

Permalink
Fix false positives for interpolation and shorthand in `font-family-n…
Browse files Browse the repository at this point in the history
…ame-quotes` (#6335)
  • Loading branch information
kimulaco committed Sep 11, 2022
1 parent 3d48df4 commit d8f2d9c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-cobras-clean.md
@@ -0,0 +1,5 @@
---
"stylelint": patch
---

Fixed: `font-family-name-quotes` false positives for interpolation and shorthand
31 changes: 31 additions & 0 deletions lib/rules/font-family-name-quotes/__tests__/index.js
Expand Up @@ -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'],
Expand Down Expand Up @@ -203,6 +210,14 @@ testRule({
],
});

testRule({
ruleName,
customSyntax: 'postcss-scss',
config: ['always-unless-keyword'],

accept: [...scssPositiveTests],
});

testRule({
ruleName,
config: ['always-where-recommended'],
Expand Down Expand Up @@ -378,6 +393,14 @@ testRule({
],
});

testRule({
ruleName,
customSyntax: 'postcss-scss',
config: ['always-where-recommended'],

accept: [...scssPositiveTests],
});

testRule({
ruleName,
config: ['always-where-required'],
Expand Down Expand Up @@ -503,6 +526,14 @@ testRule({
],
});

testRule({
ruleName,
customSyntax: 'postcss-scss',
config: ['always-where-required'],

accept: [...scssPositiveTests],
});

testRule({
ruleName,
config: ['always-unless-keyword'],
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/font-family-name-quotes/index.js
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down

0 comments on commit d8f2d9c

Please sign in to comment.