@keeex/eslint-config 2.2.5 → 2.4.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 +38 -24
- package/package.json +14 -10
- package/prettier.config.js +0 -1
- package/src/bin/kxeslint-dump.js +1 -0
- package/src/bin/kxeslint-setup.js +166 -7
- package/src/config/globals.js +7 -0
- package/src/config/importx.js +1 -0
- package/src/config/mocha.js +7 -0
- package/src/config/react.js +1 -0
- package/src/config/typescript.js +1 -0
- package/src/defaults.js +2 -0
- package/src/dependencies.js +12 -0
- package/src/environ.js +1 -0
- package/src/index.js +2 -0
- package/src/pathutils.js +8 -0
- package/src/sections.js +3 -0
package/README.md
CHANGED
|
@@ -23,7 +23,8 @@ npm install -D @keeex/eslint-config
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
25
|
To prepare the configuration file, you can run `npx kxeslint-setup` to create a blank config file.
|
|
26
|
-
Alternatively, you can create the file yourself.
|
|
26
|
+
Alternatively, you can create the file yourself.
|
|
27
|
+
In both cases, it will be named `eslint.config.js`.
|
|
27
28
|
|
|
28
29
|
Here is all the available options with their default values:
|
|
29
30
|
|
|
@@ -67,17 +68,18 @@ export default await eslintConfig({
|
|
|
67
68
|
});
|
|
68
69
|
```
|
|
69
70
|
|
|
70
|
-
If any of the top-level property is not defined, it will be set to its default value.
|
|
71
|
-
customize the output, instead of directly exporting the return value of the function
|
|
72
|
-
|
|
71
|
+
If any of the top-level property is not defined, it will be set to its default value.
|
|
72
|
+
If you want to customize the output, instead of directly exporting the return value of the function
|
|
73
|
+
you can edit it by hand.
|
|
74
|
+
Good luck with that.
|
|
73
75
|
|
|
74
76
|
## Configuration
|
|
75
77
|
|
|
76
78
|
### `globals`
|
|
77
79
|
|
|
78
|
-
The `globals` property is an array of object to define which globals are available in the code.
|
|
79
|
-
of these objects can have two properties: `files`, which is an array of globs to match the
|
|
80
|
-
be considered, and `globals`, which is an object that can have the following properties:
|
|
80
|
+
The `globals` property is an array of object to define which globals are available in the code.
|
|
81
|
+
Each of these objects can have two properties: `files`, which is an array of globs to match the
|
|
82
|
+
files to be considered, and `globals`, which is an object that can have the following properties:
|
|
81
83
|
|
|
82
84
|
- "builtin": generic JS built-in globals
|
|
83
85
|
- "browser": globals available in the browser
|
|
@@ -93,7 +95,8 @@ be considered, and `globals`, which is an object that can have the following pro
|
|
|
93
95
|
|
|
94
96
|
### `environments`
|
|
95
97
|
|
|
96
|
-
Allows you to define general environments for specific directory.
|
|
98
|
+
Allows you to define general environments for specific directory.
|
|
99
|
+
The full configuration is:
|
|
97
100
|
|
|
98
101
|
```javascript
|
|
99
102
|
{
|
|
@@ -106,9 +109,10 @@ Allows you to define general environments for specific directory. The full confi
|
|
|
106
109
|
}
|
|
107
110
|
```
|
|
108
111
|
|
|
109
|
-
The four type of environments are: "node", "webapp", "mobile" and "mocha".
|
|
110
|
-
for the source files in the given directories, as well as restrict some
|
|
111
|
-
"webapp" or "mobile" are defined, react will only apply to these
|
|
112
|
+
The four type of environments are: "node", "webapp", "mobile" and "mocha".
|
|
113
|
+
They set-up some globals for the source files in the given directories, as well as restrict some
|
|
114
|
+
rules (for example, if "webapp" or "mobile" are defined, react will only apply to these
|
|
115
|
+
directories).
|
|
112
116
|
|
|
113
117
|
The "mocha" environment expects a full file specification, where other environments will be applied
|
|
114
118
|
to directories.
|
|
@@ -131,6 +135,13 @@ following options:
|
|
|
131
135
|
"webapp": ["src/**", "webres/*/js/**"]
|
|
132
136
|
}
|
|
133
137
|
}
|
|
138
|
+
// "environment": "weblibrary"
|
|
139
|
+
{
|
|
140
|
+
"environments": {
|
|
141
|
+
"webapp": ["src/**"],
|
|
142
|
+
"mocha": ["src/**/*.test.*", "src/tests/**/*"]
|
|
143
|
+
}
|
|
144
|
+
}
|
|
134
145
|
// "environments": "mobile"
|
|
135
146
|
{
|
|
136
147
|
"environments": {
|
|
@@ -159,9 +170,9 @@ Array of globs to globally ignore for eslint.
|
|
|
159
170
|
### `import`
|
|
160
171
|
|
|
161
172
|
Some extra rules for formatting and ordering imports can be used by setting `import` to true
|
|
162
|
-
(enabled by default with a depth of 3).
|
|
163
|
-
|
|
164
|
-
missing a dependency cycle.
|
|
173
|
+
(enabled by default with a depth of 3).
|
|
174
|
+
It is possible to pass a number instead of a boolean to limit the depth of circular imports check.
|
|
175
|
+
This greatly improves performances, at the risk of missing a dependency cycle.
|
|
165
176
|
|
|
166
177
|
### `mocha`
|
|
167
178
|
|
|
@@ -170,13 +181,14 @@ true.
|
|
|
170
181
|
|
|
171
182
|
### `noBase`
|
|
172
183
|
|
|
173
|
-
The base configuration imports all eslint recommendeds rules and promises handling rules.
|
|
174
|
-
`noBase` to true removes that.
|
|
184
|
+
The base configuration imports all eslint recommendeds rules and promises handling rules.
|
|
185
|
+
Setting `noBase` to true removes that.
|
|
186
|
+
There is absolutely no reason to do so.
|
|
175
187
|
|
|
176
188
|
### `react`
|
|
177
189
|
|
|
178
|
-
To improve handling of React/JSX, set `react` to true.
|
|
179
|
-
following boolean properties:
|
|
190
|
+
To improve handling of React/JSX, set `react` to true.
|
|
191
|
+
You can also pass an object with the following boolean properties:
|
|
180
192
|
|
|
181
193
|
- `reactHooks`: enable/disable React hooks rules
|
|
182
194
|
- `newJsxRuntime`: enable/disable new JSX runtime rules
|
|
@@ -186,14 +198,16 @@ is automatically enabled.
|
|
|
186
198
|
|
|
187
199
|
### `typescript`
|
|
188
200
|
|
|
189
|
-
Set to `true` (the default value) to enable all TypeScript rules.
|
|
201
|
+
Set to `true` (the default value) to enable all TypeScript rules.
|
|
202
|
+
This includes tsdoc rules.
|
|
190
203
|
|
|
191
204
|
## Dependencies
|
|
192
205
|
|
|
193
206
|
This configuration depends on various packages to be available depending on the user settings for
|
|
194
|
-
each individual projects.
|
|
195
|
-
|
|
196
|
-
|
|
207
|
+
each individual projects.
|
|
208
|
+
You can list the required dependencies for the current configuration by running
|
|
209
|
+
`npx kxeslint-setup`.
|
|
210
|
+
You can also automatically install missing dependencies by adding the "auto" flag to the command.
|
|
197
211
|
|
|
198
212
|
All dependencies are set as peer dependencies, as they are almost all optional depending on local
|
|
199
213
|
settings.
|
|
@@ -203,8 +217,8 @@ The tool will also uninstall older dependencies that we used to have but are not
|
|
|
203
217
|
## Migration from .eslintrc.cjs
|
|
204
218
|
|
|
205
219
|
When running `npx kxeslint-setup`, the tool will automatically detect an existing `.eslintrc.cjs`
|
|
206
|
-
file and provides instructions for the migration.
|
|
207
|
-
update the new `eslint.config.js` file by hand.
|
|
220
|
+
file and provides instructions for the migration.
|
|
221
|
+
The migration process is manual; you have to update the new `eslint.config.js` file by hand.
|
|
208
222
|
|
|
209
223
|
## Debugging config issues
|
|
210
224
|
|
package/package.json
CHANGED
|
@@ -11,31 +11,35 @@
|
|
|
11
11
|
}
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"
|
|
14
|
+
"prompts": "^2.4.2",
|
|
15
|
+
"semver": "^7.7.1"
|
|
15
16
|
},
|
|
16
17
|
"description": "Common eslint configuration",
|
|
17
18
|
"devDependencies": {
|
|
18
|
-
"@eslint/compat": "^1.2.
|
|
19
|
+
"@eslint/compat": "^1.2.6",
|
|
19
20
|
"@eslint/js": "^9.12.0",
|
|
20
|
-
"eslint": "^9.
|
|
21
|
-
"eslint-import-resolver-typescript": "^3.
|
|
21
|
+
"eslint": "^9.20.1",
|
|
22
|
+
"eslint-import-resolver-typescript": "^3.8.2",
|
|
22
23
|
"eslint-import-resolver-webpack": "^0.13.10",
|
|
23
24
|
"eslint-plugin-import-x": "^4.6.1",
|
|
24
25
|
"eslint-plugin-mocha": "^10.5.0",
|
|
25
26
|
"eslint-plugin-promise": "^7.2.1",
|
|
26
|
-
"eslint-plugin-react": "^7.37.
|
|
27
|
+
"eslint-plugin-react": "^7.37.4",
|
|
27
28
|
"eslint-plugin-react-hooks": "^5.1.0",
|
|
28
29
|
"eslint-plugin-tsdoc": "^0.4.0",
|
|
29
|
-
"globals": "^15.
|
|
30
|
-
"prettier": "^3.
|
|
31
|
-
"typescript-eslint": "^8.
|
|
30
|
+
"globals": "^15.15.0",
|
|
31
|
+
"prettier": "^3.5.1",
|
|
32
|
+
"typescript-eslint": "^8.24.1"
|
|
33
|
+
},
|
|
34
|
+
"exports": {
|
|
35
|
+
".": "./src/index.js",
|
|
36
|
+
"./prettier.config.js": "./prettier.config.js"
|
|
32
37
|
},
|
|
33
38
|
"files": [
|
|
34
39
|
"prettier.config.js",
|
|
35
40
|
"src"
|
|
36
41
|
],
|
|
37
42
|
"license": "MIT",
|
|
38
|
-
"main": "src/index.js",
|
|
39
43
|
"name": "@keeex/eslint-config",
|
|
40
44
|
"peerDependencies": {
|
|
41
45
|
"@eslint/compat": "^1.2.0",
|
|
@@ -112,5 +116,5 @@
|
|
|
112
116
|
"test": "echo No test for this project"
|
|
113
117
|
},
|
|
114
118
|
"type": "module",
|
|
115
|
-
"version": "2.
|
|
119
|
+
"version": "2.4.0"
|
|
116
120
|
}
|
package/prettier.config.js
CHANGED
package/src/bin/kxeslint-dump.js
CHANGED
|
@@ -4,10 +4,13 @@ import * as fs from "node:fs";
|
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
|
|
7
|
+
import prompts from "prompts";
|
|
8
|
+
|
|
7
9
|
import * as deps from "../dependencies.js";
|
|
8
10
|
import {setDepCheck} from "../environ.js";
|
|
9
11
|
|
|
10
12
|
const getEslintConfig = () => path.resolve(process.cwd(), "eslint.config.js");
|
|
13
|
+
|
|
11
14
|
const depsCheck = async () => {
|
|
12
15
|
console.group("eslint dependencies checking…");
|
|
13
16
|
try {
|
|
@@ -43,22 +46,159 @@ const depsCheck = async () => {
|
|
|
43
46
|
console.groupEnd();
|
|
44
47
|
}
|
|
45
48
|
};
|
|
49
|
+
|
|
46
50
|
const eslintRcCandidates = [".js", ".cjs", ".json"];
|
|
51
|
+
|
|
47
52
|
const getEslintrcPath = () => {
|
|
48
53
|
for (const candidate of eslintRcCandidates) {
|
|
49
54
|
const eslintrcPath = path.join(process.cwd(), `.eslintrc${candidate}`);
|
|
50
55
|
if (fs.existsSync(eslintrcPath)) return eslintrcPath;
|
|
51
56
|
}
|
|
52
57
|
};
|
|
58
|
+
|
|
53
59
|
const deleteLine = "DELETE THIS LINE WHEN CONFIGURED";
|
|
60
|
+
|
|
54
61
|
const defaultConfig = `
|
|
55
62
|
// ${deleteLine}
|
|
56
63
|
import eslintConfig from "@keeex/eslint-config";
|
|
57
64
|
|
|
58
65
|
export default await eslintConfig({});
|
|
59
66
|
`.trim();
|
|
67
|
+
|
|
68
|
+
const getOptionsFromTargetFilter = (target) => {
|
|
69
|
+
switch (target) {
|
|
70
|
+
case "js":
|
|
71
|
+
return {
|
|
72
|
+
haveMocha: "maybe",
|
|
73
|
+
haveReact: false,
|
|
74
|
+
};
|
|
75
|
+
case "node":
|
|
76
|
+
return {
|
|
77
|
+
haveMocha: "maybe",
|
|
78
|
+
haveReact: "maybe",
|
|
79
|
+
};
|
|
80
|
+
case "browser":
|
|
81
|
+
return {
|
|
82
|
+
haveMocha: "maybe",
|
|
83
|
+
haveReact: "maybe",
|
|
84
|
+
};
|
|
85
|
+
case "react-native":
|
|
86
|
+
return {
|
|
87
|
+
haveMocha: false,
|
|
88
|
+
haveReact: true,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
throw new Error("Unexpected state");
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const getBooleanPrompt = async (message) => {
|
|
95
|
+
const replyValue = await prompts({
|
|
96
|
+
initial: true,
|
|
97
|
+
message,
|
|
98
|
+
name: "value",
|
|
99
|
+
type: "toggle",
|
|
100
|
+
});
|
|
101
|
+
return replyValue.value;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const getOptionsFromTarget = async (target) => {
|
|
105
|
+
let {haveMocha, haveReact} = await getOptionsFromTargetFilter(target);
|
|
106
|
+
if (haveReact === "maybe") haveReact = await getBooleanPrompt("Use React?");
|
|
107
|
+
if (haveMocha === "maybe") haveMocha = await getBooleanPrompt("Use Mocha?");
|
|
108
|
+
return {haveReact, haveMocha};
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const getAvailableEnv = (target, haveMocha, haveReact) => {
|
|
112
|
+
switch (target) {
|
|
113
|
+
case "js":
|
|
114
|
+
if (haveMocha) return ["library"];
|
|
115
|
+
return [];
|
|
116
|
+
case "node":
|
|
117
|
+
if (haveReact) return ["webservice", "node", "none"];
|
|
118
|
+
return ["node"];
|
|
119
|
+
case "browser":
|
|
120
|
+
return ["webapp", "weblibrary"];
|
|
121
|
+
case "react-native":
|
|
122
|
+
return ["mobile"];
|
|
123
|
+
}
|
|
124
|
+
throw new Error("Unexpected state");
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const getEnvTitle = (envName) => {
|
|
128
|
+
switch (envName) {
|
|
129
|
+
case "webservice":
|
|
130
|
+
return "Webservice (server + webapp)";
|
|
131
|
+
case "webapp":
|
|
132
|
+
return "Webapp only";
|
|
133
|
+
case "weblibrary":
|
|
134
|
+
return "Library for browsers only";
|
|
135
|
+
case "mobile":
|
|
136
|
+
return "React-native mobile app";
|
|
137
|
+
case "library":
|
|
138
|
+
return "Pure JavaScript library";
|
|
139
|
+
case "node":
|
|
140
|
+
return "NodeJS application";
|
|
141
|
+
case "none":
|
|
142
|
+
return "Do not pick an environment";
|
|
143
|
+
}
|
|
144
|
+
throw new Error("Unexpected state");
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const getEnvFromTarget = async (target, haveMocha, haveReact) => {
|
|
148
|
+
const availableEnv = getAvailableEnv(target, haveMocha, haveReact);
|
|
149
|
+
if (availableEnv.length === 0) return null;
|
|
150
|
+
if (availableEnv.length === 1) return availableEnv[0];
|
|
151
|
+
const choice = await prompts({
|
|
152
|
+
choices: availableEnv.map((e) => ({title: getEnvTitle(e), value: e})),
|
|
153
|
+
message: "Target environment?",
|
|
154
|
+
name: "value",
|
|
155
|
+
type: "select",
|
|
156
|
+
});
|
|
157
|
+
if (!choice.value) return null;
|
|
158
|
+
return choice.value;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const genConfig = (targetEnv, mocha, react) => {
|
|
162
|
+
const configRows = [];
|
|
163
|
+
if (targetEnv && targetEnv !== "none") {
|
|
164
|
+
configRows.push(`"environments": ${JSON.stringify(targetEnv)}`);
|
|
165
|
+
}
|
|
166
|
+
configRows.push(`"mocha": ${JSON.stringify(mocha)}`);
|
|
167
|
+
configRows.push(`"react": ${JSON.stringify(react)}`);
|
|
168
|
+
configRows.push('"typescript": true');
|
|
169
|
+
return `
|
|
170
|
+
import eslintConfig from "@keeex/eslint-config";
|
|
171
|
+
|
|
172
|
+
export default await eslintConfig({
|
|
173
|
+
${configRows.map((c) => ` ${c},`).join("\n")}
|
|
174
|
+
});
|
|
175
|
+
`.trim();
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/** Generate a new base config based on a few questions. */
|
|
179
|
+
const getNewConfig = async () => {
|
|
180
|
+
const generalTarget = await prompts({
|
|
181
|
+
choices: [
|
|
182
|
+
{title: "Generic JavaScript", value: "js"},
|
|
183
|
+
{title: "NodeJS", value: "node"},
|
|
184
|
+
{title: "Browser", value: "browser"},
|
|
185
|
+
{title: "React Native", value: "react-native"},
|
|
186
|
+
],
|
|
187
|
+
message: "General target environment",
|
|
188
|
+
name: "value",
|
|
189
|
+
type: "select",
|
|
190
|
+
});
|
|
191
|
+
const target = generalTarget.value;
|
|
192
|
+
if (!target) return null;
|
|
193
|
+
const {haveMocha, haveReact} = await getOptionsFromTarget(target);
|
|
194
|
+
const targetEnv = await getEnvFromTarget(target, haveMocha, haveReact);
|
|
195
|
+
return genConfig(targetEnv, haveMocha, haveReact);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const enforceNewline = (str) => (str.endsWith("\n") ? str : `${str}\n`);
|
|
199
|
+
|
|
60
200
|
/** Return true if the flat config system is ok */
|
|
61
|
-
const checkEslintConfig = () => {
|
|
201
|
+
const checkEslintConfig = async () => {
|
|
62
202
|
console.group("Checking eslint config file…");
|
|
63
203
|
try {
|
|
64
204
|
const eslintrcPath = getEslintrcPath();
|
|
@@ -77,11 +217,15 @@ const checkEslintConfig = () => {
|
|
|
77
217
|
return false;
|
|
78
218
|
}
|
|
79
219
|
if (!fs.existsSync(eslintConfigPath)) {
|
|
80
|
-
console.log(
|
|
81
|
-
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
|
|
220
|
+
console.log(`- No ${eslintConfigPath} found. Generating new config.`);
|
|
221
|
+
const configContent = await getNewConfig();
|
|
222
|
+
if (configContent === null) {
|
|
223
|
+
console.log(" Default config file generated. You'll have to edit it manually.");
|
|
224
|
+
fs.writeFileSync(eslintConfigPath, enforceNewline(defaultConfig));
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
fs.writeFileSync(eslintConfigPath, enforceNewline(configContent));
|
|
228
|
+
return true;
|
|
85
229
|
}
|
|
86
230
|
const configContent = fs.readFileSync(eslintConfigPath, "utf8");
|
|
87
231
|
if (configContent.indexOf(deleteLine) !== -1) {
|
|
@@ -99,7 +243,9 @@ const checkEslintConfig = () => {
|
|
|
99
243
|
console.groupEnd();
|
|
100
244
|
}
|
|
101
245
|
};
|
|
246
|
+
|
|
102
247
|
const PRETTIER_CONFIG = "prettier.config.js";
|
|
248
|
+
|
|
103
249
|
const prettierSetup = () => {
|
|
104
250
|
console.group("Checking prettier config");
|
|
105
251
|
try {
|
|
@@ -120,6 +266,7 @@ export default config;
|
|
|
120
266
|
console.groupEnd();
|
|
121
267
|
}
|
|
122
268
|
};
|
|
269
|
+
|
|
123
270
|
const checkTsConfig = () => {
|
|
124
271
|
const needTsConfig = deps.needDependencies("typescript-eslint");
|
|
125
272
|
if (!needTsConfig) return;
|
|
@@ -132,10 +279,22 @@ const checkTsConfig = () => {
|
|
|
132
279
|
console.groupEnd();
|
|
133
280
|
}
|
|
134
281
|
};
|
|
282
|
+
|
|
283
|
+
const checkProjectType = () => {
|
|
284
|
+
const packageContent = JSON.parse(fs.readFileSync("package.json", "utf8"));
|
|
285
|
+
if (packageContent.type !== "module") {
|
|
286
|
+
console.error("package.json type is not module.");
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
return true;
|
|
290
|
+
};
|
|
291
|
+
|
|
135
292
|
const main = async () => {
|
|
136
293
|
console.group("KeeeX eslint and prettier configuration setup");
|
|
137
294
|
try {
|
|
138
|
-
const
|
|
295
|
+
const typeOk = checkProjectType();
|
|
296
|
+
if (!typeOk) return;
|
|
297
|
+
const configOk = await checkEslintConfig();
|
|
139
298
|
if (!configOk) return;
|
|
140
299
|
await prettierSetup();
|
|
141
300
|
await depsCheck();
|
package/src/config/globals.js
CHANGED
|
@@ -4,6 +4,7 @@ import * as pathutils from "../pathutils.js";
|
|
|
4
4
|
import * as sections from "../sections.js";
|
|
5
5
|
|
|
6
6
|
const base = {builtin: true, es2025: true};
|
|
7
|
+
|
|
7
8
|
/** Create the actual eslint globals object from user input */
|
|
8
9
|
const getGlobalsFromConfig = (configGlobals) => {
|
|
9
10
|
const res = {};
|
|
@@ -19,6 +20,7 @@ const getGlobalsFromConfig = (configGlobals) => {
|
|
|
19
20
|
if (configGlobals?.custom) Object.assign(res, configGlobals.custom);
|
|
20
21
|
return res;
|
|
21
22
|
};
|
|
23
|
+
|
|
22
24
|
const addEnv = ({configResult, eslintConfig}, name, fileTypes, globalsEsm, globalsCjs) => {
|
|
23
25
|
const envDirs = pathutils.getEnvDirectories(name, eslintConfig.environments);
|
|
24
26
|
if (envDirs.length === 0) return;
|
|
@@ -57,6 +59,7 @@ const addEnv = ({configResult, eslintConfig}, name, fileTypes, globalsEsm, globa
|
|
|
57
59
|
getGlobalsFromConfig({...(globalsCjs ?? globalsEsm), commonjs: true}),
|
|
58
60
|
);
|
|
59
61
|
};
|
|
62
|
+
|
|
60
63
|
const addNodeEnv = (configResult, eslintConfig) => {
|
|
61
64
|
addEnv(
|
|
62
65
|
{configResult, eslintConfig},
|
|
@@ -66,15 +69,19 @@ const addNodeEnv = (configResult, eslintConfig) => {
|
|
|
66
69
|
{nodeCjs: true, worker: true},
|
|
67
70
|
);
|
|
68
71
|
};
|
|
72
|
+
|
|
69
73
|
const addWebappEnv = (configResult, eslintConfig) => {
|
|
70
74
|
addEnv({configResult, eslintConfig}, "webapp", {jsx: true}, {browser: true, serviceworker: true});
|
|
71
75
|
};
|
|
76
|
+
|
|
72
77
|
const addMobileEnv = (configResult, eslintConfig) => {
|
|
73
78
|
addEnv({configResult, eslintConfig}, "mobile", {jsx: true}, {browser: true});
|
|
74
79
|
};
|
|
80
|
+
|
|
75
81
|
const addMochaEnv = (configResult, eslintConfig) => {
|
|
76
82
|
addEnv({configResult, eslintConfig}, "mocha", {}, {mocha: true});
|
|
77
83
|
};
|
|
84
|
+
|
|
78
85
|
export const apply = (configResult, eslintConfig) => {
|
|
79
86
|
const sharedGlobals = eslintConfig.globals.find((c) => c.files === undefined) ?? {globals: {}};
|
|
80
87
|
const sharedSection = sections.getNamedSection(configResult, "keeex/shared");
|
package/src/config/importx.js
CHANGED
package/src/config/mocha.js
CHANGED
|
@@ -21,8 +21,15 @@ export const apply = (configResult, eslintConfig) => {
|
|
|
21
21
|
"no-setup-in-describe": "off",
|
|
22
22
|
"prefer-arrow-callback": "off",
|
|
23
23
|
});
|
|
24
|
+
sections.configureRules(override, "mocha", {
|
|
25
|
+
"no-exports": "off",
|
|
26
|
+
"no-setup-in-describe": "off",
|
|
27
|
+
"no-top-level-hooks": "off",
|
|
28
|
+
});
|
|
24
29
|
if (eslintConfig.typescript) {
|
|
25
30
|
sections.configureRules(override, "@typescript-eslint", {
|
|
31
|
+
"explicit-function-return-type": "off",
|
|
32
|
+
"init-declarations": "off",
|
|
26
33
|
"max-params": "off",
|
|
27
34
|
"no-magic-numbers": "off",
|
|
28
35
|
});
|
package/src/config/react.js
CHANGED
|
@@ -5,6 +5,7 @@ import {getFilesEnv} from "../pathutils.js";
|
|
|
5
5
|
import * as sections from "../sections.js";
|
|
6
6
|
|
|
7
7
|
import {getReactFullConfig} from "./reactfullconfig.js";
|
|
8
|
+
|
|
8
9
|
// eslint-disable-next-line max-lines-per-function
|
|
9
10
|
export const apply = (configResult, eslintConfig) => {
|
|
10
11
|
const reactCfg = getReactFullConfig(eslintConfig.react);
|
package/src/config/typescript.js
CHANGED
package/src/defaults.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** List of ignored patterns by default */
|
|
2
2
|
export const ignores = ["lib", "web", "gen", "src/gen"];
|
|
3
|
+
|
|
3
4
|
/** Default globals affected to all projects */
|
|
4
5
|
export const globals = [
|
|
5
6
|
{globals: {builtin: true, es2025: true}},
|
|
@@ -9,5 +10,6 @@ export const globals = [
|
|
|
9
10
|
{files: ["*.cjs"], globals: {nodeCjs: true}},
|
|
10
11
|
{files: ["src/tests/**/*", "src/**/*.test.*"], globals: {mocha: true}},
|
|
11
12
|
];
|
|
13
|
+
|
|
12
14
|
/** Import cycle max depth */
|
|
13
15
|
export const cycleMaxDepth = true;
|
package/src/dependencies.js
CHANGED
|
@@ -6,8 +6,10 @@ import * as path from "node:path";
|
|
|
6
6
|
import {satisfies} from "semver";
|
|
7
7
|
|
|
8
8
|
import {getReactFullConfig} from "./config/reactfullconfig.js";
|
|
9
|
+
|
|
9
10
|
/** name => {version: string, force: boolean} */
|
|
10
11
|
const requiredDependencies = {};
|
|
12
|
+
|
|
11
13
|
/** List of dependencies no longer used and that should be removed */
|
|
12
14
|
const removedDependencies = [
|
|
13
15
|
"@typescript-eslint/eslint-plugin",
|
|
@@ -18,8 +20,11 @@ const removedDependencies = [
|
|
|
18
20
|
"eslint-plugin-import",
|
|
19
21
|
"eslint-plugin-react-native",
|
|
20
22
|
];
|
|
23
|
+
|
|
21
24
|
let pkgJson;
|
|
25
|
+
|
|
22
26
|
export const needDependencies = (name) => name in requiredDependencies;
|
|
27
|
+
|
|
23
28
|
/**
|
|
24
29
|
* Retrieve the current project's "package.json".
|
|
25
30
|
*
|
|
@@ -36,6 +41,7 @@ export const getPkgJson = () => {
|
|
|
36
41
|
}
|
|
37
42
|
return pkgJson;
|
|
38
43
|
};
|
|
44
|
+
|
|
39
45
|
/** Get installed package version */
|
|
40
46
|
const getInstalledVersion = (name) => {
|
|
41
47
|
try {
|
|
@@ -47,6 +53,7 @@ const getInstalledVersion = (name) => {
|
|
|
47
53
|
return "<unknown>";
|
|
48
54
|
}
|
|
49
55
|
};
|
|
56
|
+
|
|
50
57
|
/**
|
|
51
58
|
* Check if a particular dependency is installed in the project.
|
|
52
59
|
*
|
|
@@ -60,6 +67,7 @@ const dependencyStatus = (name) => {
|
|
|
60
67
|
const version = installed === "missing" ? undefined : getInstalledVersion(name);
|
|
61
68
|
return {installed, version};
|
|
62
69
|
};
|
|
70
|
+
|
|
63
71
|
/**
|
|
64
72
|
* Add an NPM dependency to the list
|
|
65
73
|
*
|
|
@@ -70,6 +78,7 @@ const dependencyStatus = (name) => {
|
|
|
70
78
|
export const addDependency = (depName, version) => {
|
|
71
79
|
requiredDependencies[depName] = {version: version ?? true, force: false};
|
|
72
80
|
};
|
|
81
|
+
|
|
73
82
|
/**
|
|
74
83
|
* Run a process, and display the output if an error occured.
|
|
75
84
|
*
|
|
@@ -90,6 +99,7 @@ const runProcess = (cmd, ...args) => {
|
|
|
90
99
|
}
|
|
91
100
|
return true;
|
|
92
101
|
};
|
|
102
|
+
|
|
93
103
|
/**
|
|
94
104
|
* List all missing/extra dependencies.
|
|
95
105
|
*
|
|
@@ -119,6 +129,7 @@ export const listDependencies = () => {
|
|
|
119
129
|
console.groupEnd();
|
|
120
130
|
}
|
|
121
131
|
};
|
|
132
|
+
|
|
122
133
|
/**
|
|
123
134
|
* Run the required installation/removal.
|
|
124
135
|
*
|
|
@@ -150,6 +161,7 @@ export const installAndRemoveDeps = () => {
|
|
|
150
161
|
}
|
|
151
162
|
return true;
|
|
152
163
|
};
|
|
164
|
+
|
|
153
165
|
/** Add all dependencies needed by the provided config */
|
|
154
166
|
export const configToDependencies = (eslintConfig) => {
|
|
155
167
|
addDependency("eslint", "9.x");
|
package/src/environ.js
CHANGED
package/src/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import * as defaults from "./defaults.js";
|
|
|
4
4
|
import {configToDependencies} from "./dependencies.js";
|
|
5
5
|
import * as environ from "./environ.js";
|
|
6
6
|
import {clearConfig} from "./sections.js";
|
|
7
|
+
|
|
7
8
|
/** Setup all defaults in the eslintParams config */
|
|
8
9
|
const configDefaults = (eslintParams) => ({
|
|
9
10
|
environments: eslintParams?.environments ?? "node",
|
|
@@ -15,6 +16,7 @@ const configDefaults = (eslintParams) => ({
|
|
|
15
16
|
react: eslintParams?.react ?? false,
|
|
16
17
|
typescript: eslintParams?.typescript ?? true,
|
|
17
18
|
});
|
|
19
|
+
|
|
18
20
|
/**
|
|
19
21
|
* Build the eslint configuration from the provided settings.
|
|
20
22
|
*
|
package/src/pathutils.js
CHANGED
|
@@ -2,21 +2,25 @@ const asArray = (value) => {
|
|
|
2
2
|
if (Array.isArray(value)) return value;
|
|
3
3
|
return [value];
|
|
4
4
|
};
|
|
5
|
+
|
|
5
6
|
const envShorthands = {
|
|
6
7
|
library: {mocha: ["src/**/*.test.*", "src/tests/**/*"], node: ""},
|
|
7
8
|
mobile: {mobile: "src/**"},
|
|
8
9
|
node: {node: ["", "src/**"], mocha: ["src/**/*.test.*", "src/tests/**/*"]},
|
|
9
10
|
webapp: {webapp: ["src/**", "webres/*/js/**"]},
|
|
11
|
+
weblibrary: {webapp: "src/**", mocha: ["src/**/*.test.*", "src/tests/**/*"]},
|
|
10
12
|
webservice: {
|
|
11
13
|
mocha: ["src/**/*.test.*", "src/tests/**/*"],
|
|
12
14
|
node: ["", "bin/**", "src/bin/**", "src/server/**"],
|
|
13
15
|
webapp: ["src/webapp/**", "webres/*/js/**"],
|
|
14
16
|
},
|
|
15
17
|
};
|
|
18
|
+
|
|
16
19
|
const getEffectiveEnv = (configEnv) => {
|
|
17
20
|
if (typeof configEnv !== "string") return configEnv;
|
|
18
21
|
return envShorthands[configEnv];
|
|
19
22
|
};
|
|
23
|
+
|
|
20
24
|
/**
|
|
21
25
|
* @param {Array<string>|string} environments - List of environments to pull
|
|
22
26
|
* @param {Array<string>|string} configEnv - List of configured environments
|
|
@@ -30,6 +34,7 @@ export const getEnvDirectories = (environments, configEnv, defaultDir) => {
|
|
|
30
34
|
if (dirs.length === 0 && defaultDir) return [defaultDir];
|
|
31
35
|
return dirs;
|
|
32
36
|
};
|
|
37
|
+
|
|
33
38
|
export const getExtensions = (fileTypes) => {
|
|
34
39
|
const result = [];
|
|
35
40
|
const esm = fileTypes.esm ?? true;
|
|
@@ -48,6 +53,7 @@ export const getExtensions = (fileTypes) => {
|
|
|
48
53
|
}
|
|
49
54
|
return result;
|
|
50
55
|
};
|
|
56
|
+
|
|
51
57
|
/** Configuration to build a filter list */
|
|
52
58
|
// interface FilesDefinition {
|
|
53
59
|
// /** Directories where the files are; no recursion */
|
|
@@ -74,6 +80,7 @@ export const getExtensions = (fileTypes) => {
|
|
|
74
80
|
// };
|
|
75
81
|
// }
|
|
76
82
|
const extPlaceholder = ".ext";
|
|
83
|
+
|
|
77
84
|
export const getFiles = (definitions) => {
|
|
78
85
|
const result = new Set();
|
|
79
86
|
for (const definition of asArray(definitions)) {
|
|
@@ -106,6 +113,7 @@ export const getFiles = (definitions) => {
|
|
|
106
113
|
}
|
|
107
114
|
return Array.from(result);
|
|
108
115
|
};
|
|
116
|
+
|
|
109
117
|
/** Get a list of file glob depending on config and requested file types */
|
|
110
118
|
export const getFilesEnv = (eslintConfig, environments, filePatterns, fileTypes, defaultDir) => {
|
|
111
119
|
const effectiveFileTypes = fileTypes
|
package/src/sections.js
CHANGED
|
@@ -15,6 +15,7 @@ export const getNamedSection = (configResult, name) => {
|
|
|
15
15
|
configResult.push(newSection);
|
|
16
16
|
return newSection;
|
|
17
17
|
};
|
|
18
|
+
|
|
18
19
|
/**
|
|
19
20
|
* Add a property in an object on the provided section.
|
|
20
21
|
*
|
|
@@ -37,6 +38,7 @@ export const sectionAddOption = (configSection, optionGroup, optionName, value)
|
|
|
37
38
|
configSection[optionGroup][optionName] = value;
|
|
38
39
|
}
|
|
39
40
|
};
|
|
41
|
+
|
|
40
42
|
/** Merge/create the rules property */
|
|
41
43
|
export const configureRules = (configSection, prefix, rules) => {
|
|
42
44
|
let prefixed = {};
|
|
@@ -47,6 +49,7 @@ export const configureRules = (configSection, prefix, rules) => {
|
|
|
47
49
|
}
|
|
48
50
|
configSection.rules = {...configSection.rules, ...prefixed};
|
|
49
51
|
};
|
|
52
|
+
|
|
50
53
|
/** Remove the `_kxconfig` property from all sections and return a suitable object. */
|
|
51
54
|
export const clearConfig = (configResult) => {
|
|
52
55
|
const emptySectionsId = [];
|