Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. JavaScriptLintSniff.php

function JavaScriptLintSniff::process

Processes the tokens that this sniff is interested in.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.:

int $stackPtr The position in the stack where: the token was found.

Return value

int

Throws

\PHP_CodeSniffer\Exceptions\RuntimeException If Javascript Lint ran into trouble.

Overrides Sniff::process

File

vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Debug/JavaScriptLintSniff.php, line 53

Class

JavaScriptLintSniff

Namespace

PHP_CodeSniffer\Standards\Squiz\Sniffs\Debug

Code

public function process(File $phpcsFile, $stackPtr) {
    $jslPath = Config::getExecutablePath('jsl');
    if ($jslPath === null) {
        return $phpcsFile->numTokens;
    }
    $fileName = $phpcsFile->getFilename();
    $cmd = '"' . Common::escapeshellcmd($jslPath) . '" -nologo -nofilelisting -nocontext -nosummary -output-format __LINE__:__ERROR__ -process ' . escapeshellarg($fileName);
    $msg = exec($cmd, $output, $retval);
    // Variable $exitCode is the last line of $output if no error occurs, on
    // error it is numeric. Try to handle various error conditions and
    // provide useful error reporting.
    if ($retval === 2 || $retval === 4) {
        if (is_array($output) === true) {
            $msg = implode('\\n', $output);
        }
        throw new RuntimeException("Failed invoking JavaScript Lint, retval was [{$retval}], output was [{$msg}]");
    }
    if (is_array($output) === true) {
        foreach ($output as $finding) {
            $split = strpos($finding, ':');
            $line = substr($finding, 0, $split);
            $message = substr($finding, $split + 1);
            $phpcsFile->addWarningOnLine(trim($message), $line, 'ExternalTool');
        }
    }
    // Ignore the rest of the file.
    return $phpcsFile->numTokens;
}
RSS feed
Powered by Drupal