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

fix: Prettier not formatting .svelte files #1360

Merged
merged 1 commit into from
May 6, 2021

Conversation

caesar
Copy link
Contributor

@caesar caesar commented May 6, 2021

Adds --plugin-search-dir=. param to Prettier call in package.json scripts, so that Prettier will format .svelte files as well as .ts, .js, etc.

I assume Prettier is intended to be applied to .svelte files, since prettier-plugin-svelte is installed.

Fixes #1358.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpx changeset and following the prompts

@Rich-Harris
Copy link
Member

Thanks, but I can't reproduce this — if I run npm run format in a fresh project, my .svelte files are formatted correctly. What am I missing?

@caesar
Copy link
Contributor Author

caesar commented May 6, 2021

That's very odd. As described in #1358 this is reproducible for me with a fresh project.
The only thing I can think of is pnpm vs npm (I used pnpm), but I can't see why it would make a difference.
I'll see if I can work it out…

@caesar
Copy link
Contributor Author

caesar commented May 6, 2021

As a side note, https://github.com/sveltejs/prettier-plugin-svelte#how-to-use-cli does suggest using --plugin-search-dir=. so it's not just me 🙂

@Conduitry
Copy link
Member

I can reproduce this issue when installing dependencies with pnpm, but not when installing them with npm. With npm. npm run format also gets the .svelte files.

@caesar
Copy link
Contributor Author

caesar commented May 6, 2021

@Conduitry I was just writing exactly the same message 😀

So this must be to do with the different layout of node_modules used by pnpm.

It would be great if the default config supported pnpm (especially since the instructions say npm install (or pnpm install, etc). So I suppose the question is whether it is appropriate to fix (work around?) it in create-svelte as I have here, or whether it is something that should be fixed in Prettier.

I'd lean towards the former in the short term, but I guess it might be something to look at from Prettier's side too.

@Rich-Harris
Copy link
Member

Ah, interesting. In that case the workaround probably makes sense, yeah

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.

Prettier does not format svelte files with default config
3 participants