-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
CS: trailing commas #53352
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
CS: trailing commas #53352
Conversation
|
In general, I'm in favor of this (and adding to |
|
I'm supportive as well (including it in @symfony by default makes sense to me as well). |
|
Great idea 😍 |
|
If i understand it correctly, any multiline argument given to a method will get a trailing coma, even if there is only one argument allowed in the method ? Imaginary code, but i feel some similar are in the changed files $foobar = 'foobar';
$foobar = ucfirst(
str_replace(
['foo', 'bar'],
['Foo', 'Bar'],
$foobar,
+ ),
); |
overall, as code-change is big, i want to see the impact on codebase first, ensure the config we want to go with, and when this will be aligned, adjust the ruleset. otherwise we adjust the ruleset and then potentially see not all changes are welcome only afterwards 😅 |
yes, if opening |
|
had to do some partial revert, looks like we found bug on Pslam |
|
I'm not convinced this is an improvement in term of readability.. but that's very personal :) $foo = my_method([
'foo' => 'foo',
'bar' => 'Bar',
-]);
+],); |
You're example wouldn't be adjusted this way (from what I can see in my app). |
src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php
Outdated
Show resolved
Hide resolved
Indeed, thanks. I over-generalized.. the "problematic" one for me would be the one i just quoted : method with a single argument. |
|
not sure if failing related anyhow? happy to get guidance https://github.com/symfony/symfony/actions/runs/7390078815/job/20104252552?pr=53352#step:8:8085 |
|
Is there a way to tweak the rule to require the comma on the declaration side, but not on the call side? |
|
If I understood right, you want elements => parameters to be enabled, but elements => arguments to be disabled. We have this tech possibility and I would encourage to have both enabled, to make the rule simpler ("trailing commas everywhere" rather than "trailing commas here and here, but not there"). Would you mind to share your reasoning for idea to not enable everywhere, so I can understand better? Yet, if you are concluding that you want to disable trailing commas on arguments, I can do it - it's already better for me to enable it in some places that in none of them. |
I would want them on both sides, tbh. |
|
I want trailing commas on constructor declarations (and on arrays) because it's quite common to add a new argument there and having to add a comma after the last existing argument creates noisy diffs that complicate reviews, blurs the git history, etc. But I'd prefer no trailing comma on function calls because a trailing comma tells my brain something can come next, while it's usually not the case ( This breaks my brain as @chalasr wrote somewhere on another CS topic :) |
|
You can train your brain to accept this. Trust me. ✌️ |
|
I use it myself and it hurts me to not have have trailing comma 😅 all is a matter of habit. Happy to go with any direction. tell me and I will follow. still, no clue on CI error :( |
|
I'm all in favor of commas at the end of a line as it minimizes the diff when adding a new line. |
|
I agree with Nicolas and Fabien. Having the trailing comma at the end of a line is great because of the reduced diffs, but having it at the end of arguments on on-liners is not so nice. |
on one-liners and multi-liners ;) |
|
Exactly, only on multiline |
|
@keradus can you please update the PR to add the trailing commas on declaration sites only? At least we have an agreement on that so let's move on. Then if one wants the comma on call sites let's make it another discussion (and I will object like I'm doing here :) ) |
not sure if we talk about same thing. To highlight... with this PR this will NOT be modified str_replace($a, $b, $c);this will be modified str_replace(
$a,
$b,
- $c
+ $c,
); |
|
@nicolas-grekas , i think all but you are to enable everything. but please clarify what you want to have, #53352 (comment) "declaration site" is blurry for me and I'm guessing which you want or want not to have - eg, I understood you would like to have trailing comma in arrays, but I struggle to call array a "declaration site". |
|
I guess I mean to enable "arguments" but not "parameters"? eg this is fine: function __construct(
$a,
$b,
- $c
+ $c,
);and this isn't to me: str_replace(
$a,
$b,
- $c
+ $c,
);The reason being the visual cluttering of the latter with no justification. It's super rare to add parameters to a call, while it's quite common on a function/method signature (esp for constructors, which is how all this discussion started) |
|
I believe it's as common to add input to function declaration as to function call, as whenever we change one, we change another ;) yeah - maybe constructor of service being good exception here. I reverted |
nicolas-grekas
left a comment
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.
Can you please squash to get rid of the merge commit.
Otherwise, that's the perfect diff: small, and exactly the kind of changes we were asking for during reviews. (But we never asked contributors to add trailing commas to multline calls ;) )
|
I will (in background), but curious - with all new greatest possibility of github and old features of git itself, why not squash during merge? :) -- |
We are using a dedicated tool to merge PRs on |
|
@OskarStark I am aware ;) I was mentioning this in context of PRs I did open for that tool (133, 140) in 2018 to solve exactly this problem ;) unfortunately they did not got enough attention to get merged 😅 |
478c32b to
0cda041
Compare
|
Thank you @keradus. |
|
follow-up created as discussed: #53395 |
kind-of requested in #53230 (comment)
cc @OskarStark
The diff may be bigger and tricky. I put each part of standalone change as separated commit, easy to revert if you don't like particular change.
This PR is more demonstration what we can do with Fixer, you decides which way to go