diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d90fbc..f499a85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Don't remove escape sequences when sorting classes in JavaScript string literals, which could produce invalid code in Vue attribute expressions ([#461](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/461)) - Restore class sorting in Svelte markup and dynamic `class={...}` expressions when using `prettier-plugin-svelte` v4 ([#462](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/462)) +- Enable compatibility with `@trivago/prettier-plugin-sort-imports` when using `prettier-plugin-svelte` ([#466](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/466)) ## [0.8.0] - 2026-04-27 diff --git a/src/index.ts b/src/index.ts index 57beef6..0f5bd58 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1181,6 +1181,10 @@ type SvelteNode = import('svelte/compiler').AST.SvelteNode & { let svelte = defineTransform({ staticAttrs: ['class'], + // Enforce README's "Compatibility with other Prettier plugins" with Svelte + // Only `@trivago/prettier-plugin-sort-imports` implements Svelte support. + // The other accepted import-sorting plugins do not register a `svelte` parser. + compatible: ['@trivago/prettier-plugin-sort-imports'], load: [{ name: 'prettier-plugin-svelte', importer: () => import('prettier-plugin-svelte') }], parsers: { diff --git a/tests/plugins.test.ts b/tests/plugins.test.ts index 9ca4e7b..57d4414 100644 --- a/tests/plugins.test.ts +++ b/tests/plugins.test.ts @@ -525,6 +525,40 @@ import Custom from '../components/Custom.astro' ], }, }, + + // Ensures that @trivago/prettier-plugin-sort-imports plugin also works + // when used together with the svelte plugin, sorting imports inside a + // Svelte file's ` +
+ `, + dedent` + + +
+ `, + ], + ], + }, + }, ] for (const group of tests) {