From 15a9612b4fc6ea21fbd2fc3b5bd5d40f664c202b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 28 Oct 2023 22:32:24 +0200 Subject: [PATCH] Various sniffs: always return EOF pointer ... for files scanning the complete file in one go as if any of the error conditions are hit, it is useless to try again for the same file. --- src/Standards/Generic/Sniffs/Debug/CSSLintSniff.php | 6 +++--- src/Standards/Generic/Sniffs/Debug/ClosureLinterSniff.php | 6 +++--- src/Standards/Generic/Sniffs/Debug/ESLintSniff.php | 4 ++-- src/Standards/Generic/Sniffs/Debug/JSHintSniff.php | 4 ++-- src/Standards/Generic/Sniffs/Files/LineEndingsSniff.php | 2 +- .../Generic/Sniffs/Files/LowercasedFilenameSniff.php | 2 +- src/Standards/PSR12/Sniffs/Files/OpenTagSniff.php | 2 +- src/Standards/Squiz/Sniffs/Debug/JSLintSniff.php | 4 ++-- src/Standards/Squiz/Sniffs/Debug/JavaScriptLintSniff.php | 4 ++-- src/Standards/Zend/Sniffs/Debug/CodeAnalyzerSniff.php | 2 +- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Standards/Generic/Sniffs/Debug/CSSLintSniff.php b/src/Standards/Generic/Sniffs/Debug/CSSLintSniff.php index 9baad8c97c..4fe8bd7cb1 100644 --- a/src/Standards/Generic/Sniffs/Debug/CSSLintSniff.php +++ b/src/Standards/Generic/Sniffs/Debug/CSSLintSniff.php @@ -44,13 +44,13 @@ public function register() * @param int $stackPtr The position in the stack where * the token was found. * - * @return void + * @return int */ public function process(File $phpcsFile, $stackPtr) { $csslintPath = Config::getExecutablePath('csslint'); if ($csslintPath === null) { - return; + return ($phpcsFile->numTokens + 1); } $fileName = $phpcsFile->getFilename(); @@ -59,7 +59,7 @@ public function process(File $phpcsFile, $stackPtr) exec($cmd, $output, $retval); if (is_array($output) === false) { - return; + return ($phpcsFile->numTokens + 1); } $count = count($output); diff --git a/src/Standards/Generic/Sniffs/Debug/ClosureLinterSniff.php b/src/Standards/Generic/Sniffs/Debug/ClosureLinterSniff.php index 926fec1555..41b7c11ae3 100644 --- a/src/Standards/Generic/Sniffs/Debug/ClosureLinterSniff.php +++ b/src/Standards/Generic/Sniffs/Debug/ClosureLinterSniff.php @@ -60,14 +60,14 @@ public function register() * @param int $stackPtr The position in the stack where * the token was found. * - * @return void + * @return int * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If jslint.js could not be run */ public function process(File $phpcsFile, $stackPtr) { $lintPath = Config::getExecutablePath('gjslint'); if ($lintPath === null) { - return; + return ($phpcsFile->numTokens + 1); } $fileName = $phpcsFile->getFilename(); @@ -77,7 +77,7 @@ public function process(File $phpcsFile, $stackPtr) exec($cmd, $output, $retval); if (is_array($output) === false) { - return; + return ($phpcsFile->numTokens + 1); } foreach ($output as $finding) { diff --git a/src/Standards/Generic/Sniffs/Debug/ESLintSniff.php b/src/Standards/Generic/Sniffs/Debug/ESLintSniff.php index cf576383f6..8145dc70a1 100644 --- a/src/Standards/Generic/Sniffs/Debug/ESLintSniff.php +++ b/src/Standards/Generic/Sniffs/Debug/ESLintSniff.php @@ -51,14 +51,14 @@ public function register() * @param int $stackPtr The position in the stack where * the token was found. * - * @return void + * @return int * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If jshint.js could not be run */ public function process(File $phpcsFile, $stackPtr) { $eslintPath = Config::getExecutablePath('eslint'); if ($eslintPath === null) { - return; + return ($phpcsFile->numTokens + 1); } $filename = $phpcsFile->getFilename(); diff --git a/src/Standards/Generic/Sniffs/Debug/JSHintSniff.php b/src/Standards/Generic/Sniffs/Debug/JSHintSniff.php index aa3e6bd7f6..a8f6e2d279 100644 --- a/src/Standards/Generic/Sniffs/Debug/JSHintSniff.php +++ b/src/Standards/Generic/Sniffs/Debug/JSHintSniff.php @@ -45,7 +45,7 @@ public function register() * @param int $stackPtr The position in the stack where * the token was found. * - * @return void + * @return int * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If jshint.js could not be run */ public function process(File $phpcsFile, $stackPtr) @@ -53,7 +53,7 @@ public function process(File $phpcsFile, $stackPtr) $rhinoPath = Config::getExecutablePath('rhino'); $jshintPath = Config::getExecutablePath('jshint'); if ($jshintPath === null) { - return; + return ($phpcsFile->numTokens + 1); } $fileName = $phpcsFile->getFilename(); diff --git a/src/Standards/Generic/Sniffs/Files/LineEndingsSniff.php b/src/Standards/Generic/Sniffs/Files/LineEndingsSniff.php index 2a8647e44f..1d17ada436 100644 --- a/src/Standards/Generic/Sniffs/Files/LineEndingsSniff.php +++ b/src/Standards/Generic/Sniffs/Files/LineEndingsSniff.php @@ -79,7 +79,7 @@ public function process(File $phpcsFile, $stackPtr) if ($tokens[$lastToken]['line'] === 1 && $tokens[$lastToken]['content'] !== "\n" ) { - return; + return ($phpcsFile->numTokens + 1); } } diff --git a/src/Standards/Generic/Sniffs/Files/LowercasedFilenameSniff.php b/src/Standards/Generic/Sniffs/Files/LowercasedFilenameSniff.php index c6ab14ce21..90af44f6e6 100644 --- a/src/Standards/Generic/Sniffs/Files/LowercasedFilenameSniff.php +++ b/src/Standards/Generic/Sniffs/Files/LowercasedFilenameSniff.php @@ -44,7 +44,7 @@ public function process(File $phpcsFile, $stackPtr) { $filename = $phpcsFile->getFilename(); if ($filename === 'STDIN') { - return; + return ($phpcsFile->numTokens + 1); } $filename = basename($filename); diff --git a/src/Standards/PSR12/Sniffs/Files/OpenTagSniff.php b/src/Standards/PSR12/Sniffs/Files/OpenTagSniff.php index c5cd9d5b6e..bb8a75d0b5 100644 --- a/src/Standards/PSR12/Sniffs/Files/OpenTagSniff.php +++ b/src/Standards/PSR12/Sniffs/Files/OpenTagSniff.php @@ -54,7 +54,7 @@ public function process(File $phpcsFile, $stackPtr) $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); if ($next === false) { // Empty file. - return; + return $phpcsFile->numTokens; } if ($tokens[$next]['line'] === $tokens[$stackPtr]['line']) { diff --git a/src/Standards/Squiz/Sniffs/Debug/JSLintSniff.php b/src/Standards/Squiz/Sniffs/Debug/JSLintSniff.php index 11ed4f26c8..67cac55086 100644 --- a/src/Standards/Squiz/Sniffs/Debug/JSLintSniff.php +++ b/src/Standards/Squiz/Sniffs/Debug/JSLintSniff.php @@ -44,7 +44,7 @@ public function register() * @param int $stackPtr The position in the stack where * the token was found. * - * @return void + * @return int * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If jslint.js could not be run */ public function process(File $phpcsFile, $stackPtr) @@ -52,7 +52,7 @@ public function process(File $phpcsFile, $stackPtr) $rhinoPath = Config::getExecutablePath('rhino'); $jslintPath = Config::getExecutablePath('jslint'); if ($rhinoPath === null || $jslintPath === null) { - return; + return ($phpcsFile->numTokens + 1); } $fileName = $phpcsFile->getFilename(); diff --git a/src/Standards/Squiz/Sniffs/Debug/JavaScriptLintSniff.php b/src/Standards/Squiz/Sniffs/Debug/JavaScriptLintSniff.php index 8eae332f16..8f9989ed23 100644 --- a/src/Standards/Squiz/Sniffs/Debug/JavaScriptLintSniff.php +++ b/src/Standards/Squiz/Sniffs/Debug/JavaScriptLintSniff.php @@ -45,14 +45,14 @@ public function register() * @param int $stackPtr The position in the stack where * the token was found. * - * @return void + * @return int * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If Javascript Lint ran into trouble. */ public function process(File $phpcsFile, $stackPtr) { $jslPath = Config::getExecutablePath('jsl'); if ($jslPath === null) { - return; + return ($phpcsFile->numTokens + 1); } $fileName = $phpcsFile->getFilename(); diff --git a/src/Standards/Zend/Sniffs/Debug/CodeAnalyzerSniff.php b/src/Standards/Zend/Sniffs/Debug/CodeAnalyzerSniff.php index a77635eadd..5bcfdc0e1c 100644 --- a/src/Standards/Zend/Sniffs/Debug/CodeAnalyzerSniff.php +++ b/src/Standards/Zend/Sniffs/Debug/CodeAnalyzerSniff.php @@ -46,7 +46,7 @@ public function process(File $phpcsFile, $stackPtr) { $analyzerPath = Config::getExecutablePath('zend_ca'); if ($analyzerPath === null) { - return; + return ($phpcsFile->numTokens + 1); } $fileName = $phpcsFile->getFilename();