-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat: Add trailing comma in multiline to PER-CS 2.0 #7916
feat: Add trailing comma in multiline to PER-CS 2.0 #7916
Conversation
I'll need to take some advice on how's best to pass the PHP 7.4 tests, will it be simply a case of removing the |
src/RuleSet/Sets/PERCS2x0Set.php
Outdated
'trailing_comma_in_multiline' => [ | ||
'after_heredoc' => true, | ||
'elements' => ['arguments', 'arrays', 'match', 'parameters'], | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand, the PER rule covers any kind of multiline list that can have a comma after the last item. I think it would be nice to rework trailing_comma_in_multiline
in the future so it can fix everything without the need to configure every possible kind of list, by default or with e.g. option ['elements' => '@all']
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PER rule covers any kind of multiline list
I'm not sure. eg, it mentions function arguments in function declaration, but not function call params.
I'm +1 to have @all
available.
I would be careful with @all
by default, as it can easily create bc breaks in someone CS.
Parameters and match options will be ignored if PHP version < 8.0
7ac2ed4
to
ea4d1ea
Compare
0ad855c
to
091cdaa
Compare
091cdaa
to
44fe005
Compare
tests/Fixer/ControlStructure/TrailingCommaInMultilineFixerTest.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
@keradus Do you want to check again before merging?
I don't mind, but as you poked me it got my attention anyway. old concerns of mine are solved 👍🏻 |
Thanks @michaelvickersuk! |
This is an another (see #6933) BC break in a minor version. My config: return (new PhpCsFixer\Config())->setRules([
'@PER-CS' => true,
'not_operator_with_successor_space' => true,
'no_break_comment' => false,
])
->setFinder($finder)
->setCacheFile(__DIR__ . '/storage/.php-cs-fixer.cache')
; Now I have 5% of my codebase "breaking" thanks to this PR. |
What I mean is, people set up CI pipelines to analyze and deploy their code. (P.S. why else do people use php-cs-fixer for?) Someone in the team does an innocent composer update and CI pipeline is broken because 5% of the codebase is now not passing the cs-fixer step. I meant to reference issue #6658 in my original comment, it's the second time in less than two years that this scenario happens. |
Sound to me like the problem is not on PHP CS Fixer side 😉. Maybe you need to have constraint like Also, similarly to #6658, the same reasoning @keradus made there, according to https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/feature-or-bug.rst#feature this is no BC break, but more of a feature, and I agree with it. You are using PER and E stands for evolving, and in this case it simply evolved. |
@raveren You need to decide whether you follow the
Thank you for understanding and in the future, please consider interacting without accusations. |
Replying to @Wirone: in that case maybe it would be nice to notify your users on the website (https://cs.symfony.com/doc/ruleSets/PER-CS.html) that the rulesets can and will change under their noses, it's a VERY important consideration when building a CI pipeline. |
I think this info is hugely important:
I can't find that stated anywhere, and that already constitutes a constructive and valid BC policy. But users need to know that to prevent such unpleasant surprises in the future. |
Why would it be not advised? If you follow pre-defined ruleset, you agree to its rules. It's not a problem of the tool, it's the problem of your CI pipeline and development process. There is nothing like "someone in the team does an innocent composer update" - if there was Composer update and Fixer's version was bumped, developer who did the update should apply CS rules, so nothing fails in CI. If applied changes are not wanted, then your own config should be improved to continue with what you had before (override rulesets' config with custom config for specific rules).
I don't remember now if we have such explicit information about rulesets, but I always thought it's obvious. Imagine bumping major version after every ruleset modification, or adding more and more clones of existing rulesets 🤷. You want stable ruleset? Prepare your own. |
Ah, yeah it's true. However php-cs-fixer has no "killer" features above the PHPStorm one, and there are important things that cs-fixer does not support (e.g.: import cleanup, notably max line length, etc). Plus: the inbuilt formatter is simpler to set up and use, which is especially relevant when we're talking about a rotating team of developers on different platforms: some might not even have PHP running locally. |
can you elaborate how import cleanup is not supported?
that's by design, because it can never be fully supported |
Import cleanup is sorting and removing the unused |
You mean this? 🤷♂️
How's sharing parts of
Set up Docker stack and configure remote PHP interpreter within shared |
Hey, thanks for trying, but this is not a conversation about options for my tech stack, I am simply giving you a real world situation as feedback from your users so you have a better idea. Besides, no hard feelings, but the number one reason I wouldn't base so much of a business on this project is because it broke its SemVer (and my trust) twice and the support response both times was "no we didn't! 👺". |
Modifying built-in rulesets is not a SemVer violation, as the engine (public API) does not change and each specific rule also works the same. The only thing that changes is the scope of the ruleset, which you implicitly agree on by opting-in when you base your setup on such ruleset. It's like complaining that PHPStan reports new issues when you have bleeding edge enabled. Sorry if it was not clear, we'll try to add such information in the docs. However, stating that Fixer violates SemVer after all the effort we put into keeping backward compatibility is just rude. |
I mean, yeah, none of the maintainers here has a "real world" job where they could use the thing they build and see how it actually works 🤷 Also, even a little bugfix can break a CI. This is true for any package you might rely on but especially for us. Like e.g. a bug that prevents a rule from fixing code in an edge-case that happens to exist in your codebase. Fixing that bug will make your CI fail too, this does't mean we should make a major release each time we fix a bug. So please, pin the versions of your tools, check what happens when you do upgrade them, and be nice when reporting actual issues. Thanks. |
This is thanks to PHP-CS-Fixer/PHP-CS-Fixer#7916 that adds `trailing_comma_in_multiline` to the PER-CS-2.0 ruleset
This is thanks to PHP-CS-Fixer/PHP-CS-Fixer#7916 that adds `trailing_comma_in_multiline` to the PER-CS-2.0 ruleset
As per https://www.php-fig.org/per/coding-style/#26-trailing-commas
Closes #7664