Skip to content

Conversation

@sajdakabir
Copy link
Contributor

Which issue, if any, is this issue related to?

Closes #8805

Is there anything in the PR that needs further explanation?

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.

@changeset-bot
Copy link

changeset-bot bot commented Oct 13, 2025

🦋 Changeset detected

Latest commit: 6caf395

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
stylelint Patch

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

@otomad
Copy link
Contributor

otomad commented Oct 13, 2025

Can you also add these tests:

  1. Error code:
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;
    );
}
  1. Error code:
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;
    );
}

@sajdakabir
Copy link
Contributor Author

@otomad i have updated the pr accordingly to requested changes

@jeddy3 jeddy3 changed the title Fix/style query no var Fix custom-property-no-missing-var-function false positives for style query in if() function Oct 14, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 20, 2025

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

Copy link
Member

@jeddy3 jeddy3 left a 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.)

Comment on lines 63 to 65
const { prop, value } = decl;

if (!value.includes('--')) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { prop, value } = decl;
if (!value.includes('--')) return;
const { prop, value } = decl;
if (!value.includes('--')) return;

@otomad
Copy link
Contributor

otomad commented Oct 20, 2025

Sorry I have no edit permission, so I just reviewed it by adding suggested changes in the comments.

@sajdakabir sajdakabir requested review from jeddy3 and otomad October 20, 2025 17:08
@sajdakabir
Copy link
Contributor Author

@otomad thanks for the review. I’ve completed the updates please let me know if you need any other changes.

@sajdakabir sajdakabir requested a review from otomad October 27, 2025 07:16
Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@otomad Thanks for the further reviews.

@sajdakabir Thanks for enacting them.

LGTM, thank you.

* @param {boolean} insideStyleQuery - Whether we're inside a style() query
*/
function check(node, decl) {
function check(node, decl, insideStyleQuery) {
Copy link
Member

@Mouvedia Mouvedia Nov 2, 2025

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.

Suggested change
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?

@sajdakabir
Copy link
Contributor Author

@Mouvedia i have remove unused insideStyleQuery parameter

@jeddy3 jeddy3 mentioned this pull request Nov 10, 2025
4 tasks
Copy link
Member

@romainmenke romainmenke left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Strip trailing semicolons for lookup and reporting
// `postcss-value-parser` incorrectly includes semicolons in word tokens.

Maybe document why we need to do this.

Comment on lines 142 to 145
// Strip trailing semicolons that may be part of conditional syntax
const cleanValue = value.replace(/;+$/, '');

return type === 'word' && cleanValue.startsWith('--');
Copy link
Member

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 sajdakabir requested a review from a team as a code owner November 17, 2025 18:08
@ybiquitous
Copy link
Member

@sajdakabir This PR includes extra files, such as .changeset/chubby-donkeys-remain.md. Can you rebase the main branch, please? 🙏🏼

sajdakabir and others added 8 commits November 21, 2025 14:18
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>
@sajdakabir sajdakabir force-pushed the fix/style-query-no-var branch from c2bda06 to 6caf395 Compare November 21, 2025 08:49
@jeddy3
Copy link
Member

jeddy3 commented Nov 21, 2025

@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.

@jeddy3 jeddy3 merged commit de3a8f0 into stylelint:main Nov 21, 2025
15 checks passed
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Nov 22, 2025
| 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)).
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Nov 22, 2025
| 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)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Fix custom-property-no-missing-var-function false positives for style query in if() function

6 participants