@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/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2024 KeeeX SAS
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|
package/README.md
CHANGED
|
@@ -1,176 +1,123 @@
|
|
|
1
|
-
Common eslint configuration
|
|
2
|
-
===========================
|
|
1
|
+
# Common eslint configuration for KeeeX
|
|
3
2
|
|
|
4
|
-
Installation
|
|
5
|
-
|
|
3
|
+
## Installation
|
|
4
|
+
The package is available on npmjs and can be installed with any package manager that supports it.
|
|
6
5
|
|
|
7
6
|
```bash
|
|
8
7
|
npm install -D @keeex/eslint-config
|
|
9
8
|
```
|
|
10
9
|
|
|
11
|
-
Usage
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
## Usage
|
|
11
|
+
To prepare the configuration file, you can run `npx kxeslint-setup` to create a blank config file.
|
|
12
|
+
Alternatively, you can create the file yourself.
|
|
13
|
+
In both cases, it will be named `eslint.config.js`.
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
const eslintConfig = require("@keeex/eslint-config");
|
|
18
|
-
module.exports = eslintConfig(
|
|
19
|
-
{
|
|
20
|
-
base: true,
|
|
21
|
-
promise: true,
|
|
22
|
-
jsx: true,
|
|
23
|
-
import: true,
|
|
24
|
-
reacthooks: true,
|
|
25
|
-
reactnative: true,
|
|
26
|
-
typescript: "./tsconfig.json",
|
|
27
|
-
tsdoc: true,
|
|
28
|
-
deprecation: true,
|
|
29
|
-
mocha: true,
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
env: {
|
|
33
|
-
es2021: true,
|
|
34
|
-
node: true,
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
);
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
The first argument is the configurations to pull-in. `base` is the generic
|
|
41
|
-
JavaScript options, `jsx` add rules for React and JSX, `reacthook` add rules for
|
|
42
|
-
React hooks and `typescript` add rules for TypeScript.
|
|
43
|
-
For TypeScript, you can specify the name of your TypeScript configuration file,
|
|
44
|
-
in which case more rules will be enabled.
|
|
45
|
-
|
|
46
|
-
The second argument is the base eslint configuration, to specify extra options
|
|
47
|
-
that are not defined by the default configuration. It can be empty if not
|
|
48
|
-
needed.
|
|
49
|
-
|
|
50
|
-
The default configuration is:
|
|
15
|
+
Here is all the available options with their default values:
|
|
51
16
|
|
|
52
17
|
```JavaScript
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
18
|
+
import eslintConfig from "@keeex/eslint-config";
|
|
19
|
+
|
|
20
|
+
export default await eslintConfig({
|
|
21
|
+
globals: [
|
|
22
|
+
{globals: {builtin: true, es2025: true}},
|
|
23
|
+
{
|
|
24
|
+
files: ["**/*.cjs"],
|
|
25
|
+
globals: {commonjs: true},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
files: ["src/webapp/**/*"],
|
|
29
|
+
globals: {browser: true, serviceworker: true},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
files: ["src/bin/**/*", "src/server/**/*"],
|
|
33
|
+
globals: {node: true},
|
|
34
|
+
},
|
|
65
35
|
{
|
|
66
|
-
files: ["
|
|
67
|
-
|
|
68
|
-
browser: true,
|
|
69
|
-
},
|
|
36
|
+
files: ["src/tests/**/*", "src/**/*.test.*"],
|
|
37
|
+
globals: {mocha: true},
|
|
70
38
|
},
|
|
71
39
|
],
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
40
|
+
ignores: ["lib", "web", "gen", "src/gen"],
|
|
41
|
+
import: 3,
|
|
42
|
+
mocha: true,
|
|
43
|
+
noBase: false,
|
|
44
|
+
react: {react: false, reactHooks: false, reactNative: false},
|
|
45
|
+
typescript: true,
|
|
46
|
+
});
|
|
75
47
|
```
|
|
76
48
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
49
|
+
If any of the top-level property is not defined, it will be set to its default value.
|
|
50
|
+
If you want to customize the output, instead of directly exporting the return value of the function
|
|
51
|
+
you can edit it by hand.
|
|
52
|
+
Good luck with that.
|
|
53
|
+
|
|
54
|
+
## Configuration
|
|
55
|
+
|
|
56
|
+
### `globals`
|
|
57
|
+
The `globals` property is an array of object to define which globals are available in the code.
|
|
58
|
+
Each of these objects can have two properties: `files`, which is an array of globs to match the files to
|
|
59
|
+
be considered, and `globals`, which is an object that can have the following properties:
|
|
60
|
+
|
|
61
|
+
- "builtin": generic JS built-in globals
|
|
62
|
+
- "browser": globals available in the browser
|
|
63
|
+
- "commonjs": globals available in CommonJS scripts
|
|
64
|
+
- "es2025": globals available in ES2025 scripts
|
|
65
|
+
- "mocha": globals available in Mocha tests
|
|
66
|
+
- "node": globals available in Node.js
|
|
67
|
+
- "serviceworker": globals available in Service Workers
|
|
68
|
+
- "worker": globals available in Workers
|
|
69
|
+
- "custom": an object of custom identifiers to be made available, whose keys are the identifiers and
|
|
70
|
+
the values are boolean indicating if these identifiers are read-only (false) or not (true)
|
|
71
|
+
|
|
72
|
+
### `ignores`
|
|
73
|
+
Array of globs to globally ignore for eslint.
|
|
74
|
+
|
|
75
|
+
### `import`
|
|
92
76
|
Some extra rules for formatting and ordering imports can be used by setting
|
|
93
|
-
`import` to true (enabled by default).
|
|
94
|
-
It is possible to pass
|
|
77
|
+
`import` to true (enabled by default with a depth of 3).
|
|
78
|
+
It is possible to pass a number instead of a boolean to limit the depth of circular imports check.
|
|
79
|
+
This greatly improves performances, at the risk of missing a dependency cycle.
|
|
95
80
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
```
|
|
81
|
+
### `mocha`
|
|
82
|
+
To enable mocha-specific rules, as well as loosen some regular rules for
|
|
83
|
+
testing, set `mocha` to true.
|
|
101
84
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
85
|
+
### `noBase`
|
|
86
|
+
The base configuration imports all eslint recommendeds rules and promises handling rules.
|
|
87
|
+
Setting `noBase` to true removes that.
|
|
88
|
+
There is absolutely no reason to do so.
|
|
105
89
|
|
|
106
|
-
###
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
(typically `tsconfig.json`), in which case rules that requires typing
|
|
110
|
-
informations are enabled.
|
|
90
|
+
### `react`
|
|
91
|
+
To improve handling of React/JSX, set `react` to true.
|
|
92
|
+
You can also pass an object with the following boolean properties:
|
|
111
93
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
94
|
+
- `react`: enable/disable react rules
|
|
95
|
+
- `reactHooks`: enable/disable React hooks rules
|
|
96
|
+
- `reactNative`: enable/disable React Native rules
|
|
115
97
|
|
|
116
|
-
|
|
117
|
-
Warn when using deprecated calls/properties.
|
|
118
|
-
This only work with TypeScript enabled with project types.
|
|
98
|
+
You can't enable the hooks or React Native rules without enabling React.
|
|
119
99
|
|
|
120
|
-
###
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
If not specified, will set to "detect" and use the version installed in the
|
|
124
|
-
project.
|
|
100
|
+
### `typescript`
|
|
101
|
+
Set to `true` (the default value) to enable all TypeScript rules.
|
|
102
|
+
This includes tsdoc rules.
|
|
125
103
|
|
|
126
|
-
|
|
127
|
-
|
|
104
|
+
## Dependencies
|
|
105
|
+
This configuration depends on various packages to be available depending on the user settings for
|
|
106
|
+
each individual projects.
|
|
107
|
+
You can list the required dependencies for the current configuration by running
|
|
108
|
+
`npx kxeslint-setup`.
|
|
109
|
+
You can also automatically install missing dependencies by adding the "auto" flag to the command.
|
|
128
110
|
|
|
129
|
-
|
|
130
|
-
|
|
111
|
+
All dependencies are set as peer dependencies, as they are almost all optional depending on local
|
|
112
|
+
settings.
|
|
131
113
|
|
|
132
|
-
|
|
133
|
-
To enable mocha-specific rules, as well as loosen some regular rules for
|
|
134
|
-
testing, set `mocha` to true.
|
|
135
|
-
Fine-tuned control is possible by providing an object instead of true with
|
|
136
|
-
the following properties:
|
|
114
|
+
The tool will also uninstall older dependencies that we used to have but are not used anymore.
|
|
137
115
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
"**/*.test.js",
|
|
143
|
-
"**/testutils.ts",
|
|
144
|
-
"**/testutils.js",
|
|
145
|
-
"tests/**/*.ts",
|
|
146
|
-
"tests/**/*.js",
|
|
147
|
-
"test/**/*.ts",
|
|
148
|
-
"test/**/*.js",
|
|
149
|
-
],
|
|
150
|
-
expectHelper: true,
|
|
151
|
-
}
|
|
152
|
-
```
|
|
116
|
+
## Migration from .eslintrc.cjs
|
|
117
|
+
When running `npx kxeslint-setup`, the tool will automatically detect an existing `.eslintrc.cjs`
|
|
118
|
+
file and provides instructions for the migration.
|
|
119
|
+
The migration process is manual; you have to update the new `eslint.config.js` file by hand.
|
|
153
120
|
|
|
154
|
-
|
|
155
|
-
`
|
|
156
|
-
|
|
157
|
-
assertions in test files.
|
|
158
|
-
|
|
159
|
-
Dependencies
|
|
160
|
-
------------
|
|
161
|
-
|
|
162
|
-
Depend on `eslint`.
|
|
163
|
-
If typescript is enabled, `@typescript-eslint/eslint-plugin`,
|
|
164
|
-
`@typescript-eslint/parser`, `eslint-plugin-tsdoc` must be installed.
|
|
165
|
-
If deprecation is enabled, `eslint-plugin-deprecation` must be installed.
|
|
166
|
-
If React/JSX is enabled, `eslint-plugin-react` must be installed.
|
|
167
|
-
If React Hooks is enabled, `eslint-plugin-react-hooks` must be installed.
|
|
168
|
-
If React Native is enabled, `eslint-plugin-react-native` must be installed.
|
|
169
|
-
Promise support requires `eslint-plugin-promise`.
|
|
170
|
-
If mocha is used as the testsuite, `eslint-plugin-mocha` must be installed.
|
|
171
|
-
Import support requires `eslint-plugin-i`.
|
|
172
|
-
|
|
173
|
-
### Automatic dependency check
|
|
174
|
-
You can run the binary `npx eslint-depcheck` to check if all the currently required dependencies are
|
|
175
|
-
installed.
|
|
176
|
-
Add the flag `auto` to automatically install missing one/remove old ones.
|
|
121
|
+
## Debugging config issues
|
|
122
|
+
Running `npx eslint --inspect-config` will launch a debugger interface that allows checking all the
|
|
123
|
+
rules and individual file rules.
|
package/package.json
CHANGED
|
@@ -1,85 +1,119 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"description": "Common eslint configuration",
|
|
4
|
-
"version": "1.12.6",
|
|
5
|
-
"main": "src/index.js",
|
|
6
|
-
"files": [
|
|
7
|
-
"src/**/*.js"
|
|
8
|
-
],
|
|
2
|
+
"author": "KeeeX SAS",
|
|
9
3
|
"bin": {
|
|
10
|
-
"
|
|
4
|
+
"kxeslint-setup": "src/bin/kxeslint-setup.js",
|
|
5
|
+
"kxeslint-dump": "src/bin/kxeslint-dump.js"
|
|
11
6
|
},
|
|
12
|
-
"scripts": {
|
|
13
|
-
"check": "npx eslint .",
|
|
14
|
-
"prepublishOnly": "publish_check.sh",
|
|
15
|
-
"test": "echo No test for this project"
|
|
16
|
-
},
|
|
17
|
-
"repository": {
|
|
18
|
-
"type": "git",
|
|
19
|
-
"url": "https://github.com/KeeeX/eslint-config.git"
|
|
20
|
-
},
|
|
21
|
-
"author": "KeeeX SAS",
|
|
22
7
|
"contributors": [
|
|
23
8
|
{
|
|
24
|
-
"
|
|
25
|
-
"
|
|
9
|
+
"email": "gabriel@keeex.net",
|
|
10
|
+
"name": "Gabriel Paul \"Cley Faye\" Risterucci"
|
|
26
11
|
}
|
|
27
12
|
],
|
|
28
|
-
"
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"semver": "^7.6.3"
|
|
15
|
+
},
|
|
16
|
+
"description": "Common eslint configuration",
|
|
29
17
|
"devDependencies": {
|
|
30
|
-
"eslint": "^
|
|
31
|
-
"eslint
|
|
32
|
-
"eslint
|
|
18
|
+
"@eslint/compat": "^1.2.0",
|
|
19
|
+
"@eslint/js": "^9.12.0",
|
|
20
|
+
"eslint": "^9.12.0",
|
|
21
|
+
"eslint-import-resolver-typescript": "^3.6.3",
|
|
22
|
+
"eslint-import-resolver-webpack": "*",
|
|
23
|
+
"eslint-plugin-import-x": "^4.3.1",
|
|
24
|
+
"eslint-plugin-mocha": "^10.5.0",
|
|
25
|
+
"eslint-plugin-promise": "^7.1.0",
|
|
26
|
+
"eslint-plugin-react": "^7.37.1",
|
|
27
|
+
"eslint-plugin-react-hooks": "^5.1.0-rc-83825814-20241015",
|
|
28
|
+
"eslint-plugin-react-native": "^4.1.0",
|
|
29
|
+
"eslint-plugin-tsdoc": "^0.3.0",
|
|
30
|
+
"globals": "^15.11.0",
|
|
31
|
+
"typescript-eslint": "^8.9.0"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"src"
|
|
35
|
+
],
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"main": "src/index.js",
|
|
38
|
+
"name": "@keeex/eslint-config",
|
|
39
|
+
"overrides": {
|
|
40
|
+
"eslint": "^9.12.0",
|
|
41
|
+
"eslint-plugin-react-native": "^4.1.0"
|
|
33
42
|
},
|
|
34
43
|
"peerDependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"eslint": "
|
|
38
|
-
"eslint-
|
|
39
|
-
"eslint-
|
|
44
|
+
"@eslint/compat": "^1.2.0",
|
|
45
|
+
"@eslint/js": "9.x",
|
|
46
|
+
"eslint": "9.x",
|
|
47
|
+
"eslint-import-resolver-typescript": "3.x",
|
|
48
|
+
"eslint-import-resolver-webpack": "0.x",
|
|
49
|
+
"eslint-plugin-import-x": "4.x",
|
|
40
50
|
"eslint-plugin-mocha": "10.x",
|
|
41
|
-
"eslint-plugin-promise": "
|
|
51
|
+
"eslint-plugin-promise": "7.x",
|
|
42
52
|
"eslint-plugin-react": "7.x",
|
|
43
|
-
"eslint-plugin-react-hooks": "
|
|
53
|
+
"eslint-plugin-react-hooks": "5.x",
|
|
44
54
|
"eslint-plugin-react-native": "4.x",
|
|
45
|
-
"eslint-plugin-tsdoc": "0.x"
|
|
55
|
+
"eslint-plugin-tsdoc": "0.x",
|
|
56
|
+
"globals": "15.x",
|
|
57
|
+
"typescript-eslint": "8.x"
|
|
46
58
|
},
|
|
47
59
|
"peerDependenciesMeta": {
|
|
60
|
+
"@eslint/compat": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
48
63
|
"eslint": {
|
|
49
64
|
"optional": false
|
|
50
65
|
},
|
|
51
|
-
"
|
|
66
|
+
"eslint-plugin-deprecation": {
|
|
52
67
|
"optional": true
|
|
53
68
|
},
|
|
54
|
-
"
|
|
69
|
+
"eslint-import-resolver-typescript": {
|
|
55
70
|
"optional": true
|
|
56
71
|
},
|
|
57
|
-
"eslint-
|
|
72
|
+
"eslint-import-resolver-webpack": {
|
|
58
73
|
"optional": true
|
|
59
74
|
},
|
|
60
|
-
"eslint-plugin-
|
|
75
|
+
"eslint-plugin-import-x": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"eslint-plugin-mocha": {
|
|
61
79
|
"optional": true
|
|
62
80
|
},
|
|
63
81
|
"eslint-plugin-promise": {
|
|
64
82
|
"optional": true
|
|
65
83
|
},
|
|
66
|
-
"eslint-plugin-
|
|
84
|
+
"eslint-plugin-react": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"eslint-plugin-react-hooks": {
|
|
67
88
|
"optional": true
|
|
68
89
|
},
|
|
69
90
|
"eslint-plugin-react-native": {
|
|
70
91
|
"optional": true
|
|
71
92
|
},
|
|
72
|
-
"eslint-plugin-
|
|
93
|
+
"eslint-plugin-tsdoc": {
|
|
73
94
|
"optional": true
|
|
74
95
|
},
|
|
75
|
-
"
|
|
96
|
+
"globals": {
|
|
76
97
|
"optional": true
|
|
77
98
|
},
|
|
78
|
-
"eslint
|
|
99
|
+
"typescript-eslint": {
|
|
79
100
|
"optional": true
|
|
80
101
|
}
|
|
81
102
|
},
|
|
82
103
|
"publishConfig": {
|
|
83
104
|
"access": "public"
|
|
84
|
-
}
|
|
105
|
+
},
|
|
106
|
+
"repository": {
|
|
107
|
+
"type": "git",
|
|
108
|
+
"url": "https://github.com/KeeeX/eslint-config.git"
|
|
109
|
+
},
|
|
110
|
+
"scripts": {
|
|
111
|
+
"bin:dump": "node src/bin/kxeslint-dump.js",
|
|
112
|
+
"bin:setup": "node src/bin/kxeslint-setup.js",
|
|
113
|
+
"check": "npx eslint --cache --cache-strategy content .",
|
|
114
|
+
"prepublishOnly": "publish_check.sh",
|
|
115
|
+
"test": "echo No test for this project"
|
|
116
|
+
},
|
|
117
|
+
"type": "module",
|
|
118
|
+
"version": "2.0.0"
|
|
85
119
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
|
|
7
|
+
const eslintFile = path.resolve(process.cwd(), "eslint.config.js");
|
|
8
|
+
if (!fs.existsSync(eslintFile)) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
"This command must be run in the root of the project and contain an eslint.config.js file.",
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const eslintConfig = (await import(eslintFile)).default;
|
|
15
|
+
const JSON_INDENT = 2;
|
|
16
|
+
console.log(JSON.stringify(eslintConfig, null, JSON_INDENT));
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/* eslint-disable no-console */
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
|
|
7
|
+
import * as deps from "../dependencies.js";
|
|
8
|
+
import {setDepCheck} from "../environ.js";
|
|
9
|
+
|
|
10
|
+
const getEslintConfig = () => path.resolve(process.cwd(), "eslint.config.js");
|
|
11
|
+
|
|
12
|
+
const depsCheck = async () => {
|
|
13
|
+
console.group("eslint dependencies checking…");
|
|
14
|
+
try {
|
|
15
|
+
setDepCheck();
|
|
16
|
+
console.log("- loading eslint.config.js");
|
|
17
|
+
const eslintFile = getEslintConfig();
|
|
18
|
+
await import(eslintFile);
|
|
19
|
+
console.log("- listing dependencies");
|
|
20
|
+
const dependencies = deps.listDependencies();
|
|
21
|
+
if (dependencies.length === 0) {
|
|
22
|
+
console.log("- All eslint dependencies installed");
|
|
23
|
+
} else {
|
|
24
|
+
const toRemove = dependencies.filter(c => c.action === "remove");
|
|
25
|
+
const toInstall = dependencies.filter(c => c.action === "install");
|
|
26
|
+
if (toRemove.length > 0) {
|
|
27
|
+
console.group("- Dependencies to remove:");
|
|
28
|
+
toRemove.forEach(c => console.log(`- ${c.name}`));
|
|
29
|
+
console.groupEnd();
|
|
30
|
+
}
|
|
31
|
+
if (toInstall.length > 0) {
|
|
32
|
+
console.group("Dependencies to install:");
|
|
33
|
+
toInstall.forEach(c => console.log(`- ${c.name}`));
|
|
34
|
+
console.groupEnd();
|
|
35
|
+
}
|
|
36
|
+
if (process.argv.includes("auto")) {
|
|
37
|
+
console.log("Auto mode enabled, installing dependencies");
|
|
38
|
+
deps.installAndRemoveDeps();
|
|
39
|
+
} else if (dependencies.length > 0) {
|
|
40
|
+
console.log("To enable auto mode, run this command with the \"auto\" flag");
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
} finally {
|
|
44
|
+
console.groupEnd();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const eslintRcCandidates = [".js", ".cjs", ".json"];
|
|
49
|
+
|
|
50
|
+
const getEslintrcPath = () => {
|
|
51
|
+
for (const candidate of eslintRcCandidates) {
|
|
52
|
+
const eslintrcPath = path.join(process.cwd(), `.eslintrc${candidate}`);
|
|
53
|
+
if (fs.existsSync(eslintrcPath)) return eslintrcPath;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const deleteLine = "DELETE THIS LINE WHEN CONFIGURED";
|
|
58
|
+
|
|
59
|
+
const defaultConfig = `
|
|
60
|
+
// ${deleteLine}
|
|
61
|
+
import eslintConfig from "@keeex/eslint-config";
|
|
62
|
+
|
|
63
|
+
export default await eslintConfig({});
|
|
64
|
+
`.trim();
|
|
65
|
+
|
|
66
|
+
/** Return true if the flat config system is ok */
|
|
67
|
+
const checkEslintConfig = () => {
|
|
68
|
+
console.group("Checking eslint config file…");
|
|
69
|
+
try {
|
|
70
|
+
const eslintrcPath = getEslintrcPath();
|
|
71
|
+
const eslintConfigPath = getEslintConfig();
|
|
72
|
+
if (eslintrcPath) {
|
|
73
|
+
if (fs.existsSync(eslintConfigPath)) {
|
|
74
|
+
console.log(`- Found ${eslintrcPath} but ${eslintConfigPath} already exists; remove ${eslintrcPath} when the configuration migration is complete.`);
|
|
75
|
+
} else {
|
|
76
|
+
console.log(`- Found ${eslintrcPath} but no ${eslintConfigPath}; generating empty config. Please migrate from the old config then delete the old file.`);
|
|
77
|
+
fs.writeFileSync(eslintConfigPath, `${defaultConfig}\n`);
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
if (!fs.existsSync(eslintConfigPath)) {
|
|
82
|
+
console.log(`- No ${eslintConfigPath} found. Generating empty config. Please configure it appropriately.`);
|
|
83
|
+
fs.writeFileSync(eslintConfigPath, `${defaultConfig}\n`);
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
const configContent = fs.readFileSync(eslintConfigPath, "utf8");
|
|
87
|
+
if (configContent.indexOf(deleteLine) !== -1) {
|
|
88
|
+
console.log(`- Found ${eslintConfigPath} with the delete line; configure eslint and remove that line.`);
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
if (fs.existsSync(".eslintignore")) {
|
|
92
|
+
console.log(`- Found .eslintignore; please remove it.`);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
96
|
+
} finally {
|
|
97
|
+
console.groupEnd();
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const main = async () => {
|
|
102
|
+
console.group("KeeeX eslint configuration setup");
|
|
103
|
+
try {
|
|
104
|
+
const configOk = checkEslintConfig();
|
|
105
|
+
if (configOk) await depsCheck();
|
|
106
|
+
} finally {
|
|
107
|
+
console.groupEnd();
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
await main();
|