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
PSR-12 / PER-CS v1 Support #4502
Comments
What about this - specifically the part about spaces between class/function/const imports. It this possible currently? |
No, the newlines between different use types is not yet possible, however there is a longstanding issue (without PR) addressing it: #3582 edit: I would like to see that being resolved as well as part of this meta-issue |
Is this part already covered somewhere? As to your boolean operator fixer: I'd like the fixer to be able to do both, depending on config (always_front, always_back, when_mixed_front, when_mixed_back). It was not clear from your suggestion if you meant this, or just let it do only one of the bullet-points. |
@kbond Indeed, I updated my post with PR ref given by @dmvdbrugge. @dmvdbrugge Actually even the "each subsequent line is indented at least once" isn't supported currently. I updated my post to add the rules. As they both deal with whitespace, maybe we could implement them in a single fixer? I also updated my suggestion for the boolean operator position fixer, hope it's better now :) Thanks! |
From #4568, perhaps PSR-12 should be the default configuration for v3. |
Since PHP-CS-Fixer/PHP-CS-Fixer#4502 has been merged and is now supported, the documentation should mention this too
Any update on psr-12 support? |
Nope, nobody gave it a try yet. |
Perhaps it makes sense to create a branch that aggregates a |
We can create a |
If useful, Rule set * not checked. |
For the imports section https://www.php-fig.org/psr/psr-12/#3-declare-statements-namespace-and-import-statements
The support for ordering imports by type first is implemented https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/doc/rules/import/ordered_imports.rst#imports_order so the checkbox can be checked. And the support for forcing blank line between import statement types was recently added But there is one missing item in this list.
should be fixed to
Can you add it to the list ? @julienfalque |
Thanks @VincentLanglet, description updated. |
I still have an issue with traits. Using <?php
class MyClass
{
use SomeTrait;
private $em;
// ...
} To be fixed to : <?php
class MyClass
{
use SomeTrait;
private $em;
// ...
} But it does nothing. Any clue what could I do ? Thanks 😉 |
Hi, Try configuring class_attributes_separation. $ php php-cs-fixer fix test.php --rules=class_attributes_separation --dry-run -vvv --diff
PHP CS Fixer 3.9.6-DEV Grand Awaiting by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 7.4.24
Loaded config default from "/home/possum/work/PHP-CS-Fixer/.php-cs-fixer.dist.php".
Paths from configuration file have been overridden by paths provided as command arguments.
F 1 / 1 (100%)
Legend: .-no changes, F-fixed, S-skipped (cached or empty file), I-invalid file syntax (file ignored), E-error
1) PHP-CS-Fixer/test.php (class_attributes_separation)
---------- begin diff ---------- --- /home/possum/work/PHP-CS-Fixer/test.php
+++ /home/possum/work/PHP-CS-Fixer/test.php
@@ -15,6 +15,7 @@
class test
{
use SomeTrait;
+
private $em;
// ...
} (seems the SF set config for For more questions, please ask here: |
What about spaces around string binary operators (see https://www.php-fig.org/psr/psr-12/#62-binary-operators) like concatinaion? |
@a-menshchikov there's #6861 created recently after discussion #6849. |
PSR-PER standard has been published recently (2 weeks ago). It is an evolving standard which builds onto PSR-12. Ref: |
Since this issue has not had any activity within the last 90 days, I have marked it as stale. I will close it if no further activity occurs within the next 30 days. |
@Wirone what about splitting this issue into the separate ones? I want to comment on 5.x, but the discussion here on multitopic is quite too long to be helpful. |
@mvorisek I agree, that's why I unpinned this issue some time ago. First of all I believe we should focus on PER-CS now, since #6707 was merged it's now possible to work on v2. I am not sure if investing time in PSR-12 is good at this point. Anyway, if we want to continue working on this, we should create milestone with dedicated issues for each remaining task from this issue's checklist. @keradus what do you think about this idea? I could split this issue in the meantime. |
@Wirone keep in mind that PER-CS 1.0 is (intentionally) basically the same as PSR-12: https://groups.google.com/g/php-fig/c/bBh4Y-R5gxE So you could split this up in sub-issues and keep them as valid, and just review them against the PER-CS 2.0 change list: https://github.com/php-fig/per-coding-style/releases/tag/2.0.0 |
This comment was marked as outdated.
This comment was marked as outdated.
Hi @Wirone, what about adding The rule seems pretty similar to what is asked in PSR12. Currently it's used by Symfony Ruleset and PSR12 ruleset. |
PSR-12 just got approved. PER-CS v1 is the same in terms of rules, so all the changes must be included in both of them (
@PSR12
,@PER-CS1.0
).I think PHP CS Fixer already supports almost all of its rules. The missing cases I could notice are the following:
3. Declare Statements, Namespace, and Import Statements
ordered_imports
currently sorts imports without considering their type. We should add an option to sort by type first. We should also add an option (or dedicated rule) to add a separation line between each import group.We need to create a fixer that could force boolean operators to always be at the same position with two options like e.g.:
position
(beginning
orend
): choose whether the operators should be at the beginning or end of the lines;when
(always
ormixed
): whether the rule should always be applied or only when a mix of positions is found.We also need to support the multiple lines part of the rule:
You need to update
class_definition
to support adding a spacing before the parentheses innew class()
.I think this is currently covered by the rule
braces
. Not sure if we should add a new option to it or create a new fixer.TODO
implements
list wrapsnew class()
(ClassDefinitionFixer - PSR12 for anonymous class #5877)@PSR12
ruleset (Add PSR12 ruleset #4943)The text was updated successfully, but these errors were encountered: