eslint 0.22.0 → 0.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -20
- package/README.md +111 -95
- package/bin/eslint.js +41 -41
- package/conf/environments.js +87 -81
- package/conf/eslint.json +186 -179
- package/lib/api.js +13 -12
- package/lib/cli-engine.js +441 -451
- package/lib/cli.js +196 -196
- package/lib/config-initializer.js +145 -145
- package/lib/config-validator.js +110 -110
- package/lib/config.js +428 -416
- package/lib/eslint.js +1072 -1073
- package/lib/file-finder.js +167 -167
- package/lib/formatters/checkstyle.js +68 -68
- package/lib/formatters/compact.js +53 -53
- package/lib/formatters/jslint-xml.js +40 -40
- package/lib/formatters/junit.js +63 -63
- package/lib/formatters/stylish.js +90 -90
- package/lib/formatters/tap.js +86 -86
- package/lib/ignored-paths.js +137 -137
- package/lib/load-rules.js +39 -39
- package/lib/options.js +132 -126
- package/lib/rule-context.js +107 -107
- package/lib/rules/accessor-pairs.js +65 -65
- package/lib/rules/array-bracket-spacing.js +180 -0
- package/lib/rules/block-scoped-var.js +339 -320
- package/lib/rules/brace-style.js +228 -228
- package/lib/rules/camelcase.js +111 -111
- package/lib/rules/comma-dangle.js +67 -64
- package/lib/rules/comma-spacing.js +191 -191
- package/lib/rules/comma-style.js +195 -195
- package/lib/rules/complexity.js +94 -94
- package/lib/rules/computed-property-spacing.js +144 -0
- package/lib/rules/consistent-return.js +75 -75
- package/lib/rules/consistent-this.js +119 -119
- package/lib/rules/constructor-super.js +108 -0
- package/lib/rules/curly.js +109 -109
- package/lib/rules/default-case.js +66 -66
- package/lib/rules/dot-location.js +63 -63
- package/lib/rules/dot-notation.js +119 -119
- package/lib/rules/eol-last.js +38 -38
- package/lib/rules/eqeqeq.js +96 -96
- package/lib/rules/func-names.js +45 -45
- package/lib/rules/func-style.js +49 -49
- package/lib/rules/generator-star-spacing.js +104 -87
- package/lib/rules/generator-star.js +76 -76
- package/lib/rules/global-strict.js +49 -49
- package/lib/rules/guard-for-in.js +32 -32
- package/lib/rules/handle-callback-err.js +81 -124
- package/lib/rules/indent.js +486 -486
- package/lib/rules/key-spacing.js +325 -325
- package/lib/rules/linebreak-style.js +44 -44
- package/lib/rules/lines-around-comment.js +228 -160
- package/lib/rules/max-depth.js +89 -89
- package/lib/rules/max-len.js +76 -76
- package/lib/rules/max-nested-callbacks.js +73 -73
- package/lib/rules/max-params.js +45 -45
- package/lib/rules/max-statements.js +61 -61
- package/lib/rules/new-cap.js +224 -224
- package/lib/rules/new-parens.js +29 -29
- package/lib/rules/newline-after-var.js +127 -127
- package/lib/rules/no-alert.js +153 -153
- package/lib/rules/no-array-constructor.js +31 -31
- package/lib/rules/no-bitwise.js +57 -57
- package/lib/rules/no-caller.js +29 -29
- package/lib/rules/no-catch-shadow.js +52 -52
- package/lib/rules/no-comma-dangle.js +45 -45
- package/lib/rules/no-cond-assign.js +123 -123
- package/lib/rules/no-console.js +27 -27
- package/lib/rules/no-constant-condition.js +73 -73
- package/lib/rules/no-continue.js +23 -23
- package/lib/rules/no-control-regex.js +58 -58
- package/lib/rules/no-debugger.js +22 -22
- package/lib/rules/no-delete-var.js +25 -25
- package/lib/rules/no-div-regex.js +27 -27
- package/lib/rules/no-dupe-args.js +89 -85
- package/lib/rules/no-dupe-keys.js +43 -43
- package/lib/rules/no-duplicate-case.js +67 -67
- package/lib/rules/no-else-return.js +125 -125
- package/lib/rules/no-empty-character-class.js +43 -43
- package/lib/rules/no-empty-class.js +45 -45
- package/lib/rules/no-empty-label.js +27 -27
- package/lib/rules/no-empty.js +49 -49
- package/lib/rules/no-eq-null.js +29 -29
- package/lib/rules/no-eval.js +26 -26
- package/lib/rules/no-ex-assign.js +42 -42
- package/lib/rules/no-extend-native.js +103 -103
- package/lib/rules/no-extra-bind.js +81 -81
- package/lib/rules/no-extra-boolean-cast.js +71 -71
- package/lib/rules/no-extra-parens.js +368 -355
- package/lib/rules/no-extra-semi.js +70 -23
- package/lib/rules/no-extra-strict.js +86 -86
- package/lib/rules/no-fallthrough.js +97 -97
- package/lib/rules/no-floating-decimal.js +30 -30
- package/lib/rules/no-func-assign.js +83 -83
- package/lib/rules/no-implied-eval.js +76 -76
- package/lib/rules/no-inline-comments.js +49 -49
- package/lib/rules/no-inner-declarations.js +78 -78
- package/lib/rules/no-invalid-regexp.js +53 -53
- package/lib/rules/no-irregular-whitespace.js +135 -135
- package/lib/rules/no-iterator.js +28 -28
- package/lib/rules/no-label-var.js +64 -64
- package/lib/rules/no-labels.js +44 -44
- package/lib/rules/no-lone-blocks.js +106 -27
- package/lib/rules/no-lonely-if.js +30 -30
- package/lib/rules/no-loop-func.js +58 -58
- package/lib/rules/no-mixed-requires.js +165 -165
- package/lib/rules/no-mixed-spaces-and-tabs.js +74 -74
- package/lib/rules/no-multi-spaces.js +119 -119
- package/lib/rules/no-multi-str.js +43 -43
- package/lib/rules/no-multiple-empty-lines.js +98 -98
- package/lib/rules/no-native-reassign.js +62 -62
- package/lib/rules/no-negated-in-lhs.js +25 -25
- package/lib/rules/no-nested-ternary.js +24 -24
- package/lib/rules/no-new-func.js +25 -25
- package/lib/rules/no-new-object.js +25 -25
- package/lib/rules/no-new-require.js +25 -25
- package/lib/rules/no-new-wrappers.js +26 -26
- package/lib/rules/no-new.js +27 -27
- package/lib/rules/no-obj-calls.js +28 -28
- package/lib/rules/no-octal-escape.js +39 -39
- package/lib/rules/no-octal.js +25 -25
- package/lib/rules/no-param-reassign.js +87 -87
- package/lib/rules/no-path-concat.js +39 -39
- package/lib/rules/no-plusplus.js +24 -24
- package/lib/rules/no-process-env.js +30 -30
- package/lib/rules/no-process-exit.js +33 -33
- package/lib/rules/no-proto.js +28 -28
- package/lib/rules/no-redeclare.js +68 -68
- package/lib/rules/no-regex-spaces.js +35 -35
- package/lib/rules/no-reserved-keys.js +56 -56
- package/lib/rules/no-restricted-modules.js +85 -85
- package/lib/rules/no-return-assign.js +53 -24
- package/lib/rules/no-script-url.js +34 -34
- package/lib/rules/no-self-compare.js +29 -29
- package/lib/rules/no-sequences.js +94 -94
- package/lib/rules/no-shadow-restricted-names.js +51 -51
- package/lib/rules/no-shadow.js +181 -136
- package/lib/rules/no-space-before-semi.js +98 -98
- package/lib/rules/no-spaced-func.js +37 -37
- package/lib/rules/no-sparse-arrays.js +33 -33
- package/lib/rules/no-sync.js +30 -30
- package/lib/rules/no-ternary.js +24 -24
- package/lib/rules/no-this-before-super.js +144 -0
- package/lib/rules/no-throw-literal.js +33 -33
- package/lib/rules/no-trailing-spaces.js +74 -63
- package/lib/rules/no-undef-init.js +28 -28
- package/lib/rules/no-undef.js +92 -92
- package/lib/rules/no-undefined.js +27 -27
- package/lib/rules/no-underscore-dangle.js +73 -73
- package/lib/rules/no-unexpected-multiline.js +58 -0
- package/lib/rules/no-unneeded-ternary.js +48 -48
- package/lib/rules/no-unreachable.js +98 -98
- package/lib/rules/no-unused-expressions.js +76 -76
- package/lib/rules/no-unused-vars.js +252 -250
- package/lib/rules/no-use-before-define.js +105 -105
- package/lib/rules/no-var.js +26 -26
- package/lib/rules/no-void.js +28 -28
- package/lib/rules/no-warning-comments.js +102 -102
- package/lib/rules/no-with.js +22 -22
- package/lib/rules/no-wrap-func.js +65 -65
- package/lib/rules/object-curly-spacing.js +231 -206
- package/lib/rules/object-shorthand.js +74 -73
- package/lib/rules/one-var.js +311 -304
- package/lib/rules/operator-assignment.js +118 -118
- package/lib/rules/operator-linebreak.js +114 -114
- package/lib/rules/padded-blocks.js +98 -98
- package/lib/rules/prefer-const.js +91 -0
- package/lib/rules/quote-props.js +72 -72
- package/lib/rules/quotes.js +92 -92
- package/lib/rules/radix.js +41 -41
- package/lib/rules/semi-spacing.js +167 -167
- package/lib/rules/semi.js +136 -136
- package/lib/rules/sort-vars.js +49 -49
- package/lib/rules/space-after-function-name.js +49 -49
- package/lib/rules/space-after-keywords.js +82 -82
- package/lib/rules/space-before-blocks.js +91 -91
- package/lib/rules/space-before-function-paren.js +139 -139
- package/lib/rules/space-before-function-parentheses.js +139 -139
- package/lib/rules/space-in-brackets.js +305 -305
- package/lib/rules/space-in-parens.js +281 -281
- package/lib/rules/space-infix-ops.js +106 -106
- package/lib/rules/space-return-throw-case.js +38 -38
- package/lib/rules/space-unary-ops.js +124 -133
- package/lib/rules/spaced-comment.js +143 -0
- package/lib/rules/spaced-line-comment.js +89 -89
- package/lib/rules/strict.js +242 -242
- package/lib/rules/use-isnan.js +26 -26
- package/lib/rules/valid-jsdoc.js +215 -215
- package/lib/rules/valid-typeof.js +42 -42
- package/lib/rules/vars-on-top.js +115 -115
- package/lib/rules/wrap-iife.js +48 -48
- package/lib/rules/wrap-regex.js +38 -38
- package/lib/rules/yoda.js +242 -225
- package/lib/rules.js +88 -88
- package/lib/timing.js +109 -109
- package/lib/token-store.js +201 -201
- package/lib/util/traverse.js +105 -105
- package/lib/util.js +125 -85
- package/package.json +6 -6
- package/CHANGELOG.md +0 -1638
package/lib/cli-engine.js
CHANGED
@@ -1,451 +1,441 @@
|
|
1
|
-
/**
|
2
|
-
* @fileoverview Main CLI object.
|
3
|
-
* @author Nicholas C. Zakas
|
4
|
-
* @copyright 2014 Nicholas C. Zakas. All rights reserved.
|
5
|
-
*/
|
6
|
-
|
7
|
-
"use strict";
|
8
|
-
|
9
|
-
/*
|
10
|
-
* The CLI object should *not* call process.exit() directly. It should only return
|
11
|
-
* exit codes. This allows other programs to use the CLI object and still control
|
12
|
-
* when the program exits.
|
13
|
-
*/
|
14
|
-
|
15
|
-
//------------------------------------------------------------------------------
|
16
|
-
// Requirements
|
17
|
-
//------------------------------------------------------------------------------
|
18
|
-
|
19
|
-
var fs = require("fs"),
|
20
|
-
path = require("path"),
|
21
|
-
|
22
|
-
assign = require("object-assign"),
|
23
|
-
debug = require("debug"),
|
24
|
-
|
25
|
-
rules = require("./rules"),
|
26
|
-
eslint = require("./eslint"),
|
27
|
-
traverse = require("./util/traverse"),
|
28
|
-
IgnoredPaths = require("./ignored-paths"),
|
29
|
-
Config = require("./config"),
|
30
|
-
util = require("./util")
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
*
|
39
|
-
* @
|
40
|
-
* @property {
|
41
|
-
* @property {boolean
|
42
|
-
* @property {boolean}
|
43
|
-
* @property {
|
44
|
-
* @property {
|
45
|
-
* @property {
|
46
|
-
* @property {string[]}
|
47
|
-
* @property {string[]}
|
48
|
-
* @property {
|
49
|
-
* @property {string}
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
*
|
55
|
-
* @
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
*
|
61
|
-
* @
|
62
|
-
* @property {
|
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
|
-
if
|
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
|
-
stat.
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
}
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
*
|
159
|
-
* @param {string}
|
160
|
-
* @param {Object} configHelper The configuration options for ESLint.
|
161
|
-
* @
|
162
|
-
* @
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
messages,
|
173
|
-
stats,
|
174
|
-
fileExtension = path.extname(filename),
|
175
|
-
processor;
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
*
|
216
|
-
*
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
}
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
}
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
*
|
387
|
-
* @param {string} filePath The path of the file to
|
388
|
-
* @returns {
|
389
|
-
*/
|
390
|
-
|
391
|
-
var
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
}
|
443
|
-
|
444
|
-
} else {
|
445
|
-
return null;
|
446
|
-
}
|
447
|
-
}
|
448
|
-
|
449
|
-
};
|
450
|
-
|
451
|
-
module.exports = CLIEngine;
|
1
|
+
/**
|
2
|
+
* @fileoverview Main CLI object.
|
3
|
+
* @author Nicholas C. Zakas
|
4
|
+
* @copyright 2014 Nicholas C. Zakas. All rights reserved.
|
5
|
+
*/
|
6
|
+
|
7
|
+
"use strict";
|
8
|
+
|
9
|
+
/*
|
10
|
+
* The CLI object should *not* call process.exit() directly. It should only return
|
11
|
+
* exit codes. This allows other programs to use the CLI object and still control
|
12
|
+
* when the program exits.
|
13
|
+
*/
|
14
|
+
|
15
|
+
//------------------------------------------------------------------------------
|
16
|
+
// Requirements
|
17
|
+
//------------------------------------------------------------------------------
|
18
|
+
|
19
|
+
var fs = require("fs"),
|
20
|
+
path = require("path"),
|
21
|
+
|
22
|
+
assign = require("object-assign"),
|
23
|
+
debug = require("debug"),
|
24
|
+
|
25
|
+
rules = require("./rules"),
|
26
|
+
eslint = require("./eslint"),
|
27
|
+
traverse = require("./util/traverse"),
|
28
|
+
IgnoredPaths = require("./ignored-paths"),
|
29
|
+
Config = require("./config"),
|
30
|
+
util = require("./util"),
|
31
|
+
validator = require("./config-validator");
|
32
|
+
|
33
|
+
//------------------------------------------------------------------------------
|
34
|
+
// Typedefs
|
35
|
+
//------------------------------------------------------------------------------
|
36
|
+
|
37
|
+
/**
|
38
|
+
* The options to configure a CLI engine with.
|
39
|
+
* @typedef {Object} CLIEngineOptions
|
40
|
+
* @property {string} configFile The configuration file to use.
|
41
|
+
* @property {boolean} reset True disables all default rules and environments.
|
42
|
+
* @property {boolean|object} baseConfig Base config object. False disables all default rules and environments.
|
43
|
+
* @property {boolean} ignore False disables use of .eslintignore.
|
44
|
+
* @property {string[]} rulePaths An array of directories to load custom rules from.
|
45
|
+
* @property {boolean} useEslintrc False disables looking for .eslintrc
|
46
|
+
* @property {string[]} envs An array of environments to load.
|
47
|
+
* @property {string[]} globals An array of global variables to declare.
|
48
|
+
* @property {string[]} extensions An array of file extensions to check.
|
49
|
+
* @property {Object<string,*>} rules An object of rules to use.
|
50
|
+
* @property {string} ignorePath The ignore file to use instead of .eslintignore.
|
51
|
+
*/
|
52
|
+
|
53
|
+
/**
|
54
|
+
* A linting warning or error.
|
55
|
+
* @typedef {Object} LintMessage
|
56
|
+
* @property {string} message The message to display to the user.
|
57
|
+
*/
|
58
|
+
|
59
|
+
/**
|
60
|
+
* A linting result.
|
61
|
+
* @typedef {Object} LintResult
|
62
|
+
* @property {string} filePath The path to the file that was linted.
|
63
|
+
* @property {LintMessage[]} messages All of the messages for the result.
|
64
|
+
*/
|
65
|
+
|
66
|
+
//------------------------------------------------------------------------------
|
67
|
+
// Private
|
68
|
+
//------------------------------------------------------------------------------
|
69
|
+
|
70
|
+
|
71
|
+
var defaultOptions = {
|
72
|
+
configFile: null,
|
73
|
+
reset: false,
|
74
|
+
baseConfig: require(path.resolve(__dirname, "..", "conf", "eslint.json")),
|
75
|
+
rulePaths: [],
|
76
|
+
useEslintrc: true,
|
77
|
+
envs: [],
|
78
|
+
globals: [],
|
79
|
+
rules: {},
|
80
|
+
extensions: [".js"],
|
81
|
+
ignore: true,
|
82
|
+
ignorePath: null
|
83
|
+
},
|
84
|
+
loadedPlugins = Object.create(null);
|
85
|
+
|
86
|
+
//------------------------------------------------------------------------------
|
87
|
+
// Helpers
|
88
|
+
//------------------------------------------------------------------------------
|
89
|
+
|
90
|
+
debug = debug("eslint:cli-engine");
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Load the given plugins if they are not loaded already.
|
94
|
+
* @param {string[]} pluginNames An array of plugin names which should be loaded.
|
95
|
+
* @returns {void}
|
96
|
+
*/
|
97
|
+
function loadPlugins(pluginNames) {
|
98
|
+
if (pluginNames) {
|
99
|
+
pluginNames.forEach(function (pluginName) {
|
100
|
+
var pluginNamespace = util.getNamespace(pluginName),
|
101
|
+
pluginNameWithoutNamespace = util.removeNameSpace(pluginName),
|
102
|
+
pluginNameWithoutPrefix = util.removePluginPrefix(pluginNameWithoutNamespace),
|
103
|
+
plugin;
|
104
|
+
|
105
|
+
if (!loadedPlugins[pluginNameWithoutPrefix]) {
|
106
|
+
debug("Load plugin " + pluginNameWithoutPrefix);
|
107
|
+
|
108
|
+
plugin = require(pluginNamespace + util.PLUGIN_NAME_PREFIX + pluginNameWithoutPrefix);
|
109
|
+
// if this plugin has rules, import them
|
110
|
+
if (plugin.rules) {
|
111
|
+
rules.import(plugin.rules, pluginNameWithoutPrefix);
|
112
|
+
}
|
113
|
+
|
114
|
+
loadedPlugins[pluginNameWithoutPrefix] = plugin;
|
115
|
+
}
|
116
|
+
});
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
/**
|
121
|
+
* It will calculate the error and warning count for collection of messages per file
|
122
|
+
* @param {Object[]} messages - Collection of messages
|
123
|
+
* @returns {Object} Contains the stats
|
124
|
+
* @private
|
125
|
+
*/
|
126
|
+
function calculateStatsPerFile(messages) {
|
127
|
+
return messages.reduce(function(stat, message) {
|
128
|
+
if (message.fatal || message.severity === 2) {
|
129
|
+
stat.errorCount++;
|
130
|
+
} else {
|
131
|
+
stat.warningCount++;
|
132
|
+
}
|
133
|
+
return stat;
|
134
|
+
}, {
|
135
|
+
errorCount: 0,
|
136
|
+
warningCount: 0
|
137
|
+
});
|
138
|
+
}
|
139
|
+
|
140
|
+
/**
|
141
|
+
* It will calculate the error and warning count for collection of results from all files
|
142
|
+
* @param {Object[]} results - Collection of messages from all the files
|
143
|
+
* @returns {Object} Contains the stats
|
144
|
+
* @private
|
145
|
+
*/
|
146
|
+
function calculateStatsPerRun(results) {
|
147
|
+
return results.reduce(function(stat, result) {
|
148
|
+
stat.errorCount += result.errorCount;
|
149
|
+
stat.warningCount += result.warningCount;
|
150
|
+
return stat;
|
151
|
+
}, {
|
152
|
+
errorCount: 0,
|
153
|
+
warningCount: 0
|
154
|
+
});
|
155
|
+
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* Processes an source code using ESLint.
|
159
|
+
* @param {string} text The source code to check.
|
160
|
+
* @param {Object} configHelper The configuration options for ESLint.
|
161
|
+
* @param {string} filename An optional string representing the texts filename.
|
162
|
+
* @returns {Result} The results for linting on this text.
|
163
|
+
* @private
|
164
|
+
*/
|
165
|
+
function processText(text, configHelper, filename) {
|
166
|
+
|
167
|
+
// clear all existing settings for a new file
|
168
|
+
eslint.reset();
|
169
|
+
|
170
|
+
var filePath,
|
171
|
+
config,
|
172
|
+
messages,
|
173
|
+
stats,
|
174
|
+
fileExtension = path.extname(filename),
|
175
|
+
processor;
|
176
|
+
|
177
|
+
if (filename) {
|
178
|
+
filePath = path.resolve(filename);
|
179
|
+
}
|
180
|
+
|
181
|
+
filename = filename || "<text>";
|
182
|
+
debug("Linting " + filename);
|
183
|
+
config = configHelper.getConfig(filePath);
|
184
|
+
loadPlugins(config.plugins);
|
185
|
+
|
186
|
+
for (var plugin in loadedPlugins) {
|
187
|
+
if (loadedPlugins[plugin].processors && Object.keys(loadedPlugins[plugin].processors).indexOf(fileExtension) >= 0) {
|
188
|
+
processor = loadedPlugins[plugin].processors[fileExtension];
|
189
|
+
break;
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
if (processor) {
|
194
|
+
var parsedBlocks = processor.preprocess(text, filename);
|
195
|
+
var unprocessedMessages = [];
|
196
|
+
parsedBlocks.forEach(function(block) {
|
197
|
+
unprocessedMessages.push(eslint.verify(block, config, filename));
|
198
|
+
});
|
199
|
+
messages = processor.postprocess(unprocessedMessages, filename);
|
200
|
+
} else {
|
201
|
+
messages = eslint.verify(text, config, filename);
|
202
|
+
}
|
203
|
+
|
204
|
+
stats = calculateStatsPerFile(messages);
|
205
|
+
|
206
|
+
return {
|
207
|
+
filePath: filename,
|
208
|
+
messages: messages,
|
209
|
+
errorCount: stats.errorCount,
|
210
|
+
warningCount: stats.warningCount
|
211
|
+
};
|
212
|
+
}
|
213
|
+
|
214
|
+
/**
|
215
|
+
* Processes an individual file using ESLint. Files used here are known to
|
216
|
+
* exist, so no need to check that here.
|
217
|
+
* @param {string} filename The filename of the file being checked.
|
218
|
+
* @param {Object} configHelper The configuration options for ESLint.
|
219
|
+
* @returns {Result} The results for linting on this file.
|
220
|
+
* @private
|
221
|
+
*/
|
222
|
+
function processFile(filename, configHelper) {
|
223
|
+
|
224
|
+
var text = fs.readFileSync(path.resolve(filename), "utf8");
|
225
|
+
|
226
|
+
return processText(text, configHelper, filename);
|
227
|
+
}
|
228
|
+
|
229
|
+
/**
|
230
|
+
* Returns result with warning by ignore settings
|
231
|
+
* @param {string} filePath File path of checked code
|
232
|
+
* @returns {Result} Result with single warning
|
233
|
+
* @private
|
234
|
+
*/
|
235
|
+
function createIgnoreResult(filePath) {
|
236
|
+
return {
|
237
|
+
filePath: filePath,
|
238
|
+
messages: [
|
239
|
+
{
|
240
|
+
fatal: false,
|
241
|
+
severity: 1,
|
242
|
+
message: "File ignored because of your .eslintignore file. Use --no-ignore to override."
|
243
|
+
}
|
244
|
+
],
|
245
|
+
errorCount: 0,
|
246
|
+
warningCount: 1
|
247
|
+
};
|
248
|
+
}
|
249
|
+
|
250
|
+
//------------------------------------------------------------------------------
|
251
|
+
// Public Interface
|
252
|
+
//------------------------------------------------------------------------------
|
253
|
+
|
254
|
+
/**
|
255
|
+
* Creates a new instance of the core CLI engine.
|
256
|
+
* @param {CLIEngineOptions} options The options for this instance.
|
257
|
+
* @constructor
|
258
|
+
*/
|
259
|
+
function CLIEngine(options) {
|
260
|
+
|
261
|
+
/**
|
262
|
+
* Stored options for this instance
|
263
|
+
* @type {Object}
|
264
|
+
*/
|
265
|
+
this.options = assign(Object.create(defaultOptions), options || {});
|
266
|
+
|
267
|
+
// load in additional rules
|
268
|
+
if (this.options.rulePaths) {
|
269
|
+
this.options.rulePaths.forEach(function(rulesdir) {
|
270
|
+
debug("Loading rules from " + rulesdir);
|
271
|
+
rules.load(rulesdir);
|
272
|
+
});
|
273
|
+
}
|
274
|
+
|
275
|
+
Object.keys(this.options.rules || {}).forEach(function(name) {
|
276
|
+
validator.validateRuleOptions(name, this.options.rules[name], "CLI");
|
277
|
+
}.bind(this));
|
278
|
+
}
|
279
|
+
|
280
|
+
CLIEngine.prototype = {
|
281
|
+
|
282
|
+
constructor: CLIEngine,
|
283
|
+
|
284
|
+
/**
|
285
|
+
* Add a plugin by passing it's configuration
|
286
|
+
* @param {string} name Name of the plugin.
|
287
|
+
* @param {Object} pluginobject Plugin configuration object.
|
288
|
+
* @returns {void}
|
289
|
+
*/
|
290
|
+
addPlugin: function(name, pluginobject) {
|
291
|
+
var pluginNameWithoutPrefix = util.removePluginPrefix(util.removeNameSpace(name));
|
292
|
+
if (pluginobject.rules) {
|
293
|
+
rules.import(pluginobject.rules, pluginNameWithoutPrefix);
|
294
|
+
}
|
295
|
+
loadedPlugins[pluginNameWithoutPrefix] = pluginobject;
|
296
|
+
},
|
297
|
+
|
298
|
+
/**
|
299
|
+
* Executes the current configuration on an array of file and directory names.
|
300
|
+
* @param {string[]} files An array of file and directory names.
|
301
|
+
* @returns {Object} The results for all files that were linted.
|
302
|
+
*/
|
303
|
+
executeOnFiles: function(files) {
|
304
|
+
|
305
|
+
var results = [],
|
306
|
+
processed = [],
|
307
|
+
options = this.options,
|
308
|
+
configHelper = new Config(options),
|
309
|
+
ignoredPaths = IgnoredPaths.load(options),
|
310
|
+
exclude = ignoredPaths.contains.bind(ignoredPaths),
|
311
|
+
stats;
|
312
|
+
|
313
|
+
traverse({
|
314
|
+
files: files,
|
315
|
+
extensions: options.extensions,
|
316
|
+
exclude: options.ignore ? exclude : false
|
317
|
+
}, function(filename) {
|
318
|
+
|
319
|
+
debug("Processing " + filename);
|
320
|
+
|
321
|
+
processed.push(filename);
|
322
|
+
results.push(processFile(filename, configHelper));
|
323
|
+
});
|
324
|
+
|
325
|
+
// only warn for files explicitly passed on the command line
|
326
|
+
if (options.ignore) {
|
327
|
+
files.forEach(function(file) {
|
328
|
+
if (fs.statSync(path.resolve(file)).isFile() && processed.indexOf(file) === -1) {
|
329
|
+
results.push(createIgnoreResult(file));
|
330
|
+
}
|
331
|
+
});
|
332
|
+
}
|
333
|
+
|
334
|
+
stats = calculateStatsPerRun(results);
|
335
|
+
|
336
|
+
return {
|
337
|
+
results: results,
|
338
|
+
errorCount: stats.errorCount,
|
339
|
+
warningCount: stats.warningCount
|
340
|
+
};
|
341
|
+
},
|
342
|
+
|
343
|
+
/**
|
344
|
+
* Executes the current configuration on text.
|
345
|
+
* @param {string} text A string of JavaScript code to lint.
|
346
|
+
* @param {string} filename An optional string representing the texts filename.
|
347
|
+
* @returns {Object} The results for the linting.
|
348
|
+
*/
|
349
|
+
executeOnText: function(text, filename) {
|
350
|
+
|
351
|
+
var results = [],
|
352
|
+
stats,
|
353
|
+
options = this.options,
|
354
|
+
configHelper = new Config(options),
|
355
|
+
ignoredPaths = IgnoredPaths.load(options),
|
356
|
+
exclude = ignoredPaths.contains.bind(ignoredPaths);
|
357
|
+
|
358
|
+
if (filename && options.ignore && exclude(filename)) {
|
359
|
+
results.push(createIgnoreResult(filename));
|
360
|
+
} else {
|
361
|
+
results.push(processText(text, configHelper, filename));
|
362
|
+
}
|
363
|
+
|
364
|
+
stats = calculateStatsPerRun(results);
|
365
|
+
|
366
|
+
return {
|
367
|
+
results: results,
|
368
|
+
errorCount: stats.errorCount,
|
369
|
+
warningCount: stats.warningCount
|
370
|
+
};
|
371
|
+
},
|
372
|
+
|
373
|
+
/**
|
374
|
+
* Returns a configuration object for the given file based on the CLI options.
|
375
|
+
* This is the same logic used by the ESLint CLI executable to determine
|
376
|
+
* configuration for each file it processes.
|
377
|
+
* @param {string} filePath The path of the file to retrieve a config object for.
|
378
|
+
* @returns {Object} A configuration object for the file.
|
379
|
+
*/
|
380
|
+
getConfigForFile: function(filePath) {
|
381
|
+
var configHelper = new Config(this.options);
|
382
|
+
return configHelper.getConfig(filePath);
|
383
|
+
},
|
384
|
+
|
385
|
+
/**
|
386
|
+
* Checks if a given path is ignored by ESLint.
|
387
|
+
* @param {string} filePath The path of the file to check.
|
388
|
+
* @returns {boolean} Whether or not the given path is ignored.
|
389
|
+
*/
|
390
|
+
isPathIgnored: function (filePath) {
|
391
|
+
var ignoredPaths;
|
392
|
+
|
393
|
+
if (this.options.ignore) {
|
394
|
+
ignoredPaths = IgnoredPaths.load(this.options);
|
395
|
+
return ignoredPaths.contains(filePath);
|
396
|
+
}
|
397
|
+
|
398
|
+
return false;
|
399
|
+
},
|
400
|
+
|
401
|
+
/**
|
402
|
+
* Returns the formatter representing the given format or null if no formatter
|
403
|
+
* with the given name can be found.
|
404
|
+
* @param {string} [format] The name of the format to load or the path to a
|
405
|
+
* custom formatter.
|
406
|
+
* @returns {Function} The formatter function or null if not found.
|
407
|
+
*/
|
408
|
+
getFormatter: function(format) {
|
409
|
+
|
410
|
+
var formatterPath;
|
411
|
+
|
412
|
+
// default is stylish
|
413
|
+
format = format || "stylish";
|
414
|
+
|
415
|
+
// only strings are valid formatters
|
416
|
+
if (typeof format === "string") {
|
417
|
+
|
418
|
+
// replace \ with / for Windows compatibility
|
419
|
+
format = format.replace(/\\/g, "/");
|
420
|
+
|
421
|
+
// if there's a slash, then it's a file
|
422
|
+
if (format.indexOf("/") > -1) {
|
423
|
+
formatterPath = path.resolve(process.cwd(), format);
|
424
|
+
} else {
|
425
|
+
formatterPath = "./formatters/" + format;
|
426
|
+
}
|
427
|
+
|
428
|
+
try {
|
429
|
+
return require(formatterPath);
|
430
|
+
} catch (ex) {
|
431
|
+
return null;
|
432
|
+
}
|
433
|
+
|
434
|
+
} else {
|
435
|
+
return null;
|
436
|
+
}
|
437
|
+
}
|
438
|
+
|
439
|
+
};
|
440
|
+
|
441
|
+
module.exports = CLIEngine;
|