prettier / plugin-php

Prettier PHP Plugin
https://loilo.github.io/prettier-php-playground/
MIT License
1.75k stars 130 forks source link

[PSR-12] Property visibility #1179

Open loilo opened 5 years ago

loilo commented 5 years ago

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.

alexander-akait commented 5 years ago

Need discussion, maybe it is not bad idea

glen-84 commented 4 years ago

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

loilo commented 4 years ago

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.

glen-84 commented 4 years ago

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).

loilo commented 4 years ago

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.