eslint 7.7.0 → 7.10.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 +67 -0
- package/README.md +1 -1
- package/conf/config-schema.js +12 -0
- package/lib/cli-engine/cascading-config-array-factory.js +12 -0
- package/lib/cli-engine/cli-engine.js +2 -2
- package/lib/cli-engine/config-array/config-array.js +12 -0
- package/lib/cli-engine/config-array/config-dependency.js +12 -0
- package/lib/cli-engine/config-array/extracted-config.js +12 -0
- package/lib/cli-engine/config-array/ignore-pattern.js +12 -0
- package/lib/cli-engine/config-array/index.js +12 -0
- package/lib/cli-engine/config-array/override-tester.js +12 -0
- package/lib/cli-engine/config-array-factory.js +24 -6
- package/lib/eslint/eslint.js +7 -1
- package/lib/init/autoconfig.js +1 -1
- package/lib/init/config-initializer.js +3 -3
- package/lib/linter/code-path-analysis/code-path-analyzer.js +38 -0
- package/lib/linter/code-path-analysis/code-path-state.js +2 -2
- package/lib/linter/config-comment-parser.js +1 -1
- package/lib/linter/linter.js +6 -3
- package/lib/rules/constructor-super.js +17 -1
- package/lib/rules/id-length.js +20 -7
- package/lib/rules/no-inline-comments.js +25 -4
- package/lib/rules/no-loss-of-precision.js +10 -2
- package/lib/rules/no-magic-numbers.js +20 -3
- package/lib/rules/no-warning-comments.js +40 -7
- package/lib/rules/operator-assignment.js +1 -1
- package/lib/rules/prefer-destructuring.js +7 -0
- package/lib/rules/prefer-numeric-literals.js +10 -0
- package/lib/rules/utils/ast-utils.js +49 -13
- package/lib/shared/config-validator.js +14 -2
- package/lib/shared/relative-module-resolver.js +12 -0
- package/lib/shared/types.js +1 -1
- package/messages/plugin-invalid.txt +8 -0
- package/package.json +4 -3
- package/conf/environments.js +0 -168
- package/lib/shared/config-ops.js +0 -130
- package/lib/shared/naming.js +0 -97
package/lib/shared/config-ops.js
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @fileoverview Config file operations. This file must be usable in the browser,
|
3
|
-
* so no Node-specific code can be here.
|
4
|
-
* @author Nicholas C. Zakas
|
5
|
-
*/
|
6
|
-
"use strict";
|
7
|
-
|
8
|
-
//------------------------------------------------------------------------------
|
9
|
-
// Private
|
10
|
-
//------------------------------------------------------------------------------
|
11
|
-
|
12
|
-
const RULE_SEVERITY_STRINGS = ["off", "warn", "error"],
|
13
|
-
RULE_SEVERITY = RULE_SEVERITY_STRINGS.reduce((map, value, index) => {
|
14
|
-
map[value] = index;
|
15
|
-
return map;
|
16
|
-
}, {}),
|
17
|
-
VALID_SEVERITIES = [0, 1, 2, "off", "warn", "error"];
|
18
|
-
|
19
|
-
//------------------------------------------------------------------------------
|
20
|
-
// Public Interface
|
21
|
-
//------------------------------------------------------------------------------
|
22
|
-
|
23
|
-
module.exports = {
|
24
|
-
|
25
|
-
/**
|
26
|
-
* Normalizes the severity value of a rule's configuration to a number
|
27
|
-
* @param {(number|string|[number, ...*]|[string, ...*])} ruleConfig A rule's configuration value, generally
|
28
|
-
* received from the user. A valid config value is either 0, 1, 2, the string "off" (treated the same as 0),
|
29
|
-
* the string "warn" (treated the same as 1), the string "error" (treated the same as 2), or an array
|
30
|
-
* whose first element is one of the above values. Strings are matched case-insensitively.
|
31
|
-
* @returns {(0|1|2)} The numeric severity value if the config value was valid, otherwise 0.
|
32
|
-
*/
|
33
|
-
getRuleSeverity(ruleConfig) {
|
34
|
-
const severityValue = Array.isArray(ruleConfig) ? ruleConfig[0] : ruleConfig;
|
35
|
-
|
36
|
-
if (severityValue === 0 || severityValue === 1 || severityValue === 2) {
|
37
|
-
return severityValue;
|
38
|
-
}
|
39
|
-
|
40
|
-
if (typeof severityValue === "string") {
|
41
|
-
return RULE_SEVERITY[severityValue.toLowerCase()] || 0;
|
42
|
-
}
|
43
|
-
|
44
|
-
return 0;
|
45
|
-
},
|
46
|
-
|
47
|
-
/**
|
48
|
-
* Converts old-style severity settings (0, 1, 2) into new-style
|
49
|
-
* severity settings (off, warn, error) for all rules. Assumption is that severity
|
50
|
-
* values have already been validated as correct.
|
51
|
-
* @param {Object} config The config object to normalize.
|
52
|
-
* @returns {void}
|
53
|
-
*/
|
54
|
-
normalizeToStrings(config) {
|
55
|
-
|
56
|
-
if (config.rules) {
|
57
|
-
Object.keys(config.rules).forEach(ruleId => {
|
58
|
-
const ruleConfig = config.rules[ruleId];
|
59
|
-
|
60
|
-
if (typeof ruleConfig === "number") {
|
61
|
-
config.rules[ruleId] = RULE_SEVERITY_STRINGS[ruleConfig] || RULE_SEVERITY_STRINGS[0];
|
62
|
-
} else if (Array.isArray(ruleConfig) && typeof ruleConfig[0] === "number") {
|
63
|
-
ruleConfig[0] = RULE_SEVERITY_STRINGS[ruleConfig[0]] || RULE_SEVERITY_STRINGS[0];
|
64
|
-
}
|
65
|
-
});
|
66
|
-
}
|
67
|
-
},
|
68
|
-
|
69
|
-
/**
|
70
|
-
* Determines if the severity for the given rule configuration represents an error.
|
71
|
-
* @param {int|string|Array} ruleConfig The configuration for an individual rule.
|
72
|
-
* @returns {boolean} True if the rule represents an error, false if not.
|
73
|
-
*/
|
74
|
-
isErrorSeverity(ruleConfig) {
|
75
|
-
return module.exports.getRuleSeverity(ruleConfig) === 2;
|
76
|
-
},
|
77
|
-
|
78
|
-
/**
|
79
|
-
* Checks whether a given config has valid severity or not.
|
80
|
-
* @param {number|string|Array} ruleConfig The configuration for an individual rule.
|
81
|
-
* @returns {boolean} `true` if the configuration has valid severity.
|
82
|
-
*/
|
83
|
-
isValidSeverity(ruleConfig) {
|
84
|
-
let severity = Array.isArray(ruleConfig) ? ruleConfig[0] : ruleConfig;
|
85
|
-
|
86
|
-
if (typeof severity === "string") {
|
87
|
-
severity = severity.toLowerCase();
|
88
|
-
}
|
89
|
-
return VALID_SEVERITIES.indexOf(severity) !== -1;
|
90
|
-
},
|
91
|
-
|
92
|
-
/**
|
93
|
-
* Checks whether every rule of a given config has valid severity or not.
|
94
|
-
* @param {Object} config The configuration for rules.
|
95
|
-
* @returns {boolean} `true` if the configuration has valid severity.
|
96
|
-
*/
|
97
|
-
isEverySeverityValid(config) {
|
98
|
-
return Object.keys(config).every(ruleId => this.isValidSeverity(config[ruleId]));
|
99
|
-
},
|
100
|
-
|
101
|
-
/**
|
102
|
-
* Normalizes a value for a global in a config
|
103
|
-
* @param {(boolean|string|null)} configuredValue The value given for a global in configuration or in
|
104
|
-
* a global directive comment
|
105
|
-
* @returns {("readable"|"writeable"|"off")} The value normalized as a string
|
106
|
-
* @throws Error if global value is invalid
|
107
|
-
*/
|
108
|
-
normalizeConfigGlobal(configuredValue) {
|
109
|
-
switch (configuredValue) {
|
110
|
-
case "off":
|
111
|
-
return "off";
|
112
|
-
|
113
|
-
case true:
|
114
|
-
case "true":
|
115
|
-
case "writeable":
|
116
|
-
case "writable":
|
117
|
-
return "writable";
|
118
|
-
|
119
|
-
case null:
|
120
|
-
case false:
|
121
|
-
case "false":
|
122
|
-
case "readable":
|
123
|
-
case "readonly":
|
124
|
-
return "readonly";
|
125
|
-
|
126
|
-
default:
|
127
|
-
throw new Error(`'${configuredValue}' is not a valid configuration for a global (use 'readonly', 'writable', or 'off')`);
|
128
|
-
}
|
129
|
-
}
|
130
|
-
};
|
package/lib/shared/naming.js
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @fileoverview Common helpers for naming of plugins, formatters and configs
|
3
|
-
*/
|
4
|
-
"use strict";
|
5
|
-
|
6
|
-
const NAMESPACE_REGEX = /^@.*\//iu;
|
7
|
-
|
8
|
-
/**
|
9
|
-
* Brings package name to correct format based on prefix
|
10
|
-
* @param {string} name The name of the package.
|
11
|
-
* @param {string} prefix Can be either "eslint-plugin", "eslint-config" or "eslint-formatter"
|
12
|
-
* @returns {string} Normalized name of the package
|
13
|
-
* @private
|
14
|
-
*/
|
15
|
-
function normalizePackageName(name, prefix) {
|
16
|
-
let normalizedName = name;
|
17
|
-
|
18
|
-
/**
|
19
|
-
* On Windows, name can come in with Windows slashes instead of Unix slashes.
|
20
|
-
* Normalize to Unix first to avoid errors later on.
|
21
|
-
* https://github.com/eslint/eslint/issues/5644
|
22
|
-
*/
|
23
|
-
if (normalizedName.includes("\\")) {
|
24
|
-
normalizedName = normalizedName.replace(/\\/gu, "/");
|
25
|
-
}
|
26
|
-
|
27
|
-
if (normalizedName.charAt(0) === "@") {
|
28
|
-
|
29
|
-
/**
|
30
|
-
* it's a scoped package
|
31
|
-
* package name is the prefix, or just a username
|
32
|
-
*/
|
33
|
-
const scopedPackageShortcutRegex = new RegExp(`^(@[^/]+)(?:/(?:${prefix})?)?$`, "u"),
|
34
|
-
scopedPackageNameRegex = new RegExp(`^${prefix}(-|$)`, "u");
|
35
|
-
|
36
|
-
if (scopedPackageShortcutRegex.test(normalizedName)) {
|
37
|
-
normalizedName = normalizedName.replace(scopedPackageShortcutRegex, `$1/${prefix}`);
|
38
|
-
} else if (!scopedPackageNameRegex.test(normalizedName.split("/")[1])) {
|
39
|
-
|
40
|
-
/**
|
41
|
-
* for scoped packages, insert the prefix after the first / unless
|
42
|
-
* the path is already @scope/eslint or @scope/eslint-xxx-yyy
|
43
|
-
*/
|
44
|
-
normalizedName = normalizedName.replace(/^@([^/]+)\/(.*)$/u, `@$1/${prefix}-$2`);
|
45
|
-
}
|
46
|
-
} else if (!normalizedName.startsWith(`${prefix}-`)) {
|
47
|
-
normalizedName = `${prefix}-${normalizedName}`;
|
48
|
-
}
|
49
|
-
|
50
|
-
return normalizedName;
|
51
|
-
}
|
52
|
-
|
53
|
-
/**
|
54
|
-
* Removes the prefix from a fullname.
|
55
|
-
* @param {string} fullname The term which may have the prefix.
|
56
|
-
* @param {string} prefix The prefix to remove.
|
57
|
-
* @returns {string} The term without prefix.
|
58
|
-
*/
|
59
|
-
function getShorthandName(fullname, prefix) {
|
60
|
-
if (fullname[0] === "@") {
|
61
|
-
let matchResult = new RegExp(`^(@[^/]+)/${prefix}$`, "u").exec(fullname);
|
62
|
-
|
63
|
-
if (matchResult) {
|
64
|
-
return matchResult[1];
|
65
|
-
}
|
66
|
-
|
67
|
-
matchResult = new RegExp(`^(@[^/]+)/${prefix}-(.+)$`, "u").exec(fullname);
|
68
|
-
if (matchResult) {
|
69
|
-
return `${matchResult[1]}/${matchResult[2]}`;
|
70
|
-
}
|
71
|
-
} else if (fullname.startsWith(`${prefix}-`)) {
|
72
|
-
return fullname.slice(prefix.length + 1);
|
73
|
-
}
|
74
|
-
|
75
|
-
return fullname;
|
76
|
-
}
|
77
|
-
|
78
|
-
/**
|
79
|
-
* Gets the scope (namespace) of a term.
|
80
|
-
* @param {string} term The term which may have the namespace.
|
81
|
-
* @returns {string} The namespace of the term if it has one.
|
82
|
-
*/
|
83
|
-
function getNamespaceFromTerm(term) {
|
84
|
-
const match = term.match(NAMESPACE_REGEX);
|
85
|
-
|
86
|
-
return match ? match[0] : "";
|
87
|
-
}
|
88
|
-
|
89
|
-
//------------------------------------------------------------------------------
|
90
|
-
// Public Interface
|
91
|
-
//------------------------------------------------------------------------------
|
92
|
-
|
93
|
-
module.exports = {
|
94
|
-
normalizePackageName,
|
95
|
-
getShorthandName,
|
96
|
-
getNamespaceFromTerm
|
97
|
-
};
|