Follow-up to #2707371: Fix several errors in the 'Drupal.Commenting.DocComment' coding standard

Problem/Motivation

Let's fix drupal/coder's sniffs in core.

Proposed resolution

Add drupal/coder and the phpcs package to your Drupal codebase:

# From Drupal root directory
$ composer require drupal/coder
$ ./vendor/bin/phpcs --config-set installed_paths DRUPALPATH/vendor/drupal/coder/coder_sniffer/

Modify the Drupal.Commenting.DocComment errors to not be excluded from within core/phpcs.xml.dist.

Run phpcbf from the core directory:

$ cd core
$ ../vendor/bin/phpcbf

This will fix some errors. Review what it did and fix problematic changes.

Run phpcs from the core directory in order to verify that no errors remain:

$ ../vendor/bin/phpcs -p

To review this issue

Install coder/phpcs as above.

Apply the patch.

Run phpcs from the core directory to verify that no errors remain.

$ cd core
$ ../vendor/bin/phpcs -p

Read the patch to check for errors.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

attiks created an issue. See original summary.

attiks’s picture

Status: Needs work » Needs review
longwave’s picture

Status: Needs review » Needs work
-    if (empty($comments))
-      return '';
+    if (empty($comments)) {
+      return ''; }

While adding braces is good for readability, the closing braces should be on a line on their own.

The empty cases might also warrant adding a comment as to why the block is empty.

duaelfr’s picture

Issue tags: -Novice

As agreed between the mentors at Drupalcon, according to issues to avoid for novices, I am untagging this issue as "Beginner". This issue contains changes across a very wide range of files and might create too many other patches to need to be rerolled at this particular time. This patch has an automated way to be rerolled later so better to implement it after Drupalcon.

andriyun’s picture

Status: Needs work » Needs review
StatusFileSize
new77.57 KB

Rerolled patch. After phpcbf changes.

droplet’s picture

Status: Needs review » Needs work

vendor libs should be excluded.

andriyun’s picture

Status: Needs work » Needs review

Vendor libs are excluded from patch fix-2572693-5.patch :)

andypost’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php
    @@ -97,7 +97,8 @@ public function build($class_name, $proxy_class_name = '') {
    -            if (isset($interfaces[$parent_interface])) {}
    +            if (isset($interfaces[$parent_interface])) {
    +}
    

    not sure about that, but indent is wrong

  2. +++ b/core/lib/Drupal/Core/Archiver/ArchiveTar.php
    @@ -181,45 +182,54 @@ public function __construct($p_tarname, $p_compress = null)
    -                    } elseif ($data == "BZ") {
    +                    }
    +elseif ($data == "BZ") {
    ...
    -                    } elseif (file_get_contents($p_tarname, false, null, 1, 4) == '7zXZ') {
    +                    }
    +elseif (file_get_contents($p_tarname, false, null, 1, 4) == '7zXZ') {
    ...
    -            } else {
    +            }
    +else {
    ...
    -                } elseif ((substr($p_tarname, -3) == 'bz2') ||
    +                }
    +elseif ((substr($p_tarname, -3) == 'bz2') ||
    

    indent wrong, in that file

droplet’s picture

ArchiveTar.php should be excluded I think. It's a slightly mod version.

andriyun’s picture

Status: Needs work » Needs review
StatusFileSize
new77.79 KB

Fix indentation after phpcbf auto correction.
To fix indentation I used Code > Reformat code tool in PhpStorm with with "Only VCS changed text".
It's really powerful option :)

@droplet Can you add more argument and details about reason to exclude ArchiveTar.php file please.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Now patch is great.
ArchiveTar.php is a part of core so should be fixed as well, another round on it should convert indent to 2spaces

droplet’s picture

Fixing ArchiveTar.php would bring some headache for next release port. There're more things in ArchiveTar.php can be improve but we skipped on each patching.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I'm not sure about ArchiveTar.php changes either.

+++ b/core/lib/Drupal/Core/Datetime/Element/Datelist.php
index 4c7fea9..a09f6dd 100644
--- a/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php

--- a/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
+++ b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php

From the top of the file...

 * NOTE: 98% of this code is a literal copy of Symfony's YamlFileLoader.
 *
 * This file does NOT follow Drupal coding standards, so as to simplify future
 * synchronizations.

See not good reason given here to break that.

droplet’s picture

* NOTE: 98% of this code is a literal copy of Symfony's YamlFileLoader.

ArchiveTar.php is 99.9%.

attiks’s picture

I see 2 proper options:

- we fix the coding standard of ArchiveTar.php
- we move the original ArchiveTar.php to vendor and we provide a wrapper

And 1 not so proper, but easy fix

- we exclude ArchiveTar.php from code sniffer

Personally the last option will help move the rest forward

longwave’s picture

We could just pull in https://github.com/pear/Archive_Tar via Composer?

longwave’s picture

Actually, #2610984: Add Archive Tar via Composer, with BC shim is already dealing with that.

pfrenssen’s picture

Issue summary: View changes
andypost’s picture

Status: Needs work » Postponed
Related issues: +#2610984: Add Archive Tar via Composer, with BC shim

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

pfrenssen’s picture

Issue summary: View changes
pfrenssen’s picture

Issue summary: View changes
andypost’s picture

Version: 8.1.x-dev » 8.2.x-dev
Status: Postponed » Needs review
StatusFileSize
new7.01 KB
new51.61 KB

This rule needs work cos indent is wrong, so manually fixed patch

      3 Drupal.ControlStructures.ControlSignature.NewlineAfterOpenBrace
      3 Drupal.ControlStructures.ControlSignature.SpaceAfterCloseBrace
     11 Drupal.ControlStructures.ControlSignature.NewlineAfterCloseBrace
     19 Drupal.ControlStructures.ControlSignature.SpaceAfterCloseParenthesis
     44 Drupal.ControlStructures.ControlSignature.SpaceAfterKeyword
mile23’s picture

Status: Needs review » Needs work

Patch in #23 gives me this:

$ git apply 2572693-23-fixed.patch 
2572693-23-fixed.patch:266: trailing whitespace.
                  if (count($parameters) === 3) {  
2572693-23-fixed.patch:429: trailing whitespace.
                if ($file->getOwnerId() != \Drupal::currentUser()->id()) {  
2572693-23-fixed.patch:521: trailing whitespace.
      foreach (array('form', 'view') as $type) {  
2572693-23-fixed.patch:534: trailing whitespace.
    elseif (trim($values['title'])) {  
2572693-23-fixed.patch:622: trailing whitespace.
    if ($path instanceof Url) {  
warning: squelched 4 whitespace errors
warning: 9 lines add whitespace errors.

...which I suppose is a bit backwards.

But the patch also yields no errors when phpcs is run.

pfrenssen’s picture

Issue summary: View changes
mile23’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new51.56 KB

Patch no longer applies, so I just re-did the work with phpcbf and some manual whitespace edits.

alexpott’s picture

Status: Needs review » Needs work
  1. +++ b/core/lib/Drupal/Component/ProxyBuilder/ProxyBuilder.php
    @@ -92,7 +92,8 @@ public function build($class_name, $proxy_class_name = '') {
    -            if (isset($interfaces[$parent_interface])) {}
    +            if (isset($interfaces[$parent_interface])) {
    +}
                 unset($interfaces[$parent_interface]);
    

    This if should be removed.

  2. +++ b/core/modules/file/src/Element/ManagedFile.php
    @@ -97,7 +97,7 @@ public static function valueCallback(&$element, $input, FormStateInterface $form
    -                if ($file->getOwnerId() != \Drupal::currentUser()->id())  {
    +                if ($file->getOwnerId() != \Drupal::currentUser()->id()) {  ¶
    

    The fixer added some space on the end of the line :(

  3. +++ b/core/tests/Drupal/KernelTests/Core/Database/InsertDefaultsTest.php
    @@ -34,7 +34,8 @@ function testDefaultEmptyInsert() {
    +    }
    +catch (NoFieldsException $e) {
    
    +++ b/core/tests/Drupal/KernelTests/Core/Database/LargeQueryTest.php
    @@ -31,7 +31,8 @@ function testMaxAllowedPacketQueryTruncating() {
    +        }
    +catch (DatabaseException $e) {
    
    +++ b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
    @@ -230,7 +230,8 @@ function testSchema() {
    +    catch (\Exception $e) {
    +}
    

    Needs indenting

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new51.52 KB
new3.39 KB

Fixed the issues in #27, and went through the diff *again* to double-check...

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Looks great for me now!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed a6efc8c and pushed to 8.1.x and 8.2.x. Thanks!

  • alexpott committed a1d3a68 on 8.2.x
    Issue #2572693 by Mile23, andriyun, andypost, attiks: Fix 'Drupal....

Status: Fixed » Needs work

The last submitted patch, 28: 2572693_28.patch, failed testing.

dawehner’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

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