Skip to content

feat(css): add support for SCSS @mixin at-rule#9423

Merged
denbezrukov merged 3 commits intomainfrom
db/scss-at-rule-5
Mar 9, 2026
Merged

feat(css): add support for SCSS @mixin at-rule#9423
denbezrukov merged 3 commits intomainfrom
db/scss-at-rule-5

Conversation

@denbezrukov
Copy link
Contributor

Summary

Adds SCSS @mixin at-rule support to the CSS parser and formatter.

Test Plan

  • Added parser coverage for valid and invalid SCSS @mixin
  • Added formatter coverage for SCSS @mixin
  • Ran:
    • cargo test -p biome_css_parser
    • cargo test -p biome_css_formatter

@changeset-bot
Copy link

changeset-bot bot commented Mar 9, 2026

⚠️ No Changeset found

Latest commit: 618d16a

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 github-actions bot added A-Parser Area: parser A-Formatter Area: formatter A-Tooling Area: internal tools L-CSS Language: CSS and super languages L-Grit Language: GritQL labels Mar 9, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 53071 53071 0
Passed 51851 51851 0
Failed 1178 1178 0
Panics 42 42 0
Coverage 97.70% 97.70% 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 5466 5466 0
Passed 1915 1915 0
Failed 3551 3551 0
Panics 0 0 0
Coverage 35.03% 35.03% 0.00%

ts/babel

Test result main count This PR count Difference
Total 636 636 0
Passed 568 568 0
Failed 68 68 0
Panics 0 0 0
Coverage 89.31% 89.31% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 18875 18875 0
Passed 13014 13014 0
Failed 5860 5860 0
Panics 1 1 0
Coverage 68.95% 68.95% 0.00%

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 9, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks
⏩ 187 skipped benchmarks1


Comparing db/scss-at-rule-5 (618d16a) with main (ecd00e8)

Open in CodSpeed

Footnotes

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 067a1965-af62-468b-97d8-e85c7de10ed9

📥 Commits

Reviewing files that changed from the base of the PR and between c86513d and 618d16a.

⛔ Files ignored due to path filters (1)
  • crates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/mixin.scss.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (2)
  • crates/biome_css_parser/src/syntax/at_rule/mod.rs
  • crates/biome_css_parser/src/syntax/scss/at_rule/mixin_at_rule.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_css_parser/src/syntax/scss/at_rule/mixin_at_rule.rs

Walkthrough

Adds full SCSS @mixin support across parser and formatter. Changes include lexer keyword for mixin, parser rules and recovery for mixin declarations and nested parameter syntax, formatter FormatRule implementations and AsFormat/IntoFormat plumbing for mixin and parameter nodes, generated-kind and grammar updates, new test fixtures (ok and error) and corresponding formatter modules for parameter lists and defaults.

Possibly related PRs

Suggested labels

L-SCSS

Suggested reviewers

  • ematipico
  • dyc3
  • siketyan
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding SCSS @mixin at-rule support to the CSS parser and formatter.
Description check ✅ Passed The description directly relates to the changeset, outlining the addition of SCSS @mixin support with test coverage and verification steps.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch db/scss-at-rule-5

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
crates/biome_css_parser/src/lexer/mod.rs (1)

843-843: Please add one regression where mixin is not an at-rule keyword.

This now lexes as a dedicated keyword everywhere, so one parser case using mixin in an ordinary identifier/value position would guard against contextual-keyword fallout.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_css_parser/src/lexer/mod.rs` at line 843, Add a regression test
that ensures the lexer/parser treats "mixin" as an ordinary identifier/value
(not an at-rule keyword) in non-@-rule positions: create a test that feeds input
containing "mixin" in a declaration or selector context (e.g., as a property
name or identifier token) and assert that the produced token kind is IDENT or
value token rather than MIXIN_KW; update or add the test near existing
lexer/parser tests that exercise keyword vs identifier behavior so changes
around the match arm "b\"mixin\" => MIXIN_KW" will be caught if it becomes a
dedicated keyword in all contexts.
crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/mixin.scss (1)

1-11: Please add an explicit @mixin foo() fixture as well.

The happy-path coverage already hits omitted parentheses and non-empty parameters, but not the zero-arg () spelling. That is a handy regression case for this rule.

💡 Tiny fixture addition
 `@mixin` button {
   border-radius: 4px;
 }
 
+@mixin empty() {}
+
 `@mixin` size($width, $height: $width, $args...) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/mixin.scss`
around lines 1 - 11, Add an explicit zero-arg mixin fixture to the same test
file to cover the `@mixin foo()` spelling; currently the file only contains
`@mixin button` (no parens) and `@mixin size($width, ...)` (non-empty params).
Add a new mixin declaration using the empty-parentheses form—e.g., `@mixin
foo()`—so the parser/regression for zero-arg `()` is exercised.
crates/biome_css_parser/src/syntax/scss/at_rule/mixin_at_rule.rs (1)

73-93: Minor: Consider swapping ellipsis and default value parsing order.

In SCSS, variadic parameters ($args...) cannot have default values. The current order parses default value before ellipsis, but if you ever want to add validation that flags $args: default... as invalid, having them in the order they appear in valid syntax might be clearer.

That said, this works correctly for valid SCSS, so it's a very minor point.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_css_parser/src/syntax/scss/at_rule/mixin_at_rule.rs` around
lines 73 - 93, In parse_scss_parameter, swap the order of parsing the variadic
ellipsis and the default value so the parser checks for and consumes the
ellipsis (p.at(T![...]) / p.bump(T![...])) before attempting to parse a default
via is_at_scss_parameter_default_value and parse_scss_parameter_default_value;
ensure the default value is only parsed when the ellipsis is not present to
match SCSS semantics (refer to functions/guards parse_scss_parameter,
is_at_scss_parameter_default_value, parse_scss_parameter_default_value, and the
p.at/p.bump handling of T![...]).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/biome_css_parser/src/lexer/mod.rs`:
- Line 843: Add a regression test that ensures the lexer/parser treats "mixin"
as an ordinary identifier/value (not an at-rule keyword) in non-@-rule
positions: create a test that feeds input containing "mixin" in a declaration or
selector context (e.g., as a property name or identifier token) and assert that
the produced token kind is IDENT or value token rather than MIXIN_KW; update or
add the test near existing lexer/parser tests that exercise keyword vs
identifier behavior so changes around the match arm "b\"mixin\" => MIXIN_KW"
will be caught if it becomes a dedicated keyword in all contexts.

In `@crates/biome_css_parser/src/syntax/scss/at_rule/mixin_at_rule.rs`:
- Around line 73-93: In parse_scss_parameter, swap the order of parsing the
variadic ellipsis and the default value so the parser checks for and consumes
the ellipsis (p.at(T![...]) / p.bump(T![...])) before attempting to parse a
default via is_at_scss_parameter_default_value and
parse_scss_parameter_default_value; ensure the default value is only parsed when
the ellipsis is not present to match SCSS semantics (refer to functions/guards
parse_scss_parameter, is_at_scss_parameter_default_value,
parse_scss_parameter_default_value, and the p.at/p.bump handling of T![...]).

In `@crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/mixin.scss`:
- Around line 1-11: Add an explicit zero-arg mixin fixture to the same test file
to cover the `@mixin foo()` spelling; currently the file only contains `@mixin
button` (no parens) and `@mixin size($width, ...)` (non-empty params). Add a new
mixin declaration using the empty-parentheses form—e.g., `@mixin foo()`—so the
parser/regression for zero-arg `()` is exercised.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: eb79cc88-5c2a-4f28-9051-5139226d3645

📥 Commits

Reviewing files that changed from the base of the PR and between ecd00e8 and c86513d.

⛔ Files ignored due to path filters (9)
  • 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/css/scss/at-rule/mixin.scss.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/mixin.scss.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/mixin.scss.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 **
  • crates/biome_css_syntax/src/generated/nodes_mut.rs is excluded by !**/generated/**, !**/generated/** and included by **
📒 Files selected for processing (25)
  • crates/biome_css_formatter/src/css/any/at_rule.rs
  • crates/biome_css_formatter/src/generated.rs
  • crates/biome_css_formatter/src/scss/any/mod.rs
  • crates/biome_css_formatter/src/scss/any/parameter.rs
  • crates/biome_css_formatter/src/scss/auxiliary/mod.rs
  • crates/biome_css_formatter/src/scss/auxiliary/parameter.rs
  • crates/biome_css_formatter/src/scss/auxiliary/parameter_default_value.rs
  • crates/biome_css_formatter/src/scss/auxiliary/parameter_list.rs
  • crates/biome_css_formatter/src/scss/lists/mod.rs
  • crates/biome_css_formatter/src/scss/lists/parameter_item_list.rs
  • crates/biome_css_formatter/src/scss/statements/mixin_at_rule.rs
  • crates/biome_css_formatter/src/scss/statements/mod.rs
  • crates/biome_css_formatter/tests/specs/css/scss/at-rule/mixin.scss
  • crates/biome_css_parser/src/lexer/mod.rs
  • crates/biome_css_parser/src/lexer/tests.rs
  • crates/biome_css_parser/src/syntax/at_rule/mod.rs
  • crates/biome_css_parser/src/syntax/scss/at_rule/if_at_rule.rs
  • crates/biome_css_parser/src/syntax/scss/at_rule/mixin_at_rule.rs
  • crates/biome_css_parser/src/syntax/scss/at_rule/mod.rs
  • crates/biome_css_parser/src/syntax/scss/mod.rs
  • crates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/mixin.scss
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/mixin.scss
  • crates/biome_grit_patterns/src/grit_target_language/css_target_language/generated_mappings.rs
  • xtask/codegen/css.ungram
  • xtask/codegen/src/css_kinds_src.rs

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-Tooling Area: internal tools L-CSS Language: CSS and super languages L-Grit Language: GritQL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants