Skip to content

Commit db24dcc

Browse files
committed
Squiz/OperatorSpacing: fix potential fixer conflict
[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.
1 parent f6fd848 commit db24dcc

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ public function process(File $phpcsFile, $stackPtr)
9999
}
100100
}//end if
101101

102+
$hasNext = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
103+
if ($hasNext === false) {
104+
// Live coding/parse error at end of file.
105+
return;
106+
}
107+
102108
// Check there is one space after the & operator.
103109
if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
104110
$error = 'Expected 1 space after "&" operator; 0 found';
@@ -179,7 +185,9 @@ public function process(File $phpcsFile, $stackPtr)
179185
}//end if
180186
}//end if
181187

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

src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,6 @@ function bar(): array {}
260260
if ($line{-1} === ':') {
261261
$line = substr($line, 0, -1);
262262
}
263+
264+
/* Intentional parse error. This has to be the last test in the file. */
265+
$a = 10 +

src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,6 @@ function bar(): array {}
254254
if ($line{-1} === ':') {
255255
$line = substr($line, 0, -1);
256256
}
257+
258+
/* Intentional parse error. This has to be the last test in the file. */
259+
$a = 10 +

0 commit comments

Comments
 (0)