eslint 5.12.0 → 5.14.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/CHANGELOG.md +70 -0
- package/README.md +76 -143
- package/conf/eslint-all.js +3 -5
- package/conf/eslint-recommended.js +4 -268
- package/lib/built-in-rules-index.js +277 -0
- package/lib/cli-engine.js +6 -2
- package/lib/config/config-file.js +25 -2
- package/lib/config/config-initializer.js +150 -143
- package/lib/config/config-ops.js +30 -0
- package/lib/config/config-rule.js +2 -4
- package/lib/config/plugins.js +12 -4
- package/lib/config.js +1 -1
- package/lib/formatters/table.js +13 -4
- package/lib/formatters/tap.js +7 -4
- package/lib/linter.js +31 -31
- package/lib/load-rules.js +2 -5
- package/lib/rules/accessor-pairs.js +4 -2
- package/lib/rules/array-bracket-newline.js +4 -2
- package/lib/rules/array-callback-return.js +2 -1
- package/lib/rules/array-element-newline.js +4 -2
- package/lib/rules/arrow-body-style.js +1 -1
- package/lib/rules/arrow-parens.js +2 -1
- package/lib/rules/arrow-spacing.js +7 -6
- package/lib/rules/brace-style.js +2 -1
- package/lib/rules/camelcase.js +3 -2
- package/lib/rules/capitalized-comments.js +15 -14
- package/lib/rules/class-methods-use-this.js +1 -1
- package/lib/rules/comma-spacing.js +10 -4
- package/lib/rules/complexity.js +7 -9
- package/lib/rules/consistent-return.js +2 -1
- package/lib/rules/dot-notation.js +5 -3
- package/lib/rules/eqeqeq.js +2 -1
- package/lib/rules/for-direction.js +30 -17
- package/lib/rules/func-call-spacing.js +2 -1
- package/lib/rules/func-style.js +3 -2
- package/lib/rules/getter-return.js +2 -1
- package/lib/rules/global-require.js +5 -2
- package/lib/rules/guard-for-in.js +5 -2
- package/lib/rules/handle-callback-err.js +5 -2
- package/lib/rules/id-blacklist.js +4 -1
- package/lib/rules/id-length.js +9 -6
- package/lib/rules/id-match.js +11 -5
- package/lib/rules/implicit-arrow-linebreak.js +7 -3
- package/lib/rules/indent-legacy.js +11 -5
- package/lib/rules/indent.js +18 -9
- package/lib/rules/init-declarations.js +13 -13
- package/lib/rules/jsx-quotes.js +5 -2
- package/lib/rules/key-spacing.js +70 -35
- package/lib/rules/keyword-spacing.js +18 -12
- package/lib/rules/line-comment-position.js +15 -8
- package/lib/rules/linebreak-style.js +6 -6
- package/lib/rules/lines-around-comment.js +20 -16
- package/lib/rules/lines-around-directive.js +5 -2
- package/lib/rules/lines-between-class-members.js +8 -6
- package/lib/rules/max-depth.js +11 -9
- package/lib/rules/max-len.js +24 -13
- package/lib/rules/max-lines-per-function.js +17 -18
- package/lib/rules/max-lines.js +14 -10
- package/lib/rules/max-nested-callbacks.js +12 -11
- package/lib/rules/max-params.js +11 -9
- package/lib/rules/max-statements-per-line.js +8 -5
- package/lib/rules/max-statements.js +12 -11
- package/lib/rules/multiline-comment-style.js +18 -17
- package/lib/rules/multiline-ternary.js +8 -6
- package/lib/rules/new-cap.js +18 -11
- package/lib/rules/new-parens.js +5 -2
- package/lib/rules/newline-after-var.js +6 -8
- package/lib/rules/newline-before-return.js +5 -1
- package/lib/rules/newline-per-chained-call.js +7 -3
- package/lib/rules/no-async-promise-executor.js +5 -2
- package/lib/rules/no-bitwise.js +2 -1
- package/lib/rules/no-confusing-arrow.js +1 -1
- package/lib/rules/no-constant-condition.js +24 -2
- package/lib/rules/no-duplicate-imports.js +17 -11
- package/lib/rules/no-else-return.js +2 -1
- package/lib/rules/no-empty.js +2 -1
- package/lib/rules/no-eval.js +1 -1
- package/lib/rules/no-extra-parens.js +4 -4
- package/lib/rules/no-fallthrough.js +8 -4
- package/lib/rules/no-floating-decimal.js +7 -3
- package/lib/rules/no-implicit-coercion.js +9 -6
- package/lib/rules/no-irregular-whitespace.js +8 -4
- package/lib/rules/no-labels.js +6 -4
- package/lib/rules/no-magic-numbers.js +6 -3
- package/lib/rules/no-mixed-operators.js +5 -4
- package/lib/rules/no-mixed-requires.js +4 -2
- package/lib/rules/no-multi-spaces.js +2 -1
- package/lib/rules/no-param-reassign.js +1 -1
- package/lib/rules/no-plusplus.js +2 -1
- package/lib/rules/no-redeclare.js +2 -2
- package/lib/rules/no-self-assign.js +2 -1
- package/lib/rules/no-shadow-restricted-names.js +16 -2
- package/lib/rules/no-shadow.js +3 -3
- package/lib/rules/no-sync.js +2 -1
- package/lib/rules/no-tabs.js +2 -1
- package/lib/rules/no-trailing-spaces.js +5 -3
- package/lib/rules/no-undef.js +7 -3
- package/lib/rules/no-underscore-dangle.js +6 -3
- package/lib/rules/no-unexpected-multiline.js +14 -13
- package/lib/rules/no-unneeded-ternary.js +2 -1
- package/lib/rules/no-unsafe-negation.js +6 -3
- package/lib/rules/no-unused-expressions.js +6 -3
- package/lib/rules/no-unused-labels.js +7 -2
- package/lib/rules/no-unused-vars.js +8 -4
- package/lib/rules/no-use-before-define.js +3 -3
- package/lib/rules/no-useless-rename.js +3 -3
- package/lib/rules/object-curly-newline.js +6 -4
- package/lib/rules/object-property-newline.js +5 -3
- package/lib/rules/object-shorthand.js +9 -5
- package/lib/rules/one-var.js +24 -38
- package/lib/rules/operator-assignment.js +8 -4
- package/lib/rules/padded-blocks.js +32 -9
- package/lib/rules/prefer-arrow-callback.js +4 -2
- package/lib/rules/prefer-const.js +7 -4
- package/lib/rules/prefer-destructuring.js +70 -12
- package/lib/rules/prefer-promise-reject-errors.js +1 -1
- package/lib/rules/prefer-spread.js +2 -13
- package/lib/rules/quote-props.js +10 -5
- package/lib/rules/quotes.js +4 -2
- package/lib/rules/require-jsdoc.js +13 -7
- package/lib/rules/semi-spacing.js +6 -8
- package/lib/rules/semi.js +5 -4
- package/lib/rules/sort-imports.js +6 -3
- package/lib/rules/sort-keys.js +13 -5
- package/lib/rules/sort-vars.js +2 -1
- package/lib/rules/space-before-function-paren.js +6 -3
- package/lib/rules/space-infix-ops.js +2 -1
- package/lib/rules/space-unary-ops.js +20 -10
- package/lib/rules/spaced-comment.js +2 -1
- package/lib/rules/strict.js +34 -35
- package/lib/rules/switch-colon-spacing.js +11 -8
- package/lib/rules/symbol-description.js +6 -3
- package/lib/rules/template-curly-spacing.js +10 -10
- package/lib/rules/template-tag-spacing.js +7 -3
- package/lib/rules/unicode-bom.js +7 -3
- package/lib/rules/use-isnan.js +5 -2
- package/lib/rules/valid-jsdoc.js +40 -19
- package/lib/rules/valid-typeof.js +9 -4
- package/lib/rules/vars-on-top.js +6 -4
- package/lib/rules/wrap-iife.js +12 -6
- package/lib/rules/yield-star-spacing.js +17 -10
- package/lib/rules/yoda.js +9 -4
- package/lib/rules.js +4 -34
- package/lib/util/ajv.js +1 -0
- package/lib/util/config-comment-parser.js +7 -10
- package/package.json +20 -20
package/lib/linter.js
CHANGED
@@ -70,30 +70,30 @@ const commentParser = new ConfigCommentParser();
|
|
70
70
|
* @returns {void}
|
71
71
|
*/
|
72
72
|
function addDeclaredGlobals(globalScope, configGlobals, commentDirectives) {
|
73
|
-
Object.
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
variable.eslintExplicitGlobal = false;
|
79
|
-
globalScope.variables.push(variable);
|
80
|
-
globalScope.set.set(name, variable);
|
81
|
-
}
|
82
|
-
variable.writeable = configGlobals[name];
|
83
|
-
});
|
84
|
-
|
85
|
-
Object.keys(commentDirectives.enabledGlobals).forEach(name => {
|
86
|
-
let variable = globalScope.set.get(name);
|
73
|
+
const mergedGlobalsInfo = Object.assign(
|
74
|
+
{},
|
75
|
+
lodash.mapValues(configGlobals, value => ({ sourceComment: null, value: ConfigOps.normalizeConfigGlobal(value) })),
|
76
|
+
lodash.mapValues(commentDirectives.enabledGlobals, ({ comment, value }) => ({ sourceComment: comment, value: ConfigOps.normalizeConfigGlobal(value) }))
|
77
|
+
);
|
87
78
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
variable
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
79
|
+
Object.keys(mergedGlobalsInfo)
|
80
|
+
.filter(name => mergedGlobalsInfo[name].value !== "off")
|
81
|
+
.forEach(name => {
|
82
|
+
let variable = globalScope.set.get(name);
|
83
|
+
|
84
|
+
if (!variable) {
|
85
|
+
variable = new eslintScope.Variable(name, globalScope);
|
86
|
+
if (mergedGlobalsInfo[name].sourceComment === null) {
|
87
|
+
variable.eslintExplicitGlobal = false;
|
88
|
+
} else {
|
89
|
+
variable.eslintExplicitGlobal = true;
|
90
|
+
variable.eslintExplicitGlobalComment = mergedGlobalsInfo[name].sourceComment;
|
91
|
+
}
|
92
|
+
globalScope.variables.push(variable);
|
93
|
+
globalScope.set.set(name, variable);
|
94
|
+
}
|
95
|
+
variable.writeable = (mergedGlobalsInfo[name].value === "writeable");
|
96
|
+
});
|
97
97
|
|
98
98
|
// mark all exported variables as such
|
99
99
|
Object.keys(commentDirectives.exportedVariables).forEach(name => {
|
@@ -191,12 +191,12 @@ function getDirectiveComments(filename, ast, ruleMapper) {
|
|
191
191
|
} else if (comment.type === "Block") {
|
192
192
|
switch (match[1]) {
|
193
193
|
case "exported":
|
194
|
-
Object.assign(exportedVariables, commentParser.
|
194
|
+
Object.assign(exportedVariables, commentParser.parseStringConfig(directiveValue, comment));
|
195
195
|
break;
|
196
196
|
|
197
197
|
case "globals":
|
198
198
|
case "global":
|
199
|
-
Object.assign(enabledGlobals, commentParser.
|
199
|
+
Object.assign(enabledGlobals, commentParser.parseStringConfig(directiveValue, comment));
|
200
200
|
break;
|
201
201
|
|
202
202
|
case "eslint-disable":
|
@@ -758,6 +758,7 @@ function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parser
|
|
758
758
|
|
759
759
|
const lastSourceCodes = new WeakMap();
|
760
760
|
const loadedParserMaps = new WeakMap();
|
761
|
+
const ruleMaps = new WeakMap();
|
761
762
|
|
762
763
|
//------------------------------------------------------------------------------
|
763
764
|
// Public Interface
|
@@ -772,9 +773,8 @@ module.exports = class Linter {
|
|
772
773
|
constructor() {
|
773
774
|
lastSourceCodes.set(this, null);
|
774
775
|
loadedParserMaps.set(this, new Map());
|
776
|
+
ruleMaps.set(this, new Rules());
|
775
777
|
this.version = pkg.version;
|
776
|
-
|
777
|
-
this.rules = new Rules();
|
778
778
|
this.environments = new Environments();
|
779
779
|
}
|
780
780
|
|
@@ -873,7 +873,7 @@ module.exports = class Linter {
|
|
873
873
|
|
874
874
|
const sourceCode = lastSourceCodes.get(this);
|
875
875
|
const commentDirectives = options.allowInlineConfig
|
876
|
-
? getDirectiveComments(options.filename, sourceCode.ast, ruleId => this.
|
876
|
+
? getDirectiveComments(options.filename, sourceCode.ast, ruleId => ruleMaps.get(this).get(ruleId))
|
877
877
|
: { configuredRules: {}, enabledGlobals: {}, exportedVariables: {}, problems: [], disableDirectives: [] };
|
878
878
|
|
879
879
|
// augment global scope with declared global variables
|
@@ -891,7 +891,7 @@ module.exports = class Linter {
|
|
891
891
|
lintingProblems = runRules(
|
892
892
|
sourceCode,
|
893
893
|
configuredRules,
|
894
|
-
ruleId => this.
|
894
|
+
ruleId => ruleMaps.get(this).get(ruleId),
|
895
895
|
parserOptions,
|
896
896
|
parserName,
|
897
897
|
settings,
|
@@ -957,7 +957,7 @@ module.exports = class Linter {
|
|
957
957
|
* @returns {void}
|
958
958
|
*/
|
959
959
|
defineRule(ruleId, ruleModule) {
|
960
|
-
this.
|
960
|
+
ruleMaps.get(this).define(ruleId, ruleModule);
|
961
961
|
}
|
962
962
|
|
963
963
|
/**
|
@@ -976,7 +976,7 @@ module.exports = class Linter {
|
|
976
976
|
* @returns {Map} All loaded rules
|
977
977
|
*/
|
978
978
|
getRules() {
|
979
|
-
return this.
|
979
|
+
return ruleMaps.get(this).getAllLoadedRules();
|
980
980
|
}
|
981
981
|
|
982
982
|
/**
|
package/lib/load-rules.js
CHANGED
@@ -20,15 +20,12 @@ const rulesDirCache = {};
|
|
20
20
|
|
21
21
|
/**
|
22
22
|
* Load all rule modules from specified directory.
|
23
|
-
* @param {string}
|
23
|
+
* @param {string} relativeRulesDir Path to rules directory, may be relative.
|
24
24
|
* @param {string} cwd Current working directory
|
25
25
|
* @returns {Object} Loaded rule modules by rule ids (file names).
|
26
26
|
*/
|
27
27
|
module.exports = function(relativeRulesDir, cwd) {
|
28
|
-
|
29
|
-
const rulesDir = relativeRulesDir
|
30
|
-
? path.resolve(cwd, relativeRulesDir)
|
31
|
-
: path.join(__dirname, "rules");
|
28
|
+
const rulesDir = path.resolve(cwd, relativeRulesDir);
|
32
29
|
|
33
30
|
// cache will help performance as IO operation are expensive
|
34
31
|
if (rulesDirCache[rulesDir]) {
|
@@ -85,10 +85,12 @@ module.exports = {
|
|
85
85
|
type: "object",
|
86
86
|
properties: {
|
87
87
|
getWithoutSet: {
|
88
|
-
type: "boolean"
|
88
|
+
type: "boolean",
|
89
|
+
default: false
|
89
90
|
},
|
90
91
|
setWithoutGet: {
|
91
|
-
type: "boolean"
|
92
|
+
type: "boolean",
|
93
|
+
default: true
|
92
94
|
}
|
93
95
|
},
|
94
96
|
additionalProperties: false
|
@@ -34,11 +34,13 @@ module.exports = {
|
|
34
34
|
type: "object",
|
35
35
|
properties: {
|
36
36
|
multiline: {
|
37
|
-
type: "boolean"
|
37
|
+
type: "boolean",
|
38
|
+
default: true
|
38
39
|
},
|
39
40
|
minItems: {
|
40
41
|
type: ["integer", "null"],
|
41
|
-
minimum: 0
|
42
|
+
minimum: 0,
|
43
|
+
default: null
|
42
44
|
}
|
43
45
|
},
|
44
46
|
additionalProperties: false
|
@@ -34,11 +34,13 @@ module.exports = {
|
|
34
34
|
type: "object",
|
35
35
|
properties: {
|
36
36
|
multiline: {
|
37
|
-
type: "boolean"
|
37
|
+
type: "boolean",
|
38
|
+
default: false
|
38
39
|
},
|
39
40
|
minItems: {
|
40
41
|
type: ["integer", "null"],
|
41
|
-
minimum: 0
|
42
|
+
minimum: 0,
|
43
|
+
default: null
|
42
44
|
}
|
43
45
|
},
|
44
46
|
additionalProperties: false
|
@@ -32,10 +32,12 @@ module.exports = {
|
|
32
32
|
type: "object",
|
33
33
|
properties: {
|
34
34
|
before: {
|
35
|
-
type: "boolean"
|
35
|
+
type: "boolean",
|
36
|
+
default: true
|
36
37
|
},
|
37
38
|
after: {
|
38
|
-
type: "boolean"
|
39
|
+
type: "boolean",
|
40
|
+
default: true
|
39
41
|
}
|
40
42
|
},
|
41
43
|
additionalProperties: false
|
@@ -54,11 +56,10 @@ module.exports = {
|
|
54
56
|
create(context) {
|
55
57
|
|
56
58
|
// merge rules with default
|
57
|
-
const rule = {
|
58
|
-
option = context.options[0] || {};
|
59
|
+
const rule = Object.assign({}, context.options[0]);
|
59
60
|
|
60
|
-
rule.before =
|
61
|
-
rule.after =
|
61
|
+
rule.before = rule.before !== false;
|
62
|
+
rule.after = rule.after !== false;
|
62
63
|
|
63
64
|
const sourceCode = context.getSourceCode();
|
64
65
|
|
package/lib/rules/brace-style.js
CHANGED
package/lib/rules/camelcase.js
CHANGED
@@ -25,7 +25,8 @@ module.exports = {
|
|
25
25
|
type: "object",
|
26
26
|
properties: {
|
27
27
|
ignoreDestructuring: {
|
28
|
-
type: "boolean"
|
28
|
+
type: "boolean",
|
29
|
+
default: false
|
29
30
|
},
|
30
31
|
properties: {
|
31
32
|
enum: ["always", "never"]
|
@@ -54,7 +55,7 @@ module.exports = {
|
|
54
55
|
|
55
56
|
const options = context.options[0] || {};
|
56
57
|
let properties = options.properties || "";
|
57
|
-
const ignoreDestructuring = options.ignoreDestructuring
|
58
|
+
const ignoreDestructuring = options.ignoreDestructuring;
|
58
59
|
const allow = options.allow || [];
|
59
60
|
|
60
61
|
if (properties !== "always" && properties !== "never") {
|
@@ -17,12 +17,7 @@ const astUtils = require("../util/ast-utils");
|
|
17
17
|
|
18
18
|
const DEFAULT_IGNORE_PATTERN = astUtils.COMMENTS_IGNORE_PATTERN,
|
19
19
|
WHITESPACE = /\s/g,
|
20
|
-
MAYBE_URL = /^\s*[^:/?#\s]+:\/\/[^?#]
|
21
|
-
DEFAULTS = {
|
22
|
-
ignorePattern: null,
|
23
|
-
ignoreInlineComments: false,
|
24
|
-
ignoreConsecutiveComments: false
|
25
|
-
};
|
20
|
+
MAYBE_URL = /^\s*[^:/?#\s]+:\/\/[^?#]/; // TODO: Combine w/ max-len pattern?
|
26
21
|
|
27
22
|
/*
|
28
23
|
* Base schema body for defining the basic capitalization rule, ignorePattern,
|
@@ -33,17 +28,27 @@ const SCHEMA_BODY = {
|
|
33
28
|
type: "object",
|
34
29
|
properties: {
|
35
30
|
ignorePattern: {
|
36
|
-
type: "string"
|
31
|
+
type: "string",
|
32
|
+
default: ""
|
37
33
|
},
|
38
34
|
ignoreInlineComments: {
|
39
|
-
type: "boolean"
|
35
|
+
type: "boolean",
|
36
|
+
default: false
|
40
37
|
},
|
41
38
|
ignoreConsecutiveComments: {
|
42
|
-
type: "boolean"
|
39
|
+
type: "boolean",
|
40
|
+
default: false
|
43
41
|
}
|
44
42
|
},
|
45
43
|
additionalProperties: false
|
46
44
|
};
|
45
|
+
const DEFAULTS = Object.keys(SCHEMA_BODY.properties).reduce(
|
46
|
+
(obj, current) => {
|
47
|
+
obj[current] = SCHEMA_BODY.properties[current].default;
|
48
|
+
return obj;
|
49
|
+
},
|
50
|
+
{}
|
51
|
+
);
|
47
52
|
|
48
53
|
/**
|
49
54
|
* Get normalized options for either block or line comments from the given
|
@@ -59,11 +64,7 @@ const SCHEMA_BODY = {
|
|
59
64
|
* @param {string} which Either "line" or "block".
|
60
65
|
* @returns {Object} The normalized options.
|
61
66
|
*/
|
62
|
-
function getNormalizedOptions(rawOptions, which) {
|
63
|
-
if (!rawOptions) {
|
64
|
-
return Object.assign({}, DEFAULTS);
|
65
|
-
}
|
66
|
-
|
67
|
+
function getNormalizedOptions(rawOptions = {}, which) {
|
67
68
|
return Object.assign({}, DEFAULTS, rawOptions[which] || rawOptions);
|
68
69
|
}
|
69
70
|
|
@@ -38,7 +38,7 @@ module.exports = {
|
|
38
38
|
}
|
39
39
|
},
|
40
40
|
create(context) {
|
41
|
-
const config =
|
41
|
+
const config = Object.assign({}, context.options[0]);
|
42
42
|
const exceptMethods = new Set(config.exceptMethods || []);
|
43
43
|
|
44
44
|
const stack = [];
|
@@ -28,10 +28,12 @@ module.exports = {
|
|
28
28
|
type: "object",
|
29
29
|
properties: {
|
30
30
|
before: {
|
31
|
-
type: "boolean"
|
31
|
+
type: "boolean",
|
32
|
+
default: false
|
32
33
|
},
|
33
34
|
after: {
|
34
|
-
type: "boolean"
|
35
|
+
type: "boolean",
|
36
|
+
default: true
|
35
37
|
}
|
36
38
|
},
|
37
39
|
additionalProperties: false
|
@@ -50,8 +52,8 @@ module.exports = {
|
|
50
52
|
const tokensAndComments = sourceCode.tokensAndComments;
|
51
53
|
|
52
54
|
const options = {
|
53
|
-
before: context.options[0] ?
|
54
|
-
after: context.options[0] ?
|
55
|
+
before: context.options[0] ? context.options[0].before : false,
|
56
|
+
after: context.options[0] ? context.options[0].after : true
|
55
57
|
};
|
56
58
|
|
57
59
|
//--------------------------------------------------------------------------
|
@@ -118,6 +120,10 @@ module.exports = {
|
|
118
120
|
report(reportItem, "before", tokens.left);
|
119
121
|
}
|
120
122
|
|
123
|
+
if (tokens.right && astUtils.isClosingParenToken(tokens.right)) {
|
124
|
+
return;
|
125
|
+
}
|
126
|
+
|
121
127
|
if (tokens.right && !options.after && tokens.right.type === "Line") {
|
122
128
|
return;
|
123
129
|
}
|
package/lib/rules/complexity.js
CHANGED
@@ -41,11 +41,13 @@ module.exports = {
|
|
41
41
|
properties: {
|
42
42
|
maximum: {
|
43
43
|
type: "integer",
|
44
|
-
minimum: 0
|
44
|
+
minimum: 0,
|
45
|
+
default: 20
|
45
46
|
},
|
46
47
|
max: {
|
47
48
|
type: "integer",
|
48
|
-
minimum: 0
|
49
|
+
minimum: 0,
|
50
|
+
default: 20
|
49
51
|
}
|
50
52
|
},
|
51
53
|
additionalProperties: false
|
@@ -63,13 +65,9 @@ module.exports = {
|
|
63
65
|
const option = context.options[0];
|
64
66
|
let THRESHOLD = 20;
|
65
67
|
|
66
|
-
if (typeof option === "object"
|
67
|
-
THRESHOLD = option.maximum;
|
68
|
-
}
|
69
|
-
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
|
70
|
-
THRESHOLD = option.max;
|
71
|
-
}
|
72
|
-
if (typeof option === "number") {
|
68
|
+
if (typeof option === "object") {
|
69
|
+
THRESHOLD = option.maximum || option.max;
|
70
|
+
} else if (typeof option === "number") {
|
73
71
|
THRESHOLD = option;
|
74
72
|
}
|
75
73
|
|
@@ -33,10 +33,12 @@ module.exports = {
|
|
33
33
|
type: "object",
|
34
34
|
properties: {
|
35
35
|
allowKeywords: {
|
36
|
-
type: "boolean"
|
36
|
+
type: "boolean",
|
37
|
+
default: true
|
37
38
|
},
|
38
39
|
allowPattern: {
|
39
|
-
type: "string"
|
40
|
+
type: "string",
|
41
|
+
default: ""
|
40
42
|
}
|
41
43
|
},
|
42
44
|
additionalProperties: false
|
@@ -53,7 +55,7 @@ module.exports = {
|
|
53
55
|
|
54
56
|
create(context) {
|
55
57
|
const options = context.options[0] || {};
|
56
|
-
const allowKeywords = options.allowKeywords === void 0 ||
|
58
|
+
const allowKeywords = options.allowKeywords === void 0 || options.allowKeywords;
|
57
59
|
const sourceCode = context.getSourceCode();
|
58
60
|
|
59
61
|
let allowPattern;
|
package/lib/rules/eqeqeq.js
CHANGED
@@ -42,6 +42,23 @@ module.exports = {
|
|
42
42
|
});
|
43
43
|
}
|
44
44
|
|
45
|
+
/**
|
46
|
+
* check the right side of the assignment
|
47
|
+
* @param {ASTNode} update UpdateExpression to check
|
48
|
+
* @param {int} dir expected direction that could either be turned around or invalidated
|
49
|
+
* @returns {int} return dir, the negated dir or zero if it's not clear for identifiers
|
50
|
+
*/
|
51
|
+
function getRightDirection(update, dir) {
|
52
|
+
if (update.right.type === "UnaryExpression") {
|
53
|
+
if (update.right.operator === "-") {
|
54
|
+
return -dir;
|
55
|
+
}
|
56
|
+
} else if (update.right.type === "Identifier") {
|
57
|
+
return 0;
|
58
|
+
}
|
59
|
+
return dir;
|
60
|
+
}
|
61
|
+
|
45
62
|
/**
|
46
63
|
* check UpdateExpression add/sub the counter
|
47
64
|
* @param {ASTNode} update UpdateExpression to check
|
@@ -69,10 +86,10 @@ module.exports = {
|
|
69
86
|
function getAssignmentDirection(update, counter) {
|
70
87
|
if (update.left.name === counter) {
|
71
88
|
if (update.operator === "+=") {
|
72
|
-
return 1;
|
89
|
+
return getRightDirection(update, 1);
|
73
90
|
}
|
74
91
|
if (update.operator === "-=") {
|
75
|
-
return -1;
|
92
|
+
return getRightDirection(update, -1);
|
76
93
|
}
|
77
94
|
}
|
78
95
|
return 0;
|
@@ -85,26 +102,22 @@ module.exports = {
|
|
85
102
|
const operator = node.test.operator;
|
86
103
|
const update = node.update;
|
87
104
|
|
88
|
-
|
89
|
-
|
90
|
-
// report error if update sub the counter (--, -=)
|
91
|
-
if (update.type === "UpdateExpression" && getUpdateDirection(update, counter) < 0) {
|
92
|
-
report(node);
|
93
|
-
}
|
105
|
+
let wrongDirection;
|
94
106
|
|
95
|
-
|
96
|
-
|
97
|
-
}
|
107
|
+
if (operator === "<" || operator === "<=") {
|
108
|
+
wrongDirection = -1;
|
98
109
|
} else if (operator === ">" || operator === ">=") {
|
110
|
+
wrongDirection = 1;
|
111
|
+
} else {
|
112
|
+
return;
|
113
|
+
}
|
99
114
|
|
100
|
-
|
101
|
-
if (
|
102
|
-
report(node);
|
103
|
-
}
|
104
|
-
|
105
|
-
if (update.type === "AssignmentExpression" && getAssignmentDirection(update, counter) > 0) {
|
115
|
+
if (update.type === "UpdateExpression") {
|
116
|
+
if (getUpdateDirection(update, counter) === wrongDirection) {
|
106
117
|
report(node);
|
107
118
|
}
|
119
|
+
} else if (update.type === "AssignmentExpression" && getAssignmentDirection(update, counter) === wrongDirection) {
|
120
|
+
report(node);
|
108
121
|
}
|
109
122
|
}
|
110
123
|
}
|
package/lib/rules/func-style.js
CHANGED
@@ -27,7 +27,8 @@ module.exports = {
|
|
27
27
|
type: "object",
|
28
28
|
properties: {
|
29
29
|
allowArrowFunctions: {
|
30
|
-
type: "boolean"
|
30
|
+
type: "boolean",
|
31
|
+
default: false
|
31
32
|
}
|
32
33
|
},
|
33
34
|
additionalProperties: false
|
@@ -43,7 +44,7 @@ module.exports = {
|
|
43
44
|
create(context) {
|
44
45
|
|
45
46
|
const style = context.options[0],
|
46
|
-
allowArrowFunctions = context.options[1] && context.options[1].allowArrowFunctions
|
47
|
+
allowArrowFunctions = context.options[1] && context.options[1].allowArrowFunctions,
|
47
48
|
enforceDeclarations = (style === "declaration"),
|
48
49
|
stack = [];
|
49
50
|
|
@@ -57,7 +57,10 @@ module.exports = {
|
|
57
57
|
url: "https://eslint.org/docs/rules/global-require"
|
58
58
|
},
|
59
59
|
|
60
|
-
schema: []
|
60
|
+
schema: [],
|
61
|
+
messages: {
|
62
|
+
unexpected: "Unexpected require()."
|
63
|
+
}
|
61
64
|
},
|
62
65
|
|
63
66
|
create(context) {
|
@@ -69,7 +72,7 @@ module.exports = {
|
|
69
72
|
const isGoodRequire = context.getAncestors().every(parent => ACCEPTABLE_PARENTS.indexOf(parent.type) > -1);
|
70
73
|
|
71
74
|
if (!isGoodRequire) {
|
72
|
-
context.report({ node,
|
75
|
+
context.report({ node, messageId: "unexpected" });
|
73
76
|
}
|
74
77
|
}
|
75
78
|
}
|
@@ -20,7 +20,10 @@ module.exports = {
|
|
20
20
|
url: "https://eslint.org/docs/rules/guard-for-in"
|
21
21
|
},
|
22
22
|
|
23
|
-
schema: []
|
23
|
+
schema: [],
|
24
|
+
messages: {
|
25
|
+
wrap: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype."
|
26
|
+
}
|
24
27
|
},
|
25
28
|
|
26
29
|
create(context) {
|
@@ -65,7 +68,7 @@ module.exports = {
|
|
65
68
|
}
|
66
69
|
}
|
67
70
|
|
68
|
-
context.report({ node,
|
71
|
+
context.report({ node, messageId: "wrap" });
|
69
72
|
}
|
70
73
|
};
|
71
74
|
|
@@ -24,7 +24,10 @@ module.exports = {
|
|
24
24
|
{
|
25
25
|
type: "string"
|
26
26
|
}
|
27
|
-
]
|
27
|
+
],
|
28
|
+
messages: {
|
29
|
+
expected: "Expected error to be handled."
|
30
|
+
}
|
28
31
|
},
|
29
32
|
|
30
33
|
create(context) {
|
@@ -77,7 +80,7 @@ module.exports = {
|
|
77
80
|
|
78
81
|
if (firstParameter && matchesConfiguredErrorName(firstParameter.name)) {
|
79
82
|
if (firstParameter.references.length === 0) {
|
80
|
-
context.report({ node,
|
83
|
+
context.report({ node, messageId: "expected" });
|
81
84
|
}
|
82
85
|
}
|
83
86
|
}
|