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

Breadcrumb

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

function JSLintSniff::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 jslint.js could not be run.

Overrides Sniff::process

File

vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Debug/JSLintSniff.php, line 52

Class

JSLintSniff

Namespace

PHP_CodeSniffer\Standards\Squiz\Sniffs\Debug

Code

public function process(File $phpcsFile, $stackPtr) {
    $rhinoPath = Config::getExecutablePath('rhino');
    $jslintPath = Config::getExecutablePath('jslint');
    if ($rhinoPath === null || $jslintPath === null) {
        return $phpcsFile->numTokens;
    }
    $fileName = $phpcsFile->getFilename();
    $rhinoPath = Common::escapeshellcmd($rhinoPath);
    $jslintPath = Common::escapeshellcmd($jslintPath);
    $cmd = "{$rhinoPath} \"{$jslintPath}\" " . escapeshellarg($fileName);
    exec($cmd, $output, $retval);
    if (is_array($output) === true) {
        foreach ($output as $finding) {
            $matches = [];
            $numMatches = preg_match('/Lint at line ([0-9]+).*:(.*)$/', $finding, $matches);
            if ($numMatches === 0) {
                continue;
            }
            $line = (int) $matches[1];
            $message = 'jslint says: ' . trim($matches[2]);
            $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool');
        }
    }
    // Ignore the rest of the file.
    return $phpcsFile->numTokens;
}
RSS feed
Powered by Drupal