diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a79df24..f62b0a0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add support for `prettier-plugin-multiline-arrays` ([#299](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/299)) - Add resolution cache for known plugins ([#301](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/301)) +### Added + +- Add support for `@zackad/prettier-plugin-twig` ([#255](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/255)) + ## [0.6.5] - 2024-06-17 - Only re-apply string escaping when necessary ([#295](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/295)) diff --git a/package-lock.json b/package-lock.json index a67ee18f..716271a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "@prettier/plugin-pug": "^3.0", "@shopify/prettier-plugin-liquid": "^1.4.0", "@trivago/prettier-plugin-sort-imports": "^4.3.0", + "@zackad/prettier-plugin-twig": "^0.7.0", "@zackad/prettier-plugin-twig-melody": "^0.5.0", "ast-types": "^0.14.2", "clear-module": "^4.1.2", @@ -164,13 +165,13 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.22.13", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz", - "integrity": "sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", + "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", "dev": true, "dependencies": { - "@babel/highlight": "^7.22.13", - "chalk": "^2.4.2" + "@babel/highlight": "^7.24.7", + "picocolors": "^1.0.0" }, "engines": { "node": ">=6.9.0" @@ -460,9 +461,9 @@ } }, "node_modules/@babel/helper-string-parser": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.7.tgz", - "integrity": "sha512-7MbVt6xrwFQbunH2DNQsAP5sTGxfqQtErvBIvIMi6EQnbgUOuVYanvREcmFrOPhoXBrTtjhhP+lW+o5UfK+tDg==", + "version": "7.24.8", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.8.tgz", + "integrity": "sha512-pO9KhhRcuUyGnJWwyEgnRJTSIZHiT+vMD0kPeD+so0l7mxkMT19g3pjY9GTnHySck/hDzq+dtW/4VgnMkippsQ==", "dev": true, "engines": { "node": ">=6.9.0" @@ -501,24 +502,28 @@ } }, "node_modules/@babel/highlight": { - "version": "7.22.20", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.20.tgz", - "integrity": "sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==", + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.7.tgz", + "integrity": "sha512-EStJpq4OuY8xYfhGVXngigBJRWxftKX9ksiGDnmlY3o7B/V7KIAc9X4oiK87uPJSc/vs5L869bem5fhZa8caZw==", "dev": true, "dependencies": { - "@babel/helper-validator-identifier": "^7.22.20", + "@babel/helper-validator-identifier": "^7.24.7", "chalk": "^2.4.2", - "js-tokens": "^4.0.0" + "js-tokens": "^4.0.0", + "picocolors": "^1.0.0" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/parser": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.0.tgz", - "integrity": "sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==", + "version": "7.25.3", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.25.3.tgz", + "integrity": "sha512-iLTJKDbJ4hMvFPgQwwsVoxtHyWpKKPBrxkANrSYewDPaPpT5py5yeVkgPIJ7XYXhndxJpaA3PyALSXQ7u8e/Dw==", "dev": true, + "dependencies": { + "@babel/types": "^7.25.2" + }, "bin": { "parser": "bin/babel-parser.js" }, @@ -589,14 +594,14 @@ } }, "node_modules/@babel/template": { - "version": "7.22.15", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.15.tgz", - "integrity": "sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==", + "version": "7.25.0", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.25.0.tgz", + "integrity": "sha512-aOOgh1/5XzKvg1jvVz7AVrx2piJ2XBi227DHmbY6y+bM9H2FlN+IfecYu4Xl0cNiiVejlsCri89LUsbj8vJD9Q==", "dev": true, "dependencies": { - "@babel/code-frame": "^7.22.13", - "@babel/parser": "^7.22.15", - "@babel/types": "^7.22.15" + "@babel/code-frame": "^7.24.7", + "@babel/parser": "^7.25.0", + "@babel/types": "^7.25.0" }, "engines": { "node": ">=6.9.0" @@ -624,12 +629,12 @@ } }, "node_modules/@babel/types": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.24.7.tgz", - "integrity": "sha512-XEFXSlxiG5td2EJRe8vOmRbaXVgfcBlszKujvVmWIK/UpywWljQCfzAv3RQCGujWQ1RD4YYWEAqDXfuJiy8f5Q==", + "version": "7.25.2", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.25.2.tgz", + "integrity": "sha512-YTnYtra7W9e6/oAZEHj0bJehPRUlLH9/fbpT5LfB0NhQXyALCRkRs3zH9v07IYhkgpqX6Z78FnuccZr/l4Fs4Q==", "dev": true, "dependencies": { - "@babel/helper-string-parser": "^7.24.7", + "@babel/helper-string-parser": "^7.24.8", "@babel/helper-validator-identifier": "^7.24.7", "to-fast-properties": "^2.0.0" }, @@ -1992,6 +1997,23 @@ "url": "https://opencollective.com/vitest" } }, + "node_modules/@zackad/prettier-plugin-twig": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@zackad/prettier-plugin-twig/-/prettier-plugin-twig-0.7.0.tgz", + "integrity": "sha512-AedIV7MwAsxfRBvOmxiujLNqDl0fSwWpoVllDXgm5v/uBlr06EUTsLgJCvBtUviYWk/zTg6qkTzEgSHkVrGRmg==", + "dev": true, + "dependencies": { + "@babel/template": "^7.24.7", + "@babel/types": "^7.24.9", + "he": "^1.2.0", + "lodash": "^4.17.21", + "prettier": "^3.0.0", + "resolve": "^1.12.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/@zackad/prettier-plugin-twig-melody": { "version": "0.5.0", "resolved": "https://registry.npmjs.org/@zackad/prettier-plugin-twig-melody/-/prettier-plugin-twig-melody-0.5.0.tgz", diff --git a/package.json b/package.json index 5bf93bbc..958ccf27 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "@shopify/prettier-plugin-liquid": "^1.4.0", "@trivago/prettier-plugin-sort-imports": "^4.3.0", "@zackad/prettier-plugin-twig-melody": "^0.5.0", + "@zackad/prettier-plugin-twig": "^0.7.0", "ast-types": "^0.14.2", "clear-module": "^4.1.2", "cpy-cli": "^5.0.0", diff --git a/src/index.ts b/src/index.ts index 25f76bce..ec59647b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1174,6 +1174,14 @@ export const parsers: Record = { }), } : {}), + ...(base.parsers.twig + ? { + // Note: Melody and twig are the same language + twig: createParser('twig', transformMelody, { + staticAttrs: ['class'], + }), + } + : {}), ...(base.parsers.pug ? { pug: createParser('pug', transformPug, { diff --git a/src/plugins.ts b/src/plugins.ts index 1fae06f9..613dc7d8 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -129,11 +129,12 @@ async function loadBuiltinPlugins(): Promise { async function loadThirdPartyPlugins(): Promise { // Commented out plugins do not currently work with Prettier v3.0 - let [astro, liquid, marko, melody, pug, svelte] = await Promise.all([ + let [astro, liquid, marko, melody, twig, pug, svelte] = await Promise.all([ loadIfExistsESM('prettier-plugin-astro'), loadIfExistsESM('@shopify/prettier-plugin-liquid'), loadIfExistsESM('prettier-plugin-marko'), loadIfExistsESM('@zackad/prettier-plugin-twig-melody'), + loadIfExistsESM('@zackad/prettier-plugin-twig'), loadIfExistsESM('@prettier/plugin-pug'), loadIfExistsESM('prettier-plugin-svelte'), ]) @@ -143,6 +144,7 @@ async function loadThirdPartyPlugins(): Promise { ...liquid.parsers, ...marko.parsers, ...melody.parsers, + ...twig.parsers, ...pug.parsers, ...svelte.parsers, }, diff --git a/tests/plugins.test.ts b/tests/plugins.test.ts index 1049a529..43dc8308 100644 --- a/tests/plugins.test.ts +++ b/tests/plugins.test.ts @@ -164,6 +164,40 @@ let tests: PluginTest[] = [ ], }, }, + { + plugins: ['@zackad/prettier-plugin-twig'], + options: { + twigAlwaysBreakObjects: false, + }, + tests: { + twig: [ + [ + `
`, + `
`, + ], + t`
`, + t`
`, + t`
`, + t`
`, + t`
`, + + // text-center is used because it's placed between p-0 and sm:p-0 + t`
`, + t`
`, + t`
`, + t`
`, + + [ + `
`, + `
`, + ], + [ + `
`, + `
`, + ], + ], + }, + }, { plugins: ['@prettier/plugin-pug'], tests: {