-
-
Notifications
You must be signed in to change notification settings - Fork 986
Fix custom-property-no-missing-var-function false positives for style query in if() function
#8813
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
Conversation
🦋 Changeset detectedLatest commit: 6caf395 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Can you also add these tests:
a {
--foo: 1;
--bar: 2;
color: if(
style(--foo: --bar): red;
else: green;
);
}After auto fix (Correct code): a {
--foo: 1;
--bar: 2;
color: if(
style(--foo: var(--bar)): red;
else: green;
);
}
a {
--foo: 1;
--color: red;
color: if(
style(--foo: 1): --color;
else: green;
);
}After auto fix (Correct code): a {
--foo: 1;
--color: red;
color: if(
style(--foo: 1): var(--color);
else: green;
);
} |
|
@otomad i have updated the pr accordingly to requested changes |
custom-property-no-missing-var-function false positives for style query in if() function
|
This PR is packaged and the instant preview is available (6caf395). View the demo website. Install it locally: npm i -D https://pkg.pr.new/stylelint@6caf395 |
jeddy3
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sajdakabir Thank you for working on this PR. Can you address the lint warnings, please?
You can use the following command to run linting locally:
npm run lint(@otomad Thanks for your review input so far. If you've time, we'd appreciate an approval from you as me and the other Stylelint members are a bit short on OSS time at the moment.)
| const { prop, value } = decl; | ||
|
|
||
| if (!value.includes('--')) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const { prop, value } = decl; | |
| if (!value.includes('--')) return; | |
| const { prop, value } = decl; | |
| if (!value.includes('--')) return; |
lib/rules/custom-property-no-missing-var-function/__tests__/index.mjs
Outdated
Show resolved
Hide resolved
lib/rules/custom-property-no-missing-var-function/__tests__/index.mjs
Outdated
Show resolved
Hide resolved
|
Sorry I have no edit permission, so I just reviewed it by adding suggested changes in the comments. |
|
@otomad thanks for the review. I’ve completed the updates please let me know if you need any other changes. |
jeddy3
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * @param {boolean} insideStyleQuery - Whether we're inside a style() query | ||
| */ | ||
| function check(node, decl) { | ||
| function check(node, decl, insideStyleQuery) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question
It seems check is never called with insideStyleQuery === true.
Hence insideStyleQuery is never set to true.
| function check(node, decl, insideStyleQuery) { | |
| function check(node, decl, insideStyleQuery = false) { |
then revert l70 and l105.
What are you planning to use passStyleQuery/insideStyleQuery for?
|
@Mouvedia i have remove unused insideStyleQuery parameter |
romainmenke
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @sajdakabir,
I've left a couple of suggestions, please take a look when you have time.
| if (!isDashedIdent(node)) return; | ||
|
|
||
| if (!knownCustomProperties.has(node.value)) return; | ||
| // Strip trailing semicolons for lookup and reporting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Strip trailing semicolons for lookup and reporting | |
| // `postcss-value-parser` incorrectly includes semicolons in word tokens. |
Maybe document why we need to do this.
| // Strip trailing semicolons that may be part of conditional syntax | ||
| const cleanValue = value.replace(/;+$/, ''); | ||
|
|
||
| return type === 'word' && cleanValue.startsWith('--'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is needed.
It didn't make sense to me to strip trailing chars, when only checking the start.
Can you revert to:
/**
* @param {Node} node
*/
function isDashedIdent({ type, value }) {
return type === 'word' && value.startsWith('--');
}|
@sajdakabir This PR includes extra files, such as |
…t CSS conditional statements
Co-authored-by: Rantetsu Inori <56647156+otomad@users.noreply.github.com>
…dex.mjs Co-authored-by: Rantetsu Inori <56647156+otomad@users.noreply.github.com>
…dex.mjs Co-authored-by: Rantetsu Inori <56647156+otomad@users.noreply.github.com>
…dex.mjs Co-authored-by: Rantetsu Inori <56647156+otomad@users.noreply.github.com>
c2bda06 to
6caf395
Compare
|
@sajdakabir Thanks for making the requested changes and for rebasing. I'll merge so that we can include this fix in the release I'm just about to start. |
| datasource | package | from | to | | ---------- | --------- | ------- | ------- | | npm | stylelint | 16.25.0 | 16.26.0 | ## [v16.26.0](https://github.com/stylelint/stylelint/blob/HEAD/CHANGELOG.md#16260---2025-11-21) It adds 1 feature and fixes 2 bugs. - Added: support for `customSyntax` with function export ([#8834](stylelint/stylelint#8834)) ([@silverwind](https://github.com/silverwind)). - Fixed: `custom-property-no-missing-var-function` false positives for style query in `if()` function ([#8813](stylelint/stylelint#8813)) ([@sajdakabir](https://github.com/sajdakabir)). - Fixed: `media-feature-range-notation` false positives for multiple queries and `except: exact-value` ([#8832](stylelint/stylelint#8832)) ([@jeddy3](https://github.com/jeddy3)).
| datasource | package | from | to | | ---------- | --------- | ------- | ------- | | npm | stylelint | 16.25.0 | 16.26.0 | ## [v16.26.0](https://github.com/stylelint/stylelint/blob/HEAD/CHANGELOG.md#16260---2025-11-21) It adds 1 feature and fixes 2 bugs. - Added: support for `customSyntax` with function export ([#8834](stylelint/stylelint#8834)) ([@silverwind](https://github.com/silverwind)). - Fixed: `custom-property-no-missing-var-function` false positives for style query in `if()` function ([#8813](stylelint/stylelint#8813)) ([@sajdakabir](https://github.com/sajdakabir)). - Fixed: `media-feature-range-notation` false positives for multiple queries and `except: exact-value` ([#8832](stylelint/stylelint#8832)) ([@jeddy3](https://github.com/jeddy3)).
Closes #8805
No; the changes special-case style() queries inside if() by threading an insideStyleQuery flag through "custom-property-no-missing-var-function" update the generated CJS bundle, and add targeted tests to cover the new behavior.