Inspiration

Biome is an open source formatter and checker for web languages, written in Rust. In issue #12957, ogardner-stackcx showed it reformatting margin: -#{$s} -#{$s} -#{$s} auto; into margin: -#{$s} - #{$s} - #{$s} auto;. With Dart Sass, the original compiles to -8px -8px -8px auto and the formatted version to -8px-8px-8px auto, which is invalid CSS that browsers drop. A formatter should never change what a stylesheet does, so this was worth fixing.

What it does

The merged change, biomejs/biome#12983, teaches Biome's SCSS parser that a minus sign with a space or line break before it and #{ (an interpolation) directly after it starts a new list item instead of subtracting. Biome now leaves such lists as written. Subtractions like $a - #{$s} and 1 -$s are still read as subtraction.

How I built it

The formatter prints whatever syntax tree the parser builds, so I looked at the parser. Its function that decides whether a token is a binary operator (one that sits between two values) read the - in -#{$s} -#{$s} as subtraction. I added a helper, is_at_scss_negated_interpolation_list_item, with four conditions: the token is -, whitespace or a line break comes before it, #{ comes next, and nothing sits between them. When it's true, the operator check returns "not an operator".

Two new tests, one for the parser and one for the formatter, share a single input: the issue's margin, a two item padding, a spaced subtraction, 1 -$s, and a list split over two lines. Neither passes on the old parser.

Challenges I ran into

Running the whole parser test suite changed an existing snapshot of subtraction examples: 17 cases shaped like 10 -#{10} had been recorded as subtractions. To make sure the fix hadn't broken them, I compared each case with sass/sass-spec, the official Sass conformance tests. Sass keeps all 17 as separate values, so the updated snapshot matches Sass.

The other challenge was scope. The check only looks at a minus with a space before it and #{ right after it, so those are the only cases that read differently now.

Accomplishments that I'm proud of

Merged by ematipico on 6 November 2026 within an hour of opening, with no requested changes, and shipped in Biome 2.6.6 the same day. A snapshot comparing Biome with another widely used formatter also moved closer: one pair on one line now prints the same in both.

What I learned

When a formatter changes meaning, the cause is often in how the code was parsed, not how it was printed. And a full test run matters: the 17 corrected cases were in a test I hadn't touched.

What's next

The fix is deliberately limited to interpolations. If other SCSS minus sign cases turn out to differ from Sass, the sass-spec comparison I used here is the place to start.

The full story, with all the code, is on my blog: https://ashokramsi.hashnode.dev/biome-scss-negative-interpolation

Built With

Share this project:

Updates