Skip to content

fix(css_parser): gate SCSS syntax in CSS#10456

Open
denbezrukov wants to merge 3 commits into
mainfrom
db/scss-parser-10
Open

fix(css_parser): gate SCSS syntax in CSS#10456
denbezrukov wants to merge 3 commits into
mainfrom
db/scss-parser-10

Conversation

@denbezrukov

Copy link
Copy Markdown
Contributor

Don't merge till 2.5

Summary

Adds parser coverage and SCSS feature gating for interpolation syntax that was previously parsed too permissively in plain CSS contexts.

Biome now reports SCSS-only diagnostics for CSS inputs such as:

.foo {
  #{$name}: 1px;
  margin-#{$side}: 1px;
  --#{$prop}: 10px;
}

#{$tag} {}

@media #{$query} {}
@supports (#{$name}: red) {}
@#{$rule-name} #{$value};

The SCSS parser path remains supported for the same syntax in .scss files, including value interpolation, query features, selector names, property names, keyframes, and interpolated unknown at-rules.

This PR was implemented with assistance from OpenAI Codex.

Test Plan

cargo test -p biome_css_parser

@changeset-bot

changeset-bot Bot commented May 24, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b5dbddf

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a 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-Parser Area: parser L-CSS Language: CSS and super languages labels May 24, 2026
@coderabbitai

coderabbitai Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Refactors SCSS interpolation handling: removes SCSS feature gates from detection predicates, introduces selector- and value-specific interpolation helpers, and routes SCSS-only parses through CssSyntaxFeatures::Scss.parse_exclusive_syntax with scss_only_syntax_error. Updates at-rule, declaration/block, selector, property, value and URL parsing to use the new helpers and adds test fixtures covering SCSS-exclusive forms.

Possibly related PRs

  • biomejs/biome#10421: Modifies query-feature parsing logic for SCSS interpolations in at_rule/feature.rs.
  • biomejs/biome#10181: Changes SCSS interpolation handling in media query parsing paths.
  • biomejs/biome#9529: Related work on SCSS-interpolated property/name detection and parsing.

Suggested labels

A-Tooling, L-SCSS

Suggested reviewers

  • dyc3
  • ematipico
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description is directly related to the changeset, explaining what SCSS-only syntax is now gated, providing concrete examples of affected code patterns, and confirming SCSS continues to work. It's well-documented despite being lengthy.
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.
Title check ✅ Passed The title clearly describes the main objective: gating SCSS-only syntax features in CSS contexts to prevent invalid SCSS interpolation from being accepted in plain CSS files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch db/scss-parser-10

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 and usage tips.

@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

🧹 Nitpick comments (2)
crates/biome_css_parser/tests/css_test_suite/error/property/scss_exclusive_values.css (1)

40-42: 💤 Low value

Clarify the intent of the malformed case.

The space between # and {value} breaks SCSS interpolation syntax. Is this testing:

  1. Whitespace rejection in interpolation detection?
  2. General malformed syntax error handling?
  3. Something else?

A comment explaining the test intent would help future maintainers.

🤖 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_parser/tests/css_test_suite/error/property/scss_exclusive_values.css`
around lines 40 - 42, Add a one-line comment above the .malformed-css test case
clarifying the exact intent: explicitly state whether this case is testing
"whitespace-breaking SCSS interpolation" (i.e., space between '#' and '{value}'
should cause interpolation rejection), "general malformed syntax handling"
(parser should emit a syntax error), or another behavior; reference the selector
.malformed-css and the property "color: calc(# {value});" so maintainers can
immediately see which scenario is covered.
crates/biome_css_parser/src/syntax/scss/property.rs (1)

32-39: 💤 Low value

Consider adding whitespace constraint for pattern 3.

For margin-#{$side}, the interpolation should immediately follow the identifier with no whitespace. Other similar predicates (e.g., is_nth_at_scss_selector_identifier_suffix) include !p.has_nth_preceding_whitespace(n + 1). Without it, margin- #{$side} (with space) might be detected as a valid interpolated property name when it arguably shouldn't be.

That said, if the parsing layer or lexer already handles this edge case, feel free to disregard.

♻️ Suggested fix
     // `margin-#{$side}: 1px;`
-    || (is_nth_at_identifier(p, n) && is_nth_at_scss_interpolation(p, n + 1))
+    || (is_nth_at_identifier(p, n)
+        && !p.has_nth_preceding_whitespace(n + 1)
+        && is_nth_at_scss_interpolation(p, n + 1))
🤖 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_parser/src/syntax/scss/property.rs` around lines 32 - 39,
The third branch of is_nth_at_scss_interpolated_property_name can falsely match
"margin- #{$side}" because it doesn't ensure the interpolation immediately
follows the identifier; update the predicate in
is_nth_at_scss_interpolated_property_name to also require that there is no
preceding whitespace before the interpolation by adding a check like
!p.has_nth_preceding_whitespace(n + 1) alongside the existing
is_nth_at_identifier(p, n) && is_nth_at_scss_interpolation(p, n + 1) so the
pattern only matches when the interpolation directly follows the identifier.
🤖 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_parser/tests/css_test_suite/error/at_rule/scss_exclusive_values.css`:
- Around line 65-87: Add positive SCSS fixtures mirroring the negative cases so
the parser has bidirectional coverage: update
ok/scss/at-rule/exclusive-value-gates.scss to include valid SCSS examples for
interpolated media queries and ranges (e.g. `@media` #{$query} { ... }, `@media`
(#{$min} <= width) { ... }, `@media` (#{$min} <= width <= #{$max}) { ... }),
keyframe percentages using interpolation (e.g. `@keyframes` loader { #{$i}% { ...
} }), and interpolated at-rule names/blocks (e.g. @#{$rule-name} #{$value}; and
@#{$block-rule} #{$value} { color: red; }) so the ok fixture matches the error
fixture constructs.

---

Nitpick comments:
In `@crates/biome_css_parser/src/syntax/scss/property.rs`:
- Around line 32-39: The third branch of
is_nth_at_scss_interpolated_property_name can falsely match "margin- #{$side}"
because it doesn't ensure the interpolation immediately follows the identifier;
update the predicate in is_nth_at_scss_interpolated_property_name to also
require that there is no preceding whitespace before the interpolation by adding
a check like !p.has_nth_preceding_whitespace(n + 1) alongside the existing
is_nth_at_identifier(p, n) && is_nth_at_scss_interpolation(p, n + 1) so the
pattern only matches when the interpolation directly follows the identifier.

In
`@crates/biome_css_parser/tests/css_test_suite/error/property/scss_exclusive_values.css`:
- Around line 40-42: Add a one-line comment above the .malformed-css test case
clarifying the exact intent: explicitly state whether this case is testing
"whitespace-breaking SCSS interpolation" (i.e., space between '#' and '{value}'
should cause interpolation rejection), "general malformed syntax handling"
(parser should emit a syntax error), or another behavior; reference the selector
.malformed-css and the property "color: calc(# {value});" so maintainers can
immediately see which scenario is covered.
🪄 Autofix (Beta)

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: 7579ed28-f33a-446c-8df0-c2eaec91f5bf

📥 Commits

Reviewing files that changed from the base of the PR and between 001f94f and 19ee293.

⛔ Files ignored due to path filters (7)
  • crates/biome_css_parser/tests/css_test_suite/error/at_rule/scss_exclusive_values.css.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/error/property/scss_exclusive_values.css.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/error/scss/declaration/scss-variable-declaration-in-css.css.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/error/selector/scss_exclusive_values.css.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/ok/at_rule/scss-named-at-rules-unknown.css.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/exclusive-value-gates.scss.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/value/exclusive-value-gates.scss.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (45)
  • crates/biome_css_parser/src/syntax/at_rule/feature.rs
  • crates/biome_css_parser/src/syntax/at_rule/keyframes.rs
  • crates/biome_css_parser/src/syntax/at_rule/media.rs
  • crates/biome_css_parser/src/syntax/at_rule/mod.rs
  • crates/biome_css_parser/src/syntax/at_rule/supports/mod.rs
  • crates/biome_css_parser/src/syntax/at_rule/unknown.rs
  • crates/biome_css_parser/src/syntax/block/declaration_or_at_rule_list_block.rs
  • crates/biome_css_parser/src/syntax/block/declaration_or_rule_list_block.rs
  • crates/biome_css_parser/src/syntax/declaration.rs
  • crates/biome_css_parser/src/syntax/mod.rs
  • crates/biome_css_parser/src/syntax/property/mod.rs
  • crates/biome_css_parser/src/syntax/scss/at_rule/keyframes.rs
  • crates/biome_css_parser/src/syntax/scss/declaration/nesting.rs
  • crates/biome_css_parser/src/syntax/scss/expression/interpolation.rs
  • crates/biome_css_parser/src/syntax/scss/expression/operand.rs
  • crates/biome_css_parser/src/syntax/scss/identifiers/interpolated_dashed.rs
  • crates/biome_css_parser/src/syntax/scss/identifiers/interpolated_identifier.rs
  • crates/biome_css_parser/src/syntax/scss/identifiers/interpolated_regular.rs
  • crates/biome_css_parser/src/syntax/scss/identifiers/interpolated_selector.rs
  • crates/biome_css_parser/src/syntax/scss/identifiers/mod.rs
  • crates/biome_css_parser/src/syntax/scss/mod.rs
  • crates/biome_css_parser/src/syntax/scss/property.rs
  • crates/biome_css_parser/src/syntax/scss/selector/attribute.rs
  • crates/biome_css_parser/src/syntax/scss/selector/interpolated_pseudo.rs
  • crates/biome_css_parser/src/syntax/scss/selector/parent_selector.rs
  • crates/biome_css_parser/src/syntax/scss/selector/placeholder.rs
  • crates/biome_css_parser/src/syntax/scss/selector/pseudo_class_nth.rs
  • crates/biome_css_parser/src/syntax/scss/value/any.rs
  • crates/biome_css_parser/src/syntax/scss/value/interpolated_string.rs
  • crates/biome_css_parser/src/syntax/scss/value/interpolated_value.rs
  • crates/biome_css_parser/src/syntax/scss/value/mod.rs
  • crates/biome_css_parser/src/syntax/scss/value/parent_selector.rs
  • crates/biome_css_parser/src/syntax/selector/attribute.rs
  • crates/biome_css_parser/src/syntax/selector/mod.rs
  • crates/biome_css_parser/src/syntax/selector/nested_selector.rs
  • crates/biome_css_parser/src/syntax/selector/pseudo_class/function_nth.rs
  • crates/biome_css_parser/src/syntax/selector/pseudo_class/function_value_list.rs
  • crates/biome_css_parser/src/syntax/value/url.rs
  • crates/biome_css_parser/tests/css_test_suite/error/at_rule/scss_exclusive_values.css
  • crates/biome_css_parser/tests/css_test_suite/error/property/scss_exclusive_values.css
  • crates/biome_css_parser/tests/css_test_suite/error/scss/declaration/scss-variable-declaration-in-css.css
  • crates/biome_css_parser/tests/css_test_suite/error/selector/scss_exclusive_values.css
  • crates/biome_css_parser/tests/css_test_suite/ok/at_rule/scss-named-at-rules-unknown.css
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/exclusive-value-gates.scss
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/value/exclusive-value-gates.scss

Comment on lines +65 to +87
@media #{$query} {
.media-query {}
}

@media (#{$min} <= width) {
.media-reverse-range {}
}

@media (#{$min} <= width <= #{$max}) {
.media-interval-range {}
}

@keyframes loader {
#{$i}% {
opacity: 1;
}
}

@#{$rule-name} #{$value};

@#{$block-rule} #{$value} {
color: red;
}

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Test coverage gap: missing SCSS positive cases.

