-
Notifications
You must be signed in to change notification settings - Fork 0
/
gjslintReport.php
executable file
·68 lines (56 loc) · 1.75 KB
/
gjslintReport.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
$ignore = array(
'E:0110'
);
$invalidChars = array(
'"' => '\'',
'&' => '&',
'>' => '>',
'<' => '<'
);
if (!isset($_SERVER['argv'][1]) || !isset($_SERVER['argv'][2])) {
echo 'Usage:- php gjslintReport.php [inputFile] [outputFile]';
die();
}
$handle = fopen($_SERVER['argv'][1], "r");
$errors = array();
while (!feof($handle)) {
$line = fgets($handle);
if (substr($line, 0, 15) == '----- FILE : ') {
$file = trim(str_replace(array('----- FILE : ', '-----'), '', $line));
$errors[$file] = array();
$key = 0;
} else if (substr($line, 0, 5) == 'Line ') {
$error = explode(', ', $line);
if (!in_array(substr($error[1], 0, 6), $ignore)) {
$errors[$file][$key] = array();
$errors[$file][$key]['line'] = trim(str_replace('Line ', '',
$error[0]));
$errors[$file][$key]['reason'] = trim($error[1]);
$errors[$file][$key]['severity'] = 'error';
$key++;
}
}
}
fclose($handle);
$xml = '<jslint>';
foreach ($errors as $fileName => $issues) {
$xml .= '<file name="' . $fileName . '">';
foreach ($issues as $issue) {
$xml .= '<issue line="' . $issue['line'] . '" severity="' .
$issue['severity'] . '" reason="' . removeInvalidChars($issue['reason'], $invalidChars) . '"/>';
}
$xml .= '</file>';
}
$xml .='</jslint>';
$handle = fopen($_SERVER['argv'][2], "w");
fwrite($handle, $xml);
fclose($handle);
function removeInvalidChars($text, $invalidChars) {
$result = $text;
foreach ($invalidChars as $invalid => $valid) {
$result = str_replace($invalid, $valid, $result);
}
return $result;
}
?>