forked from eslint/eslint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jakefile.js
173 lines (141 loc) · 5.64 KB
/
Jakefile.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
* @fileoverview Build file for ESLint. You must have Jake installed to use
* this. You can install Jake via npm i -g jake.
* @author Nicholas C. Zakas
*/
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
var jake = require("jake");
var config = require("./conf/eslint.json");
var eslint = require("./lib/eslint"),
fs = require("fs"),
path = require("path"),
existsSync = fs.existsSync || path.existsSync;
//------------------------------------------------------------------------------
// Constants
//------------------------------------------------------------------------------
var ISTANBUL_CLI = "./node_modules/istanbul/lib/cli.js",
VOWS_CLI = "./node_modules/vows/bin/vows",
JSHINT_CLI = "node_modules/jshint/bin/jshint",
ESLINT_CLI = "./bin/eslint",
ESLINT_CONFIG = "./tests/eslint.json",
COVERAGE_THRESHOLDS = "--statement 90 --branch 90 --function 90",
LINTABLE_FILES = (new jake.FileList().include("package.json").include("./conf/*.json").include("lib")).toArray().join(" ").replace(/\\/g, "/"),
ESLINT_LINTABLE_FILES = (new jake.FileList().include("lib")).toArray().join(" ").replace(/\\/g, "/"),
TEST_FILES = (new jake.FileList().include("tests/*.js").exclude("tests/fixtures/*.js").exclude("tests/performance/*.js").include("tests/*/*.js").include("tests/*/*/*.js")).toArray().join(" ").replace(/\\/g, "/");
//npm run-script lint && node $istanbul cover --print both $vows -- --spec $testfiles && node $istanbul check-coverage $thresholds
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
/**
* Runs JSHint on the given files.
* @param {string} files A space-separated list of filenames to lint.
* @param {Function} callback The function to call when complete.
* @returns {void}
*/
function jshint(files, callback) {
var command = [ "node", JSHINT_CLI, files].join(" ");
jake.exec(command, { printStdout: true, printStderr: true }, function() {
callback();
});
}
//------------------------------------------------------------------------------
// Tasks
//------------------------------------------------------------------------------
task("default", [ "test" ], function() {
});
desc("Lints all JavaScript files with eslint.");
task("eslint", [], function() {
var command = [ "node", ESLINT_CLI, "-c", ESLINT_CONFIG, ESLINT_LINTABLE_FILES].join(" ");
jake.exec(command, { printStdout: true, printStderr: true }, function() {
complete();
});
});
desc("Lints all JSON and JavaScript files.");
task("lint", [], function() {
jshint(LINTABLE_FILES, complete);
});
desc("Runs all of the tests.");
task("test", [ "lint" ], function() {
var command = [
"node",
ISTANBUL_CLI,
"cover --print both",
VOWS_CLI,
"-- --spec",
TEST_FILES
].join(" ");
jake.exec(command, { printStdout: true, printStderr: true }, function() {
jake.Task["check-coverage"].invoke();
complete();
});
});
desc("Checks code coverage information.");
task("check-coverage", [ ], function() {
var command = [
"node",
ISTANBUL_CLI,
"check-coverage",
COVERAGE_THRESHOLDS
].join(" ");
jake.exec(command, { printStdout: true, printStderr: true }, function() {
complete();
});
});
desc("Check performance of eslint.");
task("check-performance", [ ], function() {
var startTime = new Date().getTime();
var command = "node bin/eslint.js tests/performance/jshint.js";
jake.exec(command, { printStdout: false, printStderr: true}, function() {
complete();
var endTime = new Date().getTime();
var runTime = endTime - startTime;
console.log("Linting jshint took " + runTime + "ms");
});
});
desc("Check performance of each eslint rule separatly.");
task("get-perf-table", [ ], function() {
var startTime, endTime, results = [];
var testRun = function(text, rules, name) {
var resultTime = 0;
for (var i = 2; i; i--) {
startTime = new Date().getTime();
eslint.verify(text, { rules: rules });
endTime = new Date().getTime();
resultTime = (resultTime + (endTime - startTime)) / 2;
}
results.push({ name: name, time: resultTime});
console.log("|" + name.toString() + "|" + resultTime + "|");
};
var filePath = "tests/performance/jshint.js";
var text;
if (existsSync(filePath)) {
text = fs.readFileSync(path.resolve(filePath), "utf8");
}
if (text) {
testRun(text, {}, "none");
Object.keys(config.rules).forEach(function(key) {
rules = {};
if (typeof config.rules[key] === "number") {
rules[key] = config.rules[key] || 1;
} else {
var configValue = config.rules[key];
configValue[0] = 1;
rules[key] = configValue;
}
testRun(text, rules, key);
});
console.log(JSON.stringify(results));
} else {
console.log("Failed to load " + path.resolve(filePath) + " file");
}
jake.exec("echo perf tests complete", { printStdout: true, printStderr: true}, complete);
});
desc("Run single test.");
task("test-one", function(file) {
if (file) {
var command = "node tests/lib/rules/" + file;
jake.exec(command, { printStdout: true, printStderr: true}, complete);
}
});