Skip to content

feat(css): add support for SCSS @function and @return at-rules#9431

Merged
denbezrukov merged 4 commits intomainfrom
db/scss-at-rule-9
Mar 10, 2026
Merged

feat(css): add support for SCSS @function and @return at-rules#9431
denbezrukov merged 4 commits intomainfrom
db/scss-at-rule-9

Conversation

@denbezrukov
Copy link
Contributor

This PR was created with AI assistance (Codex).

Summary

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

Test Plan

cargo test -p biome_css_parser
cargo test -p biome_css_formatter

@changeset-bot
Copy link

changeset-bot bot commented Mar 10, 2026

⚠️ No Changeset found

Latest commit: 0566077

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 10, 2026
@github-actions
Copy link
Contributor

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 53077 53077 0
Passed 51857 51857 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 10, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks
⏩ 187 skipped benchmarks1


Comparing db/scss-at-rule-9 (0566077) with main (1555948)

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 10, 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: ae92cfe8-d2ee-40b0-a4d1-94160297a998

📥 Commits

Reviewing files that changed from the base of the PR and between 0662098 and a346113.

📒 Files selected for processing (1)
  • crates/biome_css_parser/src/syntax/at_rule/mod.rs

Walkthrough

This PR adds SCSS support for two at-rules: @function and @return. Changes include lexer keyword recognition, grammar/codegen updates, new parser modules (function, return, and a parameter-list helper), parser dispatch wiring, formatter implementations and generated formatting bindings, scss statement modules, language-kind mappings, and numerous new tests and snapshots for both OK and error cases.

Possibly related PRs

Suggested labels

L-SCSS

Suggested reviewers

  • ematipico
  • siketyan
  • dyc3
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarises the main change: adding SCSS @function and @return at-rule support to the CSS parser and formatter.
Description check ✅ Passed The description is directly related to the changeset, explaining the addition of SCSS at-rule support and providing a test plan.

✏️ 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-9

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.

Actionable comments posted: 2

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

312-341: Add a RETURNS_KW check while you’re here.

return and returns are easy neighbours to trip over. One extra assertion would make this smoke test a bit less trusting.

🧪 Tiny follow-up
-        "media keyframes important from through sass each debug warn error for function include mixin return",
+        "media keyframes important from through sass each debug warn error for function include mixin return returns",
@@
-        RETURN_KW:6
+        RETURN_KW:6,
+        WHITESPACE:1,
+        RETURNS_KW:7
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_css_parser/src/lexer/tests.rs` around lines 312 - 341, Add an
additional assertion for the "returns" keyword in the token counts: locate the
token list in crates/biome_css_parser/src/lexer/tests.rs (the block containing
RETURN_KW:6) and add a RETURNS_KW entry with an appropriate count (e.g.,
RETURNS_KW:7) and a following WHITESPACE:1 to mirror the existing pattern (so
the sequence includes RETURN_KW:6, WHITESPACE:1, RETURNS_KW:7, WHITESPACE:1).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/biome_css_formatter/src/scss/statements/function_at_rule.rs`:
- Around line 17-27: The formatting emits an unconditional space between the
name and the block even when `parameters: Option<ScssParameterList>` is None,
causing a double space; update the formatter in the `write!(..., [
function_token.format(), space(), name.format(), parameters.format(), space(),
block.format() ])` sequence so the space before `block.format()` is only emitted
when `parameters` is Some — e.g., conditionally include the `space()` element
(or replace `parameters.format()` with a compact conditional that includes the
preceding space) so that when `parameters` is None you get a single space
between `name` and `block`.

In `@crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/return.scss`:
- Around line 1-2: The test fixture contains top-level `@return` statements
which are invalid per the Sass spec ( `@return` is only allowed inside
`@function` bodies ); update the test so the top-level `@return 42;` and
`@return $width * 2;` are moved from the `ok` suite into the `error` suite (or
replace one with a valid case by wrapping it inside a proper `@function`
definition) so that `@return` appears only inside `@function` bodies in any `ok`
fixtures and top-level `@return` examples live in the error fixtures.

---

Nitpick comments:
In `@crates/biome_css_parser/src/lexer/tests.rs`:
- Around line 312-341: Add an additional assertion for the "returns" keyword in
the token counts: locate the token list in
crates/biome_css_parser/src/lexer/tests.rs (the block containing RETURN_KW:6)
and add a RETURNS_KW entry with an appropriate count (e.g., RETURNS_KW:7) and a
following WHITESPACE:1 to mirror the existing pattern (so the sequence includes
RETURN_KW:6, WHITESPACE:1, RETURNS_KW:7, WHITESPACE:1).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a7221914-3876-4da2-91ef-5368d219367d

📥 Commits

Reviewing files that changed from the base of the PR and between 1555948 and 0662098.

⛔ Files ignored due to path filters (13)
  • 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/function.scss.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_formatter/tests/specs/css/scss/at-rule/return.scss.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/error/at_rule/at_rule_function_error.css.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/function.scss.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/return.scss.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/function.scss.snap is excluded by !**/*.snap and included by **
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/return.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 (26)
  • crates/biome_css_formatter/src/css/any/at_rule.rs
  • crates/biome_css_formatter/src/generated.rs
  • crates/biome_css_formatter/src/scss/statements/function_at_rule.rs
  • crates/biome_css_formatter/src/scss/statements/mod.rs
  • crates/biome_css_formatter/src/scss/statements/return_at_rule.rs
  • crates/biome_css_formatter/tests/specs/css/scss/at-rule/function.scss
  • crates/biome_css_formatter/tests/specs/css/scss/at-rule/return.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/function_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/at_rule/parameter.rs
  • crates/biome_css_parser/src/syntax/scss/at_rule/return_at_rule.rs
  • crates/biome_css_parser/src/syntax/scss/mod.rs
  • crates/biome_css_parser/tests/css_test_suite/error/at_rule/at_rule_function_error.css.snap.new
  • crates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/function.scss
  • crates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/function.scss.snap.new
  • crates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/return.scss
  • crates/biome_css_parser/tests/css_test_suite/error/scss/at-rule/return.scss.snap.new
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/function.scss
  • crates/biome_css_parser/tests/css_test_suite/ok/scss/at-rule/return.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

@denbezrukov denbezrukov merged commit 795bad4 into main Mar 10, 2026
18 checks passed
@denbezrukov denbezrukov deleted the db/scss-at-rule-9 branch March 10, 2026 09:30
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.

1 participant