New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix function-no-unknown
false positives for SCSS functions with namespace
#6920
Comments
@re757575 Thanks for the report using the template. And for providing the demo! But I think the reported rule |
Sorry I didn't notice, but I haven't changed stylelint-scss (5.0.1) version. Work:stylelint: 15.6.1 Error:stylelint: 15.6.2 |
Maybe, the behavior change seems related to #6842. 🤔 The The |
Maybe related to also stylelint-scss/stylelint-scss#817 |
Definitely caused by the change in tokenizer/parser. I think the In the new parser that is handled as This test passes in testRule({
ruleName,
config: [true, { ignoreFunctions: ['color.adjust'] }],
customSyntax: 'postcss-scss',
accept: [
{
code: 'a { transform: color.adjust(1px); }',
},
],
}); Option 1 :We already have // SCSS namespace (example namespace.$variable)
if (/^.+\.\$/.test(value)) {
return false;
} Changing it to also detect name spaced function would make the error go away. Option 2 :Intercept the token stream and rewrite This would restore the old behavior but it might cause issues later if standard CSS has a use case for this token sequence. |
@romainmenke Thanks for the investigation! Let's take Option 1 as you suggest. I think a plugin should handle non-standard syntaxes as possible. |
I think this should work : // SCSS namespace (example namespace.$variable)
if (/^.+\.\$/.test(value)) {
return false;
}
// SCSS namespace (example namespace.function-name())
if (/^.+\.[-\w]+\(/.test(value)) {
return false;
} |
function-no-unknown
false positives for SCSS functions with namespace
@romainmenke Sounds good 👍🏼 I've labeled the issue as ready to implement. Please consider contributing if you have time. There are steps on how to fix a bug in a rule in the Developer guide. |
Just for reference : /**
* Convert <ident><full_stop><function> to <function> to support scss name spacing
*
* @param {Array<import('@csstools/css-tokenizer').CSSToken>} tokens
* @returns {Array<import('@csstools/css-tokenizer').CSSToken>}
*/
function normalizeTokenStream(tokens) {
for (let i = 0; i < tokens.length; i++) {
const token = tokens[0];
if (!token || token[0] !== TokenType.Ident) continue;
const tokenPlus1 = tokens[1];
if (!tokenPlus1 || tokenPlus1[0] !== TokenType.Delim || tokenPlus1[4].value !== '.') continue;
const tokenPlus2 = tokens[2];
if (!tokenPlus2 || tokenPlus2[0] !== TokenType.Function) continue;
if (!tokenPlus2) continue;
tokens.splice(i, 3, [
TokenType.Function,
token[1] + tokenPlus1[1] + tokenPlus2[1],
token[2],
tokenPlus2[3],
{
value: token[4].value + tokenPlus1[4].value + tokenPlus2[4].value,
},
]);
}
return tokens;
} |
What steps are needed to reproduce the bug?
File
Run stylelint
Will got Error: Unexpected unknown function "u.f-rem" scss/function-no-unknown
Demo
https://codesandbox.io/p/sandbox/stylelint-test-function-no-unknown-t5ylc3?file=%2Fsrc%2FApp.scss
What Stylelint configuration is needed to reproduce the bug?
How did you run Stylelint?
stylelint '**/*.{css,scss}'
Which version of Stylelint or dependencies are you using?
>= 15.6.2
What did you expect to happen?
The 15.6.1 version does not have this error, and the version after updating to 15.6.2 has an error.
Or how do I need to adjust
ignoreFunctions
?What actually happened?
Does the bug relate to non-standard syntax?
SCSS
Proposal to fix the bug
No response
The text was updated successfully, but these errors were encountered: