GitHub PR https://github.com/pfrenssen/coder/pull/237

Problem/Motivation

We have now https://www.drupal.org/project/coder/issues/3400560. 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.

Comments

claudiu.cristea created an issue. See original summary.

claudiu.cristea’s picture

Assigned: Unassigned » claudiu.cristea

Let's try it

claudiu.cristea’s picture

Assigned: claudiu.cristea » Unassigned
Issue summary: View changes

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.

claudiu.cristea’s picture

Status: Active » Needs review
klausi’s picture

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.

claudiu.cristea’s picture

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

klausi’s picture

Status: Needs review » Needs work

Right, we can add this in a way to leave it disabled. Then add a documentation section somewhere how people can enable it. On drupal.org or in the README file?

I think the pull request should be good once you remove the special constructor handling?

We also need a new test case to demonstrate that this addition works.