Problem/Motivation

There is a coding standard now to require trailing commas on multi-line function declarations in #3295249: Allow multi-line function declarations.

Steps to reproduce

This should throw an error on PHP higher than 8.0 because comma missing

/**
 * Last parameter should have a trailing comma.
 */
function test29(
  int $a,
  string $b
) {
  echo "Hello";
}

Proposed resolution

Check if we can find any existing sniff upstream and use that. Otherwise contribute improvement or write sniff in Coder.

Remaining tasks

Comments

klausi created an issue. See original summary.

klausi’s picture

Status: Active » Needs review
klausi’s picture

Found a better solution by forking our own function declaration multi-line sniff in https://github.com/pfrenssen/coder/pull/226

  • klausi authored ad1de270 on 8.3.x
    feat(MultiLineFunctionDeclaration): Add new sniff for multi-line...
klausi’s picture

Status: Needs review » Fixed

Merged the latter one.

  • klausi authored 1a59890f on 8.3.x
    chore(composer): Bump minimum version of PHPCS (#3440603)
    
    

Status: Fixed » Closed (fixed)

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

dpi’s picture

Why a custom sniff over SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration ?

klausi’s picture

Hm, I probably did not find that sniff. Good to know that it exists, but with the fork of the upstream PHPCS sniff we cover all our requirements for Drupal, so I think it is fine.

dpi’s picture

Just a note that if one uses the slevomat version also, multiple errors are reported on a line. One for each rule.