Skip to content

Commit

Permalink
Various sniffs: always return EOF pointer
Browse files Browse the repository at this point in the history
... 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.
  • Loading branch information
jrfnl committed Oct 28, 2023
1 parent 321d252 commit 5677632
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/Standards/Generic/Sniffs/Debug/CSSLintSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/Standards/Generic/Sniffs/Debug/ClosureLinterSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/Standards/Generic/Sniffs/Debug/ESLintSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/Standards/Generic/Sniffs/Debug/JSHintSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ 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)
{
$rhinoPath = Config::getExecutablePath('rhino');
$jshintPath = Config::getExecutablePath('jshint');
if ($jshintPath === null) {
return;
return ($phpcsFile->numTokens + 1);
}

$fileName = $phpcsFile->getFilename();
Expand Down
2 changes: 1 addition & 1 deletion src/Standards/Generic/Sniffs/Files/LineEndingsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function process(File $phpcsFile, $stackPtr)
if ($tokens[$lastToken]['line'] === 1
&& $tokens[$lastToken]['content'] !== "\n"
) {
return;
return ($phpcsFile->numTokens + 1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function process(File $phpcsFile, $stackPtr)
{
$filename = $phpcsFile->getFilename();
if ($filename === 'STDIN') {
return;
return ($phpcsFile->numTokens + 1);
}

$filename = basename($filename);
Expand Down
2 changes: 1 addition & 1 deletion src/Standards/PSR12/Sniffs/Files/OpenTagSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down
4 changes: 2 additions & 2 deletions src/Standards/Squiz/Sniffs/Debug/JSLintSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ 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)
{
$rhinoPath = Config::getExecutablePath('rhino');
$jslintPath = Config::getExecutablePath('jslint');
if ($rhinoPath === null || $jslintPath === null) {
return;
return ($phpcsFile->numTokens + 1);
}

$fileName = $phpcsFile->getFilename();
Expand Down
4 changes: 2 additions & 2 deletions src/Standards/Squiz/Sniffs/Debug/JavaScriptLintSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Standards/Zend/Sniffs/Debug/CodeAnalyzerSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5677632

Please sign in to comment.