Skip to content

Work on external plugin compat#90

Merged
thecrypticace merged 8 commits intomainfrom
plugin-compat
Sep 1, 2022
Merged

Work on external plugin compat#90
thecrypticace merged 8 commits intomainfrom
plugin-compat

Conversation

@thecrypticace
Copy link
Copy Markdown
Contributor

Prettier itself does not allow for multiple parsers covering the same AST / language at one time. This means that plugins that override existing languages are inherently incompatible.

However, with Prettier, it's common to take one of the built-in parsers, copy it, and mutate the preprocess or parse methods (we do this as well). This PR attempts to enable compatibility with specific plugins that extend / overwrite Prettier's built-in parsers by deferring to the parsers from the plugin instead.

This requires two things:

  1. You MUST customize your plugins and not rely on autoloading. This is because, when autoloading, the order is not defined.
  2. You MUST put prettier-plugin-tailwindcss last.

This PR also enables us to no longer bundle the Svelte plugin. There's still complicated issues there because of the way the plugin and prettier both work. In Prettier parsers from plugins are last one wins but printers from plugins are first one wins — this isn't normally a problem because you normally only have one for a given AST (… or it's been copied from the base plugin). However when these don't match, like in our case, you have to override the printer when parse is called. This is problematic but seems to work and hopefully won't break in the future.


Right now we're enabling support for these two plugins:

  • @trivago/prettier-plugin-sort-imports
  • prettier-plugin-organize-imports

Note: If you have both installed and enabled (either through autoloading or explicit customization) the one that is picked is undefined and subject to change.

@thecrypticace
Copy link
Copy Markdown
Contributor Author

Need to do a bit more testing before we release this. It'll be a new "major" version of the plugin due to some breaking changes re: svelte. (v0.2)

bronisMateusz pushed a commit to bronisMateusz/prettier-plugin-tailwindcss-drupal that referenced this pull request Apr 16, 2025
* Don’t bundle svelte

* Overwrite the printer

* Refactor

* Add compat with `@trivago/prettier-plugin-sort-imports`

* Verify compatibility with `prettier-plugin-organize-imports`

* Update lockfile

* Support autoloaded plugin paths

* Fix naming
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.

1 participant