eslint 7.4.0 → 7.8.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 (93) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/README.md +29 -17
  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 +13 -1
  13. package/lib/cli-engine/formatters/checkstyle.js +2 -2
  14. package/lib/eslint/eslint.js +7 -1
  15. package/lib/init/autoconfig.js +1 -1
  16. package/lib/init/config-initializer.js +3 -3
  17. package/lib/linter/code-path-analysis/code-path-analyzer.js +76 -0
  18. package/lib/linter/code-path-analysis/code-path-segment.js +0 -1
  19. package/lib/linter/code-path-analysis/code-path-state.js +61 -2
  20. package/lib/linter/code-path-analysis/debug-helpers.js +26 -19
  21. package/lib/linter/config-comment-parser.js +1 -1
  22. package/lib/linter/linter.js +6 -3
  23. package/lib/rule-tester/rule-tester.js +10 -0
  24. package/lib/rules/accessor-pairs.js +1 -14
  25. package/lib/rules/array-callback-return.js +5 -7
  26. package/lib/rules/arrow-body-style.js +41 -6
  27. package/lib/rules/comma-dangle.js +1 -2
  28. package/lib/rules/consistent-return.js +1 -12
  29. package/lib/rules/constructor-super.js +18 -1
  30. package/lib/rules/dot-location.js +20 -14
  31. package/lib/rules/dot-notation.js +36 -33
  32. package/lib/rules/func-call-spacing.js +42 -6
  33. package/lib/rules/func-name-matching.js +1 -4
  34. package/lib/rules/global-require.js +2 -1
  35. package/lib/rules/id-blacklist.js +233 -0
  36. package/lib/rules/id-length.js +19 -1
  37. package/lib/rules/indent.js +23 -3
  38. package/lib/rules/index.js +1 -3
  39. package/lib/rules/keyword-spacing.js +2 -2
  40. package/lib/rules/max-len.js +13 -2
  41. package/lib/rules/new-cap.js +10 -14
  42. package/lib/rules/newline-per-chained-call.js +15 -5
  43. package/lib/rules/no-alert.js +10 -3
  44. package/lib/rules/no-duplicate-case.js +23 -4
  45. package/lib/rules/no-eval.js +8 -38
  46. package/lib/rules/no-extend-native.js +37 -40
  47. package/lib/rules/no-extra-bind.js +57 -17
  48. package/lib/rules/no-extra-boolean-cast.js +7 -0
  49. package/lib/rules/no-extra-parens.js +27 -7
  50. package/lib/rules/no-implicit-coercion.js +11 -6
  51. package/lib/rules/no-implied-eval.js +7 -28
  52. package/lib/rules/no-import-assign.js +33 -32
  53. package/lib/rules/no-irregular-whitespace.js +22 -12
  54. package/lib/rules/no-loss-of-precision.js +10 -2
  55. package/lib/rules/no-magic-numbers.js +24 -11
  56. package/lib/rules/no-obj-calls.js +7 -4
  57. package/lib/rules/no-prototype-builtins.js +13 -3
  58. package/lib/rules/no-self-assign.js +3 -53
  59. package/lib/rules/no-setter-return.js +5 -8
  60. package/lib/rules/no-underscore-dangle.js +66 -21
  61. package/lib/rules/no-unexpected-multiline.js +2 -2
  62. package/lib/rules/no-unneeded-ternary.js +0 -2
  63. package/lib/rules/no-unused-expressions.js +55 -23
  64. package/lib/rules/no-useless-call.js +10 -7
  65. package/lib/rules/no-warning-comments.js +40 -7
  66. package/lib/rules/no-whitespace-before-property.js +16 -4
  67. package/lib/rules/object-curly-newline.js +4 -4
  68. package/lib/rules/operator-assignment.js +4 -43
  69. package/lib/rules/padding-line-between-statements.js +2 -2
  70. package/lib/rules/prefer-arrow-callback.js +90 -25
  71. package/lib/rules/prefer-exponentiation-operator.js +1 -1
  72. package/lib/rules/prefer-numeric-literals.js +14 -13
  73. package/lib/rules/prefer-promise-reject-errors.js +1 -3
  74. package/lib/rules/prefer-regex-literals.js +2 -5
  75. package/lib/rules/prefer-spread.js +2 -6
  76. package/lib/rules/radix.js +5 -2
  77. package/lib/rules/sort-imports.js +28 -0
  78. package/lib/rules/use-isnan.js +1 -1
  79. package/lib/rules/utils/ast-utils.js +363 -165
  80. package/lib/rules/wrap-iife.js +9 -2
  81. package/lib/rules/yoda.js +2 -55
  82. package/lib/shared/config-validator.js +14 -2
  83. package/lib/shared/relative-module-resolver.js +12 -0
  84. package/lib/shared/types.js +1 -1
  85. package/messages/extend-config-missing.txt +1 -1
  86. package/messages/no-config-found.txt +1 -1
  87. package/messages/plugin-conflict.txt +1 -1
  88. package/messages/plugin-missing.txt +1 -1
  89. package/messages/whitespace-found.txt +1 -1
  90. package/package.json +7 -7
  91. package/conf/environments.js +0 -168
  92. package/lib/shared/config-ops.js +0 -130
  93. package/lib/shared/naming.js +0 -97
