Skip to content

feat(enforce-consistent-line-wrapping): wrapStrings: "all" turns JS strings into templates (#216) - #232

Merged
sergioazoc merged 1 commit into
mainfrom
feat/wrap-js-strings
Oct 10, 2026
Merged

sergioazoc merged 1 commit into
mainfrom
feat/wrap-js-strings

Conversation

@sergioazoc

Copy link
Copy Markdown
Owner

Follow-up to #216 (the request).

Summary

wrapStrings: "jsx" wraps a JSX attribute's own string in place. Every JS string kept reporting without a fix, because it can't hold a raw newline. People moving from eslint-plugin-better-tailwindcss want what it does there: when a JS string has to wrap, it becomes a template literal.

// options: { "classesPerLine": 3, "wrapStrings": "all" }
const card = cn("flex items-center justify-between p-4 m-2 bg-white")
// → const card = cn(`
//     flex items-center justify-between
//     p-4 m-2 bg-white
//   `)
  • Where: wherever the string's place takes any expression. That means a call argument (cn("…")), className={"…"}, an array element, an object value (cva, tv), a ternary branch, a &&/|| operand, or a variable's value. These are the same places better-tailwindcss converts (checked in its 4.9.0 source). A JSX attribute's own string is still wrapped in place.
  • Never: an object key or a + operand. Also never a string a template would read differently: its source between the quotes must equal its value (no escape sequence) and contain no backtick or ${. Those keep reporting. better-tailwindcss only escapes the backtick, so a ${ in a string becomes an interpolation there.
  • The fix replaces the whole literal, quotes included, so meta.fixable is now 'code'. A CRLF file gets CRLF breaks.
  • Opt-in: the string's value gains the newlines and the indentation. In a class list that's whitespace, but it matters where the string is used as something else. "jsx" and the default "never" are unchanged.

Test plan

  • Rule: every place that converts, and the ones that don't. Also the base indent, CRLF, classesPerLine and both width fixers. Dropping the escape check, the backtick or ${ exclusion, or the object-key or + exclusion each fails a test.
  • no-unnecessary-whitespace and enforce-consistent-line-wrapping contradict each other #14 cycle: no-unnecessary-whitespace and the rule itself stay silent on the converted block.
  • oxfmt e2e: a helper's template block survives sortTailwindcss only with preserveWhitespace: true, like a JSX string's. Checked by hand first, then pinned.
  • Docs: the rule page (EN/ES) with a ✗ example the docs test runs through oxlint, /interop (EN/ES), the better-tailwindcss migration row, CLAUDE.md and CHANGELOG.
  • Lint, lint:types, format:check, typecheck, build and pnpm test (3811 + 312). pnpm -C packages/docs build: check-dist ok. Bench corpus and synthetic identical to the baselines.

🤖 Generated with Claude Code

https://claude.ai/code/session_019vTh6S5A41M1HLkmk3FaM1

…trings into templates (#216)

`wrapStrings: "jsx"` wraps a JSX attribute's own string in place, and every JS
string kept reporting without a fix: it can't hold a raw newline. People moving
from eslint-plugin-better-tailwindcss asked for its behaviour there (#216):
when a JS string has to wrap, it becomes a template literal.

- `"all"` does that, with a template's block layout, wherever the string's
  place takes any expression: a call argument (`cn("…")`), `className={"…"}`,
  an array element, an object value (`cva`, `tv`), a ternary branch, a
  `&&`/`||` operand, a variable's value. A JSX attribute's own string is still
  wrapped in place.
- Never an object key or a `+` operand, and never a string a template would
  read differently: its source between the quotes must equal its value (no
  escape sequence) and hold no backtick or `${`. Those keep reporting.
- The fix replaces the whole literal, quotes included, so `meta.fixable` is
  now 'code'. A CRLF file gets CRLF breaks.
- Opt-in, because the string's value gains the newlines and the indentation:
  whitespace in a class list, not where the string is used as something else.
  `"jsx"` and the default `"never"` are unchanged.

Tests: every place that converts and the ones that don't, the base indent,
CRLF, both width fixers; dropping the escape check, the backtick or `${`
exclusion, or the object-key or `+` exclusion each fails one. The #14 cycle
(no-unnecessary-whitespace stays silent on the converted block), and an oxfmt
e2e: a helper's template block survives only with preserveWhitespace, like a
JSX string's.

Docs: the rule page (EN/ES) with a ✗ example the docs test runs through oxlint,
/interop (EN/ES), the better-tailwindcss migration row, CLAUDE.md, CHANGELOG.
Bench corpus and synthetic identical.

Claude-Session: https://claude.ai/code/session_019vTh6S5A41M1HLkmk3FaM1
@sergioazoc
sergioazoc merged commit fdf7b5b into main Oct 10, 2026
12 checks passed
@sergioazoc
sergioazoc deleted the feat/wrap-js-strings branch October 10, 2026 00:50
@sergioazoc sergioazoc mentioned this pull request Oct 10, 2026
3 tasks done
sergioazoc added a commit that referenced this pull request Oct 10, 2026
- packages/oxlint-tailwindcss/package.json and the Claude Code plugin's
  plugin.json at 1.16.0.
- CHANGELOG: Unreleased → 1.16.0 — Features (#216, #232: wrapStrings "all")
  and Documentation (#233: the eslint-plugin-tailwindcss migration guide).
  Nothing changes with the same config.
- bench/results/latest.json regenerated after the bump (only the version and
  timings move), /benchmark and /comparison regenerated from it.

Claude-Session: https://claude.ai/code/session_019vTh6S5A41M1HLkmk3FaM1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant