Skip to content

Commit

Permalink
better handling of function-no-unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
m4thieulavoie committed Feb 14, 2022
1 parent 2db2c94 commit 0ab582d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 9 additions & 0 deletions lib/rules/function-no-unknown/__tests__/index.js
Expand Up @@ -78,6 +78,9 @@ testRule({
{
code: 'a { transform: BAR(1px); }',
},
{
code: 'a { --primary-color: #{theme(1px)}; }',
},
],

reject: [
Expand All @@ -93,5 +96,11 @@ testRule({
line: 1,
column: 16,
},
{
code: 'a { --primary-color: #{theme-custom(1px)}; }',
message: messages.rejected('#{theme-custom'),
line: 1,
column: 22,
},
],
});
8 changes: 5 additions & 3 deletions lib/rules/function-no-unknown/index.js
Expand Up @@ -51,6 +51,8 @@ const rule = (primary, secondaryOptions) => {
const { value } = decl;

valueParser(value).walk((node) => {
const sanitizedValue = node.value.replace(/^(#\{)/g, '').replace(/\}/g, '');

if (node.type !== 'function') {
return;
}
Expand All @@ -59,15 +61,15 @@ const rule = (primary, secondaryOptions) => {
return;
}

if (isCustomFunction(node.value)) {
if (isCustomFunction(sanitizedValue)) {
return;
}

if (optionsMatches(secondaryOptions, 'ignoreFunctions', node.value)) {
if (optionsMatches(secondaryOptions, 'ignoreFunctions', sanitizedValue)) {
return;
}

if (functionsList.includes(node.value.toLowerCase())) {
if (functionsList.includes(sanitizedValue.toLowerCase())) {
return;
}

Expand Down

0 comments on commit 0ab582d

Please sign in to comment.