Skip to content

Commit 2bc173a

Browse files
fix: enforce compatible plugins load order for proper interoperability (#372)
* fix: enforce compatible plugins load order for proper interoperability * Pull in dedent to make some tests nicer * Add test * Tweak test * Add comments * Update changelog --------- Co-authored-by: Jordan Pittman <jordan@cryptica.me>
1 parent 03dd9a5 commit 2bc173a

File tree

5 files changed

+84
-8
lines changed

5 files changed

+84
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010
- Prevent Svelte files from breaking when there are duplicate classes ([#359](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/359))
11+
- Ensure `prettier-plugin-multiline-arrays` and `prettier-plugin-jsdoc` work used together with this plugin ([#372](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/372))
1112

1213
## [0.6.12] - 2025-05-30
1314

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"ast-types": "^0.14.2",
4545
"clear-module": "^4.1.2",
4646
"cpy-cli": "^5.0.0",
47+
"dedent": "^1.6.0",
4748
"enhanced-resolve": "^5.17.1",
4849
"esbuild": "^0.19.8",
4950
"escalade": "^3.1.1",

src/plugins.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ async function loadBuiltinPlugins(): Promise<PluginDetails> {
128128
}
129129

130130
async function loadThirdPartyPlugins(): Promise<PluginDetails> {
131-
// Commented out plugins do not currently work with Prettier v3.0
132131
let [astro, liquid, marko, twig, pug, svelte] = await Promise.all([
133132
loadIfExistsESM('prettier-plugin-astro'),
134133
loadIfExistsESM('@shopify/prettier-plugin-liquid'),
@@ -153,18 +152,25 @@ async function loadThirdPartyPlugins(): Promise<PluginDetails> {
153152
}
154153

155154
async function loadCompatiblePlugins() {
156-
// Commented out plugins do not currently work with Prettier v3.0
155+
// Plugins are loaded in a specific order for proper interoperability
157156
let plugins = [
158-
'@ianvs/prettier-plugin-sort-imports',
159-
'@trivago/prettier-plugin-sort-imports',
160-
'prettier-plugin-organize-imports',
161157
'prettier-plugin-css-order',
162-
'prettier-plugin-import-sort',
163-
'prettier-plugin-jsdoc',
164-
'prettier-plugin-multiline-arrays',
165158
'prettier-plugin-organize-attributes',
166159
'prettier-plugin-style-order',
160+
161+
// The following plugins must come *before* the jsdoc plugin for it to
162+
// function correctly. Additionally `multiline-arrays` usually needs to be
163+
// placed before import sorting plugins.
164+
//
165+
// https://github.com/electrovir/prettier-plugin-multiline-arrays#compatibility
166+
'prettier-plugin-multiline-arrays',
167+
'@ianvs/prettier-plugin-sort-imports',
168+
'@trivago/prettier-plugin-sort-imports',
169+
'prettier-plugin-import-sort',
170+
'prettier-plugin-organize-imports',
167171
'prettier-plugin-sort-imports',
172+
173+
'prettier-plugin-jsdoc',
168174
]
169175

170176
// Load all the available compatible plugins up front

tests/plugins.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createRequire } from 'node:module'
2+
import dedent from 'dedent'
23
import { test } from 'vitest'
34
import type { TestEntry } from './utils.js'
45
import { format, no, pluginPath, t, yes } from './utils.js'
@@ -467,6 +468,57 @@ import Custom from '../components/Custom.astro'
467468
],
468469
},
469470
},
471+
472+
// This test ensures that our plugin works with the multiline array, JSDoc,
473+
// and import sorting plugins when used together.
474+
//
475+
// The plugins actually have to be *imported* in a specific order for
476+
// them to function correctly *together*.
477+
{
478+
plugins: [
479+
'prettier-plugin-multiline-arrays',
480+
'@trivago/prettier-plugin-sort-imports',
481+
'prettier-plugin-jsdoc',
482+
],
483+
options: {
484+
multilineArraysWrapThreshold: 0,
485+
importOrder: ['^@one/(.*)$', '^@two/(.*)$', '^[./]'],
486+
importOrderSortSpecifiers: true,
487+
},
488+
tests: {
489+
babel: [
490+
[
491+
dedent`
492+
import './three'
493+
import '@two/file'
494+
import '@one/file'
495+
496+
/**
497+
* - Position
498+
*/
499+
const position = {}
500+
const arr = ['a', 'b', 'c', 'd', 'e', 'f']
501+
`,
502+
dedent`
503+
import '@one/file'
504+
import '@two/file'
505+
import './three'
506+
507+
/** - Position */
508+
const position = {}
509+
const arr = [
510+
'a',
511+
'b',
512+
'c',
513+
'd',
514+
'e',
515+
'f',
516+
]
517+
`,
518+
],
519+
],
520+
},
521+
},
470522
]
471523

472524
for (const group of tests) {

0 commit comments

Comments
 (0)