From e8b344d734d799dbc4f7cfd071482f7a5d14db19 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 11 Jul 2026 14:47:51 +0000 Subject: [PATCH] fix: preserve indentation for rules with an empty selector list print_rule only indented via print_rule_selectors, which pushes one indented line per selector. For malformed/unknown blocks with zero selectors (e.g. a bare `{ }` nested inside another block), no line was pushed at all, so the opening brace lost its indentation and printed with a single leading space instead of a tab. --- src/lib/index.ts | 6 ++++++ test/rules.test.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/index.ts b/src/lib/index.ts index 515d26f..0481d60 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -564,6 +564,12 @@ export function format( if (node.has_prelude && is_selector_list(node.prelude)) { let list = print_rule_selectors(node.prelude) + // An empty selector list (malformed/unknown block) prints no selector + // lines, so the indentation that print_rule_selectors would normally add + // per-selector has to be added here instead. + if (list === EMPTY_STRING) { + list = indent(depth) + } let comment = get_comment(node.first_child?.end, node.block?.start) if (comment) { diff --git a/test/rules.test.ts b/test/rules.test.ts index 32ba894..6500b28 100644 --- a/test/rules.test.ts +++ b/test/rules.test.ts @@ -176,7 +176,7 @@ test('formats unknown stuff in curly braces', () => { } `) let expected = `selector { - { + { color: red; } }`