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
Comment #2
tikaszvince commentedIf i add the open short array to the list of "invalid tokens" the error disappears.
Comment #3
klausiCool, can you add your test case to good.php so that this is covered there?
Comment #4
tikaszvince commentedNew attached patch contains the modification of Sniff and adds 2 new line to good.php.
Comment #5
tikaszvince commentedComment #7
klausiCommitted, thanks!