Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin detection issue with prettier v3 #2215

Closed
mermshaus opened this issue Aug 17, 2023 · 7 comments
Closed

Plugin detection issue with prettier v3 #2215

mermshaus opened this issue Aug 17, 2023 · 7 comments

Comments

@mermshaus
Copy link

Hi,

thanks for the prettier v3 update from yesterday!

I tried to update today but couldn’t figure out how to do it.

Works: prettier 2.8.8, plugin-php 0.19.0

$ nvm use 20 && npm install --global prettier@2.8.8 @prettier/plugin-php@0.19.0 && npm list --global && echo '<?php $foo="bar";' | prettier --stdin-filepath=foo.php
Now using node v20.5.1 (npm v9.8.0)

changed 8 packages in 1s

2 packages are looking for funding
  run `npm fund` for details
/home/marc/.nvm/versions/node/v20.5.1/lib
├── @prettier/plugin-php@0.19.0
├── corepack@0.19.0
├── npm@9.8.0
└── prettier@2.8.8

<?php $foo = "bar";

Doesn't work: prettier 3.0.2, plugin-php 0.20.0

$ nvm use 20 && npm install --global prettier@3.0.2 @prettier/plugin-php@0.20.0 && npm list --global && echo '<?php $foo="bar";' | prettier --stdin-filepath=foo.php
Now using node v20.5.1 (npm v9.8.0)

changed 8 packages in 863ms

2 packages are looking for funding
  run `npm fund` for details
/home/marc/.nvm/versions/node/v20.5.1/lib
├── @prettier/plugin-php@0.20.0
├── corepack@0.19.0
├── npm@9.8.0
└── prettier@3.0.2

[error] No parser could be inferred for file "foo.php".
$ prettier --support-info | grep -i php
(1) $

Maybe I’m making an obvious mistake, but I thought it couldn’t hurt to add this as an issue.

Thanks!

Marc

@czosel
Copy link
Collaborator

czosel commented Aug 18, 2023

Hi @mermshaus, thanks for the bug report! It seems that plugins now have to be registered explicitly, e.g. by passing --plugin=@prettier/plugin-php. See here for details and alternatives. We'll have to update our docs to reflect this.

@fisker has the implicit plugin registration been dropped?

@fisker
Copy link
Member

fisker commented Aug 19, 2023

The plugin search feature has been removed.

@mermshaus
Copy link
Author

mermshaus commented Aug 19, 2023

Hi everyone,

thanks for the quick help! Adding the plugin configuration/CLI arguments solves this issue.

There is one thing of note: If you have a global installation of prettier, plugin configuration won’t work (right now), at least not by simply specifying the package name. It’s possible to use an absolute path to a plugin’s entry point to work around this. E.g. prettier --plugin /usr/lib/node_modules/@prettier/plugin-php/src/index.js.

@coffebar
Copy link

@mermshaus I have tried your workaround with plugin-php and I see the error message is gone, but it's not gonna work: no formatting.
Is it still work for you?

test.php

<?php
if(1 ){ echo 2;  }
?>
prettier --log-level debug test.php \
  --plugin /home/abc/.node_modules/lib/node_modules/@prettier/plugin-php/src/index.js \
  --parser php

Output:

[debug] normalized argv: {"":["test.php"],"cache":false,"color":true,"editorconfig":true,"logLevel":"debug","plugins":["/home/abc/.node_modules/lib/node_modules/@prettier/plugin-php/src/index.js"],"parser":"php","configPrecedence":"cli-override","debugRepeat":0,"ignorePath":[".gitignore",".prettierignore"],"_":["test.php"],"__raw":{"_":["test.php"],"cache":false,"color":true,"editorconfig":true,"log-level":"debug","plugin":"/home/abc/.node_modules/lib/node_modules/@prettier/plugin-php/src/index.js","parser":"php","config-precedence":"cli-override","debug-repeat":0,"ignore-path":[".gitignore",".prettierignore"]}}
[debug] resolve config from '/home/abc/test.php'
[debug] loaded options `{"parser":"php","plugins":["/home/abc/.node_modules/lib/node_modules/@prettier/plugin-php/src/index.js"],"useTabs":false,"tabWidth":2}`
[debug] applied config-precedence (cli-override): {"parser":"php","plugins":["/home/abc/.node_modules/lib/node_modules/@prettier/plugin-php/src/index.js"],"tabWidth":2,"useTabs":false}
<?php
if(1 ){ echo 2;  }
?>

@mjsteinbaugh
Copy link

@coffebar Specifying the full plugin path works for me, but I find this to be an annoying regression as this wasn't required previously with prettier v2

@mermshaus
Copy link
Author

@coffebar Yes, it still works for me. To avoid derailing this issue, I put more info here. I hope it may be of help to you.

@felixmosh
Copy link

Downgraded to v2 since phpStorm uses global prettier & php plugin instances 👎🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants