As part of the initiative to fix coding standards in Drupal core, a problem was discovered in the Drupal.Array.Array sniff. Ref. #2572613: Fix 'Drupal.Array.Array.CommaLastItem' coding standard.

It fails on the new array syntax, all lines get de-indented

       '#cache' => [
-        'contexts' => $this->entityType->getListCacheContexts(),
+      'contexts' => $this->entityType->getListCacheContexts(),
       ],

Comments

attiks created an issue. See original summary.

attiks’s picture

It is even worse, the following does not get detected

  $form['region-' . $region]['title'] = [
    'data-dialog-type' => 'modal',
      'data-dialog-type' => 'modal',
  ];

attiks’s picture

Status: Active » Needs review
StatusFileSize
new8.49 KB

First patch

pfrenssen’s picture

Priority: Critical » Normal
StatusFileSize
new10.54 KB
new2.06 KB

Added a test. This only specifically testing for warnings on the missing final commas, but since the phpcbf fixing of whitespace is also part of the test I guess this is sufficient to cover the whitespace bug.

pfrenssen’s picture

attiks’s picture

StatusFileSize
new9.13 KB

Add support for nested short arrays

attiks’s picture

StatusFileSize
new11.18 KB

Ignore #6

attiks’s picture

StatusFileSize
new13.29 KB

Added more tests

attiks’s picture

StatusFileSize
new13.17 KB

Fixed the unit tests

pfrenssen’s picture

Great work, nice test coverage was added, and it's all green!

klausi’s picture

Status: Needs review » Needs work

Makes sense, please use the PHPCS coding standard for our sniff code (4 space indentation etc) to be in line with PHPCS code and to be consistent in one file.

attiks’s picture

Status: Needs work » Needs review
StatusFileSize
new13.01 KB

Patch fixing - hopefully - the coding standards

  • klausi committed a4dd621 on authored by attiks
    Issue #2572587 by attiks, pfrenssen, klausi: Extend array sniff to short...
klausi’s picture

Title: phpcbf - Drupal.Array.Array » Extend array sniff to short array syntax
Status: Needs review » Fixed

Did a bit of cleanup by running "phpcs --standard=PHPCS" on the file. Committed, thanks!

  • klausi committed 53350dd on 8.x-2.x
    Issue #2572587: Add test coverage for allowed short array syntax
    
klausi’s picture

Status: Fixed » Closed (fixed)

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