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

[PSR-12] Property visibility

Open loilo opened this issue 6 years ago • 5 comments

Disclaimer: I am aware that it's not make-or-break for Prettier to adhere to PSR-12.

However, now that it is officially accepted as a standard, we should discuss (and, if necessary, reject) each current violation of PSR-12 — if only to have point to refer to in future discussions or issues.

PSR-12 Violations

  1. Visibility MUST be declared on all properties. – Section 4.3

  2. Visibility MUST be declared on all constants if your project PHP minimum version supports constant visibilities (PHP 7.1 or later). – Section 4.3

    Solving this would need an --engine flag.

loilo avatar Sep 17 '19 00:09 loilo

Need discussion, maybe it is not bad idea

alexander-akait avatar Sep 23 '19 11:09 alexander-akait

This also sounds like it's out of scope. Prettier doesn't usually add code, right?

glen-84 avatar Dec 18 '19 10:12 glen-84

Prettier does not add semantics. It adds/removes/moves punctuation though and you could argue that a previously missing public keyword is kind of that.

However, I could see this being perceived as kind of... encroaching, maybe.

loilo avatar Dec 18 '19 10:12 loilo

This is not done with Prettier for TypeScript. Also, you could argue that automatically inserting the visibility could result in the developer forgetting to set the correct visibility (for example, they may have intended to make the property private).

glen-84 avatar Dec 18 '19 10:12 glen-84

I can't imagine someone doing that, but I certainly won't assume that my coding habits are representative.

But I agree that while this would not add semantics, it would make implicit semantics explicit which may be unintended/confusing/annoying.

loilo avatar Dec 18 '19 10:12 loilo