plugin-php
plugin-php copied to clipboard
[PSR-12] Line breaks before `extends`/`implements`
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
-
The
extends
andimplements
keywords MUST be declared on the same line as the class name. – Section 4.1
We already support
The extends and implements keywords MUST be declared on the same line as the class name.
Maybe we should improve output when implements
contains only one item
We already support
The playground link above suggests that this is not supported.
Another example that I ran into when evaluating prettier-php
: playground link
This results in the following PSR12 violation:
[exec] FILE: app/Notifications/PasswordResetForUnactivatedAccountNotification.php
[exec] -----------------------------------------------------------------------------------------------------------
[exec] FOUND 1 ERROR AFFECTING 1 LINE
[exec] -----------------------------------------------------------------------------------------------------------
[exec] 8 | ERROR | [x] Expected 1 space before "SomeBaseNotification"; 5 found
[exec] -----------------------------------------------------------------------------------------------------------
[exec] PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
[exec] -----------------------------------------------------------------------------------------------------------
Maybe this one is just impossible to support in combination with the max line length with sufficiently long class names, as PSR12 states that:
The
extends
andimplements
keywords MUST be declared on the same line as the class name.
By definition, this means that the base class would also have to be on the same line.