Postponed on #3112830: [policy, no patch] Allow static::methodName() and/or self::methodName() in @see comments when referring to the same class

On the database.api.php file the @see tags referring to class/interface names don't use a fully qualified class name, as the Drupal coding standards (API documentation and comment standards, classes) says.

Immediately after an @tag (@param, @return, @var, etc.), class and interface names must always include the fully-qualified namespace.

In that file, I found two comments that don't follow that standard.

/**
 * Perform alterations to a structured query.
 *
 * Structured (aka dynamic) queries that have tags associated may be altered by any module
 * before the query is executed.
 *
 * @param $query
 *   A Query object describing the composite parts of a SQL query.
 *
 * @see hook_query_TAG_alter()
 * @see node_query_node_access_alter()
 * @see AlterableInterface
 * @see SelectInterface
 *
 * @ingroup database
 */
/**
 * Perform alterations to a structured query for a given tag.
 *
 * Some common tags include:
 * - 'entity_reference': For queries that return entities that may be referenced
 *   by an entity reference field.
 * - ENTITY_TYPE . '_access': For queries of entities that will be displayed in
 *   a listing (e.g., from Views) and therefore require access control.
 *
 * @param $query
 *   An Query object describing the composite parts of a SQL query.
 *
 * @see hook_query_alter()
 * @see node_query_node_access_alter()
 * @see AlterableInterface
 * @see SelectInterface
 *
 * @ingroup database
 */

The same issue is probably present in more files.

Comments

kiamlaluno created an issue. See original summary.

gnanagowthaman sankar’s picture

Hi @kiamlaluno,

Here by i attached the patch. Please let me know for changes.

Thanks & Regards,
Gnanagowthaman sankar

gnanagowthaman sankar’s picture

Status: Active » Needs review
StatusFileSize
new1.01 KB

Patch

Thanks & Regards,
Gnanagowthaman sankar

neel24’s picture

Status: Needs review » Reviewed & tested by the community

Patch tested and applies cleanly.

git apply -v see_tags_dont_use_fully_qualified_class_interface_names-3102478-2.patch
Checking patch core/lib/Drupal/Core/Database/database.api.php...
Applied patch core/lib/Drupal/Core/Database/database.api.php cleanly.
avpaderno’s picture

Status: Reviewed & tested by the community » Needs work

The patch is not modifying any of the @see tags, which was the reason of the report.
The patch should also change all the content of the file, not just two comments.

hardik_patel_12’s picture

Status: Needs work » Needs review
StatusFileSize
new1.46 KB
new858 bytes

Follow a new patch , and @kiamlaluno can you help us here to understand what do you mean by "The patch should also change all the content of the file, not just two comments." so we can help out more easily.

Thankyou

avpaderno’s picture

Status: Needs work » Needs review

I meant that every tag in that file should be changed to use a full-qualified class name, not just the comments I shown in the OP.

avpaderno’s picture

Status: Needs review » Reviewed & tested by the community

The patch changes all the tags that reference a class name.

pratik_kamble’s picture

+1 RTBC.

Status: Reviewed & tested by the community » Needs work
avpaderno’s picture

The failing test isn't related to this patch.

Drupal\Tests\media_library\FunctionalJavascript\WidgetUploadTest::testWidgetUploadAdvancedUi
"image-1.png" not found
Failed asserting that a boolean is not empty.

hardik_patel_12’s picture

The failing test isn't related to #6 patch. So changing status.

hardik_patel_12’s picture

Status: Needs work » Needs review
longwave’s picture

Status: Needs review » Reviewed & tested by the community
hardik_patel_12’s picture

Kindly review a new patch which is collaborate with #3103803 : @see tags don't use fully qualified class/interface names

hardik_patel_12’s picture

hardik_patel_12’s picture

Status: Reviewed & tested by the community » Needs review
shimpy’s picture

Status: Needs review » Needs work
StatusFileSize
new35.36 KB

Hi I have reviewed #16. Failed to apply patch for test file changes.

/core/modules/system/src/Tests/System/SystemConfigFormTestBase.php

tag

shimpy’s picture

avpaderno’s picture

