Skip to content
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

Enhancement: Use friendsofphp/php-cs-fixer instead of StyleCI #157

Merged
merged 1 commit into from
Dec 20, 2020

Conversation

localheinz
Copy link
Member

@localheinz localheinz commented Dec 19, 2020

This PR

  • requires friendsof/php-cs-fixer and removes the integration with StyleCI

StyleCI

The integration with StyleCI has the following advantages:

  • It applies coding standard issues automatically after a merge to main.

The integration with StyleCI has the following disadvantages:

  • A developer can not run StyleCI locally. A developer can run StyleCI locally only by installing a separate package, which however, requires PHP 7.2. We currently support PHP 7.1.
  • If a developer wants to find out about the changes that would need to be applied, they have to navigate to a separate website. With the deep integration provided by GitHub Actions, that is not necessary anymore.
  • StyleCI uses friendsofphp/php-cs-fixer under the hood, but adds obscurity on top. For example, it "invents" new fixers that can be enabled or enabled, but are in reality different configurations for existing fixers). Additionally, fixers that are available today in friendsofphp/php-cs-fixer cannot be configured in StyleCI without delay (if at all). Furthermore, we do not know which version of friendsofphp/php-cs-fixer is used under the hood.
  • The integration with StyleCI violates the principle of least astonishment: When someone opens a pull request where the changes do not conform to the coding standard we configured, a reviewer can (and will be) surprised to see that the build passes. A reviewer might similarly (and rightfully) point out coding standard issues, which adds unnecessary noise to the conversation in a pull request.

friendsofphp/php-cs-fixer

Requiring friendsofphp/php-cs-fixer as a dependency (similar to phpstan/phpstan and vimeo/psalm) alleviates all of these problems. We can use and configure any fixers that is available any time we want.

If we wanted to automatically apply coding standard issues (similar to StyleCI), we could easily do that with GitHub Actions. However, I would suggest to refrain from it.

In my opinion, a pull request needs to be in mergeable state before merging it into the mainline of development, and this includes coding standard issues.

@pimjansen
Copy link

I agree with this to not be dependant on external. Running it locally is also a big advantage

@GrahamCampbell
Copy link
Member

👎 here. We are just adding more maintenance for us here. We should stop messing with the code style, and just leave StyleCI to enforce it. Contributors and maintainers alike should not ever be running code style tooling.

@GrahamCampbell
Copy link
Member

A developer can not run StyleCI locally.

This is an advantage. Nobody should be wasting their time with that.

@GrahamCampbell
Copy link
Member

Though, StyleCI can be run locally, if really wanted (https://github.com/StyleCI/CLI).

@localheinz
Copy link
Member Author

@GrahamCampbell

This is an advantage. Nobody should be wasting their time with that.

I prefer to use and run friendsofphp/php-cs-fixer directly instead of integrating an external service or installing some tool that runs friendsofphp/php-cs-fixer for me.

But, I understand your opinion and your argumentation - after all, StyleCI is your pet project.

{
"require": {
"php": "^7.1 || ^8.0",
"friendsofphp/php-cs-fixer": "^2.17.2"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Require-dev?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah its vendor-bin nvm

@GrahamCampbell
Copy link
Member

// cc @IonBazan, @mfn, @bramceulemans, @Nyholm

This change is a 👎 from me.

@bram-pkg
Copy link
Member

bram-pkg commented Dec 19, 2020

I agree with it being more transparant to run php-cs-fixer. The idea of relying on an external service always worries me a bit personally.

I don't agree with the fact that developers shouldn't be doing code style. Using editorconfig file, phpstan and php-cs-fixer/StyleCI should be part of the IDE workflow.

Adding our own code to commit php-cs-fixer changes in GH Actions feels like too much overhead, though.

My opinion is that a PR owner should be responsible for not following code style, not an external service. This should also make the build fail.

@icanhazstring
Copy link

I am also in favor for php-cs-fixer as direct a dev dependency. The PR should be blocked unless everything is green.

Changing any code afterwards seems weird to me. I on my part only allow valid code to be merged into the main branch of repositories. So fine my me 👍

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks fine.

I don't really mind either way. PHP-CS-fixer may have some benefits, but the same is true with StyleCI. If I were to decide, I would have solved this in a third way...

However, I feel like I am a better resource if I focus on code changes.

Copy link

@tomasnorre tomasnorre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would always prefer a Style Checker locally. I want to provide as clean as possible code when pushing to what ever repository.

I think it's important to see the changes done by a code style checker to learn from it. A lot of people just ignores code style, and if the CI does it for you, you will more and more often ignore what code you actually write.

My preferred option is having the phpcs for locally and what ever tool for pipeline taking care of the fixes not already done, but the two tools should follow the exact same ruleset of course.

@localheinz localheinz merged commit 8990a0f into FakerPHP:main Dec 20, 2020
@localheinz localheinz deleted the feature/php-cs-fixer branch December 20, 2020 10:22
@chris-doehring
Copy link

I see the benefit's of both strategies, but I also prefer using a "native" local tool for the following reasons:

  • better learning experience for the contributers
  • less noise within the PR for the reason that a reviewer might forget about the automatical adjustments after merging

@localheinz
Copy link
Member Author

@GrahamCampbell

Quick heads-up, after merging this pull request, StyleCI applied the following changes:

a57232a

Looks like a failure to me, to apply fixes when a configuration has been removed, and a great example for a violation of the principle of least astonishment as well.

@GrahamCampbell
Copy link
Member

This is because StyleCI is still enabled on the repo, and uses the default configuration when none is provided. This is what people expect to happen, based on user feedback. The majority of StyleCI users never set any config.

strategy:
matrix:
php-version:
- 7.1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be something like 7.4?

I'm late to the party, true.

uses: shivammathur/setup-php@v2
with:
coverage: none
extensions: intl
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is intl required here?

uses: actions/cache@v2
with:
path: .php_cs.cache
key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('composer.*') }}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

composer.lock will be all new after each composer update, so this cache might not work as expected.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if we consider vendor-bin this should be hashFiles('**/composer.*')

},
"config": {
"platform": {
"php": "7.1.33"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It this unavoidable?

This was referenced Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants