Skip to content

Commit

Permalink
Remove support for @prettier/plugin-php (#152)
Browse files Browse the repository at this point in the history
* Remove support for `@prettier/plugin-php`

* Update changelog
  • Loading branch information
thecrypticace committed Apr 28, 2023
1 parent df84d8f commit dfc4f64
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 49 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing yet!
### Fixed

- Remove support for `@prettier/plugin-php` ([#152](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/152))

## [0.2.7] - 2023-04-05

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ If a local configuration file cannot be found the plugin will fallback to the de

This plugin uses Prettier APIs that can only be used by one plugin at a time, making it incompatible with other Prettier plugins implemented the same way. To solve this we've added explicit per-plugin workarounds that enable compatibility with the following Prettier plugins:

- `@prettier/plugin-php`
- `@prettier/plugin-pug`
- `@shopify/prettier-plugin-liquid`
- `@ianvs/prettier-plugin-sort-imports`
Expand Down
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
},
"devDependencies": {
"@ianvs/prettier-plugin-sort-imports": "^3.7.0",
"@prettier/plugin-php": "^0.19.2",
"@prettier/plugin-pug": "^2.3.0",
"@shopify/prettier-plugin-liquid": "^1.0.3",
"@shufo/prettier-plugin-blade": "^1.8.4",
Expand Down Expand Up @@ -61,7 +60,6 @@
},
"peerDependencies": {
"@ianvs/prettier-plugin-sort-imports": "*",
"@prettier/plugin-php": "*",
"@prettier/plugin-pug": "*",
"@shopify/prettier-plugin-liquid": "*",
"@shufo/prettier-plugin-blade": "*",
Expand All @@ -81,9 +79,6 @@
"@ianvs/prettier-plugin-sort-imports": {
"optional": true
},
"@prettier/plugin-php": {
"optional": true
},
"@prettier/plugin-pug": {
"optional": true
},
Expand Down
31 changes: 0 additions & 31 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,6 @@ export const parsers = {
...(base.parsers.astro
? { astro: createParser('astro', transformAstro) }
: {}),
...(base.parsers.php ? { php: createParser('php', transformPHP) } : {}),
...(base.parsers.melody
? { melody: createParser('melody', transformMelody) }
: {}),
Expand Down Expand Up @@ -687,33 +686,6 @@ function transformAstro(ast, { env, changes }) {
}
}

function transformPHP(ast, { env, changes }) {
if (ast.kind === 'inline') {
let leading = ast.raw.match(/^\s*/)[0]
let trailing = ast.raw.match(/\s*$/)[0]

// If the inline block is just whitespace then we don't need to format
if (ast.raw === leading) {
return
}

// We have to parse this as HTML with prettier
let parsed = prettier.format(ast.raw, {
...env.options,
parser: 'html',
})

let formatted = `${leading}${parsed.trimEnd()}${trailing}`

ast.raw = formatted
ast.value = formatted
}

for (let child of ast.children ?? []) {
transformPHP(child, { env, changes })
}
}

/*
function transformBlade(ast, { env, changes }) {
// Blade gets formatted on parse
Expand Down Expand Up @@ -908,7 +880,6 @@ function getBasePlugins() {
// And we are not bundling it with the main Prettier plugin
let astro = loadIfExists('prettier-plugin-astro')
let svelte = loadIfExists('prettier-plugin-svelte')
let php = loadIfExists('@prettier/plugin-php')
let melody = loadIfExists('prettier-plugin-twig-melody')
let pug = loadIfExists('@prettier/plugin-pug')
let liquid = loadIfExists('@shopify/prettier-plugin-liquid')
Expand All @@ -935,7 +906,6 @@ function getBasePlugins() {

...(svelte?.parsers ?? {}),
...(astro?.parsers ?? {}),
...(php?.parsers ?? {}),
...(melody?.parsers ?? {}),
...(pug?.parsers ?? {}),
...(liquid?.parsers ?? {}),
Expand All @@ -961,7 +931,6 @@ function getCompatibleParser(parserFormat, options) {
'@ianvs/prettier-plugin-sort-imports',
'@trivago/prettier-plugin-sort-imports',
'prettier-plugin-organize-imports',
'@prettier/plugin-php',
'@prettier/plugin-pug',
'@shopify/prettier-plugin-liquid',
'@shufo/prettier-plugin-blade',
Expand Down
11 changes: 0 additions & 11 deletions tests/plugins.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,6 @@ let tests = [
],
},
},
{
plugins: ['@prettier/plugin-php'],
tests: {
php: [
[
`<?php $test = function($a,$b){}\n ?>\n <div class="sm:p-0 p-4">Example</div>\n <?php $test = function($c,$d)use($e) {}`,
`<?php $test = function ($a, $b) {}; ?>\n <div class="p-4 sm:p-0">Example</div>\n <?php $test = function ($c, $d) use ($e) {};`,
],
],
},
},
{
plugins: ['prettier-plugin-import-sort'],
tests: {
Expand Down

0 comments on commit dfc4f64

Please sign in to comment.