eslint 1.9.0 → 1.10.3
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/README.md +1 -1
- package/bin/eslint.js +1 -2
- package/lib/ast-utils.js +22 -1
- package/lib/cli-engine.js +15 -7
- package/lib/cli.js +2 -1
- package/lib/config/config-file.js +440 -0
- package/lib/config/config-initializer.js +241 -0
- package/lib/config/config-ops.js +186 -0
- package/lib/{config-validator.js → config/config-validator.js} +10 -2
- package/lib/config.js +39 -183
- package/lib/eslint.js +49 -41
- package/lib/file-finder.js +34 -15
- package/lib/ignored-paths.js +1 -1
- package/lib/options.js +7 -1
- package/lib/rules/block-spacing.js +7 -2
- package/lib/rules/brace-style.js +3 -1
- package/lib/rules/comma-spacing.js +25 -66
- package/lib/rules/consistent-this.js +25 -29
- package/lib/rules/curly.js +37 -7
- package/lib/rules/eqeqeq.js +17 -2
- package/lib/rules/id-length.js +2 -2
- package/lib/rules/indent.js +7 -10
- package/lib/rules/lines-around-comment.js +32 -12
- package/lib/rules/new-cap.js +11 -1
- package/lib/rules/no-alert.js +2 -3
- package/lib/rules/no-catch-shadow.js +7 -13
- package/lib/rules/no-extend-native.js +1 -2
- package/lib/rules/no-fallthrough.js +1 -2
- package/lib/rules/no-implicit-coercion.js +19 -0
- package/lib/rules/no-label-var.js +9 -23
- package/lib/rules/no-multiple-empty-lines.js +1 -1
- package/lib/rules/no-sequences.js +2 -1
- package/lib/rules/no-shadow.js +31 -58
- package/lib/rules/no-spaced-func.js +16 -12
- package/lib/rules/no-undef-init.js +5 -3
- package/lib/rules/no-undef.js +10 -13
- package/lib/rules/no-use-before-define.js +7 -21
- package/lib/rules/operator-linebreak.js +3 -2
- package/lib/rules/quotes.js +34 -15
- package/lib/rules/require-jsdoc.js +61 -2
- package/lib/rules/space-after-keywords.js +2 -0
- package/lib/rules/space-before-function-paren.js +5 -26
- package/lib/rules/space-before-keywords.js +5 -2
- package/lib/rules/spaced-comment.js +1 -3
- package/lib/rules/valid-jsdoc.js +8 -4
- package/lib/rules/vars-on-top.js +2 -2
- package/lib/testers/rule-tester.js +48 -7
- package/lib/util/source-code.js +4 -0
- package/lib/util.js +0 -92
- package/package.json +4 -6
- package/lib/config-initializer.js +0 -146
package/lib/rules/vars-on-top.js
CHANGED
@@ -100,8 +100,8 @@ module.exports = function(context) {
|
|
100
100
|
var parent = ancestors.pop();
|
101
101
|
var grandParent = ancestors.pop();
|
102
102
|
|
103
|
-
if (node.kind === "var") {// check variable is `var` type and not `let` or `const`
|
104
|
-
if (parent.type === "Program") {// That means its a global variable
|
103
|
+
if (node.kind === "var") { // check variable is `var` type and not `let` or `const`
|
104
|
+
if (parent.type === "Program") { // That means its a global variable
|
105
105
|
globalVarCheck(node, parent);
|
106
106
|
} else {
|
107
107
|
blockScopeVarCheck(node, parent, grandParent);
|
@@ -53,9 +53,10 @@ var assert = require("assert"),
|
|
53
53
|
merge = require("lodash.merge"),
|
54
54
|
omit = require("lodash.omit"),
|
55
55
|
clone = require("lodash.clonedeep"),
|
56
|
-
validator = require("../config-validator"),
|
56
|
+
validator = require("../config/config-validator"),
|
57
57
|
validate = require("is-my-json-valid"),
|
58
58
|
eslint = require("../eslint"),
|
59
|
+
rules = require("../rules"),
|
59
60
|
metaSchema = require("../../conf/json-schema-schema.json"),
|
60
61
|
SourceCodeFixer = require("../util/source-code-fixer");
|
61
62
|
|
@@ -106,6 +107,27 @@ function cloneDeeplyExcludesParent(x) {
|
|
106
107
|
return x;
|
107
108
|
}
|
108
109
|
|
110
|
+
/**
|
111
|
+
* Freezes a given value deeply.
|
112
|
+
*
|
113
|
+
* @param {any} x - A value to freeze.
|
114
|
+
* @returns {void}
|
115
|
+
*/
|
116
|
+
function freezeDeeply(x) {
|
117
|
+
if (typeof x === "object" && x !== null) {
|
118
|
+
if (Array.isArray(x)) {
|
119
|
+
x.forEach(freezeDeeply);
|
120
|
+
} else {
|
121
|
+
for (var key in x) {
|
122
|
+
if (key !== "parent" && hasOwnProperty(x, key)) {
|
123
|
+
freezeDeeply(x[key]);
|
124
|
+
}
|
125
|
+
}
|
126
|
+
}
|
127
|
+
Object.freeze(x);
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
109
131
|
//------------------------------------------------------------------------------
|
110
132
|
// Public Interface
|
111
133
|
//------------------------------------------------------------------------------
|
@@ -251,7 +273,8 @@ RuleTester.prototype = {
|
|
251
273
|
|
252
274
|
validator.validate(config, "rule-tester");
|
253
275
|
|
254
|
-
//
|
276
|
+
// Setup AST getters.
|
277
|
+
// To check whether or not AST was not modified in verify.
|
255
278
|
eslint.reset();
|
256
279
|
eslint.on("Program", function(node) {
|
257
280
|
beforeAST = cloneDeeplyExcludesParent(node);
|
@@ -261,11 +284,29 @@ RuleTester.prototype = {
|
|
261
284
|
});
|
262
285
|
});
|
263
286
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
287
|
+
// Freezes rule-context properties.
|
288
|
+
var originalGet = rules.get;
|
289
|
+
try {
|
290
|
+
rules.get = function(ruleId) {
|
291
|
+
var rule = originalGet(ruleId);
|
292
|
+
return function(context) {
|
293
|
+
Object.freeze(context);
|
294
|
+
freezeDeeply(context.options);
|
295
|
+
freezeDeeply(context.settings);
|
296
|
+
freezeDeeply(context.ecmaFeatures);
|
297
|
+
|
298
|
+
return rule(context);
|
299
|
+
};
|
300
|
+
};
|
301
|
+
|
302
|
+
return {
|
303
|
+
messages: eslint.verify(code, config, filename, true),
|
304
|
+
beforeAST: beforeAST,
|
305
|
+
afterAST: afterAST
|
306
|
+
};
|
307
|
+
} finally {
|
308
|
+
rules.get = originalGet;
|
309
|
+
}
|
269
310
|
}
|
270
311
|
|
271
312
|
/**
|
package/lib/util/source-code.js
CHANGED
@@ -125,6 +125,10 @@ function SourceCode(text, ast) {
|
|
125
125
|
this[methodName] = tokenStore[methodName];
|
126
126
|
}, this);
|
127
127
|
|
128
|
+
var tokensAndCommentsStore = createTokenStore(this.tokensAndComments);
|
129
|
+
this.getTokenOrCommentBefore = tokensAndCommentsStore.getTokenBefore;
|
130
|
+
this.getTokenOrCommentAfter = tokensAndCommentsStore.getTokenAfter;
|
131
|
+
|
128
132
|
// don't allow modification of this object
|
129
133
|
Object.freeze(this);
|
130
134
|
Object.freeze(this.lines);
|
package/lib/util.js
CHANGED
@@ -14,97 +14,6 @@ var PLUGIN_NAME_PREFIX = "eslint-plugin-",
|
|
14
14
|
// Public Interface
|
15
15
|
//------------------------------------------------------------------------------
|
16
16
|
|
17
|
-
/**
|
18
|
-
* Merges two config objects. This will not only add missing keys, but will also modify values to match.
|
19
|
-
* @param {Object} target config object
|
20
|
-
* @param {Object} src config object. Overrides in this config object will take priority over base.
|
21
|
-
* @param {boolean} [combine] Whether to combine arrays or not
|
22
|
-
* @param {boolean} [isRule] Whether its a rule
|
23
|
-
* @returns {Object} merged config object.
|
24
|
-
*/
|
25
|
-
function deepmerge(target, src, combine, isRule) {
|
26
|
-
/*
|
27
|
-
The MIT License (MIT)
|
28
|
-
|
29
|
-
Copyright (c) 2012 Nicholas Fisher
|
30
|
-
|
31
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
32
|
-
of this software and associated documentation files (the "Software"), to deal
|
33
|
-
in the Software without restriction, including without limitation the rights
|
34
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
35
|
-
copies of the Software, and to permit persons to whom the Software is
|
36
|
-
furnished to do so, subject to the following conditions:
|
37
|
-
|
38
|
-
The above copyright notice and this permission notice shall be included in
|
39
|
-
all copies or substantial portions of the Software.
|
40
|
-
|
41
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
42
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
43
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
44
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
45
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
46
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
47
|
-
THE SOFTWARE.
|
48
|
-
*/
|
49
|
-
// This code is taken from deepmerge repo (https://github.com/KyleAMathews/deepmerge) and modified to meet our needs.
|
50
|
-
var array = Array.isArray(src) || Array.isArray(target);
|
51
|
-
var dst = array && [] || {};
|
52
|
-
|
53
|
-
combine = !!combine;
|
54
|
-
isRule = !!isRule;
|
55
|
-
if (array) {
|
56
|
-
target = target || [];
|
57
|
-
if (isRule && src.length > 1) {
|
58
|
-
dst = dst.concat(src);
|
59
|
-
} else {
|
60
|
-
dst = dst.concat(target);
|
61
|
-
}
|
62
|
-
if (typeof src !== "object" && !Array.isArray(src)) {
|
63
|
-
src = [src];
|
64
|
-
}
|
65
|
-
Object.keys(src).forEach(function(e, i) {
|
66
|
-
e = src[i];
|
67
|
-
if (typeof dst[i] === "undefined") {
|
68
|
-
dst[i] = e;
|
69
|
-
} else if (typeof e === "object") {
|
70
|
-
if (isRule) {
|
71
|
-
dst[i] = e;
|
72
|
-
} else {
|
73
|
-
dst[i] = deepmerge(target[i], e, combine, isRule);
|
74
|
-
}
|
75
|
-
} else {
|
76
|
-
if (!combine) {
|
77
|
-
dst[i] = e;
|
78
|
-
} else {
|
79
|
-
if (dst.indexOf(e) === -1) {
|
80
|
-
dst.push(e);
|
81
|
-
}
|
82
|
-
}
|
83
|
-
}
|
84
|
-
});
|
85
|
-
} else {
|
86
|
-
if (target && typeof target === "object") {
|
87
|
-
Object.keys(target).forEach(function(key) {
|
88
|
-
dst[key] = target[key];
|
89
|
-
});
|
90
|
-
}
|
91
|
-
Object.keys(src).forEach(function(key) {
|
92
|
-
if (Array.isArray(src[key]) || Array.isArray(target[key])) {
|
93
|
-
dst[key] = deepmerge(target[key], src[key], key === "plugins", isRule);
|
94
|
-
} else if (typeof src[key] !== "object" || !src[key]) {
|
95
|
-
dst[key] = src[key];
|
96
|
-
} else {
|
97
|
-
if (!target[key]) {
|
98
|
-
dst[key] = src[key];
|
99
|
-
} else {
|
100
|
-
dst[key] = deepmerge(target[key], src[key], combine, key === "rules");
|
101
|
-
}
|
102
|
-
}
|
103
|
-
});
|
104
|
-
}
|
105
|
-
|
106
|
-
return dst;
|
107
|
-
}
|
108
17
|
|
109
18
|
/**
|
110
19
|
* Removes the prefix `eslint-plugin-` from a plugin name.
|
@@ -133,7 +42,6 @@ function removeNameSpace(pluginName) {
|
|
133
42
|
}
|
134
43
|
|
135
44
|
module.exports = {
|
136
|
-
mergeConfigs: deepmerge,
|
137
45
|
removePluginPrefix: removePluginPrefix,
|
138
46
|
getNamespace: getNamespace,
|
139
47
|
removeNameSpace: removeNameSpace,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "eslint",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.10.3",
|
4
4
|
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
|
5
5
|
"description": "An AST-based pattern checker for JavaScript.",
|
6
6
|
"bin": {
|
@@ -38,9 +38,9 @@
|
|
38
38
|
"chalk": "^1.0.0",
|
39
39
|
"concat-stream": "^1.4.6",
|
40
40
|
"debug": "^2.1.1",
|
41
|
-
"doctrine": "^0.7.
|
41
|
+
"doctrine": "^0.7.1",
|
42
42
|
"escape-string-regexp": "^1.0.2",
|
43
|
-
"escope": "^3.
|
43
|
+
"escope": "^3.3.0",
|
44
44
|
"espree": "^2.2.4",
|
45
45
|
"estraverse": "^4.1.1",
|
46
46
|
"estraverse-fb": "^1.3.1",
|
@@ -52,7 +52,7 @@
|
|
52
52
|
"inquirer": "^0.11.0",
|
53
53
|
"is-my-json-valid": "^2.10.0",
|
54
54
|
"is-resolvable": "^1.0.0",
|
55
|
-
"js-yaml": "
|
55
|
+
"js-yaml": "3.4.5",
|
56
56
|
"json-stable-stringify": "^1.0.0",
|
57
57
|
"lodash.clonedeep": "^3.0.1",
|
58
58
|
"lodash.merge": "^3.3.2",
|
@@ -66,8 +66,6 @@
|
|
66
66
|
"shelljs": "^0.5.3",
|
67
67
|
"strip-json-comments": "~1.0.1",
|
68
68
|
"text-table": "~0.2.0",
|
69
|
-
"to-double-quotes": "^2.0.0",
|
70
|
-
"to-single-quotes": "^2.0.0",
|
71
69
|
"user-home": "^2.0.0",
|
72
70
|
"xml-escape": "~1.0.0"
|
73
71
|
},
|
@@ -1,146 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @fileoverview Config initialization wizard.
|
3
|
-
* @author Ilya Volodin
|
4
|
-
* @copyright 2015 Ilya Volodin. All rights reserved.
|
5
|
-
*/
|
6
|
-
|
7
|
-
"use strict";
|
8
|
-
|
9
|
-
var exec = require("child_process").exec,
|
10
|
-
fs = require("fs"),
|
11
|
-
inquirer = require("inquirer"),
|
12
|
-
yaml = require("js-yaml");
|
13
|
-
|
14
|
-
/* istanbul ignore next: hard to test fs function */
|
15
|
-
/**
|
16
|
-
* Create .eslintrc file in the current working directory
|
17
|
-
* @param {object} config object that contains user's answers
|
18
|
-
* @param {bool} isJson should config file be json or yaml
|
19
|
-
* @param {function} callback function to call once the file is written.
|
20
|
-
* @returns {void}
|
21
|
-
*/
|
22
|
-
function writeFile(config, isJson, callback) {
|
23
|
-
try {
|
24
|
-
fs.writeFileSync("./.eslintrc", isJson ? JSON.stringify(config, null, 4) : yaml.safeDump(config));
|
25
|
-
} catch (e) {
|
26
|
-
callback(e);
|
27
|
-
return;
|
28
|
-
}
|
29
|
-
if (config.plugins && config.plugins.indexOf("react") >= 0) {
|
30
|
-
exec("npm i eslint-plugin-react --save-dev", callback);
|
31
|
-
return;
|
32
|
-
}
|
33
|
-
callback();
|
34
|
-
}
|
35
|
-
|
36
|
-
/**
|
37
|
-
* process user's answers and create config object
|
38
|
-
* @param {object} answers answers received from inquirer
|
39
|
-
* @returns {object} config object
|
40
|
-
*/
|
41
|
-
function processAnswers(answers) {
|
42
|
-
var config = {rules: {}, env: {}, extends: "eslint:recommended"};
|
43
|
-
config.rules.indent = [2, answers.indent];
|
44
|
-
config.rules.quotes = [2, answers.quotes];
|
45
|
-
config.rules["linebreak-style"] = [2, answers.linebreak];
|
46
|
-
config.rules.semi = [2, answers.semi ? "always" : "never"];
|
47
|
-
if (answers.es6) {
|
48
|
-
config.env.es6 = true;
|
49
|
-
}
|
50
|
-
answers.env.forEach(function(env) {
|
51
|
-
config.env[env] = true;
|
52
|
-
});
|
53
|
-
if (answers.jsx) {
|
54
|
-
config.ecmaFeatures = {jsx: true};
|
55
|
-
if (answers.react) {
|
56
|
-
config.plugins = ["react"];
|
57
|
-
config.ecmaFeatures.experimentalObjectRestSpread = true;
|
58
|
-
}
|
59
|
-
}
|
60
|
-
return config;
|
61
|
-
}
|
62
|
-
|
63
|
-
/* istanbul ignore next: no need to test inquirer*/
|
64
|
-
/**
|
65
|
-
* Ask use a few questions on command prompt
|
66
|
-
* @param {function} callback callback function when file has been written
|
67
|
-
* @returns {void}
|
68
|
-
*/
|
69
|
-
function promptUser(callback) {
|
70
|
-
inquirer.prompt([
|
71
|
-
{
|
72
|
-
type: "list",
|
73
|
-
name: "indent",
|
74
|
-
message: "What style of indentation do you use?",
|
75
|
-
default: "tabs",
|
76
|
-
choices: [{name: "Tabs", value: "tab"}, {name: "Spaces", value: 4}]
|
77
|
-
},
|
78
|
-
{
|
79
|
-
type: "list",
|
80
|
-
name: "quotes",
|
81
|
-
message: "What quotes do you use for strings?",
|
82
|
-
default: "double",
|
83
|
-
choices: [{name: "Double", value: "double"}, {name: "Single", value: "single"}]
|
84
|
-
},
|
85
|
-
{
|
86
|
-
type: "list",
|
87
|
-
name: "linebreak",
|
88
|
-
message: "What line endings do you use?",
|
89
|
-
default: "unix",
|
90
|
-
choices: [{name: "Unix", value: "unix"}, {name: "Windows", value: "windows"}]
|
91
|
-
},
|
92
|
-
{
|
93
|
-
type: "confirm",
|
94
|
-
name: "semi",
|
95
|
-
message: "Do you require semicolons?",
|
96
|
-
default: true
|
97
|
-
},
|
98
|
-
{
|
99
|
-
type: "confirm",
|
100
|
-
name: "es6",
|
101
|
-
message: "Are you using ECMAScript 6 features?",
|
102
|
-
default: false
|
103
|
-
},
|
104
|
-
{
|
105
|
-
type: "checkbox",
|
106
|
-
name: "env",
|
107
|
-
message: "Where will your code run?",
|
108
|
-
default: ["browser"],
|
109
|
-
choices: [{name: "Node", value: "node"}, {name: "Browser", value: "browser"}]
|
110
|
-
},
|
111
|
-
{
|
112
|
-
type: "confirm",
|
113
|
-
name: "jsx",
|
114
|
-
message: "Do you use JSX?",
|
115
|
-
default: false
|
116
|
-
},
|
117
|
-
{
|
118
|
-
type: "confirm",
|
119
|
-
name: "react",
|
120
|
-
message: "Do you use React",
|
121
|
-
default: false,
|
122
|
-
when: function(answers) {
|
123
|
-
return answers.jsx;
|
124
|
-
}
|
125
|
-
},
|
126
|
-
{
|
127
|
-
type: "list",
|
128
|
-
name: "format",
|
129
|
-
message: "What format do you want your config file to be in?",
|
130
|
-
default: "JSON",
|
131
|
-
choices: ["JSON", "YAML"]
|
132
|
-
}
|
133
|
-
], function(answers) {
|
134
|
-
var config = processAnswers(answers);
|
135
|
-
writeFile(config, answers.format === "JSON", callback);
|
136
|
-
});
|
137
|
-
}
|
138
|
-
|
139
|
-
var init = {
|
140
|
-
processAnswers: processAnswers,
|
141
|
-
initializeConfig: /* istanbul ignore next */ function(callback) {
|
142
|
-
promptUser(callback);
|
143
|
-
}
|
144
|
-
};
|
145
|
-
|
146
|
-
module.exports = init;
|