-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint.js
75 lines (66 loc) · 2.32 KB
/
lint.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
/*globals fs, require, process, JSLINT, console */
/*jslint evil:true, bitwise: true, unparam: true, maxerr: 50, white: true */
/*!
* JSLint wrapper for NodeJS
* Copyright(c) 2011 Crafity
* Copyright(c) 2011 Bart Riemens
* MIT Licensed
*/
/**
* Module dependencies.
*/
var fs = require("fs");
// Read JSLint Source Code
fs.readFile("jslint.js", function (err, data) {
"use strict";
if (err) { throw err; }
// Store JSLint source code and arguments
var jslintText = data.toString()
, inputFileName = process.argv[2]
, options = "\n";
/**
* Specify options like these if you
* want to enforce them on every run
**/
// options = "/*jslint white: true, forin: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true, immed: true, maxerr: 10 */\n";
eval(jslintText);
// Read the input file to validate against JSLint
fs.readFile(inputFileName, function (err, data) {
if (err) { throw err; }
// Store the source code from the file
var inputText = data.toString();
(function () {
if (!JSLINT(options + inputText, { passfail: false }) ||
(JSLINT.data().unused !== undefined && JSLINT.data().unused.length > 0)) {
var i, e;
if (JSLINT.data().errors !== undefined && JSLINT.data().errors.length > 0) {
for (i = 0; i < JSLINT.data().errors.length; i += 1) {
e = JSLINT.data().errors[i];
if (e) {
console.error('Lint at line ' + (e.line - 1) + ' character ' + e.character + ': ' + e.reason);
console.error('\t' + (e.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
}
}
console.error("");
}
if (JSLINT.data().unused !== undefined && JSLINT.data().unused.length > 0) {
for (i = 0; i < JSLINT.data().unused.length; i += 1) {
e = JSLINT.data().unused[i];
console.error("Unused variable '" + e.name + "' at line " + e.line + " and function " + e["function"]);
}
console.error("");
}
// Exit the process with an error code
process.exit(1);
} else {
if (JSLINT.data().globals !== undefined && JSLINT.data().globals !== null && JSLINT.data().globals.length > 0) {
console.error("Used globals: " + JSLINT.data().globals.join(", "));
} else {
console.error("No globals");
}
//Exit the process with no error
process.exit(0);
}
}());
});
});