[regression] Can no longer ignore Drupal.Commenting.FunctionComment.MissingReturnComment

Created on 9 May 2025, 24 days ago

Problem/Motivation

This line to ignore a rule is no longer ignored.
// phpcs:ignore Drupal.Commenting.FunctionComment.MissingReturnComment

📌 fix(FunctionComment): Allow PHPCS ignore directives before functions Active States "This will trip up a lot of excludes in Drupal core, but they are all fixable." . I am not sure of the intention here but in core we want to maintain the ability to ignore the missing return comment in these cases. It also seems reasonable to expect to be able to ignore the sniff in the future.

If there is a way to ignore the sniff I was not able to figure it out.

Steps to reproduce

In Drupal core, update coder to the latest and run phpcs composer

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

8.3

Component

Coder Sniffer

Created by

🇳🇿New Zealand quietone

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @quietone
  • 🇦🇹Austria klausi 🇦🇹 Vienna

    Thanks for reporting!

    We improved the handling of phpcs ignores, and now the exact line where the problem is (the @return line in the doc comment) is returned. I assumed it would be enough to move "phpcs:ignore Drupal.Commenting.FunctionComment.MissingReturnComment" into the doc comment, but turns out that this results in a different error:

    /**
     * Provides a collection of condition plugins.
     */
    class ConditionPluginCollection extends DefaultLazyPluginCollection {
    
      /**
       * {@inheritdoc}
       *
       * phpcs:ignore Drupal.Commenting.FunctionComment.MissingReturnComment
       * @return \Drupal\Core\Condition\ConditionInterface
       */
      public function &get($instance_id) {
        return 'x';
      }
    
    }
    

    Opened a PR to make that work as well: https://github.com/pfrenssen/coder/pull/265/files

    Of course it would be so much better if you just add the missing return comment. Then you don't need confusing phpcs ignore statements littered in Drupal core. Example:

    /**
     * Provides a collection of condition plugins.
     */
    class ConditionPluginCollection extends DefaultLazyPluginCollection {
    
      /**
       * {@inheritdoc}
       *
       * @return \Drupal\Core\Condition\ConditionInterface
       *   The condition for the given instance ID.
       */
      public function &get($instance_id) {
        return 'x';
      }
    
    }
    
    • klausi authored 5db17e37 on 8.3.x
      fix(DocComment): Allow phpcs ignore comments before a tag (#3523506)
      
      
  • 🇦🇹Austria klausi 🇦🇹 Vienna

    Merged that one.

    For Drupal core you have 3 options:
    1) Add a return comment to your @return docs, remove phpcs:ignore (best solution IMO)
    2) Globally ignore Drupal.Commenting.FunctionComment.MissingReturnComment in the phpcs.xml.dist config file when updating Coder, fix those instances later
    3) Wait for Coder 8.3.30 with this fix and upgrade to that, but you will still have to move the phpcs:ignore statements into the doc comment before the @return as in the example here.

  • 🇳🇿New Zealand quietone

    @klausi, thanks for the fix! I am now eagerly waiting on the next release.

Production build 0.71.5 2024