package/lib/rules/yoda.js CHANGED
@@ -111,59 +111,6 @@ function getNormalizedLiteral(node) {
111
111
  return null;
112
112
  }
113
113
 
114
- /**
115
- * Checks whether two expressions reference the same value. For example:
116
- * a = a
117
- * a.b = a.b
118
- * a[0] = a[0]
119
- * a['b'] = a['b']
120
- * @param {ASTNode} a Left side of the comparison.
121
- * @param {ASTNode} b Right side of the comparison.
122
- * @returns {boolean} True if both sides match and reference the same value.
123
- */
124
- function same(a, b) {
125
- if (a.type !== b.type) {
126
- return false;
127
- }
128
-
129
- switch (a.type) {
130
- case "Identifier":
131
- return a.name === b.name;
132
-
133
- case "Literal":
134
- return a.value === b.value;
135
-
136
- case "MemberExpression": {
137
- const nameA = astUtils.getStaticPropertyName(a);
138
-
139
- // x.y = x["y"]
140
- if (nameA !== null) {
141
- return (
142
- same(a.object, b.object) &&
143
- nameA === astUtils.getStaticPropertyName(b)
144
- );
145
- }
146
-
147
- /*
148
- * x[0] = x[0]
149
- * x[y] = x[y]
150
- * x.y = x.y
151
- */
152
- return (
153
- a.computed === b.computed &&
154
- same(a.object, b.object) &&
155
- same(a.property, b.property)
156
- );
157
- }
158
-
159
- case "ThisExpression":
160
- return true;
161
-
162
- default:
163
- return false;
164
- }
165
- }
166
-
167
114
  //------------------------------------------------------------------------------
168
115
  // Rule Definition
169
116
  //------------------------------------------------------------------------------
