Plugin-php: avoid unnecessary `?>` when program doesn't have inline nodes (html)

Created on 28 Sep 2018  路  14Comments  路  Source: prettier/plugin-php

In my opinion this should not be adding new lines to the end of a file.

discussion enhancement

Most helpful comment

Please vote :+1: for remove :heart: for leave, we need feedback, thanks

All 14 comments

@titoBouzout prettier do this, PSR also recommended do this, why you can't do this? Also it is should don't break code

My interpretation of this discussion is that the new line should be to the left of "?>" not to the right. https://groups.google.com/forum/#!topic/php-fig/PSzmcFVQst0

It looks like I could avoid the problem by omitting the closing tag "?>", so the new lines will not disturb the cookie declared after the inclusion of the code. Btw, they recommend to not use the closing tag when the file only includes php which may or not be true.. :) Anyways, Thanks for the pointer!

https://www.php-fig.org/psr/psr-2/

@titoBouzout Maybe we can avoid ?> when file doesn't have inline nodes

/cc @mgrip @czosel what do you think?

We definitely shouldn鈥檛 add newlines after ?> because that would indeed break code. I鈥檇 also be open for removing ?> if the file doesn鈥檛 contain any inline nodes.

@czosel we already don't add newline after ?>
/cc @titoBouzout you hav example where we add newline after ?>

https://imgur.com/a/zfK56fN

automatically removing "?>" looks like a good idea

@titoBouzout thanks, i will investigate this in near future

Thanks for the example @titoBouzout! It looks like a bug/edge case to me.

Input for future reference:

<? echo 2 + 2 ?>

Please vote :+1: for remove :heart: for leave, we need feedback, thanks

If you following PSR then when the file only has PHP the end tag should be removed.

@titoBouzout i agree for removing, but need some feedback

Hi.

I am using prettier in my pre-commit-hook using the php plugin, and I am also using the end-of-file hook which ensures every file ends with a newline and that there is are no trailing empty lines in text files.

Usually, both tools get along very well, but for a simple php script, which does not have a trailing ?> marker and ends with a simple echo statement, prettier insists on adding a blank line after the statement BUT the end-of-file hook insists on removing the trailing empty line... :boom:

I just got out of this endless loop by adding a ?> at the end of the file. So, if you want to enforce removing the ?> marker, that's fine. But please do not add empty lines before the final \n.

Just my 2 cents. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Selion05 picture Selion05  路  4Comments

alexander-akait picture alexander-akait  路  5Comments

hawkrives picture hawkrives  路  3Comments

alexander-akait picture alexander-akait  路  3Comments

aboyton picture aboyton  路  4Comments