Skip to content

fix(formatter): sort Tailwind calls printed as member chains - #28800

Merged
leaysgur merged 3 commits into
fix/oxfmt-tailwind-object-key-quotefrom
fix/oxfmt-tailwind-member-chain
Nov 5, 2026
Merged

leaysgur merged 3 commits into
fix/oxfmt-tailwind-object-key-quotefrom
fix/oxfmt-tailwind-member-chain

Conversation

@leaysgur

@leaysgur leaysgur commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Stacked on #28798.

What was wrong

With sortTailwindcss on, a Tailwind call with a member callee was not sorted when printed as a MemberChain:

// experimentalTailwindcss: { functions: ["cn", "tw"] }

// Input
tw.style("p-4  flex");
cn.a("p-4  flex").b("m-2  block").c();

// Before
tw.style("p-4  flex");
cn.a("p-4  flex").b("m-2  block").c();

// After
tw.style("flex p-4");
cn.a("flex p-4").b("m-2 block").c();

Cause: only the non-MemberChain branch of CallExpression::write pushed the Tailwind context.
Inside JSX className they were sorted by the attribute's context, so the existing tests didn't catch it.

What changed

  • The push moves to the call arguments printer (impl Format for AstNode<ArenaVec<Argument>>),
    which both CallExpression and MemberChain go through
    • The call's own context covers only its arguments, so cn.foo["a b"](...) keeps "a b", like the plugin
      (an outer context still covers the callee, as the plugin does)
  • CallExpression::write only hides the context for a nested non-Tailwind call
  • AGENTS.md notes the known limitation below

Not covered here (same output as before)

  • Not idempotent: a multiline template in a member chain
    (foo.bar(cn.x(`⏎p-4 flex⏎`)).baz().qux(), or a long Tailwind chain ending with one)
  • With preserveWhitespace, a multiline template argument is hugged where Prettier breaks the arguments,
    also for a direct call (foo(cn(`⏎...⏎`)))

AI assistance (Claude Code) was used for this change. I reviewed and tested it.

πŸ€– Generated with Claude Code

@leaysgur
leaysgur added this pull request to stack #28799 November 4, 2026 07:36
@github-actions github-actions Bot added A-cli Area - oxlint / oxfmt common CLI behavior: flags, ignore files, oxc_config A-formatter Area - Formatter (oxfmt). Add F-* labels for details labels Nov 4, 2026
@codspeed

codspeed Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

βœ… 77 untouched benchmarks
⏩ 19 skipped benchmarks1


Comparing fix/oxfmt-tailwind-member-chain (24273b1) with fix/oxfmt-tailwind-object-key-quote (428be95)

Open in CodSpeed

Footnotes

  1. 19 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. ↩

leaysgur and others added 3 commits November 5, 2026 11:45
Push the Tailwind context in the call arguments printer,
so the calls a `MemberChain` prints (`tw.style("...")`, `cn.a("...").b("...")`)
are sorted like a plain call, and only their arguments are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…youts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leaysgur
leaysgur force-pushed the fix/oxfmt-tailwind-member-chain branch from 587c46a to 24273b1 Compare November 5, 2026 02:45
@leaysgur
leaysgur enabled stacked auto-merge (squash) November 5, 2026 02:47
@leaysgur
leaysgur merged commit ebfd40a into main Nov 5, 2026
40 checks passed
@leaysgur
leaysgur deleted the fix/oxfmt-tailwind-member-chain branch November 5, 2026 03:00
leaysgur added a commit that referenced this pull request Nov 5, 2026
…8794)

Follow-up to #28745.

## What was wrong

