diff --git a/CHANGELOG.md b/CHANGELOG.md index e3161e6..6f2bfb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - Prevent Svelte files from breaking when there are duplicate classes ([#359](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/359)) +- 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)) ## [0.6.12] - 2025-05-30 diff --git a/package-lock.json b/package-lock.json index a4b392d..a7aad62 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "ast-types": "^0.14.2", "clear-module": "^4.1.2", "cpy-cli": "^5.0.0", + "dedent": "^1.6.0", "enhanced-resolve": "^5.17.1", "esbuild": "^0.19.8", "escalade": "^3.1.1", @@ -2937,6 +2938,21 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/dedent": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/dedent/-/dedent-1.6.0.tgz", + "integrity": "sha512-F1Z+5UCFpmQUzJa11agbyPVMbpgT/qA3/SKyJ1jyBgm7dUcUEa8v9JwDkerSQXfakBwFljIxhOJqGkjUwZ9FSA==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "babel-plugin-macros": "^3.1.0" + }, + "peerDependenciesMeta": { + "babel-plugin-macros": { + "optional": true + } + } + }, "node_modules/deep-eql": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-0.1.3.tgz", diff --git a/package.json b/package.json index 89748f1..769ff9f 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "ast-types": "^0.14.2", "clear-module": "^4.1.2", "cpy-cli": "^5.0.0", + "dedent": "^1.6.0", "enhanced-resolve": "^5.17.1", "esbuild": "^0.19.8", "escalade": "^3.1.1", diff --git a/src/plugins.ts b/src/plugins.ts index 5453154..d2e69d2 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -128,7 +128,6 @@ async function loadBuiltinPlugins(): Promise { } async function loadThirdPartyPlugins(): Promise { - // Commented out plugins do not currently work with Prettier v3.0 let [astro, liquid, marko, twig, pug, svelte] = await Promise.all([ loadIfExistsESM('prettier-plugin-astro'), loadIfExistsESM('@shopify/prettier-plugin-liquid'), @@ -153,18 +152,25 @@ async function loadThirdPartyPlugins(): Promise { } async function loadCompatiblePlugins() { - // Commented out plugins do not currently work with Prettier v3.0 + // Plugins are loaded in a specific order for proper interoperability let plugins = [ - '@ianvs/prettier-plugin-sort-imports', - '@trivago/prettier-plugin-sort-imports', - 'prettier-plugin-organize-imports', 'prettier-plugin-css-order', - 'prettier-plugin-import-sort', - 'prettier-plugin-jsdoc', - 'prettier-plugin-multiline-arrays', 'prettier-plugin-organize-attributes', 'prettier-plugin-style-order', + + // The following plugins must come *before* the jsdoc plugin for it to + // function correctly. Additionally `multiline-arrays` usually needs to be + // placed before import sorting plugins. + // + // https://github.com/electrovir/prettier-plugin-multiline-arrays#compatibility + 'prettier-plugin-multiline-arrays', + '@ianvs/prettier-plugin-sort-imports', + '@trivago/prettier-plugin-sort-imports', + 'prettier-plugin-import-sort', + 'prettier-plugin-organize-imports', 'prettier-plugin-sort-imports', + + 'prettier-plugin-jsdoc', ] // Load all the available compatible plugins up front diff --git a/tests/plugins.test.ts b/tests/plugins.test.ts index bb4cfd8..3e61c8d 100644 --- a/tests/plugins.test.ts +++ b/tests/plugins.test.ts @@ -1,4 +1,5 @@ import { createRequire } from 'node:module' +import dedent from 'dedent' import { test } from 'vitest' import type { TestEntry } from './utils.js' import { format, no, pluginPath, t, yes } from './utils.js' @@ -467,6 +468,57 @@ import Custom from '../components/Custom.astro' ], }, }, + + // This test ensures that our plugin works with the multiline array, JSDoc, + // and import sorting plugins when used together. + // + // The plugins actually have to be *imported* in a specific order for + // them to function correctly *together*. + { + plugins: [ + 'prettier-plugin-multiline-arrays', + '@trivago/prettier-plugin-sort-imports', + 'prettier-plugin-jsdoc', + ], + options: { + multilineArraysWrapThreshold: 0, + importOrder: ['^@one/(.*)$', '^@two/(.*)$', '^[./]'], + importOrderSortSpecifiers: true, + }, + tests: { + babel: [ + [ + dedent` + import './three' + import '@two/file' + import '@one/file' + + /** + * - Position + */ + const position = {} + const arr = ['a', 'b', 'c', 'd', 'e', 'f'] + `, + dedent` + import '@one/file' + import '@two/file' + import './three' + + /** - Position */ + const position = {} + const arr = [ + 'a', + 'b', + 'c', + 'd', + 'e', + 'f', + ] + `, + ], + ], + }, + }, ] for (const group of tests) {