-
Notifications
You must be signed in to change notification settings - Fork 138
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
vscode prettier formatter doesn't match npx prettier
#270
Comments
I think this has already been fixed in Tailwind 3.4.2 (#246) |
I can reproduce this issue on Tailwind 3.4.3 |
Same for me with the new whitespace removal using the following versions: |
@arishoham can you provide a reproduction repo I can clone? |
Experiencing the same thing in my SvelteKit project |
I am having the same issue with Tailwind This does not seem to be the same issue as #246, because I am seeing a mismatch between single-file CLI runs vs. the extension. If first format a single file using the CLI ( - <div className="max-w-screen-lg mx-auto flex flex-col gap-12 py-6 px-4">
+ <div className="mx-auto flex max-w-screen-lg flex-col gap-12 px-4 py-6"> At first I thought it had to do with the fact that in v4 I need to self-define The extension output looks good to me:
I can't create a self-contained reproduction right now, but I can give it a shot later if nobody else has time. |
I have the same issue:
|
Could this be an issue with OS? I noted that at my workplace, people with macOS don't have classes being sorted while others with Windows, it does; |
Happens to me on both, macOS & windows |
The problem is that the Tailwind CSS config is not found correctly. To fix it use an absolute path: Example of Prettier config that works // prettier.config.mjs
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
export default {
plugins: ['prettier-plugin-tailwindcss'],
tailwindConfig: resolve(__dirname, './tailwind/tailwind.config.js'),
tailwindFunctions: ['clsx', 'tw'],
}; |
What package manager are you using? And do you have an example project that you can provide that you see this on? |
@thecrypticace Here is a minimal reproduction + screen recording using Tailwind v4 alpha: https://github.com/aaronadamsCA/prettier-plugin-tailwindcss-issue-270 My best guess at what's happening:
One workaround is I realize this is v4 and most other reports are v3, but I have a feeling the root cause is ultimately the same—incompatible config file resolution. |
I've got an update to report, and it's a good-news-bad-news situation. The good news is that in our codebase, at some point between Tailwind 4.0.0-alpha.19 and 4.0.0-alpha.24, this plugin started returning consistent results between Prettier CLI runs and Visual Studio Code runs. The bad news is now both are incorrect. 🙃 For example, the plugin is incorrectly moving data attrributes to the front because it doesn't recognize them: -<button class="outline-none data-focus:outline-blue-500">Button</button>
+<button class="data-focus:outline-blue-500 outline-none">Button</button> This may eventually come down to incorrect configuration, but if that's the case, I wonder if the plugin should refuse to run instead of applying an incorrect sort order. |
What version of
prettier-plugin-tailwindcss
are you using?v0.5.14
What version of Tailwind CSS are you using?
v3.3.0
What version of Node.js are you using?
v20.12
What package manager are you using?
yarn
What operating system are you using?
Mac OS
Describe your issue
I use the classes below:
and in my tailwind.config.ts
and my .prettierrc.js:
When i run
npx prettier --write
it sorts the classes in a different order then when i use the prettier formatter in vscode (option + shift + f)The text was updated successfully, but these errors were encountered: