Skip to content

fix(parse/css): handle bogus declarations slightly more gracefully - #11321

Merged
dyc3 merged 1 commit into
mainfrom
dyc3/css-parse-declaration-bogus
Aug 13, 2026
Merged

fix(parse/css): handle bogus declarations slightly more gracefully#11321
dyc3 merged 1 commit into
mainfrom
dyc3/css-parse-declaration-bogus

Conversation

@dyc3

@dyc3 dyc3 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

This adds a CssBogusDeclaration node, and makes the parser recovery a little more graceful for declaration lists. This affects top level declaration lists, like in html style attributes.

fixes #11315

Test Plan

snapshots

Docs

@changeset-bot

changeset-bot Bot commented Aug 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3bae583

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

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc 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

@github-actions

Copy link
Copy Markdown
Contributor

✅ Organic activity

No automation signals detected in the analyzed events.

View full analysis →

This is an automated analysis by AgentScan

@github-actions github-actions Bot added A-Project Area: project A-Parser Area: parser A-Formatter Area: formatter A-Tooling Area: internal tools L-CSS Language: CSS and super languages labels Aug 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 53598 53598 0
Passed 52315 52315 0
Failed 1241 1241 0
Panics 42 42 0
Coverage 97.61% 97.61% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 38 38 0
Passed 37 37 0
Failed 1 1 0
Panics 0 0 0
Coverage 97.37% 97.37% 0.00%

markdown/commonmark

Test result main count This PR count Difference
Total 652 652 0
Passed 652 652 0
Failed 0 0 0
Panics 0 0 0
Coverage 100.00% 100.00% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5467 5467 0
Passed 1915 1915 0
Failed 3552 3552 0
Panics 0 0 0
Coverage 35.03% 35.03% 0.00%

ts/babel

Test result main count This PR count Difference
Total 676 676 0
Passed 592 592 0
Failed 84 84 0
Panics 0 0 0
Coverage 87.57% 87.57% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 18876 18876 0
Passed 13010 13010 0
Failed 5865 5865 0
Panics 1 1 0
Coverage 68.92% 68.92% 0.00%

@codspeed-hq

codspeed-hq Bot commented Aug 12, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 33 untouched benchmarks
⏩ 260 skipped benchmarks1


Comparing dyc3/css-parse-declaration-bogus (3bae583) with main (ff31f40)

Open in CodSpeed

Footnotes

  1. 260 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@dyc3
dyc3 force-pushed the dyc3/css-parse-declaration-bogus branch from 57f110a to 3bae583 Compare August 12, 2026 23:32
@dyc3
dyc3 marked this pull request as ready for review August 12, 2026 23:42
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The CSS grammar now represents malformed declarations with CssBogusDeclaration. Parser recovery recognises semicolons as declaration boundaries and continues parsing later declarations. The CSS formatter supports the new node. Tests cover malformed @font-face declarations and invalid CSS in HTML style attributes. Changesets document recovery and diagnostic reporting instead of a panic.

Suggested labels: L-HTML, A-Diagnostic

Suggested reviewers: denbezrukov, ematipico

Mergeability Score: 🟡 Moderate · up to 3bae5

