Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v0.1.9] Unwanted removal of leading whitespace for concatenated class #71

Closed
bennettdams opened this issue Apr 20, 2022 · 5 comments
Closed

Comments

@bennettdams
Copy link

bennettdams commented Apr 20, 2022

What version of prettier-plugin-tailwindcss are you using?

v0.1.9

What version of Tailwind CSS are you using?

v3.0.24

What version of Node.js are you using?

v16.13.0

What package manager are you using?

npm

What operating system are you using?

Windows

Reproduction URL

https://github.com/bennettdams/tailwind-prettier-whitespace-bug

Describe your issue

Version v0.1.9 introduced a change for frameworks like React that will introduce "bugs".

Here is a basic example. When a class consists of multiple concatenated strings, the plugin now removes the leading whitespace:

function Test() {
-      return <div className={"text-white" + " bg-red-100"} />;
+      return <div className={"text-white" + "bg-red-100"} />;
}

I use this format of concatenated strings for visibility when there are a lot of classes, e.g.:

className={
  'inline-flex items-center' +
  ' rounded-md p-2 shadow-sm focus:outline-none focus:ring-2 focus:ring-purple-600 focus:ring-opacity-50' +
  ' bg-dlila text-white transition duration-75 ease-in-out hover:bg-dorange' +
  ' disabled:cursor-not-allowed disabled:bg-gray-200'
}
@bennettdams bennettdams changed the title [v0.1.9] Unwanted remove of whitespace [v0.1.9] Unwanted remove of whitespace for concatenated class Apr 20, 2022
@bennettdams bennettdams changed the title [v0.1.9] Unwanted remove of whitespace for concatenated class [v0.1.9] Unwanted removal of whitespace for concatenated class Apr 20, 2022
@bennettdams bennettdams changed the title [v0.1.9] Unwanted removal of whitespace for concatenated class [v0.1.9] Unwanted removal of leading whitespace for concatenated class Apr 20, 2022
@dargmuesli
Copy link

For me it wants to replace this

function Test() {
-      :class="['button', ...(buttonClass ? [buttonClass] : [])].join(' ')"
+      :class="['button', ...(buttonClass ? [buttonClass] : [])].join('')"
}

... which is certainly not what I want 😅

@bradlc
Copy link
Contributor

bradlc commented Apr 20, 2022

Thanks for reporting this @bennettdams! For now we have published a new release (v0.1.10) that removes the whitespace removal feature while we consider solutions to the issues you were seeing 👍

@bradlc bradlc closed this as completed Apr 20, 2022
@thevuong
Copy link

thevuong commented Apr 21, 2022

I like the feature of eliminating repeated spaces as well as the same class names. The problem of long class names can be used clsx library. I hope the removed feature will reappear in the new version.

Before:

className={
  'inline-flex items-center' +
  ' rounded-md p-2 shadow-sm focus:outline-none focus:ring-2 focus:ring-purple-600 focus:ring-opacity-50' +
  ' bg-dlila text-white transition duration-75 ease-in-out hover:bg-dorange' +
  ' disabled:cursor-not-allowed disabled:bg-gray-200'
}

After:

className={clsx(
  'inline-flex items-center',
  'rounded-md p-2 shadow-sm focus:outline-none focus:ring-2 focus:ring-purple-600 focus:ring-opacity-50',
  'bg-dlila hover:bg-dorange text-white transition duration-75 ease-in-out',
  'disabled:cursor-not-allowed disabled:bg-gray-200',
)}

@karlhorky
Copy link

karlhorky commented Apr 9, 2023

@bradlc @adamwathan Any new plans for reintroducing this great feature? Maybe as a (default-off) option for the plugin as has been suggested by the community?

We've had a number of new duplicate whitespace commits creep into our codebase, hard to manually review these mistakes.

@stefanosandes
Copy link

This vscode plugin may be useful for anyone wanting to do so: https://github.com/heybourn/headwind

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

No branches or pull requests

6 participants