/
jshint.js
49 lines (43 loc) · 1.64 KB
/
jshint.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
/**
* Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com>
* MIT Licensed
*/
HTMLHint.addRule({
id: 'jshint',
description: 'Scan script with jshint.',
init: function(parser, reporter, options){
var self = this;
parser.addListener('cdata', function(event){
if(event.tagName.toLowerCase() === 'script'){
var mapAttrs = parser.getMapAttrs(event.attrs),
type = mapAttrs.type;
// Only scan internal javascript
if(mapAttrs.src !== undefined || (type && /^(text\/javascript)$/i.test(type) === false)){
return;
}
var jsVerify;
if(typeof exports === 'object' && require){
jsVerify = require('jshint').JSHINT;
}
else{
jsVerify = JSHINT;
}
if(options !== undefined){
var styleLine = event.line - 1,
styleCol = event.col - 1;
var code = event.raw.replace(/\t/g,' ');
try{
var status = jsVerify(code, options);
if(status === false){
jsVerify.errors.forEach(function(error){
var line = error.line;
reporter.warn(error.reason, styleLine + line, (line === 1 ? styleCol : 0) + error.character, self, error.evidence);
});
}
}
catch(e){}
}
}
});
}
});