From 56776323c071c93f69b0f6f59af24126ce4ea934 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 81284787a2..36f77c84cb 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 19204718b0..d4a17917c6 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 d11d347050..ce8d46ec85 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 738ab67ebe..e5bd47eee6 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 845e1bcfc4..c97976534f 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 a9fd4c5d44..24934f6c68 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 4371bee19b..143da8775b 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 49dfc2c42f..9a903a018d 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 30dca6722d..d033796f8e 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 5df4b0fc2c..fed71a9e99 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();