With `sortTailwindcss` on, strings in the arguments of a nested
non-Tailwind call are kept as is, deliberately unlike
prettier-plugin-tailwindcss
(tailwindlabs/prettier-plugin-tailwindcss#426).

Templates there were still sorted:

```tsx
// experimentalTailwindcss: { functions: ["cn"] }

// Input
cn(x.includes(`a  b`) && "p-4  flex");
cn(x.includes(`${"a  b"}  c`));
<div className={x.split(`a  b`).length ? "p-4  flex" : ""} />;

// Before
cn(x.includes(`a b`) && "flex p-4");
cn(x.includes(`${"a b"} c`));
<div className={x.split(`a b`).length ? "flex p-4" : ""} />;

// After
cn(x.includes(`a  b`) && "flex p-4");
cn(x.includes(`${"a  b"}  c`));
<div className={x.split(`a  b`).length ? "flex p-4" : ""} />;
```

Cause: the nested call set a `disabled` flag on the current context
entry, but only the string literal path checked it.
`TemplateElement` and the layout checks read the entry without it, and
the entries pushed for `${}` started with `disabled: false`.

## What changed

- `JsFormatContext`: the stack holds `Option<TailwindContextEntry>`
- A nested non-Tailwind call pushes `None` (`hide_tailwind_context`),
and `tailwind_context()` returns `None` while it's on top
- Removed the `disabled` field, `tailwind_context_mut` and the
save/restore in `CallExpression::write`
- `tailwind_context_for_class_list` replaces
`tailwind_context_for_string_literal`, shared by string literals and
template elements
- `is_short_argument` decides templates by the callee alone, like
strings
- `AGENTS.md` notes the divergence from the plugin

## Not covered here

- `new`, `import()` and non-Tailwind tags don't hide the context
(sorted, as the plugin does)
- Tailwind calls printed as a `MemberChain` are not sorted (#28800)

AI assistance (Claude Code) was used for this change. I reviewed and
tested it.

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
graphite-app Bot pushed a commit that referenced this pull request Nov 6, 2026
# Oxlint
### πŸš€ Features

- 4a52ba2 oxlint: Discover tsrs for type-aware linting (#28751) (camc314)
- b7d2c75 linter/eslint/no-redeclare: Add `ignoreDeclarationMerge` option (#28816) (Cam McHenry)

### πŸ› Bug Fixes

- fa66fde oxlint,oxfmt: Resolve Vite+ config root from the config file directory (#28801) (MK (fengmk2))
- 2091564 linter/jsdoc/require-param: Ignore enclosing function JSDoc (#28866) (camc314)
- c6ec50b linter/react/only-export-components: Classify JSX values as non-components (#28761) (camc314)
- 3c051ab linter/vitest/prefer-called-exactly-once-with: Preserve neighboring code in autofix (#28864) (camc314)
- 674b962 linter/eslint/no-misleading-character-class: Use lazy regex for combining marks (#28822) (Sysix)
- 838d339 linter/vitest/prefer-called-exactly-once-with: Avoid panic on non-ASCII text (#28850) (YT)
- 8d24c26 linter/jsx-a11y/aria-role: Allow role={undefined} (#28804) (Abhay Godavarthy)
- a7143bf linter/eslint/no-restricted-imports: Respect allowTypeImports correctly for empty patterns (#28842) (Cam McHenry)
- 3d3a6f4 react-compiler: Ignore callback-local reassignments (#28820) (camc314)
- 0cc6515 linter/unicorn/prefer-type-error: Report throws in unbraced if branches (#28819) (camc314)
- ae43c80 linter/unicorn/prefer-single-call: Remove duplicate fix status (#28763) (Mikhail Baev)
- a8a621a linter/eslint/no-fallthrough: Ignore unreachable exits from infinite loops (#28755) (camc314)
- 7a17a80 linter/eslint/prefer-spread: Report calls on non-member expressions (#28753) (camc314)
- 28442f7 oxlint: Prevent --init from overwriting existing configs (#28754) (camc314)
- 0ae350d linter/unicorn/no-zero-fractions: Preserve exponent case (#28752) (camc314)
- b5b3f3f linter/eslint/no-misleading-character-class: Detect more combining characters (#28733) (Sysix)

### ⚑ Performance

- 74d50c1 linter: Overlap import graph batches instead of polling on a pool worker (#28323) (Dunqing)
# Oxfmt
### πŸ’₯ BREAKING CHANGES

- 00d1a67 oxfmt: [**BREAKING**] Format `parser:vue` files by `oxc_formatter_htmlish` (#28848) (leaysgur)

### πŸš€ Features

- 9a81e58 formatter_htmlish: Format Vue templates (#28847) (leaysgur)
- 119d82f formatter: Format a template's expressions and handlers as `JsRoot` (#28846) (leaysgur)

### πŸ› Bug Fixes

- fa66fde oxlint,oxfmt: Resolve Vite+ config root from the config file directory (#28801) (MK (fengmk2))
- 4d4104d formatter_htmlish: Preserve `doctype` case in embedded (#28797) (leaysgur)
- ebfd40a formatter: Sort Tailwind calls printed as member chains (#28800) (Yuji Sugiura)
- e62e5cb formatter: Decide quotes of a Tailwind key printed as one class (#28798) (Yuji Sugiura)
- 959edc1 formatter: Don't sort templates in nested non-Tailwind calls (#28794) (Yuji Sugiura)
- 6ffbe32 formatter/jsdoc: Prevent `@tag` from being moved to the line start (#28835) (leaysgur)
- 94fbef5 formatter_css: Treat comments in `style` attr as fill items (#28832) (leaysgur)
- e4a80f7 formatter_css: Normalize selectors inside `:deep`, `:slotted` and `:local` (#28805) (leaysgur)
- 255c5cc formatter: Measure Tailwind class argument after collapsing whitespace (#28745) (Lee Jaeha / Adam)
- e6c4fef formatter: Decide template and object key layouts from collapsed Tailwind classes (#28791) (Yuji Sugiura)
- 0b44164 formatter: Decide JSX opening element layout from collapsed Tailwind class string (#28744) (Lee Jaeha / Adam)
- b8ba9ae formatter: Print decorators on rest parameters (#28731) (YT)

### ⚑ Performance

- 2766d07 oxfmt: Spawn Prettier workers on demand (#28789) (YT)
- 07627f7 oxfmt: Use worker_threads for tinypool again (#28787) (Yuji Sugiura)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - oxlint / oxfmt common CLI behavior: flags, ignore files, oxc_config A-formatter Area - Formatter (oxfmt). Add F-* labels for details

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant