Closed amostajo closed 4 years ago
Add WordPress formatting: https://github.com/nikic/PHP-Parser/blob/master/doc/component/Pretty_printing.markdown
First glance it appears they suggest using something like PHP-CS-Fixer as the PHP-Parser Pretty Printing 'does not provide any functionality to customize the formatting of the generated code.'
That being said they have some experimental support for preserving existing formatting; https://github.com/nikic/PHP-Parser/blob/master/doc/component/Pretty_printing.markdown#formatting-preserving-pretty-printing
Not sure if going with an experimental approach is best. If the PHP-CS-Fixer also support WPCS that could be a better avenue as it would fix any CS issues devs introduce themselves.
@garretthyder Upon reviewing PHP-CS-Fixer, I saw that it needs a PHAR file to work, I would like to keep the project as independent of executables as possible, so I ended up creating a custom Pretty Printer class that does the job: https://github.com/10quality/wpmvc-commands/blob/v1.0/src/Parser/WPPrinter.php
It currently applies the spacing requested by WordPress coding standards. In the future we can update it with more fixes if needed, it has an option to add multiple lines on parameters, so if we see that something is concatenated in one line, maybe we can code something to prettify the expression.
Nice, thanks @amostajo. Agreed the custom class is a better approach than introducing a .PHAR file. I'll give it a test when I have a chance.
https://github.com/10quality/ayuco/issues/4