Skip to content

Commit

Permalink
Squiz/OperatorSpacing: fix potential fixer conflict
Browse files Browse the repository at this point in the history
[Fixer conflict series]

The sniff had a potential fixer conflict with the `SuperfluousWhiteSpace` and the `EndFileNewline` sniffs.

This minor change fixes this by bowing out from analysing the space after the operator if the operator is the last non-whitespace token in a file.

Fixer conflict can be reproduced by running the below command over the unit test added by this patch (without the included fix):
`phpcbf ./squiz/tests/whitespace/operatorspacingunittest.inc --standard=Squiz -vv`

Includes unit test.
  • Loading branch information
jrfnl committed Jul 20, 2019
1 parent f6fd848 commit db24dcc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ public function process(File $phpcsFile, $stackPtr)
}
}//end if

$hasNext = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
if ($hasNext === false) {
// Live coding/parse error at end of file.
return;
}

// Check there is one space after the & operator.
if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
$error = 'Expected 1 space after "&" operator; 0 found';
Expand Down Expand Up @@ -179,7 +185,9 @@ public function process(File $phpcsFile, $stackPtr)
}//end if
}//end if

if (isset($tokens[($stackPtr + 1)]) === false) {
$hasNext = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
if ($hasNext === false) {
// Live coding/parse error at end of file.
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,6 @@ function bar(): array {}
if ($line{-1} === ':') {
$line = substr($line, 0, -1);
}

/* Intentional parse error. This has to be the last test in the file. */
$a = 10 +
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,6 @@ function bar(): array {}
if ($line{-1} === ':') {
$line = substr($line, 0, -1);
}

/* Intentional parse error. This has to be the last test in the file. */
$a = 10 +

0 comments on commit db24dcc

Please sign in to comment.