• 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/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/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\Exceptions\RuntimeException;
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 JavaScriptLintSniff 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()
×
38
    {
39
        return [T_OPEN_TAG];
×
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 Javascript Lint ran into trouble.
53
     */
54
    public function process(File $phpcsFile, $stackPtr)
×
55
    {
56
        $jslPath = Config::getExecutablePath('jsl');
×
57
        if ($jslPath === null) {
×
58
            return $phpcsFile->numTokens;
×
59
        }
60

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

63
        $cmd = '"'.Common::escapeshellcmd($jslPath).'" -nologo -nofilelisting -nocontext -nosummary -output-format __LINE__:__ERROR__ -process '.escapeshellarg($fileName);
×
64
        $msg = exec($cmd, $output, $retval);
×
65

66
        // Variable $exitCode is the last line of $output if no error occurs, on
67
        // error it is numeric. Try to handle various error conditions and
68
        // provide useful error reporting.
69
        if ($retval === 2 || $retval === 4) {
×
70
            if (is_array($output) === true) {
×
71
                $msg = implode('\n', $output);
×
72
            }
73

74
            throw new RuntimeException("Failed invoking JavaScript Lint, retval was [$retval], output was [$msg]");
×
75
        }
76

77
        if (is_array($output) === true) {
×
78
            foreach ($output as $finding) {
×
79
                $split   = strpos($finding, ':');
×
80
                $line    = substr($finding, 0, $split);
×
81
                $message = substr($finding, ($split + 1));
×
82
                $phpcsFile->addWarningOnLine(trim($message), $line, 'ExternalTool');
×
83
            }
84
        }
85

86
        // Ignore the rest of the file.
87
        return $phpcsFile->numTokens;
×
88

89
    }//end process()
90

91

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

101
    }//end getDeprecationVersion()
102

103

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

113
    }//end getRemovalVersion()
114

115

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

125
    }//end getDeprecationMessage()
126

127

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