Problem/Motivation

I notice there are 24 places in core where the API documentation uses a tag of "@returns" (with a trailing 's') instead of the proper tag "@return" to document the return value of a function/method.

The attached patch corrects these errors.

Steps to reproduce

Proposed resolution

Remaining tasks

Rreview

User interface changes

API changes

Data model changes

Release notes snippet

Comments

TR created an issue. See original summary.

chiranjeeb2410’s picture

Status: Needs review » Reviewed & tested by the community

@TR,

Patch applies cleanly to local. Good to go. RTBC for me.

dawehner’s picture

Status: Reviewed & tested by the community » Needs review

Thank you for providing a patch. We are fixing coding/documentation standard fixes in a more structure way though, see #2571965: [meta] Fix PHP coding standards in core, stage 1. Please ensure that changes are covered by a phpcs.yml change.

tr’s picture

Status: Needs review » Reviewed & tested by the community

Already covered by the check for a @return tag - "@returns" is not recognized as a @return tag. Setting this back to RTBC.

dawehner’s picture

Already covered by the check for a @return tag - "@returns" is not recognized as a @return tag. Setting this back to RTBC.

Well in this case I think the right approach would be to adapt the existing check so it is able to find these mistakes as well.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

@TR thanks for working on this. Coding standards are important and errors like these are annoying. As a coding standard fix and in order to make it we should change the core/phpcs.xml.dist file so that we don't make the same mistake again.

Specifically it is covered by #2572645: [Meta] Fix 'Drupal.Commenting.FunctionComment' coding standard. We need to file a child issue of that one that removes <exclude name="Drupal.Commenting.FunctionComment.MissingReturnComment"/> from the phpcs.xml.dist and fix them all. This is going to take a long time since it will involve writing docs :( It is also going to take a longer time because it appears that the sniff Drupal.Commenting.FunctionComment.MissingReturnComment doesn't actually work as described because removing the exclusion and running against core/lib/Drupal/Core/Form/EnforcedResponseException.php phpcs does not find the issue. Therefore we also need to file (and fix) an issue against the Coder module to fix the rule.

tr’s picture

Priority: Minor » Normal

OK, so there's been an open issue in the Coder queue FOR 17 MONTHS to check for misspelled tags, where "@returns" is mentioned specifically as something that would be caught. #2729697: Add a sniff for unknown docs @ tags

That issue has been open for 17 months with no action.

So the way I see it, let's spend the 30 seconds to fix a known problem here, then WHEN and IF that issue is addressed and Coder actually gets fixed we will know it won't happen again. But I'm NOT going to participate in a trivial issue like this for years (that's not hyperbole, as evidenced by #2729697: Add a sniff for unknown docs @ tags and many other issues), hoping for a resolution, because that sort of effort is all out of proportion with the problem.

&BTW, when a "@returns" tag is used, that means the API module documentation generator ignores the tag and the return value remains undocumented on api.drupal.org. Those 24 methods/functions using the wrong tag will remain without visible documentation for return value until the patch is committed or Coder is fixed.

There is NO REASON to postpone simple fixes like this until the Coder issues are fixed. It's sufficient that there is an issue in the Coder queue, as a placeholder for a known problem that needs to be avoided. This problem needs to be fixed at some point, so kicking it down the road by several years just inconveniences everyone who is trying to use the API documentation in the meantime.

You can fix this AND work on the Coder issue at the same time.

(Changing priority to Normal because existing documentation is being lost and not accessible on api.drupal.org).

tr’s picture

Title: Quick fix - use "@return" instead of "@returns" » A task that will take two years to accomplish - use "@return" instead of "@returns"
borisson_’s picture

Title: A task that will take two years to accomplish - use "@return" instead of "@returns" » Use "@return" instead of "@returns"
Status: Needs work » Postponed
Related issues: +#2729697: Add a sniff for unknown docs @ tags

Reverting the title change and postponing this on the coder issue.

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.

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.

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.

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.

quietone’s picture

Closed duplicate issue and moving credit here.

Still to do here is to merge / move credit to the issue fixing this by sniff.
'

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.

quietone’s picture

Issue summary: View changes

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.

quietone’s picture

Issue summary: View changes
Status: Postponed » Needs review
StatusFileSize
new9 KB
new14.04 KB

This was discussed in Slack by catch, larowlan, dww, bbrala, smustgrave and longwave. The consensus was that it is better to get this trival fix instead of waiting for the sniff. Also, as longwave pointed out that eventually all methods will have a return type so this will not be needed anyway.

To that end I chose to reroll the patch, yes staying with the patch workflow. Then I searched for for others instances and fixed those. Also, fixed any new errors caught php phpcs.

smustgrave’s picture

Status: Needs review » Needs work
StatusFileSize
new50.28 KB

Searching for @returns and found a few more

returns

believe the assets ones could be ignored.

tr’s picture

Status: Needs work » Needs review
StatusFileSize
new14.28 KB
new537 bytes

@smustgrave: All but one of those "few more" are in .js files. JSDoc is different than PHPDoc (JSDoc allows use of @returns, among a lot of other things that are not allowed in PHPDoc) and JavaScript code is not included in the Drupal API documentation at api.drupal.org, which is what this issue was opened to fix.

The only one missed by the patch in #24 is core/modules/jsonapi/tests/src/Kernel/ResourceType/ResourceTypeRepositoryTest.php

Here is a new patch that fixes that as well.

mrinalini9’s picture

Hi,

I have reviewed patch #26, looks good to me.
It applied cleanly and replaced all the occurrences of @returns with @return at all places except the .js files in the core.
So, for me, it is RTBC.

Thanks & Regards,
Mrinalini

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for pointing that out @TR

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed c3ff576 and pushed to 11.x. Thanks!

It didn't cleanly backport to 10.1.x

  • alexpott committed c3ff5768 on 11.x
    Issue #2916306 by TR, quietone, pfrenssen: Use "@return" instead of "@...
tr’s picture

Version: 11.x-dev » 10.1.x-dev
Status: Fixed » Needs review
StatusFileSize
new13.59 KB
new469 bytes

One hunk of the patch in #26 does not apply in Drupal 10.1.x because a usage of @returns that was recently introduced only into 11.x by #3356894: Make field selection less overwhelming by introducing groups. That code does not exist in 10.1.x, and therefore that hunk does not apply to 10.1.x.

Here is a version of #26 that applies in 10.1.x.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

10.1 patch seems good.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 7cbdf08 and pushed to 10.1.x. Thanks!

  • alexpott committed 7cbdf08f on 10.1.x
    Issue #2916306 by TR, quietone, pfrenssen: Use "@return" instead of "@...
longwave’s picture

I realised that we previously banned @inheritDoc with a rule in phpcs.xml.dist; we can do the same for @returns: #3393661: Prevent @returns from creeping back into the codebase

Status: Fixed » Closed (fixed)

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