lassik / emacs-format-all-the-code

Auto-format source code in many languages with one command
https://melpa.org/#/format-all
MIT License
621 stars 108 forks source link

can't format php code #234

Open heheda123123 opened 1 year ago

heheda123123 commented 1 year ago

when use format-all-buffer for any php file, it shows

[error] Couldn't resolve parser "php".

in *format-all-errors* image I already install the plugin image

lassik commented 1 year ago

Are your PHP files in a Node project (with its own package.json)? In that case, it might work to try npm install prettier @prettier/plugin-php with no --global option.

heheda123123 commented 1 year ago

no, it's just a single php file

heheda123123 commented 1 year ago

in a different computer, create a simple php file, still have this problem image

claytonrcarter commented 1 year ago

Just ran into the same issue, also on a one-off project w/ no package.json, but it's nothing to do w/ this package. It's related to a breaking change in prettier v3. More info here: https://github.com/prettier/plugin-php/issues/2215

I have worked around it by putting a .prettierrc.json in $HOME and explicitly adding plugins that way:

{
    "plugins": [
        "/usr/local/lib/node_modules/@prettier/plugin-php/src/index.js"
    ]
}

With this, prettier on the CLI and via emacs starts working again. (prettier searchs for configs up from the file being formatted, and – in my case – all of my code is in $HOME/src. If you put your code elsewhere, you should adjust accordingly.)

(BTW Apparently global installs still can't handle short plugin names like @prettier/plugin-php, so the full path is required.)

lassik commented 1 year ago

Thanks, glad to have this sorted out. This is excellent information. We should add this link to the readme if more people stumble upon the same problem.

rdbeni0 commented 5 months ago

little update - this is upstream issue:

https://github.com/prettier/prettier/issues/15141

https://github.com/auvred/prettier-pnp