eslint 7.6.0 → 7.9.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.
Files changed (39) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/README.md +25 -15
  3. package/conf/config-schema.js +12 -0
  4. package/lib/cli-engine/cascading-config-array-factory.js +12 -0
  5. package/lib/cli-engine/cli-engine.js +2 -2
  6. package/lib/cli-engine/config-array/config-array.js +12 -0
  7. package/lib/cli-engine/config-array/config-dependency.js +12 -0
  8. package/lib/cli-engine/config-array/extracted-config.js +12 -0
  9. package/lib/cli-engine/config-array/ignore-pattern.js +12 -0
  10. package/lib/cli-engine/config-array/index.js +12 -0
  11. package/lib/cli-engine/config-array/override-tester.js +12 -0
  12. package/lib/cli-engine/config-array-factory.js +24 -6
  13. package/lib/eslint/eslint.js +7 -1
  14. package/lib/init/autoconfig.js +1 -1
  15. package/lib/init/config-initializer.js +3 -3
  16. package/lib/linter/code-path-analysis/code-path-analyzer.js +38 -0
  17. package/lib/linter/code-path-analysis/code-path-state.js +2 -2
  18. package/lib/linter/config-comment-parser.js +1 -1
  19. package/lib/linter/linter.js +6 -3
  20. package/lib/rules/comma-dangle.js +1 -2
  21. package/lib/rules/constructor-super.js +17 -1
  22. package/lib/rules/id-length.js +20 -7
  23. package/lib/rules/indent.js +4 -3
  24. package/lib/rules/no-loss-of-precision.js +10 -2
  25. package/lib/rules/no-magic-numbers.js +20 -3
  26. package/lib/rules/no-underscore-dangle.js +66 -21
  27. package/lib/rules/no-warning-comments.js +40 -7
  28. package/lib/rules/operator-assignment.js +1 -1
  29. package/lib/rules/prefer-destructuring.js +5 -0
  30. package/lib/rules/prefer-numeric-literals.js +10 -0
  31. package/lib/rules/utils/ast-utils.js +49 -13
  32. package/lib/shared/config-validator.js +14 -2
  33. package/lib/shared/relative-module-resolver.js +12 -0
  34. package/lib/shared/types.js +1 -1
  35. package/messages/plugin-invalid.txt +8 -0
  36. package/package.json +3 -3
  37. package/conf/environments.js +0 -168
  38. package/lib/shared/config-ops.js +0 -130
  39. package/lib/shared/naming.js +0 -97
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "7.6.0",
3
+ "version": "7.9.0",
4
4
  "author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
5
5
  "description": "An AST-based pattern checker for JavaScript.",
