-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (54 loc) · 1.85 KB
/
index.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
var fs = require('fs'),
path = require('path'),
CLIEngine = require('eslint').CLIEngine;
module.exports = function(config) {
if (typeof config !== 'object') {
config = {};
}
if (!Array.isArray(config.extensions)) {
config.extensions = ['.js'];
}
var cli = new CLIEngine({ configFile: './.eslintrc' });
var cwd = process.cwd();
return {
type: 'eslint',
review: function(files, done) {
var log = {
success: true,
errors: []
};
var filter = files.filter(function(filename) {
return config.extensions.indexOf(path.extname(filename)) !== -1;
});
try {
var report = cli.executeOnFiles(filter);
var count = report.errorCount + report.warningCount;
if (count) {
report.results.forEach(function(result) {
result.messages.forEach(function(message) {
log.errors.push({
filename: result.filePath.replace(cwd + '/', ''),
line: message.line,
column: message.column,
rule: message.ruleId,
message: String(message.message).replace("\n", '')
});
});
});
}
} catch (error) {
log.errors.push({
filename: 'ESLint',
line: 0,
column: 0,
rule: '',
message: error.message
});
}
if (log.errors.length) {
log.success = false;
}
done(log);
}
};
};