Postponed on #3054969: Add sniff for \Drupal vs Drupal

Problem/Motivation

The leading \ for class names is used inconsistently. This issue is to ensure class names in comments have a leading '\'.

Original Issue Summary
The @deprecated tag for RESPONSIVE_IMAGE_EMPTY_IMAGE contains a full class name which is missing the leading "\".

Steps to reproduce

Proposed resolution

Review
Commit

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

angel.h created an issue. See original summary.

angel.h’s picture

Assigned: angel.h » Unassigned
Status: Needs work » Needs review
StatusFileSize
new674 bytes

Patch added.

valthebald’s picture

Let's check if there are other missing slashes in type comments?

angel.h’s picture

StatusFileSize
new6.5 KB

Found other occurrences in comments and added a patch.

valthebald’s picture

Title: Add missing "\" before full class name in @deprecated tag responsive_image » Add missing "\" before full class name in type comments
Version: 8.4.x-dev » 8.5.x-dev
Issue tags: -@deprecated, -deprecated +Coding standards

Updating issue title and summary to better reflect what the patch does

wengerk’s picture

StatusFileSize
new6.49 KB

Everything seems fine for the component responsive_image.module. I apply it on 8.5.x-dev.

I just found a "typo" on the DockBlock of shortcut_set_assign_user in core/modules/shortcut/shortcut.module. The parameter & type/class were inverted.

I think we can also fix this into this patch.

Also, to go further, I try to found every other // Drupal\ or * Drupal\ in the core and found plenty others (63 results), should we have to fix them in this issue or another one with a more general context should be created ?

ndobromirov’s picture

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

Together with Nevena Kostova we've found a bit more broken paths in doc blocks through the following reg-ex search (400+), during the code sprints in Vienna 2017.

(?<!types = \{)(?<!id = )(?<!type = )(?<!class: )(?<!deriver: )(?<!_form: )(?<!['"_:])(?<!namespace )(?<!use )(?<!\\)Drupal\\

Note that it is not filtering out the findings in strings in php code for some reason (there are some false-positives in the search results), but this are easy to ignore when checked manually and they are like 20-30% of the results count.

The regex was run in NetBeans reg-ex search (case insensitive way) for the whole Drupal core code-base.

angel.h’s picture

Assigned: Unassigned » angel.h

I'll get right on it. Thanks @ndobromirov.

angel.h’s picture

Assigned: angel.h » Unassigned
Status: Needs work » Needs review
StatusFileSize
new194.32 KB

Patch done. Intentionally skipped working on strings and limited it to comments only.

ndobromirov’s picture

Status: Needs review » Needs work

Hey @angel.h thanks for the great effort on fixing all the things.
The patch is HUGE (~200KB) :D.

Here are some small things that popped during the review.

  1. +++ b/core/lib/Drupal/Core/Form/FormErrorHandler.php
    @@ -72,14 +72,14 @@ protected function displayErrorMessages(array $form, FormStateInterface $form_st
        * @code
        * // The street textfield element.
        * $element = [
    -   *   '#errors' => {Drupal\Core\StringTranslation\TranslatableMarkup},
    +   *   '#errors' => {\Drupal\Core\StringTranslation\TranslatableMarkup},
        *   '#children_errors' => [],
        * ];
        * // The address detail element.
        * $element = [
        *   '#errors' => null,
        *   '#children_errors' => [
    -   *      'street' => {Drupal\Core\StringTranslation\TranslatableMarkup}
    +   *      'street' => {\Drupal\Core\StringTranslation\TranslatableMarkup}
        *   ],
        * ];
    

    This is a code example, making it close to a code change, as it's likely that people will copy-paste that.
    It might be one of the false-positives from the search...

  2. +++ b/core/modules/system/src/Tests/System/HtaccessTest.php
    @@ -65,7 +65,7 @@ protected function getProtectedFiles() {
         // Tests the .htaccess file in vendor and created by a Composer script.
         // Try and access a non PHP file in the vendor directory.
    -    // @see Drupal\\Core\\Composer\\Composer::ensureHtaccess
    +    // @see \Drupal\\Core\\Composer\\Composer::ensureHtaccess
         $file_paths['vendor/composer/installed.json'] = 403;
    

    Are this double slashes correct overall?

  3. +++ b/core/modules/views/tests/src/Functional/Wizard/PagerTest.php
    @@ -26,7 +26,7 @@ public function testPager() {
         // This technique for finding the existence of a pager
    -    // matches that used in Drupal\views_ui\Tests\PreviewTest.php.
    +    // matches that used in \Drupal\views_ui\Tests\PreviewTest.php.
         $elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
         $this->assertTrue(!empty($elements), 'Full pager found.');
    

    This is a file path, so either revert back or check that it's a class and drop the .php extension it ends with.

ivan berezhnov’s picture

Issue tags: +CSKyiv18

Version: 8.5.x-dev » 8.6.x-dev

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

wengerk’s picture

StatusFileSize
new276.75 KB

Re-rolled for 8.6.x (commit 7c1de1efa1) & apply suggestions of #10

wengerk’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 13: 2912687-13.patch, failed testing. View results

wengerk’s picture

It fails because of deprecation usage, what should we do ?

wengerk’s picture

StatusFileSize
new278.59 KB
new26.59 KB

During my previous re-roll in #13, I made a mistake during renaming with Drupal\Tests -> DrupalTests my bad.
I also found couple of missing \Drupal.

Checkout the interdiff for more infos.

wengerk’s picture

Status: Needs work » Needs review
idebr’s picture

The contents of the patch does not match the issue description.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

jhedstrom’s picture

Component: responsive_image.module » other
Parent issue: » #2571965: [meta] Fix PHP coding standards in core, stage 1

This was improperly under the responsive_image queue. It also may be a duplicate of an existing issue, but I couldn't find one.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

daffie’s picture

Status: Needs review » Needs work

The patch is failing the testbot and properly needs a reroll for 9.1.

ridhimaabrol24’s picture

Assigned: Unassigned » ridhimaabrol24
ridhimaabrol24’s picture

Assigned: ridhimaabrol24 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new165.42 KB
new116.59 KB

Rerolled patch for 9.1

Status: Needs review » Needs work

The last submitted patch, 27: 2912687-27.patch, failed testing. View results

atul4drupal’s picture

Assigned: Unassigned » atul4drupal
ridhimaabrol24’s picture

Assigned: atul4drupal » Unassigned
Status: Needs work » Needs review
StatusFileSize
new165.97 KB
new461 bytes

@atul4drupal I was working on it. Fixing failed test case

atul4drupal’s picture

Status: Needs review » Needs work

Regarding #30: Thanks for working on this.

Its a long file to review, here are few findings:

1) #10.2 is still not addressed

2) +++ b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php

- $this->assertStringContainsString('The class Drupal\Tests\Scripts\TestSiteApplicationTest contained in', $process->getErrorOutput());
+ $this->assertStringContainsString('The class \Drupal\Tests\Scripts\TestSiteApplicationTest contained in', $process->getErrorOutput());

this appears to be a scope creep and unnecessary change.

ridhimaabrol24’s picture

Assigned: Unassigned » ridhimaabrol24
ridhimaabrol24’s picture

Assigned: ridhimaabrol24 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new166.73 KB
new0 bytes

Fixing suggestions in 10.2

atul4drupal’s picture

StatusFileSize
new631 bytes

#33 thanks for the patch.
Adding the interdiff to help trace the differrence/change from #30, you mistakenly seems to have added a blank interdiff.

atul4drupal’s picture

#33 : looks good for the fix however 31.2 is more of a code change and got introduced since #13, this certainly is not in scope of this and must be left unchanged unless we have a PHPCS rule in place for usage of \Drupal

There are several open/postponed issues with respect to inconsistent usage of '\' across the application, for reference adding https://www.drupal.org/project/drupal/issues/3123593#comment-13531928
https://www.drupal.org/project/drupal/issues/3082854#comment-13658012

atul4drupal’s picture

Status: Needs review » Needs work
codersukanta’s picture

Assigned: Unassigned » codersukanta
codersukanta’s picture

Assigned: codersukanta » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.04 KB
new165.99 KB

Updating the patch based on #31.2.

atul4drupal’s picture

#38 looks good and addresses the issue.
Its RTBC +1

Will wait for clarity on the PHPCS rule for "\Drupal" as also mentioned in #35, before moving this ticket any further.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

quietone’s picture

Title: Add missing "\" before full class name in type comments » [PP -1 ] Consistent use of leading \ for class names in comments
Issue summary: View changes
Status: Needs review » Postponed
Issue tags: -Needs issue summary update
Parent issue: #2571965: [meta] Fix PHP coding standards in core, stage 1 » #3188974: [Meta] Consistent use of leading \ for class names

Changed the parent to a Meta covering all issues about the leading \ in class names.

As, atul4drupal points out this is postponed on the sniff.

quietone’s picture

Title: [PP -1 ] Consistent use of leading \ for class names in comments » [PP-1] Consistent use of leading \ for class names in comments

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.