Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pfrenssen created an issue. See original summary.

pfrenssen’s picture

Status: Active » Needs review
FileSize
52.07 KB

I tried autofixing the new rules that were added. It looks good overall. There are two new rules that are not autofixable, but this is fine, they actually require human intervention because it is not possible to automate these fixes. I've excluded them and will make followups to fix these:

  • Drupal.Commenting.FunctionComment.ParamTypeSpaces - a parameter type declaration contains a space. This can be because two types were separated by a space instead of a pipe, or it might be documentation that crept into it. Needs human judgement.
  • Drupal.Commenting.FunctionComment.ReturnTypeSpaces - the same case, but for a return type declaration. Needs human intervention.

There are two instances which are not correctly autofixed, in HandlerBase and ArgumentPluginBase the following code is wrongly autofixed:

-   * @return TRUE/FALSE
+   * @return TRUEFALSE

I think this case of using a slash instead of a pipe might be a good candidate to add as a dedicated sniff to Coder. We only have 2 instances of this in core, but I can imagine this to be a common occurrence in contrib or custom code.

pfrenssen’s picture

In this patch I hand-fixed the two instances of @return TRUE/FALSE to @return bool. I think this should be OK, since this pattern is so exceedingly rare in the code base. The sniff correctly detects this too, so we can rest assured that if new patches would add this bad return value it will be detected.

dawehner’s picture

Are you sure we don't have issues for those new sniffs already? I'm just wondering, because I would have expected that those more or less quite fundamental bits have been fixed already.

pfrenssen’s picture

These are the sniffs that are throwing errors now with the new version of Coder on the latest 8.3.x:

  • Drupal.WhiteSpace.ObjectOperatorIndent.Indent
  • Drupal.Commenting.FunctionComment.ParamTypeSpaces
  • Drupal.Commenting.FunctionComment.ReturnVarName
  • Drupal.Commenting.FunctionComment.ReturnTypeSpaces
  • Drupal.Commenting.FunctionComment.InvalidReturn
  • Drupal.Commenting.FunctionComment.IncorrectParamVarName

I had a look for issues mentioning these sniffs. Two already had issues but they were already fixed:

It appears that these sniffs have been improved in the new release of Coder so they found some more instances that needed to be fixed.

dawehner’s picture

  1. +++ b/core/modules/system/src/Tests/Update/UpdatePathTestBase.php
    @@ -268,7 +268,7 @@ protected function runUpdates() {
             foreach (\Drupal::entityDefinitionUpdateManager()
    -                   ->getChangeSummary() as $entity_type_id => $summary) {
    +          ->getChangeSummary() as $entity_type_id => $summary) {
    

    wow, I would have not expected that coder can handle that complex case well, cool!

  2. +++ b/core/tests/Drupal/Tests/Core/Database/Driver/pgsql/PostgresqlConnectionTest.php
    @@ -29,7 +29,7 @@ protected function setUp() {
        * Data provider for testEscapeTable.
        *
    -   * @return []
    +   * @return array
        *   An indexed array of where each value is an array of arguments to pass to
        *   testEscapeField. The first value is the expected value, and the second
        *   value is the value to test.
    @@ -51,7 +51,7 @@ public function providerEscapeTables() {
    
    @@ -51,7 +51,7 @@ public function providerEscapeTables() {
       /**
        * Data provider for testEscapeAlias.
        *
    -   * @return []
    +   * @return array
        *   Array of arrays with the following elements:
        *   - Expected escaped string.
        *   - String to escape.
    @@ -68,7 +68,7 @@ public function providerEscapeAlias() {
    
    @@ -68,7 +68,7 @@ public function providerEscapeAlias() {
       /**
        * Data provider for testEscapeField.
        *
    -   * @return []
    +   * @return array
        *   Array of arrays with the following elements:
    

    Should we go with array[] for all those 3 cases instead?

pfrenssen’s picture

FileSize
52.07 KB
1.23 KB

Good eye, those are indeed arrays of arrays. I agree it would be nice to update this now that we are touching those lines.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Thank you @pfrenssen!

dawehner’s picture

One thing I'm wondering though is whether we should add coder to the require-dev bit first and then update the version there.

pfrenssen’s picture

pfrenssen’s picture

One thing I'm wondering though is whether we should add coder to the require-dev bit first and then update the version there.

Well this issue is blocking all other coding standards related issues at the moment, and we already have a separate issue about the require-dev: #2744463: Add phpcs, coder 8.2.8 as --dev requirements for drupal/core. I would rather not block this on the composer dependency update.

dawehner’s picture

@pfrenssen
Well, we can keep using 8.2.7 on our global composer.json file, and be fine with that, can't we?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 7: 2803779-7.patch, failed testing.

Mile23’s picture

Category: Bug report » Task

We fixed all the 'regressions' for coder 8.2.8 in #2747073: Fix Drupal CS regressions for Coder 8.2.8, so #2744463: Add phpcs, coder 8.2.8 as --dev requirements for drupal/core will be OK if we stick to 8.2.8 there.

This issue could update the dependency to 8.2.9 and be patched against core 8.3.x.

pfrenssen’s picture

Status: Needs work » Postponed

Ok I like this approach, but then this is blocked by #2744463: Add phpcs, coder 8.2.8 as --dev requirements for drupal/core. Postponing on that issue.

pfrenssen’s picture

FileSize
57.18 KB
3.81 KB

Rerolled against latest 8.3.x and latest version of #2744463: Add phpcs, coder 8.2.8 as --dev requirements for drupal/core. This is still postponed on that issue, the patch only applies after that is in.

Interdiff only contains manual changes made, it excludes automatic code style fixes. I wasn't able to rebase the previous patch easily, there have been too many commits in the meanwhile.

pfrenssen’s picture

FileSize
6.23 KB

Here is a patch containing only the manual work. This will make it easy to reroll this patch if needed. Just apply this, run ../vendor/bin/phpcbf -p from the core/ folder and post the result.

pfrenssen’s picture

FileSize
6.83 KB

Forgot one part, in Coder 8.2.9 the test files are no longer part of the distribution build so they don't need to be excluded any more. This is also a manual change.

klausi’s picture

Version: 8.2.x-dev » 8.3.x-dev
Status: Postponed » Needs work

#2744463: Add phpcs, coder 8.2.8 as --dev requirements for drupal/core is a bit derailed now and probably needs more time, so I think we can continue here with just the fixes. Can you reroll the patch without composer changes?

tstoeckler’s picture

Forgot one part, in Coder 8.2.9 the test files are no longer part of the distribution build so they don't need to be excluded any more.

Shouldn't we still leave them in in cased people install with --prefer-source?

pfrenssen’s picture

I personally think not, why would people use the --prefer-source option for a distribution build? It will have a lot more baggage than just the test files, it will even have the entire git history present for every project.

Also, if you specify you want the source, you probably are about to start some development and you most likely want the full source, including tests :)

klausi’s picture

Status: Needs work » Needs review
FileSize
53.96 KB

Full patch of automated fixes and manual fixes from above.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

xjm’s picture

Mile23’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Sort of. The idea here was that since #2744463: Add phpcs, coder 8.2.8 as --dev requirements for drupal/core locked us into then-recent Coder 8.2.8, we'd pick up the latest fixes here afterwards.

#2794567: Make core comply with new standard spacing for anonymous functions and enable the rule in phpcs.xml.dist requires a version of Coder >=8.2.9, which this issue doesn't supply any more, though it could.

pfrenssen’s picture

I think updating to Coder 8.2.9 would be nicely in scope of this issue.

Mile23’s picture

Rerolled and updated to bring us up to fixed for 8.4.x and Coder 8.2.9.

The only real problem is this one:

--- a/core/modules/big_pipe/src/Render/BigPipe.php
+++ b/core/modules/big_pipe/src/Render/BigPipe.php
@@ -640,7 +640,7 @@ protected function filterEmbeddedResponse(Request $fake_request, Response $embed
    *
    * @param \Symfony\Component\HttpFoundation\Request $request
    *   The request for which a response is being sent.
-   * @param \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST|\Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST $request_type
+   * @param \Symfony\Component\HttpKernel\HttpKernelInterfaceMASTER_REQUEST|\Symfony\Component\HttpKernel\HttpKernelInterfaceSUB_REQUEST $request_type
    *   The request type.
    * @param \Symfony\Component\HttpFoundation\Response $response
    *   The response to filter.
Mile23’s picture

Status: Needs work » Needs review
pfrenssen’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/big_pipe/src/Render/BigPipe.php
    @@ -640,7 +640,7 @@ protected function filterEmbeddedResponse(Request $fake_request, Response $embed
    -   * @param \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST|\Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST $request_type
    +   * @param \Symfony\Component\HttpKernel\HttpKernelInterfaceMASTER_REQUEST|\Symfony\Component\HttpKernel\HttpKernelInterfaceSUB_REQUEST $request_type
        *   The request type.
    

    As you mentioned, this is now incorrect.

    This has been incorrectly documented. We don't allow specific values as parameter types. So actually there's no need to improve Coder for this, we just need to fix the documentation.

    This parameter declaration should read:

      /**
       * @param int $request_type
       *   The request type. Can be either
       *   \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST or
       *   \Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST.
       */
    
  2. +++ b/core/modules/system/src/Tests/Update/UpdatePathTestBase.php
    @@ -292,7 +292,7 @@ protected function runUpdates() {
             foreach (\Drupal::entityDefinitionUpdateManager()
    -                   ->getChangeSummary() as $entity_type_id => $summary) {
    +          ->getChangeSummary() as $entity_type_id => $summary) {
    

    I don't particularly like seeing this foreach() split on two lines. I think it is less readable, but it is technically allowed within the coding standards so let's give it a pass.

pfrenssen’s picture

Version: 8.4.x-dev » 8.3.x-dev
Issue tags: -Needs reroll

Coding standards fixes are still allowed in the RC phase.

naveenvalecha’s picture

Drupal Coder 8.x-2.10 has been out on 14th December . Do we need a new followup issue for fixing 8..x-2.10?

pfrenssen’s picture

@naveenvalecha I think that would be a good idea to do it in a separate issue, taking it one step at a time.

klausi’s picture

Status: Needs work » Needs review
FileSize
60.61 KB
1.55 KB

Rerolled + fixed BigPipe method as suggested.

Manually confirmed that phpcs output is clean and does not show errors after this patch.

klausi’s picture

Title: Fix new sniffs added in Coder 8.x-2.9 » Update Coder to 8.2.10 and fix errors from imporved sniffs
FileSize
60.62 KB
2.01 KB

Just tested Coder 8.2.10 and it has 0 new errors with this patch, so we can update straight to that.

Fixing title, we are not fixing new sniffs here but existing sniffs that got better :-)

Mile23’s picture

Status: Needs review » Reviewed & tested by the community
  1. +++ b/core/modules/big_pipe/src/Render/BigPipe.php
    @@ -640,8 +640,10 @@ protected function filterEmbeddedResponse(Request $fake_request, Response $embed
    -   * @param \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST|\Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST $request_type
    -   *   The request type.
    +   * @param int $request_type
    +   *   The request type. Can either be
    +   *   \Symfony\Component\HttpKernel\HttpKernelInterface::MASTER_REQUEST or
    +   *   \Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST.
    

    Checked that these constants are int, and they are: https://github.com/symfony/http-kernel/blob/master/HttpKernelInterface.p...

  2. +++ b/core/phpcs.xml.dist
    @@ -57,6 +57,8 @@
         <exclude name="Drupal.Commenting.FunctionComment.ParamNameNoMatch"/>
    +    <exclude name="Drupal.Commenting.FunctionComment.ParamTypeSpaces"/>
    +    <exclude name="Drupal.Commenting.FunctionComment.ReturnTypeSpaces"/>
         <exclude name="Drupal.Commenting.FunctionComment.TypeHintMissing"/>
    

    These are excluded as per #2, with follow-ups: #2803891: Fix 'Drupal.Commenting.FunctionComment.ReturnTypeSpaces' coding standard #2803893: Fix 'Drupal.Commenting.FunctionComment.ParamTypeSpaces' coding standard

Applies to both 8.3.x and 8.4.x, and phpcs passes for both.

Rawk.

naveenvalecha’s picture

#34,
Awesome klausi to update the coder to 8.2.10
Patch looks good. However, it's still showing the warnings https://dispatcher.drupalci.org/job/drupal_patches/451/checkstyleResult/...

//Naveen

Mile23’s picture

@naveenvalecha, those are *fixed* warnings. They're warnings fixed by the patch.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 34: coder-8.2.10-2803779-34.patch, failed testing.

pfrenssen’s picture

Title: Update Coder to 8.2.10 and fix errors from imporved sniffs » Update Coder to 8.2.10 and fix errors from improved sniffs
klausi’s picture

Status: Needs work » Reviewed & tested by the community

drupalci fail, queuing again.

xjm’s picture

I'm sorry. I think I broke your patch by accidentally running 8.2.10 locally and overfixing a different commit.

That said, maybe we can fix the standards in separate issues first? Since 8.2.10 is just a patch-level update, it can go into a patch release or RC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
54.93 KB

Rerolled.

+++ b/core/phpcs.xml.dist
@@ -57,6 +57,8 @@
+    <exclude name="Drupal.Commenting.FunctionComment.ParamTypeSpaces"/>
+    <exclude name="Drupal.Commenting.FunctionComment.ReturnTypeSpaces"/>

When I originally read the patch I thought why are we adding new rules - but of course we're not we're excluding new rules. So all the changes are due to fixes to existing rules that are applying. Hopefully. And yes if phpcbf can apply the fixes then it is probably okay just to run that.

The last submitted patch, 34: coder-8.2.10-2803779-34.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 42: 2803779-42.patch, failed testing.

alexpott’s picture

Status: Needs work » Needs review
pfrenssen’s picture

Status: Needs review » Reviewed & tested by the community

When I originally read the patch I thought why are we adding new rules - but of course we're not we're excluding new rules. So all the changes are due to fixes to existing rules that are applying. Hopefully. And yes if phpcbf can apply the fixes then it is probably okay just to run that.

Yes that is the idea. There have been some improvements to existing sniffs, but the newly added ones in 8.2.10 are excluded since they should be tackled in separate issues, to keep this manageable.

I'm setting this to RTBC. I have worked on earlier versions of this patch, but since this is 99% machine generated and I have not worked on it since the last RTBC I hope this is OK.

pfrenssen’s picture

BTW these are the followups to fix the two new sniffs which are excluded here, they can be worked on when this is in: #2803891: Fix 'Drupal.Commenting.FunctionComment.ReturnTypeSpaces' coding standard, #2803893: Fix 'Drupal.Commenting.FunctionComment.ParamTypeSpaces' coding standard.

pfrenssen’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed fea11b6 to 8.4.x and 71fa660 to 8.3.x. Thanks!

I've tested this locally on both 8.3.x and 8.4.x everything passes PHPCS nice.

  • alexpott committed fea11b6 on 8.4.x
    Issue #2803779 by pfrenssen, klausi, Mile23, alexpott, dawehner: Update...
alexpott’s picture

Issue tags: +8.3.0 release notes

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

klausi’s picture