eslint 3.13.1 → 3.16.0
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/CHANGELOG.md +81 -0
- package/README.md +1 -1
- package/conf/{eslint.json → eslint-recommended.js} +88 -71
- package/lib/ast-utils.js +247 -28
- package/lib/cli.js +2 -2
- package/lib/code-path-analysis/code-path-state.js +2 -2
- package/lib/config/autoconfig.js +24 -20
- package/lib/config/config-file.js +31 -24
- package/lib/config/config-initializer.js +2 -2
- package/lib/config/config-rule.js +15 -16
- package/lib/config/config-validator.js +6 -6
- package/lib/config.js +3 -2
- package/lib/eslint.js +18 -18
- package/lib/formatters/checkstyle.js +2 -2
- package/lib/formatters/codeframe.js +1 -1
- package/lib/formatters/compact.js +2 -2
- package/lib/formatters/junit.js +2 -2
- package/lib/formatters/tap.js +2 -2
- package/lib/formatters/unix.js +2 -2
- package/lib/formatters/visualstudio.js +2 -2
- package/lib/internal-rules/internal-consistent-docs-description.js +1 -1
- package/lib/rule-context.js +2 -2
- package/lib/rules/arrow-body-style.js +7 -4
- package/lib/rules/arrow-spacing.js +7 -6
- package/lib/rules/block-spacing.js +2 -2
- package/lib/rules/brace-style.js +93 -202
- package/lib/rules/capitalized-comments.js +6 -6
- package/lib/rules/comma-dangle.js +6 -6
- package/lib/rules/comma-spacing.js +16 -16
- package/lib/rules/comma-style.js +1 -1
- package/lib/rules/consistent-return.js +1 -1
- package/lib/rules/constructor-super.js +3 -3
- package/lib/rules/curly.js +11 -7
- package/lib/rules/default-case.js +3 -3
- package/lib/rules/eqeqeq.js +15 -6
- package/lib/rules/func-call-spacing.js +12 -15
- package/lib/rules/func-name-matching.js +1 -1
- package/lib/rules/generator-star-spacing.js +18 -19
- package/lib/rules/global-require.js +2 -2
- package/lib/rules/id-blacklist.js +2 -2
- package/lib/rules/id-length.js +3 -3
- package/lib/rules/id-match.js +2 -2
- package/lib/rules/indent.js +21 -20
- package/lib/rules/key-spacing.js +20 -23
- package/lib/rules/keyword-spacing.js +2 -13
- package/lib/rules/line-comment-position.js +1 -1
- package/lib/rules/linebreak-style.js +7 -1
- package/lib/rules/lines-around-comment.js +4 -4
- package/lib/rules/lines-around-directive.js +4 -4
- package/lib/rules/max-lines.js +3 -3
- package/lib/rules/max-statements-per-line.js +8 -7
- package/lib/rules/new-cap.js +2 -2
- package/lib/rules/newline-after-var.js +7 -2
- package/lib/rules/newline-before-return.js +2 -2
- package/lib/rules/newline-per-chained-call.js +3 -1
- package/lib/rules/no-await-in-loop.js +5 -5
- package/lib/rules/no-cond-assign.js +3 -3
- package/lib/rules/no-dupe-keys.js +1 -1
- package/lib/rules/no-else-return.js +88 -25
- package/lib/rules/no-extend-native.js +3 -3
- package/lib/rules/no-extra-bind.js +3 -4
- package/lib/rules/no-extra-boolean-cast.js +22 -1
- package/lib/rules/no-extra-parens.js +57 -9
- package/lib/rules/no-inner-declarations.js +4 -4
- package/lib/rules/no-irregular-whitespace.js +7 -1
- package/lib/rules/no-lone-blocks.js +10 -10
- package/lib/rules/no-mixed-operators.js +1 -7
- package/lib/rules/no-mixed-requires.js +4 -4
- package/lib/rules/no-multi-assign.js +41 -0
- package/lib/rules/no-multi-spaces.js +4 -1
- package/lib/rules/no-multi-str.js +7 -3
- package/lib/rules/no-redeclare.js +7 -7
- package/lib/rules/no-return-assign.js +7 -14
- package/lib/rules/no-return-await.js +2 -2
- package/lib/rules/no-sequences.js +7 -6
- package/lib/rules/no-throw-literal.js +2 -39
- package/lib/rules/no-trailing-spaces.js +8 -2
- package/lib/rules/no-undefined.js +45 -6
- package/lib/rules/no-unexpected-multiline.js +9 -8
- package/lib/rules/no-unneeded-ternary.js +5 -1
- package/lib/rules/no-unused-labels.js +17 -2
- package/lib/rules/no-unused-vars.js +34 -19
- package/lib/rules/no-use-before-define.js +33 -29
- package/lib/rules/no-useless-computed-key.js +9 -4
- package/lib/rules/no-useless-concat.js +10 -7
- package/lib/rules/no-useless-escape.js +1 -1
- package/lib/rules/no-useless-return.js +5 -11
- package/lib/rules/no-var.js +69 -3
- package/lib/rules/no-whitespace-before-property.js +5 -16
- package/lib/rules/object-curly-newline.js +2 -2
- package/lib/rules/object-curly-spacing.js +7 -25
- package/lib/rules/object-property-newline.js +3 -3
- package/lib/rules/object-shorthand.js +10 -10
- package/lib/rules/operator-assignment.js +2 -2
- package/lib/rules/operator-linebreak.js +8 -10
- package/lib/rules/padded-blocks.js +4 -4
- package/lib/rules/prefer-promise-reject-errors.js +124 -0
- package/lib/rules/prefer-spread.js +1 -1
- package/lib/rules/prefer-template.js +1 -1
- package/lib/rules/quotes.js +11 -7
- package/lib/rules/require-await.js +1 -1
- package/lib/rules/semi-spacing.js +4 -0
- package/lib/rules/sort-imports.js +4 -4
- package/lib/rules/sort-keys.js +2 -2
- package/lib/rules/sort-vars.js +2 -2
- package/lib/rules/space-before-function-paren.js +9 -6
- package/lib/rules/space-in-parens.js +8 -8
- package/lib/rules/spaced-comment.js +10 -10
- package/lib/rules/strict.js +2 -2
- package/lib/rules/template-tag-spacing.js +77 -0
- package/lib/rules/unicode-bom.js +1 -1
- package/lib/rules/wrap-iife.js +5 -5
- package/lib/rules/yoda.js +2 -7
- package/lib/rules.js +2 -2
- package/lib/testers/rule-tester.js +28 -21
- package/lib/token-store/backward-token-comment-cursor.js +57 -0
- package/lib/token-store/backward-token-cursor.js +56 -0
- package/lib/token-store/cursor.js +76 -0
- package/lib/token-store/cursors.js +92 -0
- package/lib/token-store/decorative-cursor.js +39 -0
- package/lib/token-store/filter-cursor.js +43 -0
- package/lib/token-store/forward-token-comment-cursor.js +57 -0
- package/lib/token-store/forward-token-cursor.js +61 -0
- package/lib/token-store/index.js +604 -0
- package/lib/token-store/limit-cursor.js +40 -0
- package/lib/token-store/padded-token-cursor.js +38 -0
- package/lib/token-store/skip-cursor.js +42 -0
- package/lib/token-store/utils.js +100 -0
- package/lib/util/comment-event-generator.js +17 -16
- package/lib/util/glob-util.js +1 -1
- package/lib/util/glob.js +1 -1
- package/lib/util/rule-fixer.js +3 -8
- package/lib/util/source-code-fixer.js +41 -45
- package/lib/util/source-code.js +35 -19
- package/messages/extend-config-missing.txt +3 -0
- package/package.json +3 -3
- package/lib/token-store.js +0 -203
@@ -176,22 +176,21 @@ function combinePropertyObjects(objArr1, objArr2) {
|
|
176
176
|
*
|
177
177
|
* ruleConfigSet.ruleConfigs // -> [[2], [2, "always"], [2, "never"]]
|
178
178
|
*
|
179
|
-
*
|
180
|
-
* @constructor
|
179
|
+
* Rule configuration set class
|
181
180
|
*/
|
182
|
-
|
181
|
+
class RuleConfigSet {
|
183
182
|
|
184
183
|
/**
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
184
|
+
* @param {ruleConfig[]} configs Valid rule configurations
|
185
|
+
*/
|
186
|
+
constructor(configs) {
|
187
|
+
|
188
|
+
/**
|
189
|
+
* Stored valid rule configurations for this instance
|
190
|
+
* @type {array}
|
191
|
+
*/
|
192
|
+
this.ruleConfigs = configs || [];
|
193
|
+
}
|
195
194
|
|
196
195
|
/**
|
197
196
|
* Add a severity level to the front of all configs in the instance.
|
@@ -210,7 +209,7 @@ RuleConfigSet.prototype = {
|
|
210
209
|
|
211
210
|
// Add a single config at the beginning consisting of only the severity
|
212
211
|
this.ruleConfigs.unshift(severity);
|
213
|
-
}
|
212
|
+
}
|
214
213
|
|
215
214
|
/**
|
216
215
|
* Add rule configs from an array of strings (schema enums)
|
@@ -219,7 +218,7 @@ RuleConfigSet.prototype = {
|
|
219
218
|
*/
|
220
219
|
addEnums(enums) {
|
221
220
|
this.ruleConfigs = this.ruleConfigs.concat(combineArrays(this.ruleConfigs, enums));
|
222
|
-
}
|
221
|
+
}
|
223
222
|
|
224
223
|
/**
|
225
224
|
* Add rule configurations from a schema object
|
@@ -261,7 +260,7 @@ RuleConfigSet.prototype = {
|
|
261
260
|
this.ruleConfigs = this.ruleConfigs.concat(combineArrays(this.ruleConfigs, objectConfigSet.objectConfigs));
|
262
261
|
}
|
263
262
|
}
|
264
|
-
}
|
263
|
+
}
|
265
264
|
|
266
265
|
/**
|
267
266
|
* Generate valid rule configurations based on a schema object
|
@@ -40,13 +40,13 @@ function getRuleOptionsSchema(id) {
|
|
40
40
|
minItems: 0,
|
41
41
|
maxItems: schema.length
|
42
42
|
};
|
43
|
-
} else {
|
44
|
-
return {
|
45
|
-
type: "array",
|
46
|
-
minItems: 0,
|
47
|
-
maxItems: 0
|
48
|
-
};
|
49
43
|
}
|
44
|
+
return {
|
45
|
+
type: "array",
|
46
|
+
minItems: 0,
|
47
|
+
maxItems: 0
|
48
|
+
};
|
49
|
+
|
50
50
|
}
|
51
51
|
|
52
52
|
// Given a full schema, leave it alone
|
package/lib/config.js
CHANGED
@@ -234,8 +234,9 @@ class Config {
|
|
234
234
|
}
|
235
235
|
|
236
236
|
/**
|
237
|
-
* Build a config object merging the base config (conf/eslint
|
238
|
-
* environments config (conf/environments.js) and eventually the user
|
237
|
+
* Build a config object merging the base config (conf/eslint-recommended),
|
238
|
+
* the environments config (conf/environments.js) and eventually the user
|
239
|
+
* config.
|
239
240
|
* @param {string} filePath a file in whose directory we start looking for a local config
|
240
241
|
* @returns {Object} config object
|
241
242
|
*/
|
package/lib/eslint.js
CHANGED
@@ -14,7 +14,7 @@ const assert = require("assert"),
|
|
14
14
|
escope = require("escope"),
|
15
15
|
levn = require("levn"),
|
16
16
|
blankScriptAST = require("../conf/blank-script.json"),
|
17
|
-
DEFAULT_PARSER = require("../conf/eslint
|
17
|
+
DEFAULT_PARSER = require("../conf/eslint-recommended").parser,
|
18
18
|
replacements = require("../conf/replacements.json"),
|
19
19
|
CodePathAnalyzer = require("./code-path-analysis/code-path-analyzer"),
|
20
20
|
ConfigOps = require("./config/config-ops"),
|
@@ -528,9 +528,9 @@ function createStubRule(message) {
|
|
528
528
|
|
529
529
|
if (message) {
|
530
530
|
return createRuleModule;
|
531
|
-
} else {
|
532
|
-
throw new Error("No message passed to stub rule");
|
533
531
|
}
|
532
|
+
throw new Error("No message passed to stub rule");
|
533
|
+
|
534
534
|
}
|
535
535
|
|
536
536
|
/**
|
@@ -660,9 +660,9 @@ module.exports = (function() {
|
|
660
660
|
try {
|
661
661
|
if (typeof parser.parseForESLint === "function") {
|
662
662
|
return parser.parseForESLint(text, parserOptions);
|
663
|
-
} else {
|
664
|
-
return parser.parse(text, parserOptions);
|
665
663
|
}
|
664
|
+
return parser.parse(text, parserOptions);
|
665
|
+
|
666
666
|
} catch (ex) {
|
667
667
|
|
668
668
|
// If the message includes a leading line number, strip it:
|
@@ -695,9 +695,9 @@ module.exports = (function() {
|
|
695
695
|
return ruleConfig;
|
696
696
|
} else if (Array.isArray(ruleConfig)) {
|
697
697
|
return ruleConfig[0];
|
698
|
-
} else {
|
699
|
-
return 0;
|
700
698
|
}
|
699
|
+
return 0;
|
700
|
+
|
701
701
|
}
|
702
702
|
|
703
703
|
/**
|
@@ -708,9 +708,9 @@ module.exports = (function() {
|
|
708
708
|
function getRuleOptions(ruleConfig) {
|
709
709
|
if (Array.isArray(ruleConfig)) {
|
710
710
|
return ruleConfig.slice(1);
|
711
|
-
} else {
|
712
|
-
return [];
|
713
711
|
}
|
712
|
+
return [];
|
713
|
+
|
714
714
|
}
|
715
715
|
|
716
716
|
// set unlimited listeners (see https://github.com/eslint/eslint/issues/524)
|
@@ -864,8 +864,8 @@ module.exports = (function() {
|
|
864
864
|
(parseResult && parseResult.services ? parseResult.services : {})
|
865
865
|
);
|
866
866
|
|
867
|
-
const rule = ruleCreator.create ? ruleCreator.create(ruleContext)
|
868
|
-
ruleCreator(ruleContext);
|
867
|
+
const rule = ruleCreator.create ? ruleCreator.create(ruleContext)
|
868
|
+
: ruleCreator(ruleContext);
|
869
869
|
|
870
870
|
// add all the node types as listeners
|
871
871
|
Object.keys(rule).forEach(nodeType => {
|
@@ -939,9 +939,9 @@ module.exports = (function() {
|
|
939
939
|
|
940
940
|
if (lineDiff === 0) {
|
941
941
|
return a.column - b.column;
|
942
|
-
} else {
|
943
|
-
return lineDiff;
|
944
942
|
}
|
943
|
+
return lineDiff;
|
944
|
+
|
945
945
|
});
|
946
946
|
|
947
947
|
return messages;
|
@@ -1109,9 +1109,9 @@ module.exports = (function() {
|
|
1109
1109
|
if (scope) {
|
1110
1110
|
if (scope.type === "function-expression-name") {
|
1111
1111
|
return scope.childScopes[0];
|
1112
|
-
} else {
|
1113
|
-
return scope;
|
1114
1112
|
}
|
1113
|
+
return scope;
|
1114
|
+
|
1115
1115
|
}
|
1116
1116
|
|
1117
1117
|
}
|
@@ -1161,9 +1161,9 @@ module.exports = (function() {
|
|
1161
1161
|
api.getFilename = function() {
|
1162
1162
|
if (typeof currentFilename === "string") {
|
1163
1163
|
return currentFilename;
|
1164
|
-
} else {
|
1165
|
-
return "<input>";
|
1166
1164
|
}
|
1165
|
+
return "<input>";
|
1166
|
+
|
1167
1167
|
};
|
1168
1168
|
|
1169
1169
|
/**
|
@@ -1192,7 +1192,7 @@ module.exports = (function() {
|
|
1192
1192
|
* @returns {Object} Object mapping rule IDs to their default configurations
|
1193
1193
|
*/
|
1194
1194
|
api.defaults = function() {
|
1195
|
-
return require("../conf/eslint
|
1195
|
+
return require("../conf/eslint-recommended");
|
1196
1196
|
};
|
1197
1197
|
|
1198
1198
|
/**
|
@@ -19,9 +19,9 @@ const xmlEscape = require("../util/xml-escape");
|
|
19
19
|
function getMessageType(message) {
|
20
20
|
if (message.fatal || message.severity === 2) {
|
21
21
|
return "error";
|
22
|
-
} else {
|
23
|
-
return "warning";
|
24
22
|
}
|
23
|
+
return "warning";
|
24
|
+
|
25
25
|
}
|
26
26
|
|
27
27
|
//------------------------------------------------------------------------------
|
@@ -56,7 +56,7 @@ function formatMessage(message, parentResult) {
|
|
56
56
|
`${type}:`,
|
57
57
|
`${msg}`,
|
58
58
|
ruleId ? `${ruleId}` : "",
|
59
|
-
sourceCode ? `at ${filePath}:` : `at ${filePath}
|
59
|
+
sourceCode ? `at ${filePath}:` : `at ${filePath}`
|
60
60
|
].filter(String).join(" ");
|
61
61
|
|
62
62
|
const result = [firstLine];
|
package/lib/formatters/junit.js
CHANGED
@@ -19,9 +19,9 @@ const xmlEscape = require("../util/xml-escape");
|
|
19
19
|
function getMessageType(message) {
|
20
20
|
if (message.fatal || message.severity === 2) {
|
21
21
|
return "Error";
|
22
|
-
} else {
|
23
|
-
return "Warning";
|
24
22
|
}
|
23
|
+
return "Warning";
|
24
|
+
|
25
25
|
}
|
26
26
|
|
27
27
|
//------------------------------------------------------------------------------
|
package/lib/formatters/tap.js
CHANGED
package/lib/formatters/unix.js
CHANGED
@@ -71,7 +71,7 @@ function checkMetaDocsDescription(context, exportsNode) {
|
|
71
71
|
if (description === "") {
|
72
72
|
context.report({
|
73
73
|
node: metaDocsDescription.value,
|
74
|
-
message: "`meta.docs.description` should not be empty."
|
74
|
+
message: "`meta.docs.description` should not be empty."
|
75
75
|
});
|
76
76
|
return;
|
77
77
|
}
|
package/lib/rule-context.js
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
// Requirements
|
9
9
|
//------------------------------------------------------------------------------
|
10
10
|
|
11
|
-
const
|
11
|
+
const ruleFixer = require("./util/rule-fixer");
|
12
12
|
|
13
13
|
//------------------------------------------------------------------------------
|
14
14
|
// Constants
|
@@ -124,7 +124,7 @@ class RuleContext {
|
|
124
124
|
|
125
125
|
// if there's a fix specified, get it
|
126
126
|
if (typeof descriptor.fix === "function") {
|
127
|
-
fix = descriptor.fix(
|
127
|
+
fix = descriptor.fix(ruleFixer);
|
128
128
|
}
|
129
129
|
|
130
130
|
this.eslint.report(
|
@@ -4,6 +4,12 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
//------------------------------------------------------------------------------
|
8
|
+
// Requirements
|
9
|
+
//------------------------------------------------------------------------------
|
10
|
+
|
11
|
+
const astUtils = require("../ast-utils");
|
12
|
+
|
7
13
|
//------------------------------------------------------------------------------
|
8
14
|
// Rule Definition
|
9
15
|
//------------------------------------------------------------------------------
|
@@ -136,10 +142,7 @@ module.exports = {
|
|
136
142
|
loc: arrowBody.loc.start,
|
137
143
|
message: "Expected block statement surrounding arrow body.",
|
138
144
|
fix(fixer) {
|
139
|
-
const lastTokenBeforeBody = sourceCode.
|
140
|
-
.reverse()
|
141
|
-
.find(token => token.value !== "(");
|
142
|
-
|
145
|
+
const lastTokenBeforeBody = sourceCode.getLastTokenBetween(sourceCode.getFirstToken(node), arrowBody, astUtils.isNotOpeningParenToken);
|
143
146
|
const firstBodyToken = sourceCode.getTokenAfter(lastTokenBeforeBody);
|
144
147
|
|
145
148
|
return fixer.replaceTextRange(
|
@@ -4,6 +4,12 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
//------------------------------------------------------------------------------
|
8
|
+
// Requirements
|
9
|
+
//------------------------------------------------------------------------------
|
10
|
+
|
11
|
+
const astUtils = require("../ast-utils");
|
12
|
+
|
7
13
|
//------------------------------------------------------------------------------
|
8
14
|
// Rule Definition
|
9
15
|
//------------------------------------------------------------------------------
|
@@ -51,12 +57,7 @@ module.exports = {
|
|
51
57
|
* @returns {Object} Tokens of arrow and before/after arrow.
|
52
58
|
*/
|
53
59
|
function getTokens(node) {
|
54
|
-
|
55
|
-
|
56
|
-
// skip '(' tokens.
|
57
|
-
while (arrow.value !== "=>") {
|
58
|
-
arrow = sourceCode.getTokenBefore(arrow);
|
59
|
-
}
|
60
|
+
const arrow = sourceCode.getTokenBefore(node.body, astUtils.isArrowToken);
|
60
61
|
|
61
62
|
return {
|
62
63
|
before: sourceCode.getTokenBefore(arrow),
|
@@ -74,8 +74,8 @@ module.exports = {
|
|
74
74
|
// Gets braces and the first/last token of content.
|
75
75
|
const openBrace = getOpenBrace(node);
|
76
76
|
const closeBrace = sourceCode.getLastToken(node);
|
77
|
-
const firstToken = sourceCode.
|
78
|
-
const lastToken = sourceCode.
|
77
|
+
const firstToken = sourceCode.getTokenAfter(openBrace, { includeComments: true });
|
78
|
+
const lastToken = sourceCode.getTokenBefore(closeBrace, { includeComments: true });
|
79
79
|
|
80
80
|
// Skip if the node is invalid or empty.
|
81
81
|
if (openBrace.type !== "Punctuator" ||
|