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

Possible to use to use multiple community plugins with the same parser? #10261

Closed
hrougier opened this issue Feb 6, 2021 · 1 comment
Closed
Labels
area:plugin api locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Comments

@hrougier
Copy link

hrougier commented Feb 6, 2021

Hi,

It seems like multiple community plugins can't work together as soon as they override a specific prettier parser.
For example, prettier-plugin-jsdoc and prettier-plugin-organize-imports.

It is most likely due to the fact that both plugins are defining their own typescript parser (here and here), both importing prettier/parser-typescript to inherit from it.

prettier-plugin-jsdoc uses the parse property of the typescript parser while prettier-plugin-organize-imports uses the preprocess property, but the last plugin loaded (alphabetical sort) completely overrides what is defined by the previous one.

I managed to have them both working by doing something like this

.prettierrc.js

const { merge } = require('lodash')

module.exports = {
  // ... prettier config
  plugins: [merge(organizeImports, jsDoc)],
}

But it is not an ideal solution as it kind of loses the plugin autoloading feature by having to manually merge them (the original plugins are still autoloaded but the merged one overrides them).
Moreover, if another plugin like prettier-plugin-tailwind is used, which also inherits and uses the parse property of the typescript parser, this makes it quite difficult to handle.

Is there a better way to handle this use case or would it be possible for prettier to manage it by automatically composing the properties defined by custom plugins ?

Thank you for your time ✌️

Environments:

  • Prettier Version: 2.2.1
  • Running Prettier via: CLI
  • Runtime: Node.js v14
  • Operating System: macOS

Steps to reproduce:

yarn add prettier-plugin-jsdoc
yarn add prettier-plugin-organize-imports
yarn add prettier-plugin-tailwind

Expected behavior:

All plugins working together.

Actual behavior:

Only the last plugin loaded by prettier works.

@thorn0
Copy link
Member

thorn0 commented Feb 6, 2021

What these plugins do isn't really an officially supported use case. However, they could be modified to take other such plugins into account. See #10259 (comment)

Closing in favor of #4424 (an issue where a non-monkeypatching API for extending Prettier's built-in plugins/languages is discussed).

See also #9417

@thorn0 thorn0 closed this as completed Feb 6, 2021
@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label May 17, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:plugin api locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

No branches or pull requests

2 participants