@keeex/eslint-config 2.0.2 → 2.1.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 +16 -0
- package/package.json +11 -6
- package/src/bin/kxeslint-setup.js +59 -12
- package/src/config/base.js +133 -141
- package/src/config/globals.js +7 -3
- package/src/config/importx.js +53 -59
- package/src/config/mocha.js +10 -18
- package/src/config/react/reacthooks.js +2 -1
- package/src/config/react/reactnative.js +10 -14
- package/src/config/react.js +60 -58
- package/src/config/reactfullconfig.js +4 -2
- package/src/config/typescript.js +28 -42
- package/src/defaults.js +6 -9
- package/src/dependencies.js +21 -11
- package/src/environ.js +1 -1
- package/src/index.js +19 -19
- package/src/sections.js +5 -5
package/README.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Common eslint configuration for KeeeX
|
|
2
2
|
|
|
3
|
+
## Description
|
|
4
|
+
Manage the eslint and prettier configuration used through all KeeeX projects.
|
|
5
|
+
|
|
6
|
+
### tl;dr
|
|
7
|
+
|
|
8
|
+
- install the package
|
|
9
|
+
- run `npx kxeslint-setup` to run some check
|
|
10
|
+
- configure eslint in `eslint.config.js`
|
|
11
|
+
- run `npx kxeslint-setup auto` to install all required dependencies
|
|
12
|
+
- enable eslint and prettier in whatever you use
|
|
13
|
+
|
|
3
14
|
## Installation
|
|
4
15
|
The package is available on npmjs and can be installed with any package manager that supports it.
|
|
5
16
|
|
|
@@ -32,6 +43,10 @@ export default await eslintConfig({
|
|
|
32
43
|
files: ["src/bin/**/*", "src/server/**/*"],
|
|
33
44
|
globals: {node: true},
|
|
34
45
|
},
|
|
46
|
+
{
|
|
47
|
+
files: ["*.cjs"],
|
|
48
|
+
globals: {nodeCjs: true},
|
|
49
|
+
},
|
|
35
50
|
{
|
|
36
51
|
files: ["src/tests/**/*", "src/**/*.test.*"],
|
|
37
52
|
globals: {mocha: true},
|
|
@@ -64,6 +79,7 @@ be considered, and `globals`, which is an object that can have the following pro
|
|
|
64
79
|
- "es2025": globals available in ES2025 scripts
|
|
65
80
|
- "mocha": globals available in Mocha tests
|
|
66
81
|
- "node": globals available in Node.js
|
|
82
|
+
- "nodeCjs": globals for Node.js in commonjs
|
|
67
83
|
- "serviceworker": globals available in Service Workers
|
|
68
84
|
- "worker": globals available in Workers
|
|
69
85
|
- "custom": an object of custom identifiers to be made available, whose keys are the identifiers and
|
package/package.json
CHANGED
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
},
|
|
16
16
|
"description": "Common eslint configuration",
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@eslint/compat": "^1.2.
|
|
18
|
+
"@eslint/compat": "^1.2.1",
|
|
19
19
|
"@eslint/js": "^9.12.0",
|
|
20
|
-
"eslint": "
|
|
20
|
+
"eslint": "9.x",
|
|
21
21
|
"eslint-import-resolver-typescript": "^3.6.3",
|
|
22
|
-
"eslint-import-resolver-webpack": "
|
|
22
|
+
"eslint-import-resolver-webpack": "^0.13.9",
|
|
23
23
|
"eslint-plugin-import-x": "^4.3.1",
|
|
24
24
|
"eslint-plugin-mocha": "^10.5.0",
|
|
25
25
|
"eslint-plugin-promise": "^7.1.0",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"eslint-plugin-react-native": "^4.1.0",
|
|
29
29
|
"eslint-plugin-tsdoc": "^0.3.0",
|
|
30
30
|
"globals": "^15.11.0",
|
|
31
|
-
"
|
|
31
|
+
"prettier": "^3.3.3",
|
|
32
|
+
"typescript-eslint": "^8.11.0"
|
|
32
33
|
},
|
|
33
34
|
"files": [
|
|
34
35
|
"src"
|
|
@@ -37,7 +38,7 @@
|
|
|
37
38
|
"main": "src/index.js",
|
|
38
39
|
"name": "@keeex/eslint-config",
|
|
39
40
|
"overrides": {
|
|
40
|
-
"eslint": "
|
|
41
|
+
"eslint": "9.x",
|
|
41
42
|
"eslint-plugin-react-native": "^4.1.0"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
@@ -54,6 +55,7 @@
|
|
|
54
55
|
"eslint-plugin-react-native": "4.x",
|
|
55
56
|
"eslint-plugin-tsdoc": "0.x",
|
|
56
57
|
"globals": "15.x",
|
|
58
|
+
"prettier": "3.x",
|
|
57
59
|
"typescript-eslint": "8.x"
|
|
58
60
|
},
|
|
59
61
|
"peerDependenciesMeta": {
|
|
@@ -96,6 +98,9 @@
|
|
|
96
98
|
"globals": {
|
|
97
99
|
"optional": true
|
|
98
100
|
},
|
|
101
|
+
"prettier": {
|
|
102
|
+
"optional": true
|
|
103
|
+
},
|
|
99
104
|
"typescript-eslint": {
|
|
100
105
|
"optional": true
|
|
101
106
|
}
|
|
@@ -115,5 +120,5 @@
|
|
|
115
120
|
"test": "echo No test for this project"
|
|
116
121
|
},
|
|
117
122
|
"type": "module",
|
|
118
|
-
"version": "2.0
|
|
123
|
+
"version": "2.1.0"
|
|
119
124
|
}
|
|
@@ -21,25 +21,25 @@ const depsCheck = async () => {
|
|
|
21
21
|
if (dependencies.length === 0) {
|
|
22
22
|
console.log("- All eslint dependencies installed");
|
|
23
23
|
} else {
|
|
24
|
-
const toRemove = dependencies.filter(c => c.action === "remove");
|
|
25
|
-
const toInstall = dependencies.filter(c => c.action === "install");
|
|
24
|
+
const toRemove = dependencies.filter((c) => c.action === "remove");
|
|
25
|
+
const toInstall = dependencies.filter((c) => c.action === "install");
|
|
26
26
|
if (toRemove.length > 0) {
|
|
27
27
|
console.group("- Dependencies to remove:");
|
|
28
|
-
toRemove.forEach(c => console.log(`- ${c.name}`));
|
|
28
|
+
toRemove.forEach((c) => console.log(`- ${c.name}`));
|
|
29
29
|
console.groupEnd();
|
|
30
30
|
}
|
|
31
31
|
if (toInstall.length > 0) {
|
|
32
32
|
console.group("Dependencies to install:");
|
|
33
|
-
toInstall.forEach(c => console.log(`- ${c.name}`));
|
|
33
|
+
toInstall.forEach((c) => console.log(`- ${c.name}`));
|
|
34
34
|
console.groupEnd();
|
|
35
35
|
}
|
|
36
36
|
if (process.argv.includes("auto")) {
|
|
37
37
|
console.log("Auto mode enabled, installing dependencies");
|
|
38
38
|
deps.installAndRemoveDeps();
|
|
39
39
|
} else if (dependencies.length > 0) {
|
|
40
|
-
console.log(
|
|
40
|
+
console.log('To enable auto mode, run this command with the "auto" flag');
|
|
41
41
|
}
|
|
42
|
-
}
|
|
42
|
+
}
|
|
43
43
|
} finally {
|
|
44
44
|
console.groupEnd();
|
|
45
45
|
}
|
|
@@ -71,21 +71,29 @@ const checkEslintConfig = () => {
|
|
|
71
71
|
const eslintConfigPath = getEslintConfig();
|
|
72
72
|
if (eslintrcPath) {
|
|
73
73
|
if (fs.existsSync(eslintConfigPath)) {
|
|
74
|
-
console.log(
|
|
74
|
+
console.log(
|
|
75
|
+
`- Found ${eslintrcPath} but ${eslintConfigPath} already exists; remove ${eslintrcPath} when the configuration migration is complete.`,
|
|
76
|
+
);
|
|
75
77
|
} else {
|
|
76
|
-
console.log(
|
|
78
|
+
console.log(
|
|
79
|
+
`- Found ${eslintrcPath} but no ${eslintConfigPath}; generating empty config. Please migrate from the old config then delete the old file.`,
|
|
80
|
+
);
|
|
77
81
|
fs.writeFileSync(eslintConfigPath, `${defaultConfig}\n`);
|
|
78
82
|
}
|
|
79
83
|
return false;
|
|
80
84
|
}
|
|
81
85
|
if (!fs.existsSync(eslintConfigPath)) {
|
|
82
|
-
console.log(
|
|
86
|
+
console.log(
|
|
87
|
+
`- No ${eslintConfigPath} found. Generating empty config. Please configure it appropriately.`,
|
|
88
|
+
);
|
|
83
89
|
fs.writeFileSync(eslintConfigPath, `${defaultConfig}\n`);
|
|
84
90
|
return false;
|
|
85
91
|
}
|
|
86
92
|
const configContent = fs.readFileSync(eslintConfigPath, "utf8");
|
|
87
93
|
if (configContent.indexOf(deleteLine) !== -1) {
|
|
88
|
-
console.log(
|
|
94
|
+
console.log(
|
|
95
|
+
`- Found ${eslintConfigPath} with the delete line; configure eslint and remove that line.`,
|
|
96
|
+
);
|
|
89
97
|
return false;
|
|
90
98
|
}
|
|
91
99
|
if (fs.existsSync(".eslintignore")) {
|
|
@@ -98,11 +106,50 @@ const checkEslintConfig = () => {
|
|
|
98
106
|
}
|
|
99
107
|
};
|
|
100
108
|
|
|
109
|
+
const PRETTIER_CONFIG = "prettier.config.js";
|
|
110
|
+
|
|
111
|
+
const prettierSetup = () => {
|
|
112
|
+
console.group("Checking prettier config");
|
|
113
|
+
try {
|
|
114
|
+
if (fs.existsSync(PRETTIER_CONFIG)) {
|
|
115
|
+
console.log("Configuration file already exist");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
console.log("Writting prettier configuration file");
|
|
119
|
+
fs.writeFileSync(
|
|
120
|
+
PRETTIER_CONFIG,
|
|
121
|
+
`
|
|
122
|
+
import config from "@keeex/eslint-config/prettier.config.js";
|
|
123
|
+
|
|
124
|
+
export default config;
|
|
125
|
+
`.trimStart(),
|
|
126
|
+
);
|
|
127
|
+
} finally {
|
|
128
|
+
console.groupEnd();
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const checkTsConfig = () => {
|
|
133
|
+
const needTsConfig = deps.needDependencies("typescript-eslint");
|
|
134
|
+
if (!needTsConfig) return;
|
|
135
|
+
console.group("Checking tsconfig");
|
|
136
|
+
try {
|
|
137
|
+
if (!fs.existsSync("tsconfig.json")) {
|
|
138
|
+
console.log("tsconfig.json missing, this will *considerably* slow down eslint");
|
|
139
|
+
}
|
|
140
|
+
} finally {
|
|
141
|
+
console.groupEnd();
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
101
145
|
const main = async () => {
|
|
102
|
-
console.group("KeeeX eslint configuration setup");
|
|
146
|
+
console.group("KeeeX eslint and prettier configuration setup");
|
|
103
147
|
try {
|
|
104
148
|
const configOk = checkEslintConfig();
|
|
105
|
-
if (configOk)
|
|
149
|
+
if (!configOk) return;
|
|
150
|
+
await prettierSetup();
|
|
151
|
+
await depsCheck();
|
|
152
|
+
checkTsConfig();
|
|
106
153
|
} finally {
|
|
107
154
|
console.groupEnd();
|
|
108
155
|
}
|
package/src/config/base.js
CHANGED
|
@@ -16,155 +16,147 @@ export const apply = (configResult, eslintConfig) => {
|
|
|
16
16
|
sections.sectionAddOption(sharedSection, "linterOptions", "reportUnusedDisableDirectives", true);
|
|
17
17
|
sections.sectionAddOption(sharedSection, "languageOptions", "ecmaVersion", "latest");
|
|
18
18
|
sections.sectionAddOption(sharedSection, "languageOptions", "sourceType", "module");
|
|
19
|
-
sections.sectionAddOption(
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
ecmaFeatures: eslintConfig.react ? {jsx: true} : undefined,
|
|
25
|
-
ecmaVersion: "latest",
|
|
26
|
-
sourceType: "module",
|
|
27
|
-
},
|
|
28
|
-
);
|
|
19
|
+
sections.sectionAddOption(sharedSection, "languageOptions", "parserOptions", {
|
|
20
|
+
ecmaFeatures: eslintConfig.react ? {jsx: true} : undefined,
|
|
21
|
+
ecmaVersion: "latest",
|
|
22
|
+
sourceType: "module",
|
|
23
|
+
});
|
|
29
24
|
// Global ignores
|
|
30
25
|
if (eslintConfig.ignores.length > 0) {
|
|
31
26
|
const globalIgnores = sections.getNamedSection(configResult, "keeex/ignores");
|
|
32
27
|
globalIgnores.ignores = [...eslintConfig.ignores];
|
|
33
28
|
}
|
|
34
29
|
// Base eslint
|
|
35
|
-
configResult.push(
|
|
30
|
+
configResult.push({
|
|
31
|
+
name: "eslint/recommended",
|
|
32
|
+
...js.configs.recommended,
|
|
33
|
+
});
|
|
36
34
|
const eslintCustom = sections.getNamedSection(configResult, "keeex/eslint-override");
|
|
37
|
-
sections.configureRules(
|
|
38
|
-
|
|
39
|
-
"",
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
"
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
"sort-keys": ["warn", "asc", {caseSensitive: false, minKeys: 3, natural: true}],
|
|
152
|
-
"symbol-description": "error",
|
|
153
|
-
},
|
|
154
|
-
);
|
|
35
|
+
sections.configureRules(eslintCustom, "", {
|
|
36
|
+
"array-callback-return": "error",
|
|
37
|
+
"arrow-body-style": ["error", "as-needed"],
|
|
38
|
+
"block-scoped-var": "warn",
|
|
39
|
+
"camelcase": "warn",
|
|
40
|
+
"class-methods-use-this": ["warn", {exceptMethods: ["render"]}],
|
|
41
|
+
"complexity": ["warn", {max: 25, variant: "modified"}],
|
|
42
|
+
"curly": ["error", "multi-line"],
|
|
43
|
+
"eqeqeq": "warn",
|
|
44
|
+
"func-style": "error",
|
|
45
|
+
"guard-for-in": "warn",
|
|
46
|
+
"max-classes-per-file": "error",
|
|
47
|
+
"max-depth": ["warn", 5],
|
|
48
|
+
"max-lines": ["warn", {max: 1000, skipBlankLines: true, skipComments: true}],
|
|
49
|
+
"max-lines-per-function": [
|
|
50
|
+
"warn",
|
|
51
|
+
{IIFEs: true, max: 60, skipBlankLines: true, skipComments: true},
|
|
52
|
+
],
|
|
53
|
+
"max-nested-callbacks": ["warn", 6],
|
|
54
|
+
"max-params": ["warn", {max: 5}],
|
|
55
|
+
"no-alert": "error",
|
|
56
|
+
"no-array-constructor": "error",
|
|
57
|
+
"no-await-in-loop": "warn",
|
|
58
|
+
"no-caller": "error",
|
|
59
|
+
"no-console": "warn",
|
|
60
|
+
"no-constant-condition": "warn",
|
|
61
|
+
"no-constructor-return": "error",
|
|
62
|
+
"no-delete-var": "error",
|
|
63
|
+
"no-div-regex": "warn",
|
|
64
|
+
"no-duplicate-imports": "error",
|
|
65
|
+
"no-else-return": "warn",
|
|
66
|
+
"no-eq-null": "error",
|
|
67
|
+
"no-eval": "error",
|
|
68
|
+
"no-extend-native": "error",
|
|
69
|
+
"no-extra-bind": "error",
|
|
70
|
+
"no-extra-label": "warn",
|
|
71
|
+
"no-global-assign": "error",
|
|
72
|
+
"no-implicit-coercion": "warn",
|
|
73
|
+
"no-implied-eval": "error",
|
|
74
|
+
"no-invalid-this": "error",
|
|
75
|
+
"no-irregular-whitespace": [
|
|
76
|
+
"error",
|
|
77
|
+
{
|
|
78
|
+
skipComments: true,
|
|
79
|
+
skipJSXText: true,
|
|
80
|
+
skipRegExps: true,
|
|
81
|
+
skipStrings: true,
|
|
82
|
+
skipTemplates: true,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
"no-iterator": "error",
|
|
86
|
+
"no-label-var": "error",
|
|
87
|
+
"no-lonely-if": "warn",
|
|
88
|
+
"no-loop-func": "warn",
|
|
89
|
+
"no-magic-numbers": [
|
|
90
|
+
"warn",
|
|
91
|
+
{
|
|
92
|
+
ignore: [1, -1, "1n", "-1n", 0, "0n"],
|
|
93
|
+
ignoreClassFieldInitialValues: true,
|
|
94
|
+
ignoreDefaultValues: true,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
"no-multi-assign": "error",
|
|
98
|
+
"no-negated-condition": "warn",
|
|
99
|
+
"no-nested-ternary": "error",
|
|
100
|
+
"no-new-func": "error",
|
|
101
|
+
"no-new-wrappers": "error",
|
|
102
|
+
"no-object-constructor": "error",
|
|
103
|
+
"no-param-reassign": "warn",
|
|
104
|
+
"no-promise-executor-return": "error",
|
|
105
|
+
"no-proto": "error",
|
|
106
|
+
"no-return-assign": "error",
|
|
107
|
+
"no-script-url": "error",
|
|
108
|
+
"no-self-compare": "warn",
|
|
109
|
+
"no-sequences": "warn",
|
|
110
|
+
"no-shadow": "warn",
|
|
111
|
+
"no-shadow-restricted-names": "error",
|
|
112
|
+
"no-throw-literal": "error",
|
|
113
|
+
"no-undef-init": "warn",
|
|
114
|
+
"no-unmodified-loop-condition": "warn",
|
|
115
|
+
"no-unneeded-ternary": "warn",
|
|
116
|
+
"no-unreachable-loop": "warn",
|
|
117
|
+
"no-unused-expressions": "warn",
|
|
118
|
+
"no-use-before-define": "warn",
|
|
119
|
+
"no-useless-assignment": "warn",
|
|
120
|
+
"no-useless-call": "error",
|
|
121
|
+
"no-useless-computed-key": "warn",
|
|
122
|
+
"no-useless-concat": "warn",
|
|
123
|
+
"no-useless-constructor": "warn",
|
|
124
|
+
"no-useless-rename": "warn",
|
|
125
|
+
"no-useless-return": "warn",
|
|
126
|
+
"no-var": "error",
|
|
127
|
+
"no-void": ["error", {allowAsStatement: true}],
|
|
128
|
+
"one-var": ["warn", "never"],
|
|
129
|
+
"prefer-arrow-callback": "warn",
|
|
130
|
+
"prefer-const": ["warn", {ignoreReadBeforeAssign: true}],
|
|
131
|
+
"prefer-exponentiation-operator": "warn",
|
|
132
|
+
"prefer-named-capture-group": "warn",
|
|
133
|
+
"prefer-numeric-literals": "warn",
|
|
134
|
+
"prefer-object-has-own": "warn",
|
|
135
|
+
"prefer-object-spread": "warn",
|
|
136
|
+
"prefer-promise-reject-errors": "error",
|
|
137
|
+
"prefer-regex-literals": "warn",
|
|
138
|
+
"prefer-rest-params": "error",
|
|
139
|
+
"prefer-spread": "error",
|
|
140
|
+
"prefer-template": "warn",
|
|
141
|
+
"radix": ["warn", "as-needed"],
|
|
142
|
+
"require-atomic-updates": "warn",
|
|
143
|
+
"require-await": "warn",
|
|
144
|
+
"require-unicode-regexp": "warn",
|
|
145
|
+
"sort-imports": ["warn", {ignoreCase: true, allowSeparatedGroups: true}],
|
|
146
|
+
"sort-keys": ["warn", "asc", {caseSensitive: false, minKeys: 3, natural: true}],
|
|
147
|
+
"symbol-description": "error",
|
|
148
|
+
});
|
|
155
149
|
// Promises
|
|
156
150
|
configResult.push(pluginPromise.configs["flat/recommended"]);
|
|
157
151
|
const promiseCustom = sections.getNamedSection(configResult, "keeex/promise-override");
|
|
158
|
-
sections.configureRules(
|
|
159
|
-
|
|
160
|
-
"
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
},
|
|
169
|
-
);
|
|
152
|
+
sections.configureRules(promiseCustom, "promise", {
|
|
153
|
+
"avoid-new": "warn",
|
|
154
|
+
"no-multiple-resolved": "error",
|
|
155
|
+
"no-promise-in-callback": "warn",
|
|
156
|
+
"prefer-await-to-then": "warn",
|
|
157
|
+
"spec-only": "error",
|
|
158
|
+
});
|
|
159
|
+
const cjsOverride = sections.getNamedSection(configResult, "keeex/files-cjs");
|
|
160
|
+
cjsOverride.files = ["**/*.cjs"];
|
|
161
|
+
sections.sectionAddOption(cjsOverride, "languageOptions", "sourceType", "commonjs");
|
|
170
162
|
};
|
package/src/config/globals.js
CHANGED
|
@@ -5,7 +5,7 @@ import * as sections from "../sections.js";
|
|
|
5
5
|
const base = {builtin: true, es2025: true};
|
|
6
6
|
|
|
7
7
|
/** Create the actual eslint globals object from user input */
|
|
8
|
-
const getGlobalsFromConfig = configGlobals => {
|
|
8
|
+
const getGlobalsFromConfig = (configGlobals) => {
|
|
9
9
|
const res = {};
|
|
10
10
|
if (configGlobals?.builtin) Object.assign(res, globals.builtin);
|
|
11
11
|
if (configGlobals?.browser) Object.assign(res, globals.browser);
|
|
@@ -13,6 +13,7 @@ const getGlobalsFromConfig = configGlobals => {
|
|
|
13
13
|
if (configGlobals?.es2025) Object.assign(res, globals.es2025);
|
|
14
14
|
if (configGlobals?.mocha) Object.assign(res, globals.mocha);
|
|
15
15
|
if (configGlobals?.node) Object.assign(res, globals.nodeBuiltin);
|
|
16
|
+
if (configGlobals?.nodeCjs) Object.assign(res, globals.node);
|
|
16
17
|
if (configGlobals?.serviceworker) Object.assign(res, globals.serviceworker);
|
|
17
18
|
if (configGlobals?.worker) Object.assign(res, globals.worker);
|
|
18
19
|
if (configGlobals?.custom) Object.assign(res, configGlobals.custom);
|
|
@@ -20,7 +21,7 @@ const getGlobalsFromConfig = configGlobals => {
|
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
export const apply = (configResult, eslintConfig) => {
|
|
23
|
-
const sharedGlobals = eslintConfig.globals.find(c => c.files === undefined);
|
|
24
|
+
const sharedGlobals = eslintConfig.globals.find((c) => c.files === undefined);
|
|
24
25
|
const sharedSection = sections.getNamedSection(configResult, "keeex/shared");
|
|
25
26
|
sections.sectionAddOption(
|
|
26
27
|
sharedSection,
|
|
@@ -30,7 +31,10 @@ export const apply = (configResult, eslintConfig) => {
|
|
|
30
31
|
);
|
|
31
32
|
for (const globalConfig of eslintConfig.globals) {
|
|
32
33
|
if (!globalConfig.files) continue;
|
|
33
|
-
const overrideSection = sections.getNamedSection(
|
|
34
|
+
const overrideSection = sections.getNamedSection(
|
|
35
|
+
configResult,
|
|
36
|
+
`keeex/globals-${globalConfig.files.join(",")}`,
|
|
37
|
+
);
|
|
34
38
|
overrideSection.files = [...globalConfig.files];
|
|
35
39
|
sections.sectionAddOption(
|
|
36
40
|
overrideSection,
|
package/src/config/importx.js
CHANGED
|
@@ -4,7 +4,7 @@ import * as sections from "../sections.js";
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Apply the import-x configs
|
|
7
|
-
*
|
|
7
|
+
*
|
|
8
8
|
* @param configResult - The eslint configuration object currently being built.
|
|
9
9
|
*/
|
|
10
10
|
// eslint-disable-next-line max-lines-per-function
|
|
@@ -14,81 +14,72 @@ export const apply = (configResult, eslintConfig) => {
|
|
|
14
14
|
...eslintPluginImportX.flatConfigs.recommended,
|
|
15
15
|
languageOptions: {},
|
|
16
16
|
});
|
|
17
|
-
if (eslintConfig.typescript)
|
|
17
|
+
if (eslintConfig.typescript) {
|
|
18
|
+
configResult.push({
|
|
19
|
+
...eslintPluginImportX.flatConfigs.typescript,
|
|
20
|
+
name: "import-x/typescript-recommended",
|
|
21
|
+
});
|
|
22
|
+
}
|
|
18
23
|
const override = sections.getNamedSection(configResult, "keeex/importx-override");
|
|
19
|
-
sections.configureRules(
|
|
20
|
-
|
|
21
|
-
"import
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
alphabetize: {
|
|
37
|
-
order: "asc",
|
|
38
|
-
caseInsensitive: true,
|
|
39
|
-
},
|
|
40
|
-
groups: [
|
|
41
|
-
"builtin",
|
|
42
|
-
"external",
|
|
43
|
-
"internal",
|
|
44
|
-
"parent",
|
|
45
|
-
"sibling",
|
|
46
|
-
"index",
|
|
47
|
-
"object",
|
|
48
|
-
"type",
|
|
49
|
-
"unknown",
|
|
50
|
-
],
|
|
51
|
-
"newlines-between": "always-and-inside-groups",
|
|
24
|
+
sections.configureRules(override, "import-x", {
|
|
25
|
+
"first": "error",
|
|
26
|
+
"newline-after-import": "warn",
|
|
27
|
+
"no-amd": "error",
|
|
28
|
+
"no-anonymous-default-export": "warn",
|
|
29
|
+
"no-commonjs": "error",
|
|
30
|
+
"no-empty-named-blocks": "warn",
|
|
31
|
+
"no-named-default": "error",
|
|
32
|
+
"no-self-import": "error",
|
|
33
|
+
"no-unresolved": "warn",
|
|
34
|
+
"no-useless-path-segments": "warn",
|
|
35
|
+
"order": [
|
|
36
|
+
"warn",
|
|
37
|
+
{
|
|
38
|
+
"alphabetize": {
|
|
39
|
+
order: "asc",
|
|
40
|
+
caseInsensitive: true,
|
|
52
41
|
},
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
42
|
+
"groups": [
|
|
43
|
+
"builtin",
|
|
44
|
+
"external",
|
|
45
|
+
"internal",
|
|
46
|
+
"parent",
|
|
47
|
+
"sibling",
|
|
48
|
+
"index",
|
|
49
|
+
"object",
|
|
50
|
+
"type",
|
|
51
|
+
"unknown",
|
|
52
|
+
],
|
|
53
|
+
"newlines-between": "always-and-inside-groups",
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
});
|
|
56
57
|
if (!eslintConfig.noBase) {
|
|
57
58
|
const baseSection = sections.getNamedSection(configResult, "keeex/eslint-override");
|
|
58
59
|
sections.configureRules(baseSection, "", {"sort-imports": "off"});
|
|
59
60
|
}
|
|
60
61
|
if (typeof eslintConfig.import === "number" && eslintConfig.import > 0) {
|
|
61
|
-
sections.configureRules(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
{
|
|
65
|
-
"no-cycle": ["error", {maxDepth: eslintConfig.import}],
|
|
66
|
-
},
|
|
67
|
-
);
|
|
62
|
+
sections.configureRules(override, "import-x", {
|
|
63
|
+
"no-cycle": ["error", {maxDepth: eslintConfig.import}],
|
|
64
|
+
});
|
|
68
65
|
} else if (eslintConfig.import) {
|
|
69
66
|
sections.configureRules(override, "import-x", {"no-cycle": "error"});
|
|
70
67
|
}
|
|
71
68
|
if (eslintConfig.typescript) {
|
|
72
|
-
sections.configureRules(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
{"no-extraneous-dependencies": ["error", {includeTypes: true}]},
|
|
76
|
-
);
|
|
69
|
+
sections.configureRules(override, "import-x", {
|
|
70
|
+
"no-extraneous-dependencies": ["error", {includeTypes: true}],
|
|
71
|
+
});
|
|
77
72
|
if (eslintConfig.react) {
|
|
78
73
|
sections.sectionAddOption(override, "settings", "import-x/extensions", [".ts", ".tsx"]);
|
|
79
74
|
} else {
|
|
80
75
|
sections.sectionAddOption(override, "settings", "import-x/extensions", [".ts"]);
|
|
81
76
|
}
|
|
82
77
|
} else {
|
|
83
|
-
sections.configureRules(
|
|
84
|
-
|
|
85
|
-
"
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
"no-deprecated": "warn",
|
|
89
|
-
"no-extraneous-dependencies": "error",
|
|
90
|
-
},
|
|
91
|
-
);
|
|
78
|
+
sections.configureRules(override, "import-x", {
|
|
79
|
+
"extensions": ["error", "ignorePackages"],
|
|
80
|
+
"no-deprecated": "warn",
|
|
81
|
+
"no-extraneous-dependencies": "error",
|
|
82
|
+
});
|
|
92
83
|
if (eslintConfig.react) {
|
|
93
84
|
sections.sectionAddOption(override, "settings", "import-x/extensions", [".js", ".jsx"]);
|
|
94
85
|
}
|
|
@@ -101,4 +92,7 @@ export const apply = (configResult, eslintConfig) => {
|
|
|
101
92
|
webOverride.files = ["src/webapp"];
|
|
102
93
|
sections.sectionAddOption(webOverride, "settings", "import-x/resolver", "webpack");
|
|
103
94
|
}
|
|
95
|
+
const overrideCjs = sections.getNamedSection(configResult, "keeex/importx-override-cjs");
|
|
96
|
+
overrideCjs.files = ["**/*.cjs"];
|
|
97
|
+
sections.configureRules(overrideCjs, "import-x", {"no-commonjs": "off"});
|
|
104
98
|
};
|
package/src/config/mocha.js
CHANGED
|
@@ -9,26 +9,18 @@ export const apply = (configResult, eslintConfig) => {
|
|
|
9
9
|
...mochaPlugin.configs.flat.recommended,
|
|
10
10
|
files: mochaFilter,
|
|
11
11
|
};
|
|
12
|
-
sections.configureRules(
|
|
13
|
-
|
|
14
|
-
"",
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
sections.configureRules(mochaSection, "", {
|
|
13
|
+
"max-classes-per-file": "off",
|
|
14
|
+
"max-lines": "off",
|
|
15
|
+
"max-lines-per-function": "off",
|
|
16
|
+
"max-params": "off",
|
|
17
|
+
"no-magic-numbers": "off",
|
|
18
|
+
});
|
|
19
|
+
if (eslintConfig.typescript) {
|
|
20
|
+
sections.configureRules(mochaSection, "@typescript-eslint", {
|
|
19
21
|
"max-params": "off",
|
|
20
22
|
"no-magic-numbers": "off",
|
|
21
|
-
}
|
|
22
|
-
);
|
|
23
|
-
if (eslintConfig.typescript) {
|
|
24
|
-
sections.configureRules(
|
|
25
|
-
mochaSection,
|
|
26
|
-
"@typescript-eslint",
|
|
27
|
-
{
|
|
28
|
-
"max-params": "off",
|
|
29
|
-
"no-magic-numbers": "off",
|
|
30
|
-
},
|
|
31
|
-
);
|
|
23
|
+
});
|
|
32
24
|
}
|
|
33
25
|
configResult.push(mochaSection);
|
|
34
26
|
};
|
|
@@ -10,17 +10,13 @@ export const apply = (configResult, eslintConfig) => {
|
|
|
10
10
|
if (!reactCfg.reactNative) return;
|
|
11
11
|
const reactNativeSection = sections.getNamedSection(configResult, "keeex/react-native");
|
|
12
12
|
reactNativeSection.plugins = {"react-native": fixupPluginRules(reactNative)};
|
|
13
|
-
sections.configureRules(
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"split-platform-components": "warn",
|
|
24
|
-
},
|
|
25
|
-
);
|
|
26
|
-
}
|
|
13
|
+
sections.configureRules(reactNativeSection, "react-native", {
|
|
14
|
+
"no-color-literals": "warn",
|
|
15
|
+
"no-inline-styles": "warn",
|
|
16
|
+
"no-raw-text": "error",
|
|
17
|
+
"no-single-element-style-arrays": "error",
|
|
18
|
+
"no-unused-styles": "warn",
|
|
19
|
+
"sort-styles": "warn",
|
|
20
|
+
"split-platform-components": "warn",
|
|
21
|
+
});
|
|
22
|
+
};
|
package/src/config/react.js
CHANGED
|
@@ -10,65 +10,67 @@ export const apply = (configResult, eslintConfig) => {
|
|
|
10
10
|
const reactCfg = getReactFullConfig(eslintConfig.react);
|
|
11
11
|
if (!reactCfg.react) return;
|
|
12
12
|
configResult.push(
|
|
13
|
-
reactPlugin.configs.flat.recommended,
|
|
14
|
-
reactPlugin.configs.flat["jsx-runtime"],
|
|
15
|
-
);
|
|
16
|
-
const override = sections.getNamedSection(configResult, "keeex/react");
|
|
17
|
-
sections.sectionAddOption(override, "settings", "react", {version: "detect"});
|
|
18
|
-
sections.configureRules(
|
|
19
|
-
override,
|
|
20
|
-
"react",
|
|
21
13
|
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
"jsx-
|
|
28
|
-
"jsx-child-element-spacing": "warn",
|
|
29
|
-
"jsx-curly-brace-presence": [
|
|
30
|
-
"error",
|
|
31
|
-
{
|
|
32
|
-
children: "never",
|
|
33
|
-
propElementValues: "always",
|
|
34
|
-
props: "never",
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
"jsx-curly-newline": "warn",
|
|
38
|
-
"jsx-curly-spacing": "warn",
|
|
39
|
-
"jsx-equals-spacing": "warn",
|
|
40
|
-
"jsx-filename-extension": ["error", {extensions: [".js", ".tsx"]}],
|
|
41
|
-
"jsx-fragments": "error",
|
|
42
|
-
"jsx-handler-names": "warn",
|
|
43
|
-
"jsx-indent": ["error", 2],
|
|
44
|
-
"jsx-indent-props": ["error", 2],
|
|
45
|
-
"jsx-max-depth": ["warn", {max: 8}],
|
|
46
|
-
"jsx-no-bind": "error",
|
|
47
|
-
"jsx-no-constructed-context-values": "error",
|
|
48
|
-
"jsx-no-leaked-render": "warn",
|
|
49
|
-
"jsx-no-script-url": "error",
|
|
50
|
-
"jsx-no-useless-fragment": "warn",
|
|
51
|
-
"jsx-pascal-case": ["warn", {allowNamespace: true}],
|
|
52
|
-
"jsx-sort-props": ["warn", { ignoreCase: true}],
|
|
53
|
-
"jsx-tag-spacing": ["warn", {beforeClosing: "never"}],
|
|
54
|
-
"no-access-state-in-setstate": "error",
|
|
55
|
-
"no-array-index-key": "warn",
|
|
56
|
-
"no-arrow-function-lifecycle": "off",
|
|
57
|
-
"no-danger": "error",
|
|
58
|
-
"no-invalid-html-attribute": "error",
|
|
59
|
-
"no-namespace": "error",
|
|
60
|
-
"no-redundant-should-component-update": "error",
|
|
61
|
-
"no-this-in-sfc": "error",
|
|
62
|
-
"no-typos": "error",
|
|
63
|
-
"no-unsafe": "error",
|
|
64
|
-
"no-unstable-nested-components": "error",
|
|
65
|
-
"no-unused-class-component-methods": "warn",
|
|
66
|
-
"no-unused-state": "warn",
|
|
67
|
-
"prefer-es6-class": ["error"],
|
|
68
|
-
"require-optimization": "warn",
|
|
69
|
-
"self-closing-comp": "error",
|
|
70
|
-
"state-in-constructor": ["error"],
|
|
71
|
-
"void-dom-elements-no-children": "error",
|
|
14
|
+
...reactPlugin.configs.flat.recommended,
|
|
15
|
+
name: "react/recommended",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
...reactPlugin.configs.flat["jsx-runtime"],
|
|
19
|
+
name: "react/jsx-runtime",
|
|
72
20
|
},
|
|
73
21
|
);
|
|
22
|
+
const override = sections.getNamedSection(configResult, "keeex/react");
|
|
23
|
+
sections.sectionAddOption(override, "settings", "react", {version: "detect"});
|
|
24
|
+
sections.configureRules(override, "react", {
|
|
25
|
+
"button-has-type": "warn",
|
|
26
|
+
"checked-requires-onchange-or-readonly": "warn",
|
|
27
|
+
"forward-ref-uses-ref": "warn",
|
|
28
|
+
"hook-use-state": "error",
|
|
29
|
+
"iframe-missing-sandbox": "error",
|
|
30
|
+
"jsx-boolean-value": "warn",
|
|
31
|
+
"jsx-child-element-spacing": "warn",
|
|
32
|
+
"jsx-curly-brace-presence": [
|
|
33
|
+
"error",
|
|
34
|
+
{
|
|
35
|
+
children: "never",
|
|
36
|
+
propElementValues: "always",
|
|
37
|
+
props: "never",
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
"jsx-curly-newline": "warn",
|
|
41
|
+
"jsx-curly-spacing": "warn",
|
|
42
|
+
"jsx-equals-spacing": "warn",
|
|
43
|
+
"jsx-filename-extension": ["error", {extensions: [".js", ".tsx"]}],
|
|
44
|
+
"jsx-fragments": "error",
|
|
45
|
+
"jsx-handler-names": "warn",
|
|
46
|
+
"jsx-indent": ["error", 2],
|
|
47
|
+
"jsx-indent-props": ["error", 2],
|
|
48
|
+
"jsx-max-depth": ["warn", {max: 8}],
|
|
49
|
+
"jsx-no-bind": "error",
|
|
50
|
+
"jsx-no-constructed-context-values": "error",
|
|
51
|
+
"jsx-no-leaked-render": "warn",
|
|
52
|
+
"jsx-no-script-url": "error",
|
|
53
|
+
"jsx-no-useless-fragment": "warn",
|
|
54
|
+
"jsx-pascal-case": ["warn", {allowNamespace: true}],
|
|
55
|
+
"jsx-sort-props": ["warn", {ignoreCase: true}],
|
|
56
|
+
"jsx-tag-spacing": ["warn", {beforeClosing: "never"}],
|
|
57
|
+
"no-access-state-in-setstate": "error",
|
|
58
|
+
"no-array-index-key": "warn",
|
|
59
|
+
"no-arrow-function-lifecycle": "off",
|
|
60
|
+
"no-danger": "error",
|
|
61
|
+
"no-invalid-html-attribute": "error",
|
|
62
|
+
"no-namespace": "error",
|
|
63
|
+
"no-redundant-should-component-update": "error",
|
|
64
|
+
"no-this-in-sfc": "error",
|
|
65
|
+
"no-typos": "error",
|
|
66
|
+
"no-unsafe": "error",
|
|
67
|
+
"no-unstable-nested-components": "error",
|
|
68
|
+
"no-unused-class-component-methods": "warn",
|
|
69
|
+
"no-unused-state": "warn",
|
|
70
|
+
"prefer-es6-class": ["error"],
|
|
71
|
+
"require-optimization": "warn",
|
|
72
|
+
"self-closing-comp": "error",
|
|
73
|
+
"state-in-constructor": ["error"],
|
|
74
|
+
"void-dom-elements-no-children": "error",
|
|
75
|
+
});
|
|
74
76
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Normalize the user configuration for react */
|
|
2
|
-
export const getReactFullConfig = configEntry => {
|
|
2
|
+
export const getReactFullConfig = (configEntry) => {
|
|
3
3
|
if (typeof configEntry === "boolean") {
|
|
4
4
|
if (configEntry) return {react: true, reactHooks: false, reactNative: false};
|
|
5
5
|
return {react: false, reactHooks: false, reactNative: false};
|
|
@@ -10,7 +10,9 @@ export const getReactFullConfig = configEntry => {
|
|
|
10
10
|
reactNative: configEntry?.reactNative ?? false,
|
|
11
11
|
};
|
|
12
12
|
if (!cfg.react && (cfg.reactHooks || cfg.reactNative)) {
|
|
13
|
-
throw new Error(
|
|
13
|
+
throw new Error(
|
|
14
|
+
"Invalid react config; react must be enabled for react-native and react-hooks to be enabled too.",
|
|
15
|
+
);
|
|
14
16
|
}
|
|
15
17
|
return cfg;
|
|
16
18
|
};
|
package/src/config/typescript.js
CHANGED
|
@@ -5,7 +5,7 @@ import tseslint from "typescript-eslint";
|
|
|
5
5
|
|
|
6
6
|
import * as sections from "../sections.js";
|
|
7
7
|
|
|
8
|
-
const filterForFiles = (rules, files) => rules.map(c => ({...c, files}));
|
|
8
|
+
const filterForFiles = (rules, files) => rules.map((c) => ({...c, files}));
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Apply the recommended typescript-eslint configuration plus KeeeX tweaks.
|
|
@@ -18,57 +18,42 @@ export const apply = (configResult, eslintConfig) => {
|
|
|
18
18
|
const tsExts = ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"];
|
|
19
19
|
configResult.push(
|
|
20
20
|
...filterForFiles(
|
|
21
|
-
[
|
|
22
|
-
...tseslint.configs.recommendedTypeChecked,
|
|
23
|
-
...tseslint.configs.stylisticTypeChecked,
|
|
24
|
-
],
|
|
21
|
+
[...tseslint.configs.recommendedTypeChecked, ...tseslint.configs.stylisticTypeChecked],
|
|
25
22
|
tsExts,
|
|
26
23
|
),
|
|
27
24
|
);
|
|
28
25
|
if (!eslintConfig.noBase) configResult.push(tseslint.configs.eslintRecommended);
|
|
29
26
|
const section = sections.getNamedSection(configResult, "keeex/typescript-parserOptions");
|
|
30
27
|
section.files = tsExts;
|
|
31
|
-
sections.sectionAddOption(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
{
|
|
36
|
-
projectService: true,
|
|
37
|
-
tsConfigRootDir: import.meta.dirname,
|
|
38
|
-
},
|
|
39
|
-
);
|
|
28
|
+
sections.sectionAddOption(section, "languageOptions", "parserOptions", {
|
|
29
|
+
projectService: true,
|
|
30
|
+
tsConfigRootDir: import.meta.dirname,
|
|
31
|
+
});
|
|
40
32
|
const override = sections.getNamedSection(configResult, "keeex/typescript-override");
|
|
41
33
|
override.files = tsExts;
|
|
42
34
|
const eslintOverride = sections.getNamedSection(configResult, "keeex/eslint-override");
|
|
43
|
-
const overrule = (name, defaultValue = "error") =>
|
|
44
|
-
override,
|
|
45
|
-
"",
|
|
46
|
-
{
|
|
35
|
+
const overrule = (name, defaultValue = "error") =>
|
|
36
|
+
sections.configureRules(override, "", {
|
|
47
37
|
[name]: "off",
|
|
48
38
|
[`@typescript-eslint/${name}`]: eslintOverride.rules?.[name] ?? defaultValue,
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"prefer-return-this-type": "warn",
|
|
68
|
-
"return-await": "error",
|
|
69
|
-
"unified-signatures": "error",
|
|
70
|
-
},
|
|
71
|
-
);
|
|
39
|
+
});
|
|
40
|
+
sections.configureRules(override, "@typescript-eslint", {
|
|
41
|
+
"array-type": ["error", {default: "generic", readonly: "generic"}],
|
|
42
|
+
"explicit-function-return-type": "warn",
|
|
43
|
+
"explicit-member-accessibility": "error",
|
|
44
|
+
"explicit-module-boundary-types": "error",
|
|
45
|
+
"naming-convention": "error",
|
|
46
|
+
"no-deprecated": "warn",
|
|
47
|
+
"no-dynamic-delete": "warn",
|
|
48
|
+
"no-unnecessary-boolean-literal-compare": "warn",
|
|
49
|
+
"no-unnecessary-condition": ["warn", {allowConstantLoopConditions: true}],
|
|
50
|
+
"no-unnecessary-template-expression": "warn",
|
|
51
|
+
"parameter-properties": "error",
|
|
52
|
+
"prefer-readonly": "warn",
|
|
53
|
+
"prefer-return-this-type": "warn",
|
|
54
|
+
"return-await": "error",
|
|
55
|
+
"unified-signatures": "error",
|
|
56
|
+
});
|
|
72
57
|
for (const baseRule of [
|
|
73
58
|
"class-methods-use-this",
|
|
74
59
|
"default-param-last",
|
|
@@ -93,7 +78,8 @@ export const apply = (configResult, eslintConfig) => {
|
|
|
93
78
|
sections.configureRules(override, "", {"no-return-await": "off"});
|
|
94
79
|
configResult.push({
|
|
95
80
|
files: tsExts,
|
|
96
|
-
|
|
81
|
+
name: "tsdoc/recommended",
|
|
82
|
+
plugins: {tsdoc: tsdocPlugin},
|
|
97
83
|
rules: {"tsdoc/syntax": "warn"},
|
|
98
84
|
});
|
|
99
85
|
};
|
package/src/defaults.js
CHANGED
|
@@ -21,18 +21,15 @@ export const globals = [
|
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
|
-
files: [
|
|
25
|
-
"src/bin/**/*",
|
|
26
|
-
"src/server/**/*",
|
|
27
|
-
"*",
|
|
28
|
-
],
|
|
24
|
+
files: ["src/bin/**/*", "src/server/**/*", "*"],
|
|
29
25
|
globals: {node: true},
|
|
30
26
|
},
|
|
31
27
|
{
|
|
32
|
-
files: [
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
files: ["*.cjs"],
|
|
29
|
+
globals: {nodeCjs: true},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
files: ["src/tests/**/*", "src/**/*.test.*"],
|
|
36
33
|
globals: {mocha: true},
|
|
37
34
|
},
|
|
38
35
|
];
|
package/src/dependencies.js
CHANGED
|
@@ -22,12 +22,14 @@ const removedDependencies = [
|
|
|
22
22
|
|
|
23
23
|
let pkgJson;
|
|
24
24
|
|
|
25
|
+
export const needDependencies = (name) => name in requiredDependencies;
|
|
26
|
+
|
|
25
27
|
/**
|
|
26
28
|
* Retrieve the current project's "package.json".
|
|
27
29
|
*
|
|
28
30
|
* This assumes that the command is run at the root of the project.
|
|
29
31
|
*/
|
|
30
|
-
const getPkgJson = () => {
|
|
32
|
+
export const getPkgJson = () => {
|
|
31
33
|
if (!pkgJson) {
|
|
32
34
|
try {
|
|
33
35
|
const data = fs.readFileSync("./package.json", "utf8");
|
|
@@ -40,9 +42,11 @@ const getPkgJson = () => {
|
|
|
40
42
|
};
|
|
41
43
|
|
|
42
44
|
/** Get installed package version */
|
|
43
|
-
const getInstalledVersion = name => {
|
|
45
|
+
const getInstalledVersion = (name) => {
|
|
44
46
|
try {
|
|
45
|
-
const depsPkg = JSON.parse(
|
|
47
|
+
const depsPkg = JSON.parse(
|
|
48
|
+
fs.readFileSync(path.join("node_modules", name, "package.json"), "utf8"),
|
|
49
|
+
);
|
|
46
50
|
return depsPkg.version;
|
|
47
51
|
} catch {
|
|
48
52
|
return "<unknown>";
|
|
@@ -54,7 +58,7 @@ const getInstalledVersion = name => {
|
|
|
54
58
|
*
|
|
55
59
|
* @returns {{installed: "prod" | "dev" | false; version: string}}
|
|
56
60
|
*/
|
|
57
|
-
const dependencyStatus = name => {
|
|
61
|
+
const dependencyStatus = (name) => {
|
|
58
62
|
const pkg = getPkgJson();
|
|
59
63
|
let installed = "missing";
|
|
60
64
|
if (pkg.devDependencies && name in pkg.devDependencies) installed = "dev";
|
|
@@ -97,7 +101,7 @@ const runProcess = (cmd, ...args) => {
|
|
|
97
101
|
|
|
98
102
|
/**
|
|
99
103
|
* List all missing/extra dependencies.
|
|
100
|
-
*
|
|
104
|
+
*
|
|
101
105
|
* @returns {{name:string;action:"install"|"remove"}[]}
|
|
102
106
|
* A list of dependencies with the action to do ("install" or "remove").
|
|
103
107
|
*/
|
|
@@ -106,13 +110,17 @@ export const listDependencies = () => {
|
|
|
106
110
|
try {
|
|
107
111
|
const res = [];
|
|
108
112
|
for (const removed of removedDependencies) {
|
|
109
|
-
if (dependencyStatus(removed).installed !== "missing")
|
|
113
|
+
if (dependencyStatus(removed).installed !== "missing") {
|
|
114
|
+
res.push({name: removed, action: "remove"});
|
|
115
|
+
}
|
|
110
116
|
}
|
|
111
117
|
for (const required of Object.keys(requiredDependencies)) {
|
|
112
118
|
const expectedVersion = requiredDependencies[required].version;
|
|
113
119
|
const status = dependencyStatus(required);
|
|
114
120
|
const needUpdate = status.installed !== "dev" || !satisfies(status.version, expectedVersion);
|
|
115
|
-
console.log(
|
|
121
|
+
console.log(
|
|
122
|
+
`dep:${required} (${status.installed}=${status.version}) (required=${expectedVersion})`,
|
|
123
|
+
);
|
|
116
124
|
if (needUpdate) res.push({name: required, action: "install"});
|
|
117
125
|
}
|
|
118
126
|
return res.toSorted((a, b) => a.name.localeCompare(b.name));
|
|
@@ -129,8 +137,8 @@ export const listDependencies = () => {
|
|
|
129
137
|
*/
|
|
130
138
|
export const installAndRemoveDeps = () => {
|
|
131
139
|
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);
|
|
140
|
+
const toInstall = deps.filter((c) => c.action === "install").map((c) => c.name);
|
|
141
|
+
const toRemove = deps.filter((c) => c.action === "remove").map((c) => c.name);
|
|
134
142
|
if (toRemove.length > 0) {
|
|
135
143
|
console.log(`Removing dependencies: ${toRemove.join(", ")}`);
|
|
136
144
|
if (!runProcess("npm", "uninstall", "--force", ...toRemove)) {
|
|
@@ -140,7 +148,7 @@ export const installAndRemoveDeps = () => {
|
|
|
140
148
|
}
|
|
141
149
|
if (toInstall.length > 0) {
|
|
142
150
|
console.log(`Installing dependencies: ${toInstall.join(", ")}`);
|
|
143
|
-
const installNames = toInstall.map(c => {
|
|
151
|
+
const installNames = toInstall.map((c) => {
|
|
144
152
|
const target = requiredDependencies[c].version;
|
|
145
153
|
if (typeof target === "string") return `${c}@${target}`;
|
|
146
154
|
return c;
|
|
@@ -154,8 +162,9 @@ export const installAndRemoveDeps = () => {
|
|
|
154
162
|
};
|
|
155
163
|
|
|
156
164
|
/** Add all dependencies needed by the provided config */
|
|
157
|
-
export const configToDependencies = eslintConfig => {
|
|
165
|
+
export const configToDependencies = (eslintConfig) => {
|
|
158
166
|
addDependency("eslint", "9.x");
|
|
167
|
+
addDependency("prettier", "3.x");
|
|
159
168
|
if (eslintConfig.globals) addDependency("globals", "15.x");
|
|
160
169
|
if (eslintConfig.import) {
|
|
161
170
|
addDependency("eslint-plugin-import-x", "4.x");
|
|
@@ -178,6 +187,7 @@ export const configToDependencies = eslintConfig => {
|
|
|
178
187
|
}
|
|
179
188
|
if (eslintConfig.typescript) {
|
|
180
189
|
addDependency("typescript-eslint", "8.x");
|
|
190
|
+
addDependency("@typescript-eslint/parser", "8.x");
|
|
181
191
|
addDependency("eslint-plugin-tsdoc", "0.x");
|
|
182
192
|
}
|
|
183
193
|
};
|
package/src/environ.js
CHANGED
package/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as lazy from "./config/lazy.js";
|
|
2
|
-
import {
|
|
2
|
+
import {getReactFullConfig} from "./config/reactfullconfig.js";
|
|
3
3
|
import * as defaults from "./defaults.js";
|
|
4
4
|
|
|
5
5
|
import {configToDependencies} from "./dependencies.js";
|
|
@@ -7,24 +7,24 @@ import {isDepCheck} from "./environ.js";
|
|
|
7
7
|
import {clearConfig} from "./sections.js";
|
|
8
8
|
|
|
9
9
|
/** Setup all defaults in the eslintParams config */
|
|
10
|
-
const configDefaults = eslintParams => ({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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,
|
|
18
|
+
});
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Build the eslint configuration from the provided settings.
|
|
22
|
-
*
|
|
22
|
+
*
|
|
23
23
|
* @param [eslintParams.noBase] {boolean} - Disable the base settings
|
|
24
|
-
*
|
|
24
|
+
*
|
|
25
25
|
* @param [eslintParams.ignores] {string[]} - List of files to ignore.
|
|
26
26
|
* Defaults to `["lib", "web", "gen", "src/gen"]`.
|
|
27
|
-
*
|
|
27
|
+
*
|
|
28
28
|
* @param [eslintParams.globals.[].files] {string[]} - List of globs to include.
|
|
29
29
|
* @param [eslintParams.globals.[].globals.builtin] {boolean} - Enable builtin JS globals
|
|
30
30
|
* @param [eslintParams.globals.[].globals.browser] {boolean} - Enable browser globals
|
|
@@ -35,22 +35,22 @@ const configDefaults = eslintParams => ({
|
|
|
35
35
|
* @param [eslintParams.globals.[].globals.serviceworker] {boolean} - Enable serviceworker globals
|
|
36
36
|
* @param [eslintParams.globals.[].globals.worker] {boolean} - Enable worker globals
|
|
37
37
|
* @param [eslintParams.globals.[].globals.custom] {Record<string, boolean>} - Enable custom globals
|
|
38
|
-
*
|
|
38
|
+
*
|
|
39
39
|
* @param [eslintParams.typescript] {boolean} - Enable typescript support (defaults to true)
|
|
40
|
-
*
|
|
40
|
+
*
|
|
41
41
|
* @param [eslintParams.import] {boolean|number} - Enable import linting support (defaults to true)
|
|
42
42
|
* If a number is provided, it's the maximum cycle detection depth.
|
|
43
|
-
*
|
|
43
|
+
*
|
|
44
44
|
* @param [eslintParams.react] {object|false} - If trueish, enable React support.
|
|
45
45
|
* @param [eslintParams.react.reactHooks] {boolean} - Enable react-hooks stuff.
|
|
46
46
|
* @param [eslintParams.react.reactNative] {boolean} - Enable react-native stuff.
|
|
47
|
-
*
|
|
47
|
+
*
|
|
48
48
|
* @param [eslintParams.mocha] {boolean} - Enable mocha plugins
|
|
49
|
-
*
|
|
49
|
+
*
|
|
50
50
|
* @returns
|
|
51
51
|
* The eslint config object
|
|
52
52
|
*/
|
|
53
|
-
const eslintConfig = async eslintParams => {
|
|
53
|
+
const eslintConfig = async (eslintParams) => {
|
|
54
54
|
const fullConfig = configDefaults(eslintParams);
|
|
55
55
|
const res = [];
|
|
56
56
|
if (isDepCheck()) {
|
package/src/sections.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Get a config section by name.
|
|
3
3
|
*
|
|
4
4
|
* When requesting a section that doesn't exist, it is added.
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* @param configResult - The currently built eslint config object
|
|
7
7
|
* @param name {string} - The name of the section to get
|
|
8
|
-
*
|
|
8
|
+
*
|
|
9
9
|
* @returns
|
|
10
10
|
* The requested section, as a new entry if needed.
|
|
11
11
|
*/
|
|
@@ -18,10 +18,10 @@ export const getNamedSection = (configResult, name) => {
|
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Add a property in an object on the provided section.
|
|
21
|
-
*
|
|
21
|
+
*
|
|
22
22
|
* This basically sets `configSection[optionGroup][optionName] = value`.
|
|
23
23
|
* It also takes care of creating/deleting new/empty objects.
|
|
24
|
-
*
|
|
24
|
+
*
|
|
25
25
|
* @param configSection - A single "section" (an entry) from the eslint config array
|
|
26
26
|
* @param optionGroup {string} - The name of the properties in the section to add a property to
|
|
27
27
|
* @param optionName {string} - The name of the property to add
|
|
@@ -51,7 +51,7 @@ export const configureRules = (configSection, prefix, rules) => {
|
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
/** Remove the `_kxconfig` property from all sections and return a suitable object. */
|
|
54
|
-
export const clearConfig = configResult => {
|
|
54
|
+
export const clearConfig = (configResult) => {
|
|
55
55
|
const emptySectionsId = [];
|
|
56
56
|
for (let i = 0; i < configResult.length; i++) {
|
|
57
57
|
// We go backwards to avoid messing up the indices on deletion
|