Bloggings

Home

Prettier when it works

24-08-2023

Prettier is a great code beautifier for PHP, once you get it to work.

https://prettier.io/

https://github.com/prettier/plugin-php

Installation

On Arch Linux, PHP 8.2

npm install --global prettier @prettier/plugin-php

usage: prettier test.php

But all I could get was

[error] No parser could be inferred for file "test.php"

After a lot of fiddling and swearing, I solved it by creating ~/.prettierrc

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

 


A minimalist blog by Philip Wittamore