Checking my code with Drupal standard I found code sniffer report errors on lines where I have an

  • array defined with bracket syntax and
  • the first value is a negative number.

Here my example code:

/**
 * @file
 * MY PROJECT include.
 */

/**
 * Get icon settings.
 */
function my_project_icon_settins() {
  return [
    'bracket-p-p' => [15, 10],
    'array-p-p' => array(19, 14),
    'bracket-n-p' => [-15, 0],
    'array-n-p' => array(-19, 1),
    'bracket-p-n' => [15, -10],
    'array-p-n' => array(19, -23),
    'bracket-n-n' => [-15, -10],
    'array-n-n' => array(-19, -23),
  ];
}

Result:

FILE: ..MY_MODULE/inc.inc
----------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
 14 | ERROR | [x] Expected 1 space before "-"; 0 found
 14 | ERROR | [x] Expected 1 space after "-"; 0 found
 18 | ERROR | [x] Expected 1 space before "-"; 0 found
 18 | ERROR | [x] Expected 1 space after "-"; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Comments

tikaszvince created an issue. See original summary.

tikaszvince’s picture

Status: Active » Needs review
StatusFileSize
new772 bytes

If i add the open short array to the list of "invalid tokens" the error disappears.

klausi’s picture

Version: 8.x-2.6 » 8.x-2.x-dev
Status: Needs review » Needs work
Issue tags: +Needs tests

Cool, can you add your test case to good.php so that this is covered there?

tikaszvince’s picture

Status: Needs work » Needs review
StatusFileSize
new1.19 KB

New attached patch contains the modification of Sniff and adds 2 new line to good.php.

tikaszvince’s picture

Issue tags: -Needs tests

  • klausi committed 9fff68f on 8.x-2.x authored by tikaszvince
    Issue #2686013 by tikaszvince: Fixed false positives with negative...
klausi’s picture

Status: Needs review » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

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