feat(css_formatter): improve formatting for SCSS parenthesized expressions and include arguments - #10269
Conversation
…sions and include arguments
|
WalkthroughThis PR refactors SCSS formatting logic for parenthesised expressions, binary expressions, and list layouts. It introduces new layout helpers to centralise parenthesised-expression and include-keyword-argument formatting decisions, replaces the Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
crates/biome_css_formatter/src/utils/scss_list_layout.rs (1)
205-240:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winKeep keyword-comment expansion scoped to the direct value list.
scss_include_keyword_argument_owner(...)is ancestor-based, so a nested list inside something like$arg: (key: (a, b)) /* end */can inherit the outer keyword argument’s dangling comment here and get forced into the include-value layout as well. That leaks outer comment ownership into inner lists that should stay inline.🤖 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_formatter/src/utils/scss_list_layout.rs` around lines 205 - 240, The issue is that scss_include_keyword_argument_owner is being run against ancestor parenthesized expressions and can surface an outer keyword argument for nested lists; in is_include_keyword_list_value_expanded_by_comments restrict the keyword-argument lookup to the immediate parenthesized wrapper only (use node.syntax().parent().and_then(ScssParenthesizedExpression::cast) instead of ancestors().skip(1).find_map(...)) and only call scss_include_keyword_argument_owner on that immediate parenthesized (or directly on node.syntax() in the no-parenthesized branch) so dangling-comment ownership is scoped to the direct value list.
🧹 Nitpick comments (1)
crates/biome_css_formatter/src/utils/scss_include_keyword_value.rs (1)
27-36: 💤 Low value
descendants()walk with per-nodescss_include_keyword_argument_ownercalls is O(n·d) — acceptable for typical SCSS.No action needed; just flagging it as a future hot-spot if people start writing deeply nested SCSS maps.
🤖 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_formatter/src/utils/scss_include_keyword_value.rs` around lines 27 - 36, No code change required for correctness, but annotate the potential O(n·d) hotspot: add a brief comment near the traversal in scss_include_keyword_value (the block using value.syntax().descendants().filter_map(ScssParenthesizedExpression::cast).any(...)) noting that repeated calls to scss_include_keyword_argument_owner for each descendant can become O(n·d) on deeply nested SCSS maps and may need optimization later (e.g., caching owner lookups or switching to a single traversal that computes owners and nesting with is_nested_in_keyword_parentheses).
🤖 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`:
- Around line 19-24: You removed ScssMapOuterParenthesizedValuePayloadKind and
scss_map_context from the pub use list in lib.rs which is semver-breaking for
published crates; either restore those two exports (re-add
ScssMapOuterParenthesizedValuePayloadKind and scss_map_context to the pub use
block that contains ScssMapContext, ScssMapPositionKind, ScssMapRole, etc.) so
existing downstream users keep compatibility, or if the removal is intentional,
update the crate version (major/minor as appropriate) and add a changelog entry
noting the removal before publishing.
In `@crates/biome_css_syntax/src/scss_ext/map.rs`:
- Around line 54-85: Add runnable doctest examples to the doc comments for the
map-shape classifier functions (e.g., is_scss_map_outer_parenthesized_value_map
and is_scss_map_outer_parenthesized_value_list and the similar functions around
the other map helpers) by replacing or augmenting the prose examples with Rust
doc code blocks (/// ```rust ... ``` ) that construct minimal Scss AST nodes (or
call existing test helpers) and assert the expected boolean result; ensure the
examples compile by importing or referencing any helper constructors in the
doctest prelude (or use fully-qualified paths) and keep the examples focused
(one assertion per example) so they run as doctests during cargo test.
---
Outside diff comments:
In `@crates/biome_css_formatter/src/utils/scss_list_layout.rs`:
- Around line 205-240: The issue is that scss_include_keyword_argument_owner is
being run against ancestor parenthesized expressions and can surface an outer
keyword argument for nested lists; in
is_include_keyword_list_value_expanded_by_comments restrict the keyword-argument
lookup to the immediate parenthesized wrapper only (use
node.syntax().parent().and_then(ScssParenthesizedExpression::cast) instead of
ancestors().skip(1).find_map(...)) and only call
scss_include_keyword_argument_owner on that immediate parenthesized (or directly
on node.syntax() in the no-parenthesized branch) so dangling-comment ownership
is scoped to the direct value list.
---
Nitpick comments:
In `@crates/biome_css_formatter/src/utils/scss_include_keyword_value.rs`:
- Around line 27-36: No code change required for correctness, but annotate the
potential O(n·d) hotspot: add a brief comment near the traversal in
scss_include_keyword_value (the block using
value.syntax().descendants().filter_map(ScssParenthesizedExpression::cast).any(...))
noting that repeated calls to scss_include_keyword_argument_owner for each
descendant can become O(n·d) on deeply nested SCSS maps and may need
optimization later (e.g., caching owner lookups or switching to a single
traversal that computes owners and nesting with
is_nested_in_keyword_parentheses).
🪄 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: a5f921f4-3c01-4f75-8710-2919e750b88e
⛔ Files ignored due to path filters (2)
crates/biome_css_formatter/tests/specs/prettier/scss/math/7419.scss.snapis excluded by!**/*.snapand included by**crates/biome_css_formatter/tests/specs/scss/at-rule/include-arguments.scss.snapis excluded by!**/*.snapand included by**
📒 Files selected for processing (12)
crates/biome_css_formatter/src/scss/auxiliary/binary_expression.rscrates/biome_css_formatter/src/scss/auxiliary/parenthesized_expression.rscrates/biome_css_formatter/src/utils/mod.rscrates/biome_css_formatter/src/utils/scss_control_condition.rscrates/biome_css_formatter/src/utils/scss_include_keyword_value.rscrates/biome_css_formatter/src/utils/scss_keyword_argument_layout.rscrates/biome_css_formatter/src/utils/scss_list_layout.rscrates/biome_css_formatter/src/utils/scss_separator_comments.rscrates/biome_css_formatter/tests/specs/scss/at-rule/include-arguments.scsscrates/biome_css_syntax/src/lib.rscrates/biome_css_syntax/src/scss_ext/map.rscrates/biome_css_syntax/src/scss_ext/mod.rs
Merging this PR will not alter performance
Comparing Footnotes
|
Summary
Improves SCSS formatter output for parenthesized expressions, map/list values, and
@includekeyword arguments to better match Prettier.Example output:
Test Plan