Skip to content

Commit

Permalink
font-family-no-missing-generic-family-keyword: allow variables
Browse files Browse the repository at this point in the history
This introduces a second parse loop through a font-family.

To avoid this, we could add an parameter to findFontFamily which
dictates whether to include variables in the result, but the function
would need to blindly include variables, without sanity checking them
(like whether a variable represents a number or something).

Fixes stylelint#4765
  • Loading branch information
srawlins committed May 27, 2020
1 parent 6cfea29 commit b6216e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Expand Up @@ -81,6 +81,9 @@ testRule({
{
code: 'a { font: namespace.$font-family; }',
},
{
code: 'a { font-family: "font", var(--font); }',
},
],

reject: [
Expand Down
Expand Up @@ -4,8 +4,10 @@

const declarationValueIndex = require('../../utils/declarationValueIndex');
const findFontFamily = require('../../utils/findFontFamily');
const isVariable = require('../../utils/isVariable');
const keywordSets = require('../../reference/keywordSets');
const optionsMatches = require('../../utils/optionsMatches');
const postcss = require('postcss');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');
Expand Down Expand Up @@ -64,6 +66,10 @@ function rule(actual, options) {
return;
}

if (postcss.list.space(decl.value).some(isVariable)) {
return;
}

if (fontFamilies.some((node) => optionsMatches(options, 'ignoreFontFamilies', node.value))) {
return;
}
Expand Down

0 comments on commit b6216e1

Please sign in to comment.