@keeex/eslint-config 1.12.6 → 2.0.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/LICENSE +1 -1
- package/README.md +97 -150
- package/package.json +75 -41
- package/src/bin/kxeslint-dump.js +16 -0
- package/src/bin/kxeslint-setup.js +111 -0
- package/src/config/base.js +168 -254
- package/src/config/globals.js +42 -0
- package/src/config/importx.js +104 -0
- package/src/config/lazy.js +8 -0
- package/src/config/mocha.js +32 -47
- package/src/config/react/reacthooks.js +12 -0
- package/src/config/react/reactnative.js +26 -0
- package/src/config/react.js +74 -0
- package/src/config/reactfullconfig.js +16 -0
- package/src/config/typescript.js +88 -340
- package/src/defaults.js +41 -0
- package/src/dependencies.js +183 -0
- package/src/environ.js +7 -0
- package/src/index.js +66 -299
- package/src/sections.js +61 -0
- package/src/bin/eslint-depcheck.js +0 -105
- package/src/config/common.js +0 -7
- package/src/config/deprecation.js +0 -8
- package/src/config/import.js +0 -63
- package/src/config/jsx.js +0 -128
- package/src/config/promise.js +0 -9
- package/src/config/reacthooks.js +0 -8
- package/src/config/reactnative.js +0 -19
- package/src/config/typescript_types.js +0 -27
- package/src/consts.js +0 -1
package/src/defaults.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** List of ignored patterns by default */
|
|
2
|
+
export const ignores = ["lib", "web", "gen", "src/gen"];
|
|
3
|
+
|
|
4
|
+
/** Default globals affected to all projects */
|
|
5
|
+
export const globals = [
|
|
6
|
+
{
|
|
7
|
+
globals: {
|
|
8
|
+
builtin: true,
|
|
9
|
+
es2025: true,
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
files: ["**/*.cjs"],
|
|
14
|
+
globals: {commonjs: true},
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
files: ["src/webapp/**/*"],
|
|
18
|
+
globals: {
|
|
19
|
+
browser: true,
|
|
20
|
+
serviceworker: true,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
files: [
|
|
25
|
+
"src/bin/**/*",
|
|
26
|
+
"src/server/**/*",
|
|
27
|
+
"*",
|
|
28
|
+
],
|
|
29
|
+
globals: {node: true},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
files: [
|
|
33
|
+
"src/tests/**/*",
|
|
34
|
+
"src/**/*.test.*",
|
|
35
|
+
],
|
|
36
|
+
globals: {mocha: true},
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
/** Import cycle max depth */
|
|
41
|
+
export const cycleMaxDepth = 3;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import * as cp from "node:child_process";
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
|
|
6
|
+
import {satisfies} from "semver";
|
|
7
|
+
|
|
8
|
+
import {getReactFullConfig} from "./config/reactfullconfig.js";
|
|
9
|
+
|
|
10
|
+
/** name => {version: string, force: boolean} */
|
|
11
|
+
const requiredDependencies = {};
|
|
12
|
+
|
|
13
|
+
/** List of dependencies no longer used and that should be removed */
|
|
14
|
+
const removedDependencies = [
|
|
15
|
+
"@typescript-eslint/eslint-plugin",
|
|
16
|
+
"@typescript-eslint/parser",
|
|
17
|
+
"eslint-plugin-chai-friendly",
|
|
18
|
+
"eslint-plugin-deprecation",
|
|
19
|
+
"eslint-plugin-i",
|
|
20
|
+
"eslint-plugin-import",
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
let pkgJson;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Retrieve the current project's "package.json".
|
|
27
|
+
*
|
|
28
|
+
* This assumes that the command is run at the root of the project.
|
|
29
|
+
*/
|
|
30
|
+
const getPkgJson = () => {
|
|
31
|
+
if (!pkgJson) {
|
|
32
|
+
try {
|
|
33
|
+
const data = fs.readFileSync("./package.json", "utf8");
|
|
34
|
+
pkgJson = JSON.parse(data);
|
|
35
|
+
} catch (e) {
|
|
36
|
+
throw new Error("Could not read ./package.json", {cause: e});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return pkgJson;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** Get installed package version */
|
|
43
|
+
const getInstalledVersion = name => {
|
|
44
|
+
try {
|
|
45
|
+
const depsPkg = JSON.parse(fs.readFileSync(path.join("node_modules", name, "package.json"), "utf8"));
|
|
46
|
+
return depsPkg.version;
|
|
47
|
+
} catch {
|
|
48
|
+
return "<unknown>";
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Check if a particular dependency is installed in the project.
|
|
54
|
+
*
|
|
55
|
+
* @returns {{installed: "prod" | "dev" | false; version: string}}
|
|
56
|
+
*/
|
|
57
|
+
const dependencyStatus = name => {
|
|
58
|
+
const pkg = getPkgJson();
|
|
59
|
+
let installed = "missing";
|
|
60
|
+
if (pkg.devDependencies && name in pkg.devDependencies) installed = "dev";
|
|
61
|
+
if (pkg.dependencies && name in pkg.dependencies) installed = "prod";
|
|
62
|
+
const version = installed === "missing" ? undefined : getInstalledVersion(name);
|
|
63
|
+
return {installed, version};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Add an NPM dependency to the list
|
|
68
|
+
*
|
|
69
|
+
* @param depName {string} - Name of the dependency
|
|
70
|
+
* @param version {string} - A specific version string (or tag) to install if the dependency is
|
|
71
|
+
* missing
|
|
72
|
+
*/
|
|
73
|
+
export const addDependency = (depName, version) => {
|
|
74
|
+
requiredDependencies[depName] = {version: version ?? true, force: false};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Run a process, and display the output if an error occured.
|
|
79
|
+
*
|
|
80
|
+
* If the process fail, its output is displayed.
|
|
81
|
+
*
|
|
82
|
+
* @returns {boolean}
|
|
83
|
+
* Returns false if the process ended with another status than 0.
|
|
84
|
+
*/
|
|
85
|
+
const runProcess = (cmd, ...args) => {
|
|
86
|
+
const res = cp.spawnSync(cmd, args, {encoding: "utf8"});
|
|
87
|
+
if (res.status !== 0) {
|
|
88
|
+
console.log(`Command ${cmd} failed with exit code ${res.status}`);
|
|
89
|
+
console.log("stdout:");
|
|
90
|
+
console.log(res.stdout);
|
|
91
|
+
console.log("stderr:");
|
|
92
|
+
console.log(res.stderr);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* List all missing/extra dependencies.
|
|
100
|
+
*
|
|
101
|
+
* @returns {{name:string;action:"install"|"remove"}[]}
|
|
102
|
+
* A list of dependencies with the action to do ("install" or "remove").
|
|
103
|
+
*/
|
|
104
|
+
export const listDependencies = () => {
|
|
105
|
+
console.group();
|
|
106
|
+
try {
|
|
107
|
+
const res = [];
|
|
108
|
+
for (const removed of removedDependencies) {
|
|
109
|
+
if (dependencyStatus(removed).installed !== "missing") res.push({name: removed, action: "remove"});
|
|
110
|
+
}
|
|
111
|
+
for (const required of Object.keys(requiredDependencies)) {
|
|
112
|
+
const expectedVersion = requiredDependencies[required].version;
|
|
113
|
+
const status = dependencyStatus(required);
|
|
114
|
+
const needUpdate = status.installed !== "dev" || !satisfies(status.version, expectedVersion);
|
|
115
|
+
console.log(`dep:${required} (${status.installed}=${status.version}) (required=${expectedVersion})`);
|
|
116
|
+
if (needUpdate) res.push({name: required, action: "install"});
|
|
117
|
+
}
|
|
118
|
+
return res.toSorted((a, b) => a.name.localeCompare(b.name));
|
|
119
|
+
} finally {
|
|
120
|
+
console.groupEnd();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Run the required installation/removal.
|
|
126
|
+
*
|
|
127
|
+
* @returns {boolean}
|
|
128
|
+
* `false` if the process failed.
|
|
129
|
+
*/
|
|
130
|
+
export const installAndRemoveDeps = () => {
|
|
131
|
+
const deps = listDependencies();
|
|
132
|
+
const toInstall = deps.filter(c => c.action === "install").map(c => c.name);
|
|
133
|
+
const toRemove = deps.filter(c => c.action === "remove").map(c => c.name);
|
|
134
|
+
if (toRemove.length > 0) {
|
|
135
|
+
console.log(`Removing dependencies: ${toRemove.join(", ")}`);
|
|
136
|
+
if (!runProcess("npm", "uninstall", "--force", ...toRemove)) {
|
|
137
|
+
process.exitCode = 1;
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (toInstall.length > 0) {
|
|
142
|
+
console.log(`Installing dependencies: ${toInstall.join(", ")}`);
|
|
143
|
+
const installNames = toInstall.map(c => {
|
|
144
|
+
const target = requiredDependencies[c].version;
|
|
145
|
+
if (typeof target === "string") return `${c}@${target}`;
|
|
146
|
+
return c;
|
|
147
|
+
});
|
|
148
|
+
if (!runProcess("npm", "install", "--save-dev", "--force", ...installNames)) {
|
|
149
|
+
process.exitCode = 1;
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/** Add all dependencies needed by the provided config */
|
|
157
|
+
export const configToDependencies = eslintConfig => {
|
|
158
|
+
addDependency("eslint", "9.x");
|
|
159
|
+
if (eslintConfig.globals) addDependency("globals", "15.x");
|
|
160
|
+
if (eslintConfig.import) {
|
|
161
|
+
addDependency("eslint-plugin-import-x", "4.x");
|
|
162
|
+
if (eslintConfig.typescript) addDependency("eslint-import-resolver-typescript", "3.x");
|
|
163
|
+
}
|
|
164
|
+
if (eslintConfig.mocha) addDependency("eslint-plugin-mocha", "10.x");
|
|
165
|
+
if (!eslintConfig.noBase) {
|
|
166
|
+
addDependency("@eslint/js", "9.x");
|
|
167
|
+
addDependency("eslint-plugin-promise", "7.x");
|
|
168
|
+
}
|
|
169
|
+
const react = getReactFullConfig(eslintConfig.react);
|
|
170
|
+
if (react.react) {
|
|
171
|
+
addDependency("eslint-plugin-react", "7.x");
|
|
172
|
+
if (eslintConfig.import) addDependency("eslint-import-resolver-webpack", "0.x");
|
|
173
|
+
if (react.reactHooks) addDependency("eslint-plugin-react-hooks", "5.x");
|
|
174
|
+
if (react.reactNative) {
|
|
175
|
+
addDependency("eslint-plugin-react-native", "4.x");
|
|
176
|
+
addDependency("@eslint/js", "9.x");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (eslintConfig.typescript) {
|
|
180
|
+
addDependency("typescript-eslint", "8.x");
|
|
181
|
+
addDependency("eslint-plugin-tsdoc", "0.x");
|
|
182
|
+
}
|
|
183
|
+
};
|
package/src/environ.js
ADDED
package/src/index.js
CHANGED
|
@@ -1,306 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
ecmaVersion: "latest",
|
|
19
|
-
sourceType: "module",
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Get an override config section
|
|
25
|
-
*/
|
|
26
|
-
const getOverride = (
|
|
27
|
-
config,
|
|
28
|
-
overrideList,
|
|
29
|
-
) => {
|
|
30
|
-
if (config.overrides === undefined) config.overrides = [];
|
|
31
|
-
|
|
32
|
-
const overrideListJSON = JSON.stringify(overrideList);
|
|
33
|
-
const existingEntry = config.overrides.find(
|
|
34
|
-
entry => {
|
|
35
|
-
const entryFilesAsJson = JSON.stringify(entry.files);
|
|
36
|
-
return entryFilesAsJson === overrideListJSON;
|
|
37
|
-
},
|
|
38
|
-
);
|
|
39
|
-
if (!existingEntry) {
|
|
40
|
-
const result = {files: [...overrideList]};
|
|
41
|
-
config.overrides.push(result);
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
return existingEntry;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Apply a preset configuration to a preset object
|
|
49
|
-
*/
|
|
50
|
-
const applyConfig = (source, config, allOptions, dependencies) => typeof source === "function"
|
|
51
|
-
? source(config, allOptions, dependencies)
|
|
52
|
-
: source;
|
|
53
|
-
|
|
54
|
-
/** Add a plugin to the plugins list */
|
|
55
|
-
const addPlugins = (
|
|
56
|
-
config,
|
|
57
|
-
presetPlugins,
|
|
58
|
-
presetConfig,
|
|
59
|
-
allOptions,
|
|
60
|
-
dependencies,
|
|
61
|
-
) => {
|
|
62
|
-
const newPlugins = applyConfig(presetPlugins, presetConfig, allOptions, dependencies);
|
|
63
|
-
if (!newPlugins) return;
|
|
64
|
-
|
|
65
|
-
if (!config.plugins) {
|
|
66
|
-
config.plugins = [...newPlugins];
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
newPlugins.forEach(newPlugin => {
|
|
70
|
-
if (config.plugins.includes(newPlugin)) return;
|
|
71
|
-
|
|
72
|
-
config.plugins.push(newPlugin);
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Add an entry to the extends list
|
|
78
|
-
*/
|
|
79
|
-
const addExtends = (
|
|
80
|
-
config,
|
|
81
|
-
presetExtends,
|
|
82
|
-
presetConfig,
|
|
83
|
-
allOptions,
|
|
84
|
-
dependencies,
|
|
85
|
-
) => {
|
|
86
|
-
const newExtends = applyConfig(presetExtends, presetConfig, allOptions, dependencies);
|
|
87
|
-
if (!newExtends) return;
|
|
88
|
-
|
|
89
|
-
if (!config.extends) {
|
|
90
|
-
config.extends = [...newExtends];
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
newExtends.forEach(finalExtend => {
|
|
94
|
-
if (config.extends.includes(finalExtend)) return;
|
|
95
|
-
|
|
96
|
-
config.extends.push(finalExtend);
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Add an env to the envs list
|
|
102
|
-
*/
|
|
103
|
-
const addEnvs = (
|
|
104
|
-
config,
|
|
105
|
-
presetEnvs,
|
|
106
|
-
presetConfig,
|
|
107
|
-
dependencies,
|
|
108
|
-
) => {
|
|
109
|
-
const newEnvs = applyConfig(presetEnvs, presetConfig, undefined, dependencies);
|
|
110
|
-
if (!newEnvs) return;
|
|
111
|
-
|
|
112
|
-
if (!config.env) {
|
|
113
|
-
config.env = {...newEnvs};
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
config.env = {
|
|
117
|
-
...config.env,
|
|
118
|
-
...newEnvs,
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
/** Add rules to a config */
|
|
123
|
-
const addRules = (
|
|
124
|
-
config,
|
|
125
|
-
presetRules,
|
|
126
|
-
presetConfig,
|
|
127
|
-
allOptions,
|
|
128
|
-
dependencies,
|
|
129
|
-
) => {
|
|
130
|
-
const newRules = applyConfig(presetRules, presetConfig, allOptions, dependencies);
|
|
131
|
-
if (!newRules) return;
|
|
132
|
-
|
|
133
|
-
if (!config.rules) {
|
|
134
|
-
config.rules = {...newRules};
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
config.rules = {
|
|
138
|
-
...config.rules,
|
|
139
|
-
...newRules,
|
|
140
|
-
};
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
/** Add parser options */
|
|
144
|
-
const addParserOptions = (
|
|
145
|
-
config,
|
|
146
|
-
presetParserOptions,
|
|
147
|
-
presetConfig,
|
|
148
|
-
dependencies,
|
|
149
|
-
) => {
|
|
150
|
-
const newParserOptions = applyConfig(presetParserOptions, presetConfig, undefined, dependencies);
|
|
151
|
-
if (!newParserOptions) return;
|
|
152
|
-
|
|
153
|
-
if (!config.parserOptions) {
|
|
154
|
-
config.parserOptions = {...newParserOptions};
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
config.parserOptions = {
|
|
158
|
-
...config.parserOptions,
|
|
159
|
-
...newParserOptions,
|
|
160
|
-
};
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Add settings entries
|
|
165
|
-
*/
|
|
166
|
-
const addSettings = (
|
|
167
|
-
config,
|
|
168
|
-
presetSettings,
|
|
169
|
-
presetConfig,
|
|
170
|
-
allOptions,
|
|
171
|
-
dependencies,
|
|
172
|
-
) => {
|
|
173
|
-
const newSettings = typeof presetSettings === "function"
|
|
174
|
-
? presetSettings(presetConfig, allOptions, dependencies)
|
|
175
|
-
: presetSettings;
|
|
176
|
-
if (!newSettings) return;
|
|
177
|
-
|
|
178
|
-
if (!config.settings) config.settings = {};
|
|
179
|
-
|
|
180
|
-
Object.keys(newSettings).forEach(sectionName => {
|
|
181
|
-
config.settings[sectionName] = {
|
|
182
|
-
...(config.settings[sectionName] || {}),
|
|
183
|
-
...newSettings[sectionName],
|
|
184
|
-
};
|
|
1
|
+
import * as lazy from "./config/lazy.js";
|
|
2
|
+
import { getReactFullConfig } from "./config/reactfullconfig.js";
|
|
3
|
+
import * as defaults from "./defaults.js";
|
|
4
|
+
|
|
5
|
+
import {configToDependencies} from "./dependencies.js";
|
|
6
|
+
import {isDepCheck} from "./environ.js";
|
|
7
|
+
import {clearConfig} from "./sections.js";
|
|
8
|
+
|
|
9
|
+
/** Setup all defaults in the eslintParams config */
|
|
10
|
+
const configDefaults = eslintParams => ({
|
|
11
|
+
globals: eslintParams?.globals ?? defaults.globals,
|
|
12
|
+
ignores: eslintParams?.ignores ?? defaults.ignores,
|
|
13
|
+
import: eslintParams?.import ?? defaults.cycleMaxDepth,
|
|
14
|
+
mocha: eslintParams?.mocha ?? true,
|
|
15
|
+
noBase: eslintParams?.noBase ?? false,
|
|
16
|
+
react: eslintParams?.react ?? false,
|
|
17
|
+
typescript: eslintParams?.typescript ?? true,
|
|
185
18
|
});
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Change the parser
|
|
190
|
-
*/
|
|
191
|
-
const setParser = (
|
|
192
|
-
config,
|
|
193
|
-
presetParser,
|
|
194
|
-
presetConfig,
|
|
195
|
-
dependencies,
|
|
196
|
-
) => {
|
|
197
|
-
const newParser = applyConfig(presetParser, presetConfig, undefined, dependencies);
|
|
198
|
-
if (!newParser) return;
|
|
199
|
-
|
|
200
|
-
config.parser = newParser;
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* List of available presets
|
|
205
|
-
*/
|
|
206
|
-
const presets = {
|
|
207
|
-
"base": cfgBase,
|
|
208
|
-
"promise": cfgPromise,
|
|
209
|
-
"jsx": cfgJSX,
|
|
210
|
-
"import": cfgImport,
|
|
211
|
-
"reacthooks": cfgReactHooks,
|
|
212
|
-
"reactnative": cfgReactNative,
|
|
213
|
-
"typescript": cfgTypescript,
|
|
214
|
-
"deprecation": cfgDeprecation,
|
|
215
|
-
"mocha": cfgMocha,
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
// Forced order is needed because some rules override previous rules
|
|
219
|
-
const presetsOrder = [
|
|
220
|
-
"base",
|
|
221
|
-
"promise",
|
|
222
|
-
"jsx",
|
|
223
|
-
"import",
|
|
224
|
-
"reactnative",
|
|
225
|
-
"reacthooks",
|
|
226
|
-
"typescript",
|
|
227
|
-
"deprecation",
|
|
228
|
-
"mocha",
|
|
229
|
-
];
|
|
230
19
|
|
|
231
20
|
/**
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
21
|
+
* Build the eslint configuration from the provided settings.
|
|
22
|
+
*
|
|
23
|
+
* @param [eslintParams.noBase] {boolean} - Disable the base settings
|
|
24
|
+
*
|
|
25
|
+
* @param [eslintParams.ignores] {string[]} - List of files to ignore.
|
|
26
|
+
* Defaults to `["lib", "web", "gen", "src/gen"]`.
|
|
27
|
+
*
|
|
28
|
+
* @param [eslintParams.globals.[].files] {string[]} - List of globs to include.
|
|
29
|
+
* @param [eslintParams.globals.[].globals.builtin] {boolean} - Enable builtin JS globals
|
|
30
|
+
* @param [eslintParams.globals.[].globals.browser] {boolean} - Enable browser globals
|
|
31
|
+
* @param [eslintParams.globals.[].globals.commonjs] {boolean} - Enable browser globals
|
|
32
|
+
* @param [eslintParams.globals.[].globals.es2025] {boolean} - Enable ES2025 globals
|
|
33
|
+
* @param [eslintParams.globals.[].globals.mocha] {boolean} - Enable mocha globals
|
|
34
|
+
* @param [eslintParams.globals.[].globals.node] {boolean} - Enable node globals
|
|
35
|
+
* @param [eslintParams.globals.[].globals.serviceworker] {boolean} - Enable serviceworker globals
|
|
36
|
+
* @param [eslintParams.globals.[].globals.worker] {boolean} - Enable worker globals
|
|
37
|
+
* @param [eslintParams.globals.[].globals.custom] {Record<string, boolean>} - Enable custom globals
|
|
38
|
+
*
|
|
39
|
+
* @param [eslintParams.typescript] {boolean} - Enable typescript support (defaults to true)
|
|
40
|
+
*
|
|
41
|
+
* @param [eslintParams.import] {boolean|number} - Enable import linting support (defaults to true)
|
|
42
|
+
* If a number is provided, it's the maximum cycle detection depth.
|
|
43
|
+
*
|
|
44
|
+
* @param [eslintParams.react] {object|false} - If trueish, enable React support.
|
|
45
|
+
* @param [eslintParams.react.reactHooks] {boolean} - Enable react-hooks stuff.
|
|
46
|
+
* @param [eslintParams.react.reactNative] {boolean} - Enable react-native stuff.
|
|
47
|
+
*
|
|
48
|
+
* @param [eslintParams.mocha] {boolean} - Enable mocha plugins
|
|
49
|
+
*
|
|
50
|
+
* @returns
|
|
51
|
+
* The eslint config object
|
|
235
52
|
*/
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
)
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
addRules(config, presetDef.rules, presetConfig, allOptions, dependencies);
|
|
253
|
-
if (presetDef.overrides) {
|
|
254
|
-
const actualOverrides = (typeof presetDef.overrides === "function")
|
|
255
|
-
? presetDef.overrides(presetConfig, allOptions, dependencies)
|
|
256
|
-
: presetDef.overrides;
|
|
257
|
-
actualOverrides.forEach(presetOverride => {
|
|
258
|
-
const overrideConfig = getOverride(config, presetOverride.files);
|
|
259
|
-
mergePreset(overrideConfig, presetOverride, presetConfig, allOptions, dependencies);
|
|
260
|
-
});
|
|
53
|
+
const eslintConfig = async eslintParams => {
|
|
54
|
+
const fullConfig = configDefaults(eslintParams);
|
|
55
|
+
const res = [];
|
|
56
|
+
if (isDepCheck()) {
|
|
57
|
+
configToDependencies(fullConfig);
|
|
58
|
+
} else {
|
|
59
|
+
if (!fullConfig.noBase) (await lazy.base()).apply(res, fullConfig);
|
|
60
|
+
if (fullConfig.globals) (await lazy.globals()).apply(res, fullConfig);
|
|
61
|
+
if (fullConfig.typescript) (await lazy.typescript()).apply(res, fullConfig);
|
|
62
|
+
if (fullConfig.import) (await lazy.importx()).apply(res, fullConfig);
|
|
63
|
+
const reactCfg = getReactFullConfig(fullConfig.react);
|
|
64
|
+
if (reactCfg.react) (await lazy.react()).apply(res, fullConfig);
|
|
65
|
+
if (reactCfg.reactNative) (await lazy.reactNative()).apply(res, fullConfig);
|
|
66
|
+
if (reactCfg.reactHooks) (await lazy.reactHooks()).apply(res, fullConfig);
|
|
67
|
+
if (fullConfig.mocha) (await lazy.mocha()).apply(res, fullConfig);
|
|
68
|
+
clearConfig(res);
|
|
261
69
|
}
|
|
70
|
+
return res;
|
|
262
71
|
};
|
|
263
72
|
|
|
264
|
-
|
|
265
|
-
* Merge all presets
|
|
266
|
-
*/
|
|
267
|
-
const mergeAllPresets = (
|
|
268
|
-
config,
|
|
269
|
-
options,
|
|
270
|
-
dependencies,
|
|
271
|
-
) => {
|
|
272
|
-
presetsOrder.forEach(presetName => {
|
|
273
|
-
const presetConfig = options[presetName];
|
|
274
|
-
if (!presetConfig) return;
|
|
275
|
-
|
|
276
|
-
mergePreset(
|
|
277
|
-
config,
|
|
278
|
-
presets[presetName],
|
|
279
|
-
presetConfig,
|
|
280
|
-
options,
|
|
281
|
-
dependencies,
|
|
282
|
-
);
|
|
283
|
-
});
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
// eslint-disable-next-line no-process-env
|
|
287
|
-
const addDependencies = () => process.env[dependencyReportKey] === "1";
|
|
288
|
-
|
|
289
|
-
module.exports = (
|
|
290
|
-
eslintConfig,
|
|
291
|
-
baseConfig,
|
|
292
|
-
) => {
|
|
293
|
-
const result = {
|
|
294
|
-
...defaultConfigBase,
|
|
295
|
-
...(baseConfig || {}),
|
|
296
|
-
};
|
|
297
|
-
const config = eslintConfig || {};
|
|
298
|
-
if (config.base === undefined) config.base = true;
|
|
299
|
-
if (config.promise === undefined) config.promise = true;
|
|
300
|
-
if (config.import === undefined) config.import = true;
|
|
301
|
-
if (config.deprecation === undefined) config.deprecation = true;
|
|
302
|
-
const dependencies = addDependencies() ? new Set() : undefined;
|
|
303
|
-
mergeAllPresets(result, config, dependencies);
|
|
304
|
-
if (dependencies) return dependencies;
|
|
305
|
-
return result;
|
|
306
|
-
};
|
|
73
|
+
export default eslintConfig;
|
package/src/sections.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get a config section by name.
|
|
3
|
+
*
|
|
4
|
+
* When requesting a section that doesn't exist, it is added.
|
|
5
|
+
*
|
|
6
|
+
* @param configResult - The currently built eslint config object
|
|
7
|
+
* @param name {string} - The name of the section to get
|
|
8
|
+
*
|
|
9
|
+
* @returns
|
|
10
|
+
* The requested section, as a new entry if needed.
|
|
11
|
+
*/
|
|
12
|
+
export const getNamedSection = (configResult, name) => {
|
|
13
|
+
for (const section of configResult) if (section.name === name) return section;
|
|
14
|
+
const newSection = {name};
|
|
15
|
+
configResult.push(newSection);
|
|
16
|
+
return newSection;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Add a property in an object on the provided section.
|
|
21
|
+
*
|
|
22
|
+
* This basically sets `configSection[optionGroup][optionName] = value`.
|
|
23
|
+
* It also takes care of creating/deleting new/empty objects.
|
|
24
|
+
*
|
|
25
|
+
* @param configSection - A single "section" (an entry) from the eslint config array
|
|
26
|
+
* @param optionGroup {string} - The name of the properties in the section to add a property to
|
|
27
|
+
* @param optionName {string} - The name of the property to add
|
|
28
|
+
* @param value - The value to add. If undefined, the property is removed.
|
|
29
|
+
*/
|
|
30
|
+
export const sectionAddOption = (configSection, optionGroup, optionName, value) => {
|
|
31
|
+
if (!(optionGroup in configSection)) configSection[optionGroup] = {};
|
|
32
|
+
if (value === undefined) {
|
|
33
|
+
if (optionName in configSection[optionGroup]) {
|
|
34
|
+
delete configSection[optionGroup][optionName];
|
|
35
|
+
if (Object.keys(configSection[optionGroup]).length === 0) delete configSection[optionGroup];
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
configSection[optionGroup][optionName] = value;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** Merge/create the rules property */
|
|
43
|
+
export const configureRules = (configSection, prefix, rules) => {
|
|
44
|
+
let prefixed = {};
|
|
45
|
+
if (prefix) {
|
|
46
|
+
for (const [name, value] of Object.entries(rules)) prefixed[`${prefix}/${name}`] = value;
|
|
47
|
+
} else {
|
|
48
|
+
prefixed = rules;
|
|
49
|
+
}
|
|
50
|
+
configSection.rules = {...configSection.rules, ...prefixed};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** Remove the `_kxconfig` property from all sections and return a suitable object. */
|
|
54
|
+
export const clearConfig = configResult => {
|
|
55
|
+
const emptySectionsId = [];
|
|
56
|
+
for (let i = 0; i < configResult.length; i++) {
|
|
57
|
+
// We go backwards to avoid messing up the indices on deletion
|
|
58
|
+
if (Object.keys(configResult[i]).length === 0) emptySectionsId.unshift(i);
|
|
59
|
+
}
|
|
60
|
+
for (const sectionId of emptySectionsId) configResult.splice(sectionId, 1);
|
|
61
|
+
};
|