-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PSR12 does not forbid blank lines at the start of the class body #3437
Comments
I am seeing this as well, it seems that it is also not notifying of a blank line after a method opening brace.
I am on
|
This looks to be a missing check from the start. PSR2 allows as many blank lines as you want after the opening brace, so using that sniff alone was not enough to enforce the PSR12 rule. I'll add a new sniff to specifically enforce no blank lines after the opening brace. |
I think that's just for control structures, not functions and methods. I can't see a rule under methods that enforces no blank lines at the start of the method body |
I've added
It is auto-fixed like this: --- temp.php
+++ PHP_CodeSniffer
@@ -4,7 +4,5 @@
class Bar
{
-
-
public const X = 1;
} Thanks for reporting this. |
Fixes PSR12.Classes.OpeningBraceSpace.Found errors introduced in PHPCS release 3.6.2 in the whole project: classes can't start with a blank line For more, see: PHPCS release notes https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.6.2 PHPCS issue: squizlabs/PHP_CodeSniffer#3437
Describe the bug
In certain situations, PSR12 does not forbid blank lines at the start of class bodies, e.g. with class constants at the top.
This is in contrast to:
<rule ref="PSR2.Classes.ClassDeclaration"/>
in file PSR12/ruleset.xml which states: "Opening braces MUST be on their own line and MUST NOT be preceded or followed by a blank line."In some other cases, blank lines at the start of class bodies are rejected by specific rules, e.g. those for trait imports (use), properties and methods (functions).
Code sample
Expected behavior
Blank lines at the start of class bodies should always result in some sort of error with PSR12.
Versions (please complete the following information):
Additional context
I think the ClassDeclaration sniff neeeds to be adjusted for PSR12 so that it does not matter which kind of element is at the start of the class body (constants, property, method, ...). Leaving this logic to specific sniffs might result in future breakages as PHP evolves.
The text was updated successfully, but these errors were encountered: