In many places in core we have comments like:

  /**
   * (optional) The short title used in the views UI.
   *
   * @var \Drupal\Core\Annotation\Translation
   *
   * @ingroup plugin_translatable
   */
  public $short_title = '';

Drupal.Commenting.DocComment.ShortNotCapital doesn't allow the comment to start with "(optional)".

CommentFileSizeAuthor
#6 2925237-6.patch7.22 KBBartoszUrbaniak

Comments

mfernea created an issue. See original summary.

alexpott’s picture

I don't think that having any optional standard for @var doesn't really make any sense. It's not a param being passed in. I don't think it adds anything to the documentation. In fact for me it makes think "huh? I wonder what they mean by optional".

Imo this is won't fix works as designed.

idebr’s picture

There is documentation available on the 'Coding standards' pages on how to type hint optional parameters:
https://www.drupal.org/docs/develop/coding-standards/api-documentation-a...

 * @param string $from
 *   (optional) The email address to send the mail from, if different from
 *   the site-wide address.
alexpott’s picture

@idebr a class property is not a parameter. These are different things.

BartoszUrbaniak’s picture

Status: Active » Needs review
Issue tags: +DrupalEurope
StatusFileSize
new7.22 KB

I have created the patch for this issue, which removes comments in class properties started with "(optional)".

mfernea’s picture

Status: Needs review » Active

@BartoszUrbaniak I think the patch uploaded relates to Drupal core while this issue is made for Coder.

liam morland’s picture

Title: Drupal.Commenting.DocComment.ShortNotCapital - "(optional)" is not allowed » ShortNotCapital triggered by non-letters
Version: 8.x-2.x-dev » 8.x-3.x-dev

The problem is that Drupal.Commenting.DocComment.ShortNotCapital is triggered by characters that cannot be capitalized. For example, the comment '0' won't work as a key for checkboxes triggers it. This should only be triggered for things that are lower-case, not characters that do not have case.

Related issue:

https://github.com/squizlabs/PHP_CodeSniffer/issues/2490

klausi’s picture

Status: Active » Postponed (maintainer needs more info)

I agree with @alexpott, the "(optional)" does not make sense as start of a doc comment for a function or class property.

@Liam: "'0' won't work as a key for checkboxes" also does not sound like a proper doc comment for a function or class property. Can you give more context where you got that example from?

liam morland’s picture

It's a comment in the Webform module.

The main point is that this error should not be triggered for characters that do not have case. If it is required that comments start with a letter that is separate from a requirement that letters be capital.