This change improves recovery for invalid CSS declarations, but the current implementation can lose the declaration-specific syntax node for some invalid declarations, which may cause incorrect downstream parsing or formatting behavior. Merge should wait until that mapping is added.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: improved CSS parser handling for bogus declarations.
Description check ✅ Passed The description explains the new CssBogusDeclaration node, parser recovery changes, affected HTML style attributes, and testing.
Linked Issues check ✅ Passed The parser changes and tests address the issue by representing invalid declarations, producing diagnostics, and avoiding the reported panic.
Out of Scope Changes check ✅ Passed The changes remain within scope and support CSS recovery, syntax representation, formatting, diagnostics, tests, and release documentation.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dyc3/css-parse-declaration-bogus

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

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/biome_css_syntax/src/lib.rs`:
- Line 110: Update the AnyCssDeclaration mapping in to_bogus to add a
CSS_BOGUS_DECLARATION arm, preserving that declaration-specific bogus node when
converting invalid declarations. Keep the existing CSS_BOGUS handling for other
node kinds and ensure the mapping aligns with the CSS_BOGUS_DECLARATION case
already recognized by is_bogus.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a1c79adf-12bf-4d05-afce-2469f2bb2edb

📥 Commits

Reviewing files that changed from the base of the PR and between ff31f40 and 3bae583.

⛔ Files ignored due to path filters (10)
  • crates/biome_css_factory/src/generated/node_factory.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_css_factory/src/generated/syntax_factory.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_css_formatter/tests/specs/prettier/scss/math/3945.scss.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/error/at_rule/at_rule_keyframes/at_rule_keyframes.css.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/error/at_rule/at_rule_keyframes/at_rule_keyframes_1.css.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/error/declaration/bogus_declaration_recovery.css.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/error/tailwind/when-enabled/plugin-with-invalid-options-2.css.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_syntax/src/generated/kind.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_css_syntax/src/generated/macros.rs is excluded by !**/generated/**, !**/generated/** and included by **
  • crates/biome_css_syntax/src/generated/nodes.rs is excluded by !**/generated/**, !**/generated/** and included by **
📒 Files selected for processing (12)
  • .changeset/bright-animals-sniff.md
  • .changeset/quick-books-join.md
  • crates/biome_css_formatter/src/css/any/declaration.rs
  • crates/biome_css_formatter/src/css/bogus/bogus_declaration.rs
  • crates/biome_css_formatter/src/css/bogus/mod.rs
  • crates/biome_css_formatter/src/generated.rs
  • crates/biome_css_parser/src/syntax/declaration.rs
  • crates/biome_css_parser/tests/css_test_suite/error/declaration/bogus_declaration_recovery.css
  • crates/biome_css_syntax/src/lib.rs
  • crates/biome_service/src/file_handlers/html/parse_embedded_nodes.tests.rs
  • xtask/codegen/css.ungram
  • xtask/codegen/src/css_kinds_src.rs

matches!(
self,
CSS_BOGUS
| CSS_BOGUS_DECLARATION

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Add the declaration mapping to to_bogus.

is_bogus now recognises CSS_BOGUS_DECLARATION, but to_bogus has no AnyCssDeclaration arm. When an invalid declaration uses this conversion path, the match falls through to CSS_BOGUS. The grammar does not include CSS_BOGUS in AnyCssDeclaration, so the declaration-specific node cannot be preserved.

Proposed mapping
         match self {
+            kind if AnyCssDeclaration::can_cast(*kind) => CSS_BOGUS_DECLARATION,
             kind if AnyCssSubSelector::can_cast(*kind) => CSS_BOGUS_SUB_SELECTOR,

Based on learnings, invalid parser syntax uses or_invalid_to_bogus() and must preserve the matching bogus node kind.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
| CSS_BOGUS_DECLARATION
match self {
kind if AnyCssDeclaration::can_cast(*kind) => CSS_BOGUS_DECLARATION,
kind if AnyCssSubSelector::can_cast(*kind) => CSS_BOGUS_SUB_SELECTOR,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/biome_css_syntax/src/lib.rs` at line 110, Update the AnyCssDeclaration
mapping in to_bogus to add a CSS_BOGUS_DECLARATION arm, preserving that
declaration-specific bogus node when converting invalid declarations. Keep the
existing CSS_BOGUS handling for other node kinds and ensure the mapping aligns
with the CSS_BOGUS_DECLARATION case already recognized by is_bogus.

Source: Learnings

@dyc3
dyc3 merged commit 41386f3 into main Aug 13, 2026
34 checks passed
@dyc3
dyc3 deleted the dyc3/css-parse-declaration-bogus branch August 13, 2026 10:05
@github-actions github-actions Bot mentioned this pull request Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Formatter Area: formatter A-Parser Area: parser A-Project Area: project A-Tooling Area: internal tools L-CSS Language: CSS and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 v2.5.8 Biome panics on invalid CSS in HTML style attributes

2 participants