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

PHPCSStandards / PHP_CodeSniffer / 8603752048

08 Apr 2024 04:45PM UTC coverage: 74.371%. Remained the same
8603752048

Pull #438

github

web-flow
Merge 96d3fd903 into 23c79fc26
Pull Request #438: CS: use `implode()` not `join()`

1 of 3 new or added lines in 3 files covered. (33.33%)

22629 of 30427 relevant lines covered (74.37%)

49.0 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\Sniff;
18
use PHP_CodeSniffer\Util\Common;
19

20
class JavaScriptLintSniff implements Sniff
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 Javascript Lint ran into trouble.
52
     */
53
    public function process(File $phpcsFile, $stackPtr)
×
54
    {
55
        $jslPath = Config::getExecutablePath('jsl');
×
56
        if ($jslPath === null) {
×
57
            return $phpcsFile->numTokens;
×
58
        }
59

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

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

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

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

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

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

88
    }//end process()
89

90

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

© 2025 Coveralls, Inc