From 5524f2d1e110697e551f0c7af5abd8c4f44ce75a Mon Sep 17 00:00:00 2001 From: Greg Sherwood Date: Mon, 30 Oct 2017 14:35:26 +1100 Subject: [PATCH] PSR1.Files.SideEffects now respects the new phpcs:disable comment syntax --- package.xml | 4 ++++ src/Standards/PSR1/Sniffs/Files/SideEffectsSniff.php | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/package.xml b/package.xml index fcdc178bc1..aeb2a602cf 100644 --- a/package.xml +++ b/package.xml @@ -45,6 +45,10 @@ http://pear.php.net/dtd/package-2.0.xsd"> -- If they are at the end of an existing line, they will only ignore the line they are on -- Stops some lines from accidently being ignored -- Same rule applies for the new phpcs:ignore comment syntax + - PSR1.Files.SideEffects now respects the new phpcs:disable comment syntax + -- The sniff will no longer check any code that is between phpcs:disable and phpcs:enable comments + -- The sniff does not support the phpcs:ignore; you must wrap code structures with disable/enable comments + -- Previously, there was no way to have this sniff ignore parts of a file - Array properties specified in ruleset files now have their keys and values trimmed -- This saves having to do this in individual sniffs, and stops errors introduced by whitespace in rulesets -- Thanks to Juliette Reinders Folmer for the patch diff --git a/src/Standards/PSR1/Sniffs/Files/SideEffectsSniff.php b/src/Standards/PSR1/Sniffs/Files/SideEffectsSniff.php index 97c979f902..c16c202489 100644 --- a/src/Standards/PSR1/Sniffs/Files/SideEffectsSniff.php +++ b/src/Standards/PSR1/Sniffs/Files/SideEffectsSniff.php @@ -94,6 +94,18 @@ private function searchForConflict($phpcsFile, $start, $end, $tokens) $firstSymbol = null; $firstEffect = null; for ($i = $start; $i <= $end; $i++) { + // Respect phpcs:disable comments. + if ($tokens[$i]['code'] === T_PHPCS_DISABLE) { + $i = $phpcsFile->findNext(T_PHPCS_ENABLE, $i); + if ($i === false) { + // The entire rest of the file is disabled, + // so return what we have so far. + break; + } + + continue; + } + // Ignore whitespace and comments. if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) { continue;