patriziotomato's avatar

Code Style to contribute to Laravel?

We want to contribute to Laravel and are requested to properly format our code. The documentation only states that Laravel is using PSR-2

https://laravel.com/docs/10.x/contributions#coding-style

We are using PHPStorm, and I cannot find any helpful tipp how I can use PHPStorm's code formatting to precisely format the code like it is supposed to be.

Thank you! Patrick

0 likes
12 replies
martinbean's avatar

@patrick.thomas If it’s this PR then Dries is pretty clear on the feedback: your PR contains lots of instances of changing whitespace when it’s clear Laravel’s style is to have a space between negation operations, i.e. ! $foo instead of !$foo

kokoshneta's avatar

@martinbean While it is pretty clear that that’s what Dries is talking about, I’m not sure I’d agree it’s particularly clear what the actual Laravel style is on the issue. I would expect a clear style to be one described in the coding style section, but that only says Laravel uses PSR-2 (which leaves spacing for operators undefined), so you have to look through the actual framework and extrapolate from there, or look through the StyleCI definitions to locate it.

It definitely could be clearer, at least.

martinbean's avatar

@patrick.thomas Not really. It’s clear from your PR that the issue is with all the spaces your PR removed from various file, when all your PR was meant to do was add a single method to collections.

So submit a PR that only includes your method addition, instead of also removing spaces from various locations.

Merklin's avatar

@patrick.thomas I am. It's the end-user choice how to implement code style persistence with CI/CD: pre-commit hook in IDE or using a GitHub action.

I'm just sharing what packages I use. In fact, I run only Duster as pre-commit as it implements both cs-fixer and then runs pint.

I've read a lot of articles and decided to use Duster as it was mostly recommended and I keep the ability to customize the inspections by editing the pint.json file.

1 like
patriziotomato's avatar

@martinbean Why do my pull request matter answering my "general question" that may also help others. I'm thinking to add this to the official documentation as well.

But if you are so focused to my PR, you can tell me why the commit that added all this wrong whitespaces, was the one I'm updating my Fork. I updated via Github that added the commit "Merge branch 'laravel:10.x' into collection-mapInstance". This added the whitespaces and I'm not sure why.

However, now they changes are in my branch and the only thing I need is advice how to easily reformat my files to re-add my PR.

Please or to participate in this conversation.