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

[PSR-12] Line breaks before `extends`/`implements`

Open loilo opened this issue 5 years ago • 3 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. The extends and implements keywords MUST be declared on the same line as the class name. – Section 4.1

Playground link (contains all listed violations)

loilo avatar Sep 16 '19 23:09 loilo

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

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

We already support

The playground link above suggests that this is not supported.

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

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 and implements 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.

MaartenStaa avatar Jul 15 '21 14:07 MaartenStaa