6
6
  "bin": {
@@ -47,6 +47,7 @@
47
47
  "bugs": "https://github.com/eslint/eslint/issues/",
48
48
  "dependencies": {
49
49
  "@babel/code-frame": "^7.0.0",
50
+ "@eslint/eslintrc": "^0.1.3",
50
51
  "ajv": "^6.10.0",
51
52
  "chalk": "^4.0.0",
52
53
  "cross-spawn": "^7.0.2",
@@ -56,7 +57,7 @@
56
57
  "eslint-scope": "^5.1.0",
57
58
  "eslint-utils": "^2.1.0",
58
59
  "eslint-visitor-keys": "^1.3.0",
59
- "espree": "^7.2.0",
60
+ "espree": "^7.3.0",
60
61
  "esquery": "^1.2.0",
61
62
  "esutils": "^2.0.2",
62
63
  "file-entry-cache": "^5.0.1",
@@ -111,7 +112,6 @@
111
112
  "karma-mocha": "^1.3.0",
112
113
  "karma-mocha-reporter": "^2.2.3",
113
114
  "karma-webpack": "^4.0.0-rc.6",
114
- "leche": "^2.2.3",
115
115
  "lint-staged": "^10.1.2",
116
116
  "load-perf": "^0.2.0",
117
117
  "markdownlint": "^0.19.0",
@@ -1,168 +0,0 @@
1
- /**
2
- * @fileoverview Defines environment settings and globals.
3
- * @author Elan Shanker
4
- */
5
- "use strict";
6
-
7
- //------------------------------------------------------------------------------
8
- // Requirements
9
- //------------------------------------------------------------------------------
10
-
11
- const globals = require("globals");
12
-
13
- //------------------------------------------------------------------------------
14
- // Helpers
15
- //------------------------------------------------------------------------------
16
-
17
- /**
18
- * Get the object that has difference.
19
- * @param {Record<string,boolean>} current The newer object.
20
- * @param {Record<string,boolean>} prev The older object.
21
- * @returns {Record<string,boolean>} The difference object.
22
- */
23
- function getDiff(current, prev) {
24
- const retv = {};
25
-
26
- for (const [key, value] of Object.entries(current)) {
27
- if (!Object.hasOwnProperty.call(prev, key)) {
28
- retv[key] = value;
29
- }
30
- }
31
-
32
- return retv;
33
- }
34
-
35
- const newGlobals2015 = getDiff(globals.es2015, globals.es5); // 19 variables such as Promise, Map, ...
36
- const newGlobals2017 = {
37
- Atomics: false,
38
- SharedArrayBuffer: false
39
- };
40
- const newGlobals2020 = {
41
- BigInt: false,
42
- BigInt64Array: false,
43
- BigUint64Array: false,
44
- globalThis: false
45
- };
46
-
47
- //------------------------------------------------------------------------------
48
- // Public Interface
49
- //------------------------------------------------------------------------------
50
-
51
- /** @type {Map<string, import("../lib/shared/types").Environment>} */
52
- module.exports = new Map(Object.entries({
53
-
54
- // Language
55
- builtin: {
56
- globals: globals.es5
57
- },
58
- es6: {
59
- globals: newGlobals2015,
60
- parserOptions: {
61
- ecmaVersion: 6
62
- }
63
- },
64
- es2015: {
65
- globals: newGlobals2015,
66
- parserOptions: {
67
- ecmaVersion: 6
68
- }
69
- },
70
- es2017: {
71
- globals: { ...newGlobals2015, ...newGlobals2017 },
72
- parserOptions: {
73
- ecmaVersion: 8
74
- }
75
- },
76
- es2020: {
77
- globals: { ...newGlobals2015, ...newGlobals2017, ...newGlobals2020 },
78
- parserOptions: {
79
- ecmaVersion: 11
80
- }
81
- },
82
-
83
- // Platforms
84
- browser: {
85
- globals: globals.browser
86
- },
87
- node: {
88
- globals: globals.node,
89
- parserOptions: {
90
- ecmaFeatures: {
91
- globalReturn: true
92
- }
93
- }
94
- },
95
- "shared-node-browser": {
96
- globals: globals["shared-node-browser"]
97
- },
98
- worker: {
99
- globals: globals.worker
100
- },
101
- serviceworker: {
102
- globals: globals.serviceworker
103
- },
104
-
105
- // Frameworks
106
- commonjs: {
107
- globals: globals.commonjs,
108
- parserOptions: {
109
- ecmaFeatures: {
110
- globalReturn: true
111
- }
112
- }
113
- },
114
- amd: {
115
- globals: globals.amd
116
- },
117
- mocha: {
118
- globals: globals.mocha
119
- },
120
- jasmine: {
121
- globals: globals.jasmine
122
- },
123
- jest: {
124
- globals: globals.jest
125
- },
126
- phantomjs: {
127
- globals: globals.phantomjs
128
- },
129
- jquery: {
130
- globals: globals.jquery
131
- },
132
- qunit: {
133
- globals: globals.qunit
134
- },
135
- prototypejs: {
136
- globals: globals.prototypejs
137
- },
138
- shelljs: {
139
- globals: globals.shelljs
140
- },
141
- meteor: {
142
- globals: globals.meteor
143
- },
144
- mongo: {
145
- globals: globals.mongo
146
- },
147
- protractor: {
148
- globals: globals.protractor
149
- },
150
- applescript: {
151
- globals: globals.applescript
152
- },
153
- nashorn: {
154
- globals: globals.nashorn
155
- },
156
- atomtest: {
157
- globals: globals.atomtest
158
- },
159
- embertest: {
160
- globals: globals.embertest
161
- },
162
- webextensions: {
163
- globals: globals.webextensions
164
- },
165
- greasemonkey: {
166
- globals: globals.greasemonkey
167
- }
168
- }));
@@ -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
- };
@@ -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
- };