@shimpy If the patch didn't apply, the automatic tests would report that, since they apply the patch before testing it. If it doesn't apply for your local copy, it means your local copy needs to be updated.

shimpy’s picture

Status: Needs work » Needs review

oh ok Thanks @kiamlaluno for reminding me to update my local copy. I will do and will test it again.

hash6’s picture

Assigned: Unassigned » hash6
hash6’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @Hardik_Patel_12 for the patch.Classname has been changed to appropriate namespace of @see tags.

hash6’s picture

Assigned: hash6 » Unassigned
longwave’s picture

Gentle hint to anyone reviewing this, can you also look at #3100251: Several code comments have incorrect namespaces for classes or interfaces they reference which is similar?

dww’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update
Related issues: +#3112830: [policy, no patch] Allow static::methodName() and/or self::methodName() in @see comments when referring to the same class

Thanks for the contributions here, and trying to improve Drupal core!

Some issues with the latest patch in #16:

  1. +++ b/core/lib/Drupal/Core/Database/Query/Condition.php
    @@ -211,14 +211,14 @@ public function compile(Connection $connection, PlaceholderInterface $queryPlace
    -          // @see ConditionInterface::condition() method (and thus have the
    +          // @see \Drupal\Core\Condition\ConditionInterface::condition() method (and thus have the
    ...
    -          // @see ConditionInterface::where() method. Put brackets around
    +          // @see \Drupal\Core\Condition\ConditionInterface::where() method. Put brackets around
    

    These comments now exceed 80 chars wide, trading one code standard "violation" for another. ;)

  2. +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
    @@ -49,7 +49,7 @@
    -   * @see ContentEntityBase::getFieldDefinitions()
    +   * @see \Drupal\Core\ContentEntityBase::getFieldDefinitions()
    

    I think #3112830: [policy, no patch] Allow static::methodName() and/or self::methodName() in @see comments when referring to the same class is the better solution when referring to other methods in the same class.

  3. +++ b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php
    @@ -187,8 +187,8 @@ public function isRequired();
    -   * @see FieldDefinitionInterface::getDefaultValue()
    -   * @see FieldDefinitionInterface::getDefaultValueCallback()
    +   * @see \Drupal\Core\Field\FieldDefinitionInterface::getDefaultValue()
    +   * @see \Drupal\Core\Field\FieldDefinitionInterface::getDefaultValueCallback()
    
    @@ -202,8 +202,8 @@ public function getDefaultValueLiteral();
    -   * @see FieldDefinitionInterface::getDefaultValue()
    -   * @see FieldDefinitionInterface::getDefaultValueLiteral()
    +   * @see \Drupal\Core\Field\FieldDefinitionInterface::getDefaultValue()
    +   * @see \Drupal\Core\Field\FieldDefinitionInterface::getDefaultValueLiteral()
    
    @@ -222,8 +222,8 @@ public function getDefaultValueCallback();
    -   * @see FieldDefinitionInterface::getDefaultValueLiteral()
    -   * @see FieldDefinitionInterface::getDefaultValueCallback()
    +   * @see \Drupal\Core\Field\FieldDefinitionInterface::getDefaultValueLiteral()
    +   * @see \Drupal\Core\Field\FieldDefinitionInterface::getDefaultValueCallback()
    

    Same here.

  4. +++ b/core/lib/Drupal/Core/Image/ImageFactory.php
    @@ -78,7 +78,7 @@ public function getToolkitId() {
    -   * @see ImageFactory::setToolkitId()
    +   * @see self::setToolkitId()
    

    Right, you're doing it here... why not be consistent about it?

  5. +++ b/core/tests/Drupal/KernelTests/Core/Plugin/PluginTestBase.php
    @@ -48,8 +48,8 @@ protected function setUp() {
    +    // @see \Drupal\plugin_test\Plugin\TestPluginManager::_construct().
    +    // @see \Drupal\plugin_test\Plugin\MockBlockManager::_construct().
    

    I thought we don't end with the period for @see comments. I believe this should be:
    @see \Drupal\plugin_test\Plugin\MockBlockManager::_construct()

  6. +++ b/core/tests/Drupal/KernelTests/Core/Plugin/PluginTestBase.php
    @@ -48,8 +48,8 @@ protected function setUp() {
    diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php
    
    diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php
    index 4845bf8..aca7d04 100644
    
    index 4845bf8..aca7d04 100644
    --- a/core/tests/Drupal/Tests/BrowserTestBase.php
    
    --- a/core/tests/Drupal/Tests/BrowserTestBase.php
    +++ b/core/tests/Drupal/Tests/BrowserTestBase.php
    
    +++ b/core/tests/Drupal/Tests/BrowserTestBase.php
    +++ b/core/tests/Drupal/Tests/BrowserTestBase.php
    @@ -257,7 +257,7 @@ protected function initMink() {
    
    @@ -257,7 +257,7 @@ protected function initMink() {
     
         // Copies cookies from the current environment, for example, XDEBUG_SESSION
         // in order to support Xdebug.
    -    // @see BrowserTestBase::initFrontPage()
    +    // @see \Drupal\Tests\BrowserTestBase::initFrontPage()
    

    static:: or self:: would be better.

  7. +++ b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php
    @@ -602,7 +602,7 @@ public function providerTestDateTimestamp() {
    -   * @see DateTimePlusTest::testDateDiff()
    +   * @see \Drupal\Tests\Component\Datetime\DateTimePlusTest::testDateDiff()
    

    And here.

Generally, is this issue trying to fix all @see references in all of core? I haven't grepped to verify if this fixes them all. The summary is only talking about a single file, but the patch is doing more than that. The summary should be updated to reflect the intention and scope of this change.

I'm strongly in favor of:

a) Postponing this until #3112830: [policy, no patch] Allow static::methodName() and/or self::methodName() in @see comments when referring to the same class is fixed and officially adopted as the standard (since core does it already, but it's not technically documented as our standard).

b) Then making sure this one issue fixes all lingering places that don't fully qualify the class in any @see comment, anywhere, in all of core (not separate issues for files, directories, subsystems, etc).

c) If @see is pointing to a constant or method in the same class, use static:: or self:: (consistently). Otherwise, use the fully qualified class name.

Thanks!
-Derek

avpaderno’s picture

-          // @see ConditionInterface::where() method. Put brackets around
+          // @see \Drupal\Core\Condition\ConditionInterface::where() method. Put brackets around

Is it correct to use a @see tag in a sentence? I understood that it should just be followed by a class or method name; in the other cases, the sentence should start with See, the verb.

dww’s picture

Yeah, that, too. ;) I believe the standards (and IDE integration) expects @see only in docblocks at the start of functions, and that they're not supposed to be used in inline comments. I personally disagree with this, but it's obviously not up to me. ;)

rithesh bk’s picture

Assigned: Unassigned » rithesh bk
Issue tags: +VbContribution2020

we will work on VbContribution2020

prabha1997’s picture

Assigned: rithesh bk » prabha1997
prabha1997’s picture

Assigned: prabha1997 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new15.35 KB
new6.44 KB

I did changes based on @dww suggestions. Kindly review patch

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.

kishor_kolekar’s picture

StatusFileSize
new14.8 KB

I've re-rolled patch for 9.1

dww’s picture

Title: @see tags don't use fully qualified class/interface names » [PP-1] @see tags don't use fully qualified class/interface names
Status: Needs review » Postponed

For the the updates and new patches, folks!

However, per #26.a, I'm going to formally postpone this issue on resolving #3112830: [policy, no patch] Allow static::methodName() and/or self::methodName() in @see comments when referring to the same class, first. Once that's fixed, we can proceed here. Until that happens, we're potentially wasting our time doing the wrong things.

Thanks,
-Derek

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.

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.

quietone’s picture

Issue tags: +Coding standards

Just adding Coding Standards tag.

quietone credited Mile23.

quietone credited jhodgdon.

quietone’s picture

Category: Bug report » Task
Issue summary: View changes
Related issues: +#2662208: Fix @see documentation in core

Turns out this is a duplicate of an earlier issue, #2662208: Fix @see documentation in core. However, this has a more discussion. So, I will close the older one in favor of this one and add credit. Coding standards issues are usually tasks, so changing category as well.

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.