/
test.js
63 lines (56 loc) · 1.52 KB
/
test.js
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
"use strict";
var JSHint = require("../../").JSHINT;
var find = require("lodash").find;
/**
* JSHint "error" messages generally indicate a parsing failure and "warning"
* messages generally indicate more objective problems with technically-valid
* programs. This convention is not consistently honored, however, so
* interpreting parsing success/failure from message code requires the
* following list of "contradictory" codes.
*/
var incorrectSeverity = {
E007: true,
// E013 describes a runtime error: the modification of a constant binding.
// Although (unlike the other errors referenced in this object) this
// condition is guaranteed to produce errors, it is not technically an early
// error and should therefore be ignored when interpreting Test262 tests.
E013: true,
E034: true,
W024: true,
W025: true,
W052: true,
W076: true,
W077: true,
W090: true,
W094: true,
W095: true,
W112: true,
W115: true,
W130: true,
W131: true,
W133: true,
W136: true
};
function isFailure(errors) {
return errors && !!find(errors, function(msg) {
if (msg.code[0] === "W") {
return msg.code in incorrectSeverity;
} else if (msg.code[0] === "I") {
return false;
}
return !(msg.code in incorrectSeverity);
});
}
module.exports = function(test) {
var isModule = !!test.attrs.flags.module;
try {
JSHint(test.contents, {
esversion: 11,
maxerr: Infinity,
module: isModule
});
} catch (e) {
return false;
}
return !isFailure(JSHint.data().errors);
};