Work on external plugin compat#90
Merged
thecrypticace merged 8 commits intomainfrom Sep 1, 2022
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
prettier-plugin-tailwindcsslast.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
parseis 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-importsprettier-plugin-organize-importsNote: If you have both installed and enabled (either through autoloading or explicit customization) the one that is picked is undefined and subject to change.