PHP_CodeSniffer
[ class tree: PHP_CodeSniffer ] [ index: PHP_CodeSniffer ] [ all elements ]

Source for file JavaScriptLintSniff.php

Documentation is available at JavaScriptLintSniff.php

  1. <?php
  2. /**
  3.  * Runs JavaScript Lint on the file.
  4.  *
  5.  * @author    Greg Sherwood <gsherwood@squiz.net>
  6.  * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
  7.  * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
  8.  */
  9.  
  10. namespace PHP_CodeSniffer\Standards\Squiz\Sniffs\Debug;
  11.  
  12. use PHP_CodeSniffer\Sniffs\Sniff;
  13. use PHP_CodeSniffer\Files\File;
  14. use PHP_CodeSniffer\Config;
  15. use PHP_CodeSniffer\Exceptions\RuntimeException;
  16.  
  17. class JavaScriptLintSniff implements Sniff
  18. {
  19.  
  20.     /**
  21.      * A list of tokenizers this sniff supports.
  22.      *
  23.      * @var array 
  24.      */
  25.     public $supportedTokenizers = array('JS');
  26.  
  27.  
  28.     /**
  29.      * Returns the token types that this sniff is interested in.
  30.      *
  31.      * @return int[] 
  32.      */
  33.     public function register()
  34.     {
  35.         return array(T_OPEN_TAG);
  36.  
  37.     }//end register()
  38.  
  39.  
  40.     /**
  41.      * Processes the tokens that this sniff is interested in.
  42.      *
  43.      * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
  44.      * @param int                         $stackPtr  The position in the stack where
  45.      *                                                the token was found.
  46.      *
  47.      * @return void 
  48.      */
  49.     public function process(File $phpcsFile$stackPtr)
  50.     {
  51.         $jslPath = Config::getExecutablePath('jsl');
  52.         if (is_null($jslPath=== true{
  53.             return;
  54.         }
  55.  
  56.         $fileName $phpcsFile->getFilename();
  57.  
  58.         $cmd '"'.escapeshellcmd($jslPath).'" -nologo -nofilelisting -nocontext -nosummary -output-format __LINE__:__ERROR__ -process '.escapeshellarg($fileName);
  59.         $msg exec($cmd$output$retval);
  60.  
  61.         // Variable $exitCode is the last line of $output if no error occurs, on
  62.         // error it is numeric. Try to handle various error conditions and
  63.         // provide useful error reporting.
  64.         if ($retval === 2 || $retval === 4{
  65.             if (is_array($output=== true{
  66.                 $msg join('\n'$output);
  67.             }
  68.  
  69.             throw new RuntimeException("Failed invoking JavaScript Lint, retval was [$retval], output was [$msg]");
  70.         }
  71.  
  72.         if (is_array($output=== true{
  73.             foreach ($output as $finding{
  74.                 $split   strpos($finding':');
  75.                 $line    substr($finding0$split);
  76.                 $message substr($finding($split + 1));
  77.                 $phpcsFile->addWarningOnLine(trim($message)$line'ExternalTool');
  78.             }
  79.         }
  80.  
  81.         // Ignore the rest of the file.
  82.         return ($phpcsFile->numTokens + 1);
  83.  
  84.     }//end process()
  85.  
  86.  
  87. }//end class

Documentation generated on Mon, 11 Mar 2019 15:27:34 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.