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

Switch from StyleCI to PHP-CS fixer #502

Merged
merged 18 commits into from
Nov 14, 2019
Merged

Conversation

crissi
Copy link
Contributor

@crissi crissi commented Oct 24, 2019

now developers can run composer fix to fix styling issues and more easily set up their IDE because we are using phpcsfixer

and travis will fail and show the error diff from php-cs-fixer

TODOs

  • Don't know how to disable styleci
  • I am running the linter on every environment in travis, this could probably be changed for faster a pipeline. Don't know how easy that is!?

Links

@mfn
Copy link
Collaborator

mfn commented Oct 24, 2019

I am running the linter on every environment in travis, this could probably be changed for faster a pipeline. Don't know how easy that is!?

Done, pushed a commit! I just use env variables for this and we just need to make sure that at least for one job it's set. Same approach used for e.g. phpstan.

I also fixed the failing lumen integration test. I boy I hate them, but it's better then nothing. They rely on scripting the manual steps necessary and easily fail due to the sensitivity of the regex when the source file changes even formatting (which happened in this case for config/config.php). Anyway, all green!

I also took the liberty to simply remove the extended tests from 5.8; it's EOL anyway and only wil receive security fixes which shouldn't be critical for the extended test.

Don't know how to disable styleci

Only admins can do that (which I'm not).

But before proceeding I would like to do some testing/feedbacking

Copy link
Collaborator

@mfn mfn left a comment

Choose a reason for hiding this comment

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

Thanks for the initiative, that's really great; love it so far!

I think the hard part is now on agreeing on the actual config, see my inline thoughts on some of this.

My perfect outcome would be the most minimal configuration with the most aggressive approach so that no room for interpretation is left.

(ps: noticed that PhpStorm detects php-cs fixer and can auto correct it: how awesome is that)

.php_cs.dist Outdated
<?php

/**
* Rules we follow are from PSR-2 as well as the rectified PSR-2 guide.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a blueprint where you got this whole fle from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

.php_cs.dist Outdated

return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

So. I was wondering since it said @PSR2 at the top, why the other rules?

I removed them all and ran fix and it did quite some changes, like these:

diff --git a/src/GraphQL.php b/src/GraphQL.php
index c5d3b0d..9562554 100644
--- a/src/GraphQL.php
+++ b/src/GraphQL.php
@@ -239,10 +239,12 @@ class GraphQL

         if (! $type instanceof TypeConvertible) {
             throw new TypeNotFound(
-                sprintf('Unable to convert %s to a GraphQL type, please add/implement the interface %s',
+                sprintf(
+                    'Unable to convert %s to a GraphQL type, please add/implement the interface %s',
                     get_class($type),
                     TypeConvertible::class
-                ));
+                )
+            );
         }

         foreach ($opts as $key => $value) {
diff --git a/src/Support/ResolveInfoFieldsAndArguments.php b/src/Support/ResolveInfoFieldsAndArguments.php
index 34aceea..bed6194 100644
--- a/src/Support/ResolveInfoFieldsAndArguments.php
+++ b/src/Support/ResolveInfoFieldsAndArguments.php
@@ -130,12 +130,16 @@ class ResolveInfoFieldsAndArguments
                 $spreadName = $selectionNode->name->value;
                 if (isset($this->info->fragments[$spreadName])) {
                     $fragment = $this->info->fragments[$spreadName];
-                    $fields = array_merge_recursive($this->foldSelectionSet($fragment->selectionSet, $descend),
-                        $fields);
+                    $fields = array_merge_recursive(
+                        $this->foldSelectionSet($fragment->selectionSet, $descend),
+                        $fields
+                    );
                 }
             } elseif ($selectionNode instanceof InlineFragmentNode) {
-                $fields = array_merge_recursive($this->foldSelectionSet($selectionNode->selectionSet, $descend),
-                    $fields);
+                $fields = array_merge_recursive(
+                    $this->foldSelectionSet($selectionNode->selectionSet, $descend),
+                    $fields
+                );
             }
         }

or

diff --git a/tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationValidationUniqueWithCustomRulesTest.php b/tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationValidationUniqueWithCustomRulesTest.php
index 82a2932..e1a7581 100644
--- a/tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationValidationUniqueWithCustomRulesTest.php
+++ b/tests/Database/MutationValidationUniqueWithCustomRulesTests/MutationValidationUniqueWithCustomRulesTest.php
@@ -36,7 +36,8 @@ GRAPHQL;
             ],
         ]);

-        $this->assertSqlQueries(<<<'SQL'
+        $this->assertSqlQueries(
+            <<<'SQL'

Basically it felt more aggressive.

I liked that because for example, in the current version these two patterns are allowed:

        $this->assertSqlQueries(
            <<<'SQL'

and

        $this->assertSqlQueries(<<<'SQL'

Nether one is touched and converted to the other.

Yet when I remove all the settings, it's converted the former form always.

I think this is better, the source will be more unified and leaves less room for interpretation.

.php_cs.dist Outdated
return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'array_syntax' => [ 'syntax' => 'short' ],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Immediately noticed though, per my above comment, removing this one here means it will not enforce $foo = array(); being converted to $foo = [];

So I guess just @PSR2 isn't specific enough and still has room for interpretation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah @psr2 is not enough to get the "prettiest" formatting:-)

Copy link
Collaborator

@mfn mfn left a comment

Choose a reason for hiding this comment

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

I've found https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200 and applied and pushed the changes for review.

Not sold yet on the config though :)

I wish there was a better way then copypasting some gist around; maybe there is a package with a maintained "Laravel" compatible PHP-CS fixer config we could just be pulled it as a dev dependency?

@@ -259,7 +259,7 @@ public function __get($key)
{
$attributes = $this->getAttributes();

return isset($attributes[$key]) ? $attributes[$key] : null;
return $attributes[$key] ?? null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now this is really nice

}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh my 🤔

@crissi
Copy link
Contributor Author

crissi commented Nov 5, 2019 via email

@mfn
Copy link
Collaborator

mfn commented Nov 8, 2019

I pushed some updates:

  • we need to use matt-allan/laravel-code-style dev-master because alphabetical sorting of imports is fixed there but it's not yet released
    • and since we already use alphabetical imports, it wouldn't make sense to go back and forth on this
    • PS: I'm fine with dev-master because it's "only" a dev package
  • the package causes conflicts with older PHP versions we test (7.1) and older Laravel rrameworks (5.5). But since we only need this be running for one job at least, I simply made it to be uninstalled for all parts we don't run the linter

@mfn mfn force-pushed the add_php_cs_fixer branch 2 times, most recently from f88223b to 9797ca6 Compare November 8, 2019 20:29
@mfn
Copy link
Collaborator

mfn commented Nov 8, 2019

Also added a PR template which mentions how to fix the code style

Copy link
Collaborator

@mfn mfn left a comment

Choose a reason for hiding this comment

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

Thanks @crissi , that's some great contribution here: I'm a sucker for code style standardization 😄

From my side this is 👍 good to go and now we need to remove StyleCI

@rebing TL;DR: we propose to switch from StyleCI to PHP-CS fixer which is fully integrated in the pipeline and has the benefit that contributors can fix code style violations locally. If that's good with you, could you please remove the StyleCI integration completely here? 🙏

@mfn mfn changed the title [WIP] add php cs fixer Switch from StyleCI to PHP-CS fixer Nov 8, 2019
@EdwinDayot
Copy link
Contributor

+1 for this ! Being able to fix everything locally is awesome. It would be great being able to do the same thing for travis, but I can imagine what a mess it could be.

@johannesnagl
Copy link
Contributor

I've added a small fix in here: crissi#9

@mfn
Copy link
Collaborator

mfn commented Nov 12, 2019

@johannesnagl

I've added a small fix in here: crissi#9

Thanks, already cherry-picked plus some other fixes!

@crissi
Copy link
Contributor Author

crissi commented Nov 12, 2019

So I gues we just need to fix to make it pass the styleci check and then after this PR is merged the styleci is gone?

mfn and others added 6 commits November 13, 2019 20:19
Otherwise composer can't install the dependencies correctly because this
package has higher version constraints.
Primarily for a way to signal devs how to fix the code style, which the linter
might error out on.
@mfn
Copy link
Collaborator

mfn commented Nov 13, 2019

@rebing can you also please remove StyleCI? Thanks 🤗

@mfn mfn merged commit 0d6320c into rebing:master Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants