- return static::class . '@' . $method;
+ return (static::class . '@' . $method);
Idem :
- return [
+ return (
+ [
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
- ] + self::profilesRules();
+ ] + self::profilesRules()
+ );
@mathieutu return always avoid parens when expression is in one line and add parens when expression is multiline
@mathieutu
return (static::class . '@' . $method);
look as bug.
Second example expected.
Idem here:
- return $this->customer->paymentService ?? null;
+ return ($this->customer->paymentService ?? null);
Imo in php, we should not add parentheses in any return cases. (Never seen that in any php code)
@mathieutu already fixed in master, here you examples https://github.com/prettier/plugin-php/pull/612, it is expected right?
@mathieutu
Imo in php, we should not add parentheses in any return cases. (Never seen that in any php code)
Disagree. return have same logic in js and php. Why we should avoid parens?
Why we should avoid parens?
Because there is not a single person anywhere doing it ?
@Meroje please create issue in prettier about this, we use logic from prettier.
/cc @vjeux can you describe why we need parens for return, thanks
In JavaScript, there’s a “feature” called automatic semi-colon insertion that makes the following
return
123
be parsed as
return;
123;
So you have to have parenthesis if you want to make it multiline otherwise you return undefined.
return (
123
);
Because of this, people in js tend to put parenthesis in a lot more places than php and put { on the same line.
Thanks for the explanation @vjeux! 🙂
So we know now that it's only linked to a js context, so it's the plugin responsibility to choose if it's kept or not.
@mathieutu feel free to send a PR
:+1: Let's remove the braces in the PHP plugin then!
ok thanks!
As I haven't contributed yet to prettier, I don't really know how it works under the hood, and how to make that done.
I'll try to check that when it'll be quieter at work.
Thank you @evilebottnawi! 🎉
After having seen your PR, I can confirm that I wasn't capable to do it right now!
@mathieutu don't worry, prettier is very easy tool, feel free to contribute
Most helpful comment
Because there is not a single person anywhere doing it ?