• 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

68.57
/src/Standards/Generic/Sniffs/Debug/JSHintSniff.php
1
<?php
2
/**
3
 * Runs jshint.js on the file.
4
 *
5
 * @author    Greg Sherwood <gsherwood@squiz.net>
6
 * @author    Alexander Wei§ <aweisswa@gmx.de>
7
 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
8
 * @license   https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
9
 *
10
 * @deprecated 3.9.0
11
 */
12

13
namespace PHP_CodeSniffer\Standards\Generic\Sniffs\Debug;
14

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

21
class JSHintSniff implements Sniff, DeprecatedSniff
22
{
23

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

31

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

41
    }//end register()
42

43

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

62
        $fileName   = $phpcsFile->getFilename();
2✔
63
        $jshintPath = Common::escapeshellcmd($jshintPath);
2✔
64

65
        if ($rhinoPath !== null) {
2✔
66
            $rhinoPath = Common::escapeshellcmd($rhinoPath);
×
67
            $cmd       = "$rhinoPath \"$jshintPath\" ".escapeshellarg($fileName);
×
68
            exec($cmd, $output, $retval);
×
69

70
            $regex = '`^(?P<error>.+)\(.+:(?P<line>[0-9]+).*:[0-9]+\)$`';
×
71
        } else {
72
            $cmd = "$jshintPath ".escapeshellarg($fileName);
2✔
73
            exec($cmd, $output, $retval);
2✔
74

75
            $regex = '`^(.+?): line (?P<line>[0-9]+), col [0-9]+, (?P<error>.+)$`';
2✔
76
        }
77

78
        if (is_array($output) === true) {
2✔
79
            foreach ($output as $finding) {
2✔
80
                $matches    = [];
2✔
81
                $numMatches = preg_match($regex, $finding, $matches);
2✔
82
                if ($numMatches === 0) {
2✔
83
                    continue;
2✔
84
                }
85

86
                $line    = (int) $matches['line'];
2✔
87
                $message = 'jshint says: '.trim($matches['error']);
2✔
88
                $phpcsFile->addWarningOnLine($message, $line, 'ExternalTool');
2✔
89
            }
1✔
90
        }
1✔
91

92
        // Ignore the rest of the file.
93
        return $phpcsFile->numTokens;
2✔
94

95
    }//end process()
96

97

98
    /**
99
     * Provide the version number in which the sniff was deprecated.
100
     *
101
     * @return string
102
     */
103
    public function getDeprecationVersion()
×
104
    {
105
        return 'v3.9.0';
×
106

107
    }//end getDeprecationVersion()
108

109

110
    /**
111
     * Provide the version number in which the sniff will be removed.
112
     *
113
     * @return string
114
     */
115
    public function getRemovalVersion()
×
116
    {
117
        return 'v4.0.0';
×
118

119
    }//end getRemovalVersion()
120

121

122
    /**
123
     * Provide a custom message to display with the deprecation.
124
     *
125
     * @return string
126
     */
127
    public function getDeprecationMessage()
×
128
    {
129
        return 'Support for scanning JavaScript files will be removed completely in v4.0.0.';
×
130

131
    }//end getDeprecationMessage()
132

133

134
}//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