plugin-php
plugin-php copied to clipboard
Improve formatting of heredoc/nowdoc
As suggested in https://github.com/prettier/plugin-php/issues/1274#issuecomment-570709723:
I'd say, it would be The Prettier Way™ (and also the prettier way ) to figure out one way to print heredocs and to enforce that.
One process which sounds reasonable to me: If the starting tag goes on its own line, align the content with that. Otherwise indent it one
tabWidthfurther.Examples of the described rule
Example 1
The heredoc-opening tag goes on its own line.
Input:
some_function(<<<'EOT' Hello World! EOT );Current output:
some_function( <<<'EOT' Hello World! EOT );Envisioned output:
some_function( <<<'EOT' Hello World! EOT );Example 2
The heredoc-opening tag goes on the same line as the preceding code.
Input:
$string = <<<'EOT' Hello World! EOT;Current output:
$string = <<<'EOT' Hello World! EOT;Envisioned output:
$string = <<<'EOT' Hello World! EOT;
The first example is actually already printed correctly, but the second one isn't (playground)
Upvoting this! 🚀