-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
78 lines (62 loc) · 2.09 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use strict';
var path = require('path');
var gjslint = require('./lib/gjslint-wrapper');
var merge = require('merge');
var through = require('through2');
var gutil = require('gulp-util');
var colors = gutil.colors;
var PluginError = gutil.PluginError;
var PLUGIN_NAME = 'gjslinter';
var gjslinter = function(opts) {
opts = merge({path: 'tools/gjslint.py'}, opts);
function transform(file, enc, cb) {
if (file.isStream()) {
return cb(new PluginError(PLUGIN_NAME, 'Streaming is not supported'));
}
gjslint(merge(opts, {src: [file.path]}), function(err) {
/*
Exit codes:
0: Linting success
1: Python not found
2: Linting failed
3: Parsing failed
4: gjslint exception
*/
if (err && (err.code !== 0 && err.code !== 2)) {
return cb(new PluginError(PLUGIN_NAME, err));
}
file.gjslinter = {
success: !err
};
if (err) {
file.gjslinter.results = err.info;
file.gjslinter.results.errors = file.gjslinter.results.fails[0].errors;
delete file.gjslinter.results.fails;
}
return cb(null, file);
});
return null;
};
return through.obj(transform);
};
gjslinter.reporter = function() {
var indent = ' ';
return through.obj(function (file, enc, cb) {
var result = file.gjslinter;
if (result.success) {
return cb(null, file);
}
var relativeFilePath = path.relative(file.cwd, file.path);
gutil.log('[' + colors.green(PLUGIN_NAME) + '] found ' + colors.yellow(result.results.total + ' errors') + ' in ' + colors.magenta(relativeFilePath));
for (var i = 0, len = result.results.errors.length; i < len; i++) {
var error = result.results.errors[i];
var descriptionLines = error.description.trim().split('\n');
console.log(indent + 'on line %s [%s] %s', error.line, error.code, colors.red(descriptionLines[0]));
if (descriptionLines.length > 1) {
console.log(colors.gray(indent+ descriptionLines.slice(1).join('\n' + indent).trim()));
}
}
return cb(null, file);
});
};
module.exports = gjslinter;