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

Prettier Pug Plugin: Not formatting as expected. #2347

Closed
3 tasks done
aaronguernsey opened this issue Sep 30, 2020 · 10 comments
Closed
3 tasks done

Prettier Pug Plugin: Not formatting as expected. #2347

aaronguernsey opened this issue Sep 30, 2020 · 10 comments

Comments

@aaronguernsey
Copy link

aaronguernsey commented Sep 30, 2020

Info

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ
  • Platform: macOS
  • Vetur version: 0.28.0 Problem Problem

Problem

Pug templates don't use @prettier/plugin-pug specific settings. According the developer over on @prettier/plugin-pug I think this is because the package needs to be updated in Vetur's package.json.

Original Issue I opened on @prettier/plugin-pug

Issue: prettier/plugin-pug#124
Related Issue: #527

Temporary Solution

I had to downgrade Vetur's version to 0.27.3, and then any @prettier/plugin-pug settings work. I will open a request on the Vetur repo and see about getting them to update to the current version.

Input

<template lang="pug">
button.hello( class="world" disabled @click="handleClick"  )
</template>

Expected Output

<template lang="pug">
button.hello.world( disabled  @click="handleClick" )
</template>

Actual Output

<template lang="pug">
button.hello.world( disabled, @click="handleClick"  )
</template>

Additional Context

My project has a .prettierrc file with the options

{
  "semi": false,
  "arrowParens": "always",
  "printWidth": 600,
  "pugAttributeSeparator": "none"
}
@aaronguernsey aaronguernsey changed the title Outdated Prettier Pug Plugin: Pug not formatting as expected. Prettier Pug Plugin: Pug not formatting as expected. Sep 30, 2020
@aaronguernsey aaronguernsey changed the title Prettier Pug Plugin: Pug not formatting as expected. Prettier Pug Plugin: Not formatting as expected. Sep 30, 2020
@lehni
Copy link

lehni commented Sep 30, 2020

It's worth mentioning that pugAttributeSeparator: 'none' is only available since @prettier/plugin-pug v1.7.0, and was released yesterday: prettier/plugin-pug#116

So any of the plugin versions bundled with Vetur wouldn't be able to handle this option. What's interesting is that apparently you've been able to use your own newer version of @prettier/plugin-pug with Vetur v0.27.3, but not with the latest release of Vetur?

@aaronguernsey
Copy link
Author

@lehni Yes, that is correct. Am I missing something?

@Shinigami92
Copy link

"@prettier/plugin-pug": "^1.6.1",

I'm a little bit curious why this isn't using the latest 1.7.0, cause it uses ^ syntax 🤔
Or is it bundled in the vetur vscode-plugin and therefore doesn't use the projects @prettier/plugin-pug version? And if so: is there a solution to tell vetur to use the latest instead of the specified one?

@lehni
Copy link

lehni commented Sep 30, 2020

I'm not sure what happens when plugins are deployed to the VSCode marketplace. Probably the version gets set in stone and the files in node_modules are prepackaged along with the rest of the plugin? Or maybe some kind of lockfile is used?

@lehni
Copy link

lehni commented Sep 30, 2020

@lehni Yes, that is correct. Am I missing something?

We probably all are missing something at the moment
I just wanted to make the situation a bit clearer with my comment.

@Shinigami92
Copy link

@octref A bunch of new features made it into 1.8.0 🎉
Would be really nice if you upgrade and release 😃

@octref
Copy link
Member

octref commented Oct 6, 2020

Will release in the next version. Note that you can install @prettier/plugin-pug in your workspace as well, if you want to use a different version than bundled plugin formatter version.

@Shinigami92 Thanks for fixing the issues!

octref added a commit that referenced this issue Oct 6, 2020
@Shinigami92
Copy link

@octref https://github.com/vuejs/vetur/runs/1212892807#step:10:629

Something weird is going on, I cannot directly see what the issue is 🤔
Is it just another line ending or something?

@octref
Copy link
Member

octref commented Oct 7, 2020

@Shinigami92 Lol, thanks for letting me know. The issue is funny. I have @prettier/plugin-pug installed in the vetur/test/lsp/fixture folder, and Vetur passes two folders as pluginSearchDirs to prettier. Prettier then loads both plugins. And when prettier loads two plugin-pug, it formats pug with error 🤣

EDIT: Those two plugins have conflicting versions. One is 1.4.4, one is 1.8.1.

I'll write some code to safeguard against this and open an issue for prettier.

@lehni
Copy link

lehni commented Oct 10, 2020

@octref funny to cross paths again! I started working on plugin-pug recently (after taking note of its existence through Vetur), you can see me pop up in the commits here and there ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants