-
-
Notifications
You must be signed in to change notification settings - Fork 374
/
reporter.js
72 lines (68 loc) · 2.21 KB
/
reporter.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
64
65
66
67
68
69
70
71
72
/**
* Copyright (c) 2015, Yanis Wang <yanis.wang@gmail.com>
* MIT Licensed
*/
(function(HTMLHint, undefined){
var Reporter = function(){
var self = this;
self._init.apply(self,arguments);
};
Reporter.prototype = {
_init: function(html, ruleset){
var self = this;
self.html = html;
self.lines = html.split(/\r?\n/);
var match = html.match(/\r?\n/);
self.brLen = match !== null ? match[0].length : 0;
self.ruleset = ruleset;
self.messages = [];
},
// error message
error: function(message, line, col, rule, raw){
this.report('error', message, line, col, rule, raw);
},
// warning message
warn: function(message, line, col, rule, raw){
this.report('warning', message, line, col, rule, raw);
},
// info message
info: function(message, line, col, rule, raw){
this.report('info', message, line, col, rule, raw);
},
// save report
report: function(type, message, line, col, rule, raw){
var self = this;
var lines = self.lines;
var brLen = self.brLen;
var evidence, evidenceLen;
for(var i=line-1, lineCount=lines.length;i<lineCount;i++){
evidence = lines[i];
evidenceLen = evidence.length;
if(col > evidenceLen && line < lineCount){
line ++;
col -= evidenceLen;
if(col !== 1){
col -= brLen;
}
}
else{
break;
}
}
self.messages.push({
type: type,
message: message,
raw: raw,
evidence: evidence,
line: line,
col: col,
rule: {
id: rule.id,
description: rule.description,
link: 'https://github.com/thedaviddias/HTMLHint/wiki/' + rule.id
}
});
}
};
HTMLHint.Reporter = Reporter;
})(HTMLHint);