forked from stephenmathieson-boneyard/node-cpplint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint-error.js
60 lines (46 loc) · 1.12 KB
/
lint-error.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
'use strict';
require('colors');
var extend = require('./extend.js');
// [whitespace/blank_line] [3]
var category = /\[([a-z]+)\/([a-z0-9_+]+)\] \[([1-5])\]/i;
function LintError(line) {
if (!line) {
throw new Error('LintError: missing line');
}
var temp,
parts = line.split(' ');
this.line = line;
// hack to handle reasons like this:
// "Blank line at the end of a code block. Is this needed?"
if (parts.length === 4) {
temp = [];
temp.push(parts[0]);
temp.push([parts[1], parts[2]].join(' '));
temp.push(parts[3]);
parts = temp;
}
temp = parts[0].split(':');
this.file = temp[0];
this.linenumber = temp[1];
this.reason = parts[1];
temp = parts[2].match(category);
this.category = temp[1];
this.sub_category = temp[2];
this.level = temp[3];
}
/**
* @return {String} this.line
*/
LintError.prototype.toString = function () {
return this.line;
};
/**
* Creates a plain Object based on properties of the LintError
*
* @return {Object}
*/
LintError.prototype.toObject = function () {
var obj = extend({}, this);
return obj;
};
module.exports = LintError;