These SCSS-exclusive features (interpolated media query, range queries, keyframes percentage, and interpolated at-rule names) lack corresponding positive test cases in ok/scss/at-rule/exclusive-value-gates.scss. If these are valid SCSS syntax, please add them to the SCSS ok fixture to ensure bidirectional coverage.

🧰 Tools
🪛 Stylelint (17.11.1)

[error] 66-66: Empty block (block-no-empty)

(block-no-empty)


[error] 70-70: Empty block (block-no-empty)

(block-no-empty)


[error] 74-74: Empty block (block-no-empty)

(block-no-empty)


[error] 83-83: Unexpected unknown at-rule "@#{$rule-name}" (scss/at-rule-no-unknown)

(scss/at-rule-no-unknown)


[error] 85-85: Unexpected unknown at-rule "@#{$block-rule}" (scss/at-rule-no-unknown)

(scss/at-rule-no-unknown)

🤖 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_parser/tests/css_test_suite/error/at_rule/scss_exclusive_values.css`
around lines 65 - 87, Add positive SCSS fixtures mirroring the negative cases so
the parser has bidirectional coverage: update
ok/scss/at-rule/exclusive-value-gates.scss to include valid SCSS examples for
interpolated media queries and ranges (e.g. `@media` #{$query} { ... }, `@media`
(#{$min} <= width) { ... }, `@media` (#{$min} <= width <= #{$max}) { ... }),
keyframe percentages using interpolation (e.g. `@keyframes` loader { #{$i}% { ...
} }), and interpolated at-rule names/blocks (e.g. @#{$rule-name} #{$value}; and
@#{$block-rule} #{$value} { color: red; }) so the ok fixture matches the error
fixture constructs.

@codspeed-hq

codspeed-hq Bot commented May 24, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 6.18%

❌ 1 regressed benchmark
✅ 28 untouched benchmarks
⏩ 227 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
tachyons_11778168428173736564.css[cached] 19.9 ms 21.2 ms -6.18%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing db/scss-parser-10 (8ad746c) with main (001f94f)

Open in CodSpeed

Footnotes

  1. 227 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.

@github-actions github-actions Bot added the A-Formatter Area: formatter label May 24, 2026
@denbezrukov denbezrukov changed the title fix(css_parser): gate SCSS-only interpolation syntax in CSS fix(css_parser): gate SCSS syntax in CSS May 25, 2026
@denbezrukov denbezrukov mentioned this pull request Jun 10, 2026
14 tasks
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 L-CSS Language: CSS and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant