I've tried the new VariableComment sniff on our codebase and it turned up a large number of instances where developers had mistakenly declared the variable name in the docblock, like this:


  /**
   * The current user.
   *
   * @var \Drupal\Core\Session\AccountProxyInterface $user
   */
  protected $user;

This presumably happens by copy-pasting from a parameter docblock, or by sheer muscle memory.

The current warning that the sniff is throwing is a little bit confusing:

Expected "\Drupal\Core\Session\AccountProxyInterfaceuser" but found "\Drupal\Core\Session\AccountProxyInterface $user" for @var tag in member variable comment

Let's provide a helpful warning + an auto fixer for this common mistake.

Comments

pfrenssen created an issue. See original summary.

pfrenssen’s picture

Issue summary: View changes
pfrenssen’s picture

Assigned: Unassigned » pfrenssen
pfrenssen’s picture

Assigned: pfrenssen » Unassigned
Status: Active » Needs review

Proposed a solution in a PR: https://github.com/klausi/coder/pull/11

klausi’s picture

Status: Needs review » Needs work

Looks like this conflicts with #2790657: VariableCommentSniff doesn't recognize multiple types, can you resolve?

pfrenssen’s picture

Status: Needs work » Needs review

Certainly! I merged it.

klausi’s picture

Status: Needs review » Fixed

Merged, thanks!

  • klausi committed 2cabb0e on 8.x-2.x authored by pfrenssen
    Issue #2790529: Detect and auto-fix appended variable names in @var...

Status: Fixed » Closed (fixed)

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