Repository navigation
fix(formatter): don't sort templates in nested non-Tailwind calls - #28794
Merged
Merged
Conversation
Contributor
Merging this PR will not alter performance
Comparing Footnotes
|
- Hide the Tailwind context with a `None` stack entry instead of a `disabled` flag,
so templates and strings in their `${}` honor it like strings did
- Note the divergence from prettier-plugin-tailwindcss#426 in AGENTS.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
leaysgur
force-pushed
the
fix/oxfmt-tailwind-nested-template
branch
from
November 5, 2026 02:45
b65809d to
8567409
Compare
leaysgur
enabled stacked auto-merge (squash)
November 5, 2026 02:47
leaysgur
added a commit
that referenced
this pull request
Nov 5, 2026
…28798) Stacked on #28794. ## What was wrong With `sortTailwindcss` on, a string key in a Tailwind context was always printed quoted. A key that collapses to a single class was unquoted only on the second pass (not idempotent): ```js // experimentalTailwindcss: { functions: ["clsx"] } // Input clsx({ " p ": x }); clsx({ " p ": x, c: y }); // Before (2nd pass: `{ p: x }`, `{ p: x, c: y }`) clsx({ "p": x }); clsx({ "p": x, c: y }); // quoteProps: "consistent" also quotes `"c"` // After (any quoteProps) clsx({ p: x }); clsx({ p: x, c: y }); ``` Prettier decides quotes after the plugin rewrote the key, so it prints `{ p: x }` directly. ## What changed - `tailwindcss.rs`: `tailwind_single_class_key` returns the class a key prints as, when sorting leaves a single class with no boundary space kept (`" p "` -> `p`) - The boundary space rule is shared with `write_tailwind_string_literal` (`kept_boundary_spaces`) - `object.rs`: `string_key_text` returns either the text to print as a plain key, or the context to sort it in - `format_property_key`, `write_member_name` and `should_preserve_quote` all branch on it, so the usual quote rules (as-needed, consistent, numbers, TS) apply to the single class - `is_quoted_new_method_signature` compares the trimmed value, so `" new "(): void` keeps its quotes instead of becoming a construct signature ## Not covered here - Duplicates of a known class (`"flex flex"`) still unquote only on the second pass, since only the sorter knows them - A key inside a template expression keeps its boundary spaces (`` clsx(`a${{ " p ": x }}b`) ``), following our writer's rule; the plugin's result depends on the parser there 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)
55 of 82 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #28745.
What was wrong
With
sortTailwindcsson, 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:
Cause: the nested call set a
disabledflag on the current context entry, but only the string literal path checked it.TemplateElementand the layout checks read the entry without it, and the entries pushed for${}started withdisabled: false.What changed
JsFormatContext: the stack holdsOption<TailwindContextEntry>None(hide_tailwind_context), andtailwind_context()returnsNonewhile it's on topdisabledfield,tailwind_context_mutand the save/restore inCallExpression::writetailwind_context_for_class_listreplacestailwind_context_for_string_literal, shared by string literals and template elementsis_short_argumentdecides templates by the callee alone, like stringsAGENTS.mdnotes the divergence from the pluginNot covered here
new,import()and non-Tailwind tags don't hide the context (sorted, as the plugin does)MemberChainare not sorted (fix(formatter): sort Tailwind calls printed as member chains #28800)AI assistance (Claude Code) was used for this change. I reviewed and tested it.
🤖 Generated with Claude Code