Skip to content

fix: skip validating values containing env() in no-invalid-properties - #510

Merged
DMartens merged 5 commits into
eslint:mainfrom
minseonkkim:main
Jul 28, 2026
Merged

fix: skip validating values containing env() in no-invalid-properties#510
DMartens merged 5 commits into
eslint:mainfrom
minseonkkim:main

Conversation

@minseonkkim

Copy link
Copy Markdown
Contributor

Prerequisites checklist

AI acknowledgment

  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

What is the purpose of this pull request?

Fixes a false positive in no-invalid-properties: any declaration whose value contains env() was reported as Unknown property '...' found, even for obviously valid properties like padding-top.

What changes did you make? (Give an overview)

As noted in #509, the csstree fork bails out with a plain Error ("Matching for a tree with env() is not supported") when a value contains env(), but the rule was routing that error to the unknownProperty report.

I added an isEnvMatchError() helper to src/util.js and made the rule skip validation when that error occurs, since env() values come from the user agent and can't be validated anyway.

Unknown property names are still reported for declarations with env() values, because the lexer checks the property reference before the env() check — added an invalid test (paddin-top: env(...)) to lock that in, plus valid tests for env() alone, with a fallback, inside calc(), and in a shorthand.

Related Issues

fixes #509

Is there anything you'd like reviewers to focus on?

isEnvMatchError() matches the lexer's error by its exact message string. Let me know if there's a better way to detect this error.

@eslint-github-bot

Copy link
Copy Markdown

Hi @minseonkkim!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.

  • The length of the commit message must be less than or equal to 72

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

@minseonkkim minseonkkim changed the title fix: skip validation for values containing env() in no-invalid-properties fix: skip validating values containing env() in no-invalid-properties Jul 21, 2026
@eslint-github-bot eslint-github-bot Bot added the bug Something isn't working label Jul 21, 2026
"a { padding-top: env(safe-area-inset-top, 20px); }",
"a { padding-top: calc(env(safe-area-inset-top) + 10px); }",
"a { width: env(titlebar-area-width); }",
"a { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) 0; }",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could please add a valid test case for a declaration with multiple values but one of them is invalid (e.g. a { padding: env(safe-area-inset-top) red }) as we do not support partial validation.

@minseonkkim minseonkkim Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, good catch! Added it. I confirmed it stays valid since env() causes the whole value to skip validation.

@DMartens DMartens moved this from Needs Triage to Implementing in Triage Jul 21, 2026
@DMartens DMartens added the accepted There is consensus among the team that this change meets the criteria for inclusion label Jul 21, 2026
Comment thread src/util.js
* @returns {boolean} True if the error is the `env()` match error, false if not.
*/
export function isEnvMatchError(error) {
return error.message === "Matching for a tree with env() is not supported";

@lumirlumir lumirlumir Jul 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Non-blocking comment: relying on an internal error message seems fragile because changes in csstree could break this check. Error messages are generally not a stable API and may vary between versions.

Currently, there does not appear to be a reliable way to distinguish this unsupported env() matching case from other generic errors, so checking the message may be the most practical option for now.

In the longer term, introducing a custom error class -- similar to the existing SyntaxReferenceError and SyntaxMatchError -- or exposing a stable error code such as ERR_LEXER_ENV_MATCH_UNSUPPORTED would provide a more robust solution.

@DMartens DMartens Jul 21, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is an error only our fork of csstree throws (reference for upstream), so we could add an error code to this, but we can do this after this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@minseonkkim

If you’d like to open an issue about it, that would be welcome.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Opened eslint/csstree#141 for this. Thanks for the suggestion!

Comment thread src/rules/no-invalid-properties.js
lumirlumir
lumirlumir previously approved these changes Jul 27, 2026

@lumirlumir lumirlumir left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

Would like @DMartens to verify before merging.

@lumirlumir lumirlumir moved this from Implementing to Second Review Needed in Triage Jul 27, 2026
"main { p:first-of-type, span { color: red; } }",
],
invalid: [
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These test cases should not be the first test cases as they check for specific scenarios.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! I've moved the env() test cases (including the new var()-in-env() case) after the existing generic cases in both arrays, grouped with a comment like the other scenario-specific test groups.

@DMartens DMartens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes LGTM, thanks.

@DMartens
DMartens merged commit ffc5c32 into eslint:main Jul 28, 2026
38 checks passed
@github-project-automation github-project-automation Bot moved this from Second Review Needed to Complete in Triage Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted There is consensus among the team that this change meets the criteria for inclusion bug Something isn't working contributor pool

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

Bug: no-invalid-properties reports "Unknown property" when the value contains env()

3 participants