-
Notifications
You must be signed in to change notification settings - Fork 0
/
jslint_uncommitted.js
executable file
·48 lines (43 loc) · 1.43 KB
/
jslint_uncommitted.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
(function () {
var fileToLint = process.argv[2],
exec = require('child_process').exec,
jsExtRegExp = /\.js\s*$/,
filesToLintCmd = 'git diff --name-only',
gitRootCmd = 'git rev-parse --show-toplevel',
lintSettings = '--indent 2 --maxerr 10 --node --devel --browser --sloppy --nomen --eqeq --vars --plusplus',
lintPredef = '--predef Backbone';
var lintFiles = function (gitRoot, files) {
var jsLintCmd = gitRoot + '/node_modules/.bin/jslint ' + lintSettings + ' ' + lintPredef,
isOkRegExp = / is OK\./, /* Example: "filname.js is OK." */
filename,
cmd;
// If single file, re-create as array
if (typeof files === 'string') {
files = [ files ];
}
files.forEach(function (file) {
if (jsExtRegExp.test(file)) {
cmd = jsLintCmd + ' ' + gitRoot + '/' + file;
exec(cmd, function (error, stdout, stderr) {
if (((stdout.length > 0) && !isOkRegExp.test(stdout)) || (stderr.length > 0)) {
console.log(stdout);
} else {
console.log('JSLint OK');
}
});
}
});
};
var run = function (gitRoot) {
if (fileToLint === undefined) {
exec(filesToLintCmd, function (error, stdout, stderr) {
lintFiles(gitRoot, stdout.split("\n"));
});
} else {
lintFiles(gitRoot, fileToLint);
}
};
exec(gitRootCmd, function (error, stdout, stderr) {
run(stdout.trim());
});
}());