Skip to content

Commit

Permalink
Add support for new twig plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed Aug 2, 2024
1 parent ee50b9b commit 521576a
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
74 changes: 48 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,14 @@ export const parsers: Record<string, Parser> = {
}),
}
: {}),
...(base.parsers.twig
? {
// Note: Melody and twig are the same language
twig: createParser('twig', transformMelody, {
staticAttrs: ['class'],
}),
}
: {}),
...(base.parsers.pug
? {
pug: createParser('pug', transformPug, {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ async function loadBuiltinPlugins(): Promise<PluginDetails> {

async function loadThirdPartyPlugins(): Promise<PluginDetails> {
// 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'),
])
Expand All @@ -143,6 +144,7 @@ async function loadThirdPartyPlugins(): Promise<PluginDetails> {
...liquid.parsers,
...marko.parsers,
...melody.parsers,
...twig.parsers,
...pug.parsers,
...svelte.parsers,
},
Expand Down
34 changes: 34 additions & 0 deletions tests/plugins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,40 @@ let tests: PluginTest[] = [
],
},
},
{
plugins: ['@zackad/prettier-plugin-twig'],
options: {
twigAlwaysBreakObjects: false,
},
tests: {
twig: [
[
`<section class="{{ {base:css.prices}|classes }}"></section>`,
`<section class="{{ { base: css.prices }|classes }}"></section>`,
],
t`<section class="${yes}"></section>`,
t`<section class="${yes} text-{{ i }}"></section>`,
t`<section class="${yes} {{ i }}-text"></section>`,
t`<section class="text-{{ i }} ${yes}"></section>`,
t`<section class="{{ i }}-text ${yes}"></section>`,

// text-center is used because it's placed between p-0 and sm:p-0
t`<section class="${yes} text-center{{ i }}"></section>`,
t`<section class="${yes} {{ i }}text-center"></section>`,
t`<section class="text-center{{ i }} ${yes}"></section>`,
t`<section class="{{ i }}text-center ${yes}"></section>`,

[
`<div class=" sm:flex underline block"></div>`,
`<div class="block underline sm:flex"></div>`,
],
[
`<div class="{{ ' flex ' + ' underline ' + ' block ' }}"></div>`,
`<div class="{{ 'flex ' + ' underline' + ' block' }}"></div>`,
],
],
},
},
{
plugins: ['@prettier/plugin-pug'],
tests: {
Expand Down

0 comments on commit 521576a

Please sign in to comment.