@keeex/eslint-config 1.11.6 → 1.12.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/README.md +1 -5
- package/package.json +7 -12
- package/src/bin/eslint-depcheck.js +102 -0
- package/src/config/base.js +1 -0
- package/src/config/deprecation.js +2 -1
- package/src/config/import.js +26 -22
- package/src/config/jsx.js +1 -0
- package/src/config/mocha.js +2 -1
- package/src/config/promise.js +1 -0
- package/src/config/reacthooks.js +1 -0
- package/src/config/reactnative.js +1 -0
- package/src/config/typescript.js +14 -5
- package/src/consts.js +1 -0
- package/src/index.js +41 -21
package/README.md
CHANGED
|
@@ -148,7 +148,6 @@ the following properties:
|
|
|
148
148
|
"test/**/*.js",
|
|
149
149
|
],
|
|
150
150
|
expectHelper: true,
|
|
151
|
-
chai: true,
|
|
152
151
|
}
|
|
153
152
|
```
|
|
154
153
|
|
|
@@ -169,7 +168,4 @@ If React Hooks is enabled, `eslint-plugin-react-hooks` must be installed.
|
|
|
169
168
|
If React Native is enabled, `eslint-plugin-react-native` must be installed.
|
|
170
169
|
Promise support requires `eslint-plugin-promise`.
|
|
171
170
|
If mocha is used as the testsuite, `eslint-plugin-mocha` must be installed.
|
|
172
|
-
|
|
173
|
-
Import support requires `eslint-plugin-import`.
|
|
174
|
-
|
|
175
|
-
If both import and typescript is used, `eslint-import-resolver-typescript` is needed.
|
|
171
|
+
Import support requires `eslint-plugin-i`.
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keeex/eslint-config",
|
|
3
3
|
"description": "Common eslint configuration",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.12.0",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"src/**/*.js"
|
|
8
8
|
],
|
|
9
|
+
"bin": {
|
|
10
|
+
"eslint-depcheck": "src/bin/eslint-depcheck.js"
|
|
11
|
+
},
|
|
9
12
|
"scripts": {
|
|
10
13
|
"check": "npx eslint .",
|
|
11
14
|
"prepublishOnly": "publish_check.sh",
|
|
@@ -25,17 +28,15 @@
|
|
|
25
28
|
"license": "MIT",
|
|
26
29
|
"devDependencies": {
|
|
27
30
|
"eslint": "^8.56.0",
|
|
28
|
-
"eslint-plugin-
|
|
31
|
+
"eslint-plugin-i": "^2.29.1",
|
|
29
32
|
"eslint-plugin-promise": "^6.1.1"
|
|
30
33
|
},
|
|
31
34
|
"peerDependencies": {
|
|
32
35
|
"@typescript-eslint/eslint-plugin": "6.x||7.x",
|
|
33
36
|
"@typescript-eslint/parser": "6.x||7.x",
|
|
34
37
|
"eslint": "8.x",
|
|
35
|
-
"eslint-import-resolver-typescript": "2.x||3.x",
|
|
36
|
-
"eslint-plugin-chai-friendly": "0.x",
|
|
37
38
|
"eslint-plugin-deprecation": "1.x||2.x",
|
|
38
|
-
"eslint-plugin-
|
|
39
|
+
"eslint-plugin-i": "^2.29.1",
|
|
39
40
|
"eslint-plugin-mocha": "10.x",
|
|
40
41
|
"eslint-plugin-promise": "6.x",
|
|
41
42
|
"eslint-plugin-react": "7.x",
|
|
@@ -62,15 +63,12 @@
|
|
|
62
63
|
"eslint-plugin-promise": {
|
|
63
64
|
"optional": true
|
|
64
65
|
},
|
|
65
|
-
"eslint-plugin-
|
|
66
|
+
"eslint-plugin-i": {
|
|
66
67
|
"optional": true
|
|
67
68
|
},
|
|
68
69
|
"eslint-plugin-react-native": {
|
|
69
70
|
"optional": true
|
|
70
71
|
},
|
|
71
|
-
"eslint-plugin-chai-friendly": {
|
|
72
|
-
"optional": true
|
|
73
|
-
},
|
|
74
72
|
"eslint-plugin-deprecation": {
|
|
75
73
|
"optional": true
|
|
76
74
|
},
|
|
@@ -79,9 +77,6 @@
|
|
|
79
77
|
},
|
|
80
78
|
"eslint-plugin-mocha": {
|
|
81
79
|
"optional": true
|
|
82
|
-
},
|
|
83
|
-
"eslint-import-resolver-typescript": {
|
|
84
|
-
"optional": true
|
|
85
80
|
}
|
|
86
81
|
},
|
|
87
82
|
"publishConfig": {
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const cp = require("node:child_process");
|
|
6
|
+
const {dependencyReportKey} = require("../consts.js");
|
|
7
|
+
|
|
8
|
+
/** List of previously used dependencies that could be removed */
|
|
9
|
+
const removedDependencies = [
|
|
10
|
+
"eslint-plugin-imports",
|
|
11
|
+
"eslint-import-resolver-typescript",
|
|
12
|
+
"eslint-plugin-chai-friendly",
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Check if a dependency is installed (and is a dev dependency).
|
|
17
|
+
*
|
|
18
|
+
* @returns
|
|
19
|
+
* "ok" if it is installed and a dev dependency, "prod" if installed and prod dependency, "missing"
|
|
20
|
+
* if not installed.
|
|
21
|
+
*/
|
|
22
|
+
const haveDependency = (pkgJson, depName) => {
|
|
23
|
+
if (pkgJson.devDependencies && depName in pkgJson.devDependencies) return "ok";
|
|
24
|
+
if (pkgJson.dependencies && depName in pkgJson.dependencies) return "prod";
|
|
25
|
+
return "missing";
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** Return the appropriate action for a required dependency */
|
|
29
|
+
const getAction = status => {
|
|
30
|
+
switch (status) {
|
|
31
|
+
case "ok": return "none";
|
|
32
|
+
case "prod": return "install-as-dev";
|
|
33
|
+
case "missing": return "install";
|
|
34
|
+
default:
|
|
35
|
+
throw new Error(`Unknown dependency status: ${status}`);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const runOn = (pkgJson, eslintConfigPath) => {
|
|
40
|
+
console.log("Reading current configuration");
|
|
41
|
+
// eslint-disable-next-line no-process-env
|
|
42
|
+
process.env[dependencyReportKey] = "1";
|
|
43
|
+
// eslint-disable-next-line global-require, i/no-dynamic-require
|
|
44
|
+
const requiredDependencies = require(eslintConfigPath);
|
|
45
|
+
const report = {};
|
|
46
|
+
console.log("Checking dependencies status");
|
|
47
|
+
for (const dep of requiredDependencies) {
|
|
48
|
+
const status = haveDependency(pkgJson, dep);
|
|
49
|
+
const action = getAction(status);
|
|
50
|
+
report[dep] = {status, action};
|
|
51
|
+
console.log(`- ${dep}: ${status} (action: ${action})`);
|
|
52
|
+
}
|
|
53
|
+
for (const oldDep of removedDependencies) {
|
|
54
|
+
const status = haveDependency(pkgJson, oldDep);
|
|
55
|
+
if (status === "missing") continue;
|
|
56
|
+
report[oldDep] = {status, action: "remove"};
|
|
57
|
+
console.log(`- ${oldDep}: ${status} (action: remove)`);
|
|
58
|
+
}
|
|
59
|
+
const toInstall = [];
|
|
60
|
+
const toRemove = [];
|
|
61
|
+
for (const [dep, {action}] of Object.entries(report)) {
|
|
62
|
+
if (action === "install") toInstall.push(dep);
|
|
63
|
+
if (action === "install-as-dev") toInstall.push(dep);
|
|
64
|
+
if (action === "remove") toRemove.push(dep);
|
|
65
|
+
}
|
|
66
|
+
if (toInstall.length === 0 && toRemove.length === 0) return;
|
|
67
|
+
if (process.argv.indexOf("auto") === -1) {
|
|
68
|
+
console.log("To automatically update dependencies, run this script with \"auto\"");
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (toInstall.length > 0) {
|
|
72
|
+
console.log(`Installing dependencies: ${toInstall.join(", ")}`);
|
|
73
|
+
cp.spawnSync("npm", ["install", "--save-dev", ...toInstall]);
|
|
74
|
+
}
|
|
75
|
+
if (toRemove.length > 0) {
|
|
76
|
+
console.log(`Removing dependencies: ${toRemove.join(", ")}`);
|
|
77
|
+
cp.spawnSync("npm", ["uninstall", ...toRemove]);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const main = () => {
|
|
82
|
+
const rootPath = path.resolve(".");
|
|
83
|
+
const pkgJsonPath = path.resolve(rootPath, "package.json");
|
|
84
|
+
if (!fs.existsSync(pkgJsonPath)) {
|
|
85
|
+
console.log("Please run this tool in the root of your project");
|
|
86
|
+
process.exitCode = 1;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
|
|
90
|
+
const eslintConfigPath = path.resolve(rootPath, ".eslintrc.cjs");
|
|
91
|
+
const eslintConfigAltPath = path.resolve(rootPath, ".eslintrc.js");
|
|
92
|
+
if (fs.existsSync(eslintConfigPath)) {
|
|
93
|
+
runOn(pkgJson, eslintConfigPath);
|
|
94
|
+
} else if (fs.existsSync(eslintConfigAltPath)) {
|
|
95
|
+
runOn(pkgJson, eslintConfigAltPath);
|
|
96
|
+
} else {
|
|
97
|
+
console.log("No eslint config found");
|
|
98
|
+
process.exitCode = 1;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
main();
|
package/src/config/base.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
plugins: (presetSettings, allOptions) => {
|
|
2
|
+
plugins: (presetSettings, allOptions, dependencies) => {
|
|
3
3
|
if (typeof allOptions.typescript !== "string") return undefined;
|
|
4
|
+
if (dependencies) dependencies.add("eslint-plugin-deprecation");
|
|
4
5
|
return ["deprecation"];
|
|
5
6
|
},
|
|
6
7
|
rules: {},
|
package/src/config/import.js
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
const base = {
|
|
2
|
-
"
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
2
|
+
"i/no-unresolved": "error",
|
|
3
|
+
"i/named": "error",
|
|
4
|
+
"i/export": "error",
|
|
5
|
+
"i/no-duplicates": "warn",
|
|
6
|
+
"i/default": "off",
|
|
7
|
+
"i/namespace": "off",
|
|
8
|
+
"i/no-absolute-path": "error",
|
|
9
|
+
"i/no-dynamic-require": "error",
|
|
10
|
+
"i/no-webpack-loader-syntax": "error",
|
|
11
|
+
"i/no-self-import": "error",
|
|
12
|
+
"i/no-relative-packages": "error",
|
|
13
|
+
"i/no-named-as-default": "off",
|
|
14
|
+
"i/no-named-as-default-member": "off",
|
|
15
|
+
"i/no-extraneous-dependencies": "warn",
|
|
16
|
+
"i/no-unused-modules": "warn",
|
|
17
|
+
"i/no-amd": "error",
|
|
18
|
+
"i/no-import-module-exports": "error",
|
|
19
|
+
"i/first": "error",
|
|
20
|
+
"i/extensions": ["error", "always"],
|
|
21
|
+
"i/order": "warn",
|
|
22
|
+
"i/newline-after-import": "warn",
|
|
23
|
+
"i/no-named-default": "error",
|
|
24
|
+
"i/no-anonymous-default-export": [
|
|
21
25
|
"warn",
|
|
22
26
|
{"allowCallExpression": true},
|
|
23
27
|
],
|
|
@@ -26,8 +30,8 @@ const base = {
|
|
|
26
30
|
const DEFAULT_CYCLE_DEPTH = 3;
|
|
27
31
|
|
|
28
32
|
module.exports = {
|
|
29
|
-
plugins: ["
|
|
30
|
-
|
|
33
|
+
plugins: ["i"],
|
|
34
|
+
dependencies: ["eslint-plugin-i"],
|
|
31
35
|
rules: presetConfig => {
|
|
32
36
|
let importDepth;
|
|
33
37
|
if (
|
|
@@ -42,7 +46,7 @@ module.exports = {
|
|
|
42
46
|
? undefined
|
|
43
47
|
: (
|
|
44
48
|
{
|
|
45
|
-
"
|
|
49
|
+
"i/no-cycle": [
|
|
46
50
|
"error",
|
|
47
51
|
{
|
|
48
52
|
ignoreExternal: true,
|
package/src/config/jsx.js
CHANGED
package/src/config/mocha.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
+
dependencies: ["eslint-plugin-mocha"],
|
|
2
3
|
overrides: (presetConfig, allOptions) => {
|
|
3
4
|
let config = {
|
|
4
5
|
fileFilter: [
|
|
@@ -23,7 +24,6 @@ module.exports = {
|
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
26
|
const extendsBase = ["plugin:mocha/recommended"];
|
|
26
|
-
if (config.chai) extendsBase.push("plugin:chai-friendly/recommended");
|
|
27
27
|
const mochaOverride = {
|
|
28
28
|
files: config.fileFilter,
|
|
29
29
|
env: {mocha: true},
|
|
@@ -33,6 +33,7 @@ module.exports = {
|
|
|
33
33
|
"mocha/no-mocha-arrows": "off",
|
|
34
34
|
"prefer-arrow-callback": "off",
|
|
35
35
|
"mocha/prefer-arrow-callback": ["warn", {"allowUnboundThis": false}],
|
|
36
|
+
"func-names": "off",
|
|
36
37
|
},
|
|
37
38
|
};
|
|
38
39
|
if (config.expectHelper) {
|
package/src/config/promise.js
CHANGED
package/src/config/reacthooks.js
CHANGED
package/src/config/typescript.js
CHANGED
|
@@ -269,6 +269,7 @@ const rulesBase = {
|
|
|
269
269
|
};
|
|
270
270
|
|
|
271
271
|
module.exports = {
|
|
272
|
+
dependencies: ["@typescript-eslint/eslint-plugin", "@typescript-eslint/parser"],
|
|
272
273
|
overrides: [
|
|
273
274
|
{
|
|
274
275
|
files: [
|
|
@@ -295,7 +296,7 @@ module.exports = {
|
|
|
295
296
|
? extendsBaseType
|
|
296
297
|
: [];
|
|
297
298
|
const importExtends = allOptions["import"]
|
|
298
|
-
? ["plugin:
|
|
299
|
+
? ["plugin:i/typescript"]
|
|
299
300
|
: [];
|
|
300
301
|
return [
|
|
301
302
|
...typescriptBase,
|
|
@@ -303,8 +304,11 @@ module.exports = {
|
|
|
303
304
|
...importExtends,
|
|
304
305
|
];
|
|
305
306
|
},
|
|
306
|
-
plugins: (presetOptions, allOptions) => {
|
|
307
|
-
if (useTSDoc(allOptions))
|
|
307
|
+
plugins: (presetOptions, allOptions, dependencies) => {
|
|
308
|
+
if (useTSDoc(allOptions)) {
|
|
309
|
+
if (dependencies) dependencies.add("eslint-plugin-tsdoc");
|
|
310
|
+
return ["eslint-plugin-tsdoc"];
|
|
311
|
+
}
|
|
308
312
|
},
|
|
309
313
|
rules: (presetOptions, allOptions) => {
|
|
310
314
|
// There seem to be no way for now to have import understand that ".js" imports should refer
|
|
@@ -315,8 +319,9 @@ module.exports = {
|
|
|
315
319
|
// If this change in the future, restore full ts-resolver support from import plugin.
|
|
316
320
|
const importOverride = allOptions.import
|
|
317
321
|
? {
|
|
318
|
-
"
|
|
319
|
-
"
|
|
322
|
+
"i/no-unresolved": "off",
|
|
323
|
+
"i/no-cycle": "off",
|
|
324
|
+
"i/named": "off",
|
|
320
325
|
}
|
|
321
326
|
: undefined;
|
|
322
327
|
const typesOverride = useTypes(presetOptions)
|
|
@@ -325,6 +330,9 @@ module.exports = {
|
|
|
325
330
|
const deprecationOverride = useDeprecation(presetOptions, allOptions)
|
|
326
331
|
? {"deprecation/deprecation": "warn"}
|
|
327
332
|
: undefined;
|
|
333
|
+
const reactOverride = allOptions.jsx
|
|
334
|
+
? {"react/sort-comp": "off"}
|
|
335
|
+
: undefined;
|
|
328
336
|
const tsdoc = useTSDoc(allOptions)
|
|
329
337
|
? {"tsdoc/syntax": "warn"}
|
|
330
338
|
: undefined;
|
|
@@ -333,6 +341,7 @@ module.exports = {
|
|
|
333
341
|
...tsdoc,
|
|
334
342
|
...typesOverride,
|
|
335
343
|
...importOverride,
|
|
344
|
+
...reactOverride,
|
|
336
345
|
...deprecationOverride,
|
|
337
346
|
};
|
|
338
347
|
},
|
package/src/consts.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = {dependencyReportKey: "ESLINT_CONFIG_DEPENDENCIES_REPORT"};
|
package/src/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const cfgTypescript = require("./config/typescript.js");
|
|
|
7
7
|
const cfgDeprecation = require("./config/deprecation.js");
|
|
8
8
|
const cfgPromise = require("./config/promise.js");
|
|
9
9
|
const cfgMocha = require("./config/mocha.js");
|
|
10
|
+
const {dependencyReportKey} = require("./consts.js");
|
|
10
11
|
|
|
11
12
|
const defaultConfigBase = {
|
|
12
13
|
env: {
|
|
@@ -46,8 +47,8 @@ const getOverride = (
|
|
|
46
47
|
/**
|
|
47
48
|
* Apply a preset configuration to a preset object
|
|
48
49
|
*/
|
|
49
|
-
const applyConfig = (source, config, allOptions) => typeof source === "function"
|
|
50
|
-
? source(config, allOptions)
|
|
50
|
+
const applyConfig = (source, config, allOptions, dependencies) => typeof source === "function"
|
|
51
|
+
? source(config, allOptions, dependencies)
|
|
51
52
|
: source;
|
|
52
53
|
|
|
53
54
|
/** Add a plugin to the plugins list */
|
|
@@ -56,8 +57,9 @@ const addPlugins = (
|
|
|
56
57
|
presetPlugins,
|
|
57
58
|
presetConfig,
|
|
58
59
|
allOptions,
|
|
60
|
+
dependencies,
|
|
59
61
|
) => {
|
|
60
|
-
const newPlugins = applyConfig(presetPlugins, presetConfig, allOptions);
|
|
62
|
+
const newPlugins = applyConfig(presetPlugins, presetConfig, allOptions, dependencies);
|
|
61
63
|
if (!newPlugins) return;
|
|
62
64
|
|
|
63
65
|
if (!config.plugins) {
|
|
@@ -79,8 +81,9 @@ const addExtends = (
|
|
|
79
81
|
presetExtends,
|
|
80
82
|
presetConfig,
|
|
81
83
|
allOptions,
|
|
84
|
+
dependencies,
|
|
82
85
|
) => {
|
|
83
|
-
const newExtends = applyConfig(presetExtends, presetConfig, allOptions);
|
|
86
|
+
const newExtends = applyConfig(presetExtends, presetConfig, allOptions, dependencies);
|
|
84
87
|
if (!newExtends) return;
|
|
85
88
|
|
|
86
89
|
if (!config.extends) {
|
|
@@ -101,8 +104,9 @@ const addEnvs = (
|
|
|
101
104
|
config,
|
|
102
105
|
presetEnvs,
|
|
103
106
|
presetConfig,
|
|
107
|
+
dependencies,
|
|
104
108
|
) => {
|
|
105
|
-
const newEnvs = applyConfig(presetEnvs, presetConfig);
|
|
109
|
+
const newEnvs = applyConfig(presetEnvs, presetConfig, undefined, dependencies);
|
|
106
110
|
if (!newEnvs) return;
|
|
107
111
|
|
|
108
112
|
if (!config.env) {
|
|
@@ -121,8 +125,9 @@ const addRules = (
|
|
|
121
125
|
presetRules,
|
|
122
126
|
presetConfig,
|
|
123
127
|
allOptions,
|
|
128
|
+
dependencies,
|
|
124
129
|
) => {
|
|
125
|
-
const newRules = applyConfig(presetRules, presetConfig, allOptions);
|
|
130
|
+
const newRules = applyConfig(presetRules, presetConfig, allOptions, dependencies);
|
|
126
131
|
if (!newRules) return;
|
|
127
132
|
|
|
128
133
|
if (!config.rules) {
|
|
@@ -140,8 +145,9 @@ const addParserOptions = (
|
|
|
140
145
|
config,
|
|
141
146
|
presetParserOptions,
|
|
142
147
|
presetConfig,
|
|
148
|
+
dependencies,
|
|
143
149
|
) => {
|
|
144
|
-
const newParserOptions = applyConfig(presetParserOptions, presetConfig);
|
|
150
|
+
const newParserOptions = applyConfig(presetParserOptions, presetConfig, undefined, dependencies);
|
|
145
151
|
if (!newParserOptions) return;
|
|
146
152
|
|
|
147
153
|
if (!config.parserOptions) {
|
|
@@ -162,9 +168,10 @@ const addSettings = (
|
|
|
162
168
|
presetSettings,
|
|
163
169
|
presetConfig,
|
|
164
170
|
allOptions,
|
|
171
|
+
dependencies,
|
|
165
172
|
) => {
|
|
166
173
|
const newSettings = typeof presetSettings === "function"
|
|
167
|
-
? presetSettings(presetConfig, allOptions)
|
|
174
|
+
? presetSettings(presetConfig, allOptions, dependencies)
|
|
168
175
|
: presetSettings;
|
|
169
176
|
if (!newSettings) return;
|
|
170
177
|
|
|
@@ -185,8 +192,9 @@ const setParser = (
|
|
|
185
192
|
config,
|
|
186
193
|
presetParser,
|
|
187
194
|
presetConfig,
|
|
195
|
+
dependencies,
|
|
188
196
|
) => {
|
|
189
|
-
const newParser = applyConfig(presetParser, presetConfig);
|
|
197
|
+
const newParser = applyConfig(presetParser, presetConfig, undefined, dependencies);
|
|
190
198
|
if (!newParser) return;
|
|
191
199
|
|
|
192
200
|
config.parser = newParser;
|
|
@@ -221,28 +229,34 @@ const presetsOrder = [
|
|
|
221
229
|
];
|
|
222
230
|
|
|
223
231
|
/**
|
|
224
|
-
* Merge entries from a preset
|
|
232
|
+
* Merge entries from a preset.
|
|
233
|
+
*
|
|
234
|
+
* `dependencies` is an optiona Set<string> where the preset can add its required dependencies.
|
|
225
235
|
*/
|
|
226
236
|
const mergePreset = (
|
|
227
237
|
config,
|
|
228
238
|
presetDef,
|
|
229
239
|
presetConfig,
|
|
230
240
|
allOptions,
|
|
241
|
+
dependencies,
|
|
231
242
|
) => {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
243
|
+
if (dependencies && presetDef.dependencies) {
|
|
244
|
+
for (const dependency of presetDef.dependencies) dependencies.add(dependency);
|
|
245
|
+
}
|
|
246
|
+
setParser(config, presetDef.parser, presetConfig, dependencies);
|
|
247
|
+
addParserOptions(config, presetDef.parserOptions, presetConfig, dependencies);
|
|
248
|
+
addSettings(config, presetDef.settings, presetConfig, allOptions, dependencies);
|
|
249
|
+
addEnvs(config, presetDef.env, presetConfig, dependencies);
|
|
250
|
+
addPlugins(config, presetDef.plugins, presetConfig, allOptions, dependencies);
|
|
251
|
+
addExtends(config, presetDef.extendsBase, presetConfig, allOptions, dependencies);
|
|
252
|
+
addRules(config, presetDef.rules, presetConfig, allOptions, dependencies);
|
|
239
253
|
if (presetDef.overrides) {
|
|
240
254
|
const actualOverrides = (typeof presetDef.overrides === "function")
|
|
241
|
-
? presetDef.overrides(presetConfig, allOptions)
|
|
255
|
+
? presetDef.overrides(presetConfig, allOptions, dependencies)
|
|
242
256
|
: presetDef.overrides;
|
|
243
257
|
actualOverrides.forEach(presetOverride => {
|
|
244
258
|
const overrideConfig = getOverride(config, presetOverride.files);
|
|
245
|
-
mergePreset(overrideConfig, presetOverride, presetConfig, allOptions);
|
|
259
|
+
mergePreset(overrideConfig, presetOverride, presetConfig, allOptions, dependencies);
|
|
246
260
|
});
|
|
247
261
|
}
|
|
248
262
|
};
|
|
@@ -253,6 +267,7 @@ const mergePreset = (
|
|
|
253
267
|
const mergeAllPresets = (
|
|
254
268
|
config,
|
|
255
269
|
options,
|
|
270
|
+
dependencies,
|
|
256
271
|
) => {
|
|
257
272
|
presetsOrder.forEach(presetName => {
|
|
258
273
|
const presetConfig = options[presetName];
|
|
@@ -263,10 +278,14 @@ const mergeAllPresets = (
|
|
|
263
278
|
presets[presetName],
|
|
264
279
|
presetConfig,
|
|
265
280
|
options,
|
|
281
|
+
dependencies,
|
|
266
282
|
);
|
|
267
283
|
});
|
|
268
284
|
};
|
|
269
285
|
|
|
286
|
+
// eslint-disable-next-line no-process-env
|
|
287
|
+
const addDependencies = () => process.env[dependencyReportKey] === "1";
|
|
288
|
+
|
|
270
289
|
module.exports = (
|
|
271
290
|
eslintConfig,
|
|
272
291
|
baseConfig,
|
|
@@ -280,7 +299,8 @@ module.exports = (
|
|
|
280
299
|
if (config.promise === undefined) config.promise = true;
|
|
281
300
|
if (config.import === undefined) config.import = true;
|
|
282
301
|
if (config.deprecation === undefined) config.deprecation = true;
|
|
283
|
-
|
|
284
|
-
mergeAllPresets(result, config);
|
|
302
|
+
const dependencies = addDependencies() ? new Set() : undefined;
|
|
303
|
+
mergeAllPresets(result, config, dependencies);
|
|
304
|
+
if (dependencies) return dependencies;
|
|
285
305
|
return result;
|
|
286
306
|
};
|