plugin-php icon indicating copy to clipboard operation
plugin-php copied to clipboard

Improve formatting of heredoc/nowdoc

Open czosel opened this issue 4 years ago • 1 comments

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 tabWidth further.

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)

czosel avatar Nov 14 '20 13:11 czosel

Upvoting this! 🚀

adevade avatar Jan 27 '21 16:01 adevade