@@ -236,7 +183,7 @@ module.exports = {
236
183
  * @returns {boolean} Whether node is a "between" range test.
237
184
  */
238
185
  function isBetweenTest() {
239
- if (node.operator === "&&" && same(left.right, right.left)) {
186
+ if (node.operator === "&&" && astUtils.isSameReference(left.right, right.left)) {
240
187
  const leftLiteral = getNormalizedLiteral(left.left);
241
188
  const rightLiteral = getNormalizedLiteral(right.right);
242
189
 
@@ -260,7 +207,7 @@ module.exports = {
260
207
  * @returns {boolean} Whether node is an "outside" range test.
261
208
  */
262
209
  function isOutsideTest() {
263
- if (node.operator === "||" && same(left.left, right.right)) {
210
+ if (node.operator === "||" && astUtils.isSameReference(left.left, right.right)) {
264
211
  const leftLiteral = getNormalizedLiteral(left.right);
265
212
  const rightLiteral = getNormalizedLiteral(right.left);
266
213
 
@@ -1,3 +1,15 @@
1
+ /*
2
+ * STOP!!! DO NOT MODIFY.
3
+ *
4
+ * This file is part of the ongoing work to move the eslintrc-style config
5
+ * system into the @eslint/eslintrc package. This file needs to remain
6
+ * unchanged in order for this work to proceed.
7
+ *
8
+ * If you think you need to change this file, please contact @nzakas first.
9
+ *
10
+ * Thanks in advance for your cooperation.
11
+ */
12
+
1
13
  /**
2
14
  * @fileoverview Validates configs.
3
15
  * @author Brandon Mills
@@ -12,9 +24,9 @@
12
24
  const
13
25
  util = require("util"),
14
26
  configSchema = require("../../conf/config-schema"),
15
- BuiltInEnvironments = require("../../conf/environments"),
27
+ BuiltInEnvironments = require("@eslint/eslintrc/conf/environments"),
16
28
  BuiltInRules = require("../rules"),
17
- ConfigOps = require("./config-ops"),
29
+ ConfigOps = require("@eslint/eslintrc/lib/shared/config-ops"),
18
30
  { emitDeprecationWarning } = require("./deprecation-warnings");
19
31
 
20
32
  const ajv = require("./ajv")();
@@ -1,3 +1,15 @@
1
+ /*
2
+ * STOP!!! DO NOT MODIFY.
3
+ *
4
+ * This file is part of the ongoing work to move the eslintrc-style config
5
+ * system into the @eslint/eslintrc package. This file needs to remain
6
+ * unchanged in order for this work to proceed.
7
+ *
8
+ * If you think you need to change this file, please contact @nzakas first.
9
+ *
10
+ * Thanks in advance for your cooperation.
11
+ */
12
+
1
13
  /**
2
14
  * Utility for resolving a module relative to another module
3
15
  * @author Teddy Katz
@@ -21,7 +21,7 @@ module.exports = {};
21
21
  /**
22
22
  * @typedef {Object} ParserOptions
23
23
  * @property {EcmaFeatures} [ecmaFeatures] The optional features.
24
- * @property {3|5|6|7|8|9|10|11|2015|2016|2017|2018|2019|2020} [ecmaVersion] The ECMAScript version (or revision number).
24
+ * @property {3|5|6|7|8|9|10|11|12|2015|2016|2017|2018|2019|2020|2021} [ecmaVersion] The ECMAScript version (or revision number).
25
25
  * @property {"script"|"module"} [sourceType] The source code type.
26
26
  */
27
27
 
@@ -2,4 +2,4 @@ ESLint couldn't find the config "<%- configName %>" to extend from. Please check
2
2
 
3
3
  The config "<%- configName %>" was referenced from the config file in "<%- importerName %>".
4
4
 
5
- If you still have problems, please stop by https://eslint.org/chat to chat with the team.
5
+ If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.
@@ -4,4 +4,4 @@ ESLint couldn't find a configuration file. To set up a configuration file for th
4
4
 
5
5
  ESLint looked for configuration files in <%= directoryPath %> and its ancestors. If it found none, it then looked in your home directory.
6
6
 
7
- If you think you already have a configuration file or if you need more help, please stop by the ESLint chat room: https://eslint.org/chat
7
+ If you think you already have a configuration file or if you need more help, please stop by the ESLint chat room: https://eslint.org/chat/help
@@ -4,4 +4,4 @@ ESLint couldn't determine the plugin "<%- pluginId %>" uniquely.
4
4
 
5
5
  Please remove the "plugins" setting from either config or remove either plugin installation.
6
6
 
7
- If you still can't figure out the problem, please stop by https://eslint.org/chat to chat with the team.
7
+ If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.
@@ -8,4 +8,4 @@ It's likely that the plugin isn't installed correctly. Try reinstalling by runni
8
8
 
9
9
  The plugin "<%- pluginName %>" was referenced from the config file in "<%- importerName %>".
10
10
 
11
- If you still can't figure out the problem, please stop by https://eslint.org/chat to chat with the team.
11
+ If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.
@@ -1,3 +1,3 @@
1
1
  ESLint couldn't find the plugin "<%- pluginName %>". because there is whitespace in the name. Please check your configuration and remove all whitespace from the plugin name.
2
2
 
3
- If you still can't figure out the problem, please stop by https://eslint.org/chat to chat with the team.
3
+ If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint",
3
- "version": "7.4.0",
3
+ "version": "7.8.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.0",
50
51
  "ajv": "^6.10.0",
51
52
  "chalk": "^4.0.0",
52
53
  "cross-spawn": "^7.0.2",
@@ -54,9 +55,9 @@
54
55
  "doctrine": "^3.0.0",
55
56
  "enquirer": "^2.3.5",
56
57
  "eslint-scope": "^5.1.0",
57
- "eslint-utils": "^2.0.0",
58
- "eslint-visitor-keys": "^1.2.0",
59
- "espree": "^7.1.0",
58
+ "eslint-utils": "^2.1.0",
59
+ "eslint-visitor-keys": "^1.3.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",
@@ -70,7 +71,7 @@
70
71
  "js-yaml": "^3.13.1",
71
72
  "json-stable-stringify-without-jsonify": "^1.0.1",
72
73
  "levn": "^0.4.1",
73
- "lodash": "^4.17.14",
74
+ "lodash": "^4.17.19",
74
75
  "minimatch": "^3.0.4",
75
76
  "natural-compare": "^1.4.0",
76
77
  "optionator": "^0.9.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",
@@ -122,7 +122,7 @@
122
122
  "npm-license": "^0.3.3",
123
123
  "nyc": "^15.0.1",
124
124
  "proxyquire": "^2.0.1",
125
- "puppeteer": "^2.1.1",
125
+ "puppeteer": "^4.0.0",
126
126
  "recast": "^0.19.0",
127
127
  "regenerator-runtime": "^0.13.2",
128
128
  "shelljs": "^0.8.2",
@@ -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
- };