• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PHPCSStandards / PHP_CodeSniffer / 15036337869

15 May 2025 04:03AM UTC coverage: 78.375% (-0.2%) from 78.556%
15036337869

Pull #856

github

web-flow
Merge 93f570b46 into f5e7943d0
Pull Request #856: [Doc] Cover all errors of PEAR ClassDeclaration

25112 of 32041 relevant lines covered (78.37%)

69.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Standards/Squiz/Sniffs/Debug/JSLintSniff.php
1
<?php
2
/**
3
 * Runs jslint.js 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/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
8
 *
9
 * @deprecated 3.9.0
10
 */
11

12
namespace PHP_CodeSniffer\Standards\Squiz\Sniffs\Debug;
13

14
use PHP_CodeSniffer\Config;
15
use PHP_CodeSniffer\Files\File;
16
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
17
use PHP_CodeSniffer\Sniffs\Sniff;
18
use PHP_CodeSniffer\Util\Common;
19

20
class JSLintSniff implements Sniff, DeprecatedSniff
21
{
22

23
    /**
24
     * A list of tokenizers this sniff supports.
25
     *
26
     * @var array
27
     */
28
    public $supportedTokenizers = ['JS'];
29

30

31
    /**
32
     * Returns the token types that this sniff is interested in.
33
     *
34
     * @return array<int|string>
35
     */
36
    public function register()
×
37
    {
38
        return [T_OPEN_TAG];
×
39

40
    }//end register()
41

42

43
    /**
44
     * Processes the tokens that this sniff is interested in.
45
     *
46
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
47
     * @param int                         $stackPtr  The position in the stack where
48
     *                                               the token was found.
49
     *
50
     * @return int
51
     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If jslint.js could not be run.
52
     */
53
    public function process(File $phpcsFile, $stackPtr)
×
54
    {
55
        $rhinoPath  = Config::getExecutablePath('rhino');
×
56
        $jslintPath = Config::getExecutablePath('jslint');
×
57
        if ($rhinoPath === null || $jslintPath === null) {
×
58
            return $phpcsFile->numTokens;
×
59
        }
60

61
        $fileName = $phpcsFile->getFilename();
×
62

63
        $rhinoPath  = Common::escapeshellcmd($rhinoPath);
×
64
        $jslintPath = Common::escapeshellcmd($jslintPath);
×
65

66
        $cmd = "$rhinoPath \"$jslintPath\" ".escapeshellarg($fileName);
×
67
        exec($cmd, $output, $retval);
×
68

69
        if (is_array($output) === true) {
×
70
            foreach ($output as $finding) {
×
71
                $matches    = [];
×
72
                $numMatches = preg_match('/Lint at line ([0-9]+).*:(.*)$/', $finding, $matches);
×
73
                if ($numMatches === 0) {
×
74
                    continue;
×
75
                }
76

77
                $line    = (int) $matches[1];
×
78
                $message = 'jslint says: '.trim($matches[2]);
×
79
                $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool');
×
80
            }
81
        }
82

83
        // Ignore the rest of the file.
84
        return $phpcsFile->numTokens;
×
85

86
    }//end process()
87

88

89
    /**
90
     * Provide the version number in which the sniff was deprecated.
91
     *
92
     * @return string
93
     */
94
    public function getDeprecationVersion()
×
95
    {
96
        return 'v3.9.0';
×
97

98
    }//end getDeprecationVersion()
99

100

101
    /**
102
     * Provide the version number in which the sniff will be removed.
103
     *
104
     * @return string
105
     */
106
    public function getRemovalVersion()
×
107
    {
108
        return 'v4.0.0';
×
109

110
    }//end getRemovalVersion()
111

112

113
    /**
114
     * Provide a custom message to display with the deprecation.
115
     *
116
     * @return string
117
     */
118
    public function getDeprecationMessage()
×
119
    {
120
        return 'Support for scanning JavaScript files will be removed completely in v4.0.0.';
×
121

122
    }//end getDeprecationMessage()
123

124

125
}//end class
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc