Skip to content

fix: handle var() and env() in no-invalid-at-rules - #570

Merged
Pixel998 merged 1 commit into
mainfrom
fix/no-invalid-at-rules-var-env
Sep 22, 2026
Merged

Pixel998 merged 1 commit into
mainfrom
fix/no-invalid-at-rules-var-env

Conversation

@Pixel998

@Pixel998 Pixel998 commented Sep 19, 2026 •

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 did you do?

/* eslint css/no-invalid-at-rules: "error" */

@supports (padding: env(safe-area-inset-top)) {
	body {
		padding-top: env(safe-area-inset-top);
	}
}

What did you expect to happen?

No lint error. The prelude is valid, and the lexer does not support matching values containing env() or var(), so the rule should skip them, as no-invalid-properties already does for env().

What actually happened?

The rule crashed:

TypeError: Cannot read properties of null (reading '1')

What is the purpose of this pull request?

This PR makes no-invalid-at-rules skip preludes and descriptor values containing var() or env(), so they no longer crash the rule or get reported as unknown descriptors.

What changes did you make? (Give an overview)

  • no-invalid-at-rules now returns early when the lexer reports it cannot match a prelude or descriptor value containing var() or env().
  • Replaced isEnvMatchError, which compared CSSTree's message text and only covered env(), with isUnsupportedMatchingTreeError, which checks the error's name and covers both functions. no-invalid-properties now uses it.

Related Issues

refs #532 (its @supports env(safe-area-inset-top) {} test case crashes without this fix)

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

Summary by CodeRabbit

  • Bug Fixes

    • CSS validation now correctly handles unresolved var() and user-agent env() values in at-rule conditions and descriptors without reporting false errors.
    • Genuine syntax and other lexer errors continue to be reported as before.
  • Tests

    • Added coverage for var() and env() usage in @supports conditions and @page descriptors.

@eslint-github-bot eslint-github-bot Bot added the bug Something isn't working label Sep 19, 2026
@github-project-automation github-project-automation Bot moved this to Needs Triage in Triage Sep 19, 2026
@coderabbitai

coderabbitai Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: dafd6a6a-92fe-4917-b7b8-025702706f1f

📥 Commits

Reviewing files that changed from the base of the PR and between 4b51c9e and 77250c3.

📒 Files selected for processing (4)
  • src/rules/no-invalid-at-rules.js
  • src/rules/no-invalid-properties.js
  • src/util.js
  • tests/rules/no-invalid-at-rules.test.js

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The change replaces env()-specific lexer error detection with UnsupportedMatchingTree detection. At-rule and property validation now skip unresolved var() and env() values. Tests cover these at-rule cases.

Changes

Unsupported matching-tree handling

Layer / File(s) Summary
Unsupported matching-tree predicate
src/util.js
The utility detects UnsupportedMatchingTree errors by name and updates its type annotation.
Rule validation and coverage
src/rules/no-invalid-at-rules.js, src/rules/no-invalid-properties.js, tests/rules/no-invalid-at-rules.test.js
The rules skip unsupported matching-tree errors for unresolved var() and env() values. Tests add valid @supports and @page cases.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: lumirlumir

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: handling var() and env() in no-invalid-at-rules.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Pixel998 Pixel998 mentioned this pull request Sep 19, 2026
2 of 3 tasks

@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. Leaving open for others to review.

@DMartens DMartens moved this from Needs Triage to Merge Candidates in Triage Sep 19, 2026
@DMartens DMartens added the accepted There is consensus among the team that this change meets the criteria for inclusion label Sep 19, 2026
@Pixel998
Pixel998 merged commit 75050c3 into main Sep 22, 2026
39 checks passed
@Pixel998
Pixel998 deleted the fix/no-invalid-at-rules-var-env branch September 22, 2026 10:01
@github-project-automation github-project-automation Bot moved this from Merge Candidates to Complete in Triage Sep 22, 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

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

2 participants