Enforce method to not have docblock

Created on 27 September 2024, 3 months ago

Problem/Motivation

We have now https://www.drupal.org/project/coder/issues/3400560 πŸ“Œ Allow _construct() method to omit docblock Needs review . That's cool. In my projects, which are using Drupal coding standards, I want to enforce this because constructor comments are only adding noise.

Proposed resolution

Allow such a setting to work and prohibit commenting the constructor:

<rule ref="Drupal.Commenting.FunctionComment">
  <properties>
    <property name="commentProhibitedFunctions" type="array">
      <element value="__construct"/>
    </property>
  </properties>
</rule>

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

✨ Feature request
Status

Active

Version

8.3

Component

Coder Sniffer

Created by

πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

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

Comments & Activities

  • Issue created by @claudiu.cristea
  • πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

    Let's try it

  • πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

    I've added the fix and also tests. However, tests are failing and, even I spent few hours, I can get it. Maybe someone with experience can find the problem.

  • πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄
  • πŸ‡¦πŸ‡ΉAustria klausi πŸ‡¦πŸ‡Ή Vienna

    Hm, I'm not sure we should do this.

    Comments in general are a good thing - they explain what code does. Maybe you want to summarize why you have that constructor and what it is doing?

    I think you never want to forbid comments, they should always be allowed on any function.

    Sure, constructors are often obvious, so we allow you to omit the function comment. But forbidding it? I think no.

  • πŸ‡·πŸ‡΄Romania claudiu.cristea Arad πŸ‡·πŸ‡΄

    It’s not specifically about constructors. It could be any method and it’s optional. Nobody is forcing you to use it.

Production build 0.71.5 2024