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

Breadcrumb

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

function ClosureLinterSniff::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/Generic/Sniffs/Debug/ClosureLinterSniff.php, line 68

Class

ClosureLinterSniff

Namespace

PHP_CodeSniffer\Standards\Generic\Sniffs\Debug

Code

public function process(File $phpcsFile, $stackPtr) {
    $lintPath = Config::getExecutablePath('gjslint');
    if ($lintPath === null) {
        return $phpcsFile->numTokens;
    }
    $fileName = $phpcsFile->getFilename();
    $lintPath = Common::escapeshellcmd($lintPath);
    $cmd = $lintPath . ' --nosummary --notime --unix_mode ' . escapeshellarg($fileName);
    exec($cmd, $output, $retval);
    if (is_array($output) === false) {
        return $phpcsFile->numTokens;
    }
    foreach ($output as $finding) {
        $matches = [];
        $numMatches = preg_match('/^(.*):([0-9]+):\\(.*?([0-9]+)\\)(.*)$/', $finding, $matches);
        if ($numMatches === 0) {
            continue;
        }
        // Skip error codes we are ignoring.
        $code = $matches[3];
        if (in_array($code, $this->ignoreCodes) === true) {
            continue;
        }
        $line = (int) $matches[2];
        $error = trim($matches[4]);
        $message = 'gjslint says: (%s) %s';
        $data = [
            $code,
            $error,
        ];
        if (in_array($code, $this->errorCodes) === true) {
            $phpcsFile->addErrorOnLine($message, $line, 'ExternalToolError', $data);
        }
        else {
            $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool', $data);
        }
    }
    
    //end foreach
    // Ignore the rest of the file.
    return $phpcsFile->numTokens;
}
RSS feed
Powered by Drupal