eslint-plugin-n 17.23.2 → 18.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/README.md +29 -61
- package/configs/recommended-module.js +2 -3
- package/configs/recommended-script.js +2 -2
- package/lib/all-rules.js +90 -47
- package/lib/configs/_commons.js +2 -5
- package/lib/configs/all.js +3 -4
- package/lib/configs/recommended-module.js +6 -8
- package/lib/configs/recommended-script.js +6 -8
- package/lib/configs/recommended.js +5 -7
- package/lib/eslint-utils.d.ts +125 -60
- package/lib/index.js +8 -10
- package/lib/rules/callback-return.js +4 -7
- package/lib/rules/exports-style.js +21 -10
- package/lib/rules/file-extension-in-import.js +9 -10
- package/lib/rules/global-require.js +10 -11
- package/lib/rules/handle-callback-err.js +4 -8
- package/lib/rules/hashbang.js +16 -15
- package/lib/rules/no-callback-literal.js +3 -5
- package/lib/rules/no-deprecated-api.js +18 -17
- package/lib/rules/no-exports-assign.js +7 -7
- package/lib/rules/no-extraneous-import.js +14 -15
- package/lib/rules/no-extraneous-require.js +16 -17
- package/lib/rules/no-hide-core-modules.js +15 -12
- package/lib/rules/no-missing-import.js +24 -25
- package/lib/rules/no-missing-require.js +18 -19
- package/lib/rules/no-mixed-requires.js +4 -6
- package/lib/rules/no-new-require.js +3 -5
- package/lib/rules/no-path-concat.js +59 -20
- package/lib/rules/no-process-env.js +3 -5
- package/lib/rules/no-process-exit.js +3 -5
- package/lib/rules/no-restricted-import.js +5 -7
- package/lib/rules/no-restricted-require.js +5 -7
- package/lib/rules/no-sync.js +36 -22
- package/lib/rules/no-top-level-await.js +17 -19
- package/lib/rules/no-unpublished-bin.js +11 -12
- package/lib/rules/no-unpublished-import.js +21 -22
- package/lib/rules/no-unpublished-require.js +21 -22
- package/lib/rules/no-unsupported-features/es-builtins.js +9 -10
- package/lib/rules/no-unsupported-features/es-syntax.js +40 -20
- package/lib/rules/no-unsupported-features/node-builtins.js +12 -14
- package/lib/rules/prefer-global/buffer.js +5 -7
- package/lib/rules/prefer-global/console.js +5 -7
- package/lib/rules/prefer-global/crypto.js +45 -0
- package/lib/rules/prefer-global/process.js +5 -7
- package/lib/rules/prefer-global/text-decoder.js +5 -7
- package/lib/rules/prefer-global/text-encoder.js +5 -7
- package/lib/rules/prefer-global/timers.js +52 -0
- package/lib/rules/prefer-global/url-search-params.js +5 -7
- package/lib/rules/prefer-global/url.js +5 -7
- package/lib/rules/prefer-node-protocol.js +10 -15
- package/lib/rules/prefer-promises/dns.js +9 -12
- package/lib/rules/prefer-promises/fs.js +14 -11
- package/lib/rules/process-exit-as-throw.js +22 -14
- package/lib/rules/rule-module.d.ts +17 -15
- package/lib/rules/shebang.js +22 -6
- package/lib/types-code-path-analysis/code-path-analyzer.d.ts +15 -15
- package/lib/types-code-path-analysis/code-path-segment.d.ts +32 -16
- package/lib/types-code-path-analysis/code-path-state.d.ts +166 -121
- package/lib/types-code-path-analysis/code-path.d.ts +32 -22
- package/lib/types-code-path-analysis/debug-helpers.d.ts +7 -7
- package/lib/types-code-path-analysis/fork-context.d.ts +33 -20
- package/lib/types-code-path-analysis/id-generator.d.ts +5 -5
- package/lib/unsupported-features/node-builtins-modules/assert.js +4 -5
- package/lib/unsupported-features/node-builtins-modules/async_hooks.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/buffer.js +8 -5
- package/lib/unsupported-features/node-builtins-modules/child_process.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/cluster.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/console.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/crypto.js +11 -4
- package/lib/unsupported-features/node-builtins-modules/dgram.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/diagnostics_channel.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/dns.js +2 -5
- package/lib/unsupported-features/node-builtins-modules/domain.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/events.js +6 -5
- package/lib/unsupported-features/node-builtins-modules/fs.js +15 -9
- package/lib/unsupported-features/node-builtins-modules/http.js +36 -17
- package/lib/unsupported-features/node-builtins-modules/http2.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/https.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/inspector.js +20 -8
- package/lib/unsupported-features/node-builtins-modules/module.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/net.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/os.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/path.js +8 -7
- package/lib/unsupported-features/node-builtins-modules/perf_hooks.js +4 -4
- package/lib/unsupported-features/node-builtins-modules/process.js +26 -9
- package/lib/unsupported-features/node-builtins-modules/punycode.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/querystring.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/readline.js +5 -8
- package/lib/unsupported-features/node-builtins-modules/repl.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/sea.js +3 -4
- package/lib/unsupported-features/node-builtins-modules/sqlite.js +3 -4
- package/lib/unsupported-features/node-builtins-modules/stream.js +35 -16
- package/lib/unsupported-features/node-builtins-modules/string_decoder.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/test.js +3 -4
- package/lib/unsupported-features/node-builtins-modules/timers.js +2 -5
- package/lib/unsupported-features/node-builtins-modules/tls.js +5 -5
- package/lib/unsupported-features/node-builtins-modules/trace_events.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/tty.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/url.js +11 -7
- package/lib/unsupported-features/node-builtins-modules/util.js +20 -9
- package/lib/unsupported-features/node-builtins-modules/v8.js +4 -5
- package/lib/unsupported-features/node-builtins-modules/vm.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/wasi.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/worker_threads.js +15 -4
- package/lib/unsupported-features/node-builtins-modules/zlib.js +2 -4
- package/lib/unsupported-features/node-builtins.js +89 -51
- package/lib/unsupported-features/node-globals.js +21 -16
- package/lib/unsupported-features/node-import-meta.js +7 -7
- package/lib/unsupported-features/types.js +1 -3
- package/lib/util/cache.js +1 -2
- package/lib/util/check-existence.js +5 -6
- package/lib/util/check-extraneous.js +5 -6
- package/lib/util/check-prefer-global.js +5 -9
- package/lib/util/check-publish.js +8 -14
- package/lib/util/check-restricted.js +8 -9
- package/lib/util/check-unsupported-builtins.js +14 -19
- package/lib/util/enumerate-property-names.js +3 -4
- package/lib/util/exists.js +4 -5
- package/lib/util/extend-trackmap-with-node-prefix.js +3 -4
- package/lib/util/get-allow-modules.js +2 -3
- package/lib/util/get-configured-node-version.js +6 -7
- package/lib/util/get-convert-path.js +3 -4
- package/lib/util/get-full-type-name.js +9 -3
- package/lib/util/get-npmignore.js +10 -8
- package/lib/util/get-package-json.js +4 -7
- package/lib/util/get-parser-services.js +7 -4
- package/lib/util/get-resolve-paths.js +2 -3
- package/lib/util/get-resolver-config.js +2 -3
- package/lib/util/get-semver-range.js +2 -3
- package/lib/util/get-try-extensions.js +4 -5
- package/lib/util/get-tsconfig.js +4 -11
- package/lib/util/get-type-of-node.js +1 -3
- package/lib/util/get-typescript-extension-map.js +9 -5
- package/lib/util/has-parent-node.js +1 -5
- package/lib/util/import-target.js +8 -11
- package/lib/util/is-bin-file.js +2 -4
- package/lib/util/is-typescript.js +3 -6
- package/lib/util/iterate-process-get-builtin-module-references.js +2 -7
- package/lib/util/map-typescript-extension.js +4 -9
- package/lib/util/merge-visitors-in-place.js +1 -2
- package/lib/util/strip-import-path-params.js +1 -2
- package/lib/util/unprefix-node-colon.js +1 -3
- package/lib/util/visit-import.js +12 -13
- package/lib/util/visit-require.js +16 -20
- package/package.json +21 -9
- package/types/index.d.ts +3 -6
- package/lib/util/eslint-compat.js +0 -45
package/README.md
CHANGED
|
@@ -20,68 +20,37 @@ npm install --save-dev eslint eslint-plugin-n
|
|
|
20
20
|
|
|
21
21
|
| Version | Supported Node.js | Supported ESLint Version | Status |
|
|
22
22
|
|---------|-------------------|---------------------------|--------|
|
|
23
|
+
| 18.x | `^20.19.0 \|\| ^22.13.0 \|\| >=24.0.0` | `>=8.57.1` | 🏃♂️actively maintained |
|
|
23
24
|
| 17.x | `^18.18.0 \|\| ^20.9.0 \|\| >=21.1.0` | `>=8.23.0` | 🏃♂️actively maintained |
|
|
24
25
|
| 16.x | `>=16.0.0` | `>=7.0.0` | ⚠️EOL |
|
|
25
26
|
| 15.x | `>=12.22.0` | `>=7.0.0` | ⚠️EOL |
|
|
26
27
|
|
|
27
28
|
**Note:** It recommends a use of [the "engines" field of package.json](https://docs.npmjs.com/files/package.json#engines). The "engines" field is used by `n/no-unsupported-features/*` rules.
|
|
28
29
|
|
|
29
|
-
### [`eslint.config.js`](https://eslint.org/docs/latest/use/configure/configuration-files
|
|
30
|
+
### [`eslint.config.js`](https://eslint.org/docs/latest/use/configure/configuration-files)
|
|
30
31
|
|
|
31
32
|
```js
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
]
|
|
33
|
+
import node from "eslint-plugin-n"
|
|
34
|
+
import {defineConfig} from "eslint/config"
|
|
35
|
+
|
|
36
|
+
export default defineConfig([
|
|
37
|
+
plugins: {n: node},
|
|
38
|
+
extends: ["n/recommended-module"],
|
|
39
|
+
])
|
|
42
40
|
```
|
|
43
41
|
|
|
44
42
|
To setup without the recommended configs, you'll need to add the plugin:
|
|
45
43
|
|
|
46
44
|
```js
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
module.exports = [
|
|
50
|
-
{
|
|
51
|
-
plugins: {n: nodePlugin},
|
|
52
|
-
rules: {
|
|
53
|
-
"n/exports-style": ["error", "module.exports"]
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
]
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### **[.eslintrc.json](https://eslint.org/docs/latest/use/configure/configuration-files)** (legacy example)
|
|
60
|
-
|
|
61
|
-
```jsonc
|
|
62
|
-
{
|
|
63
|
-
"extends": ["eslint:recommended", "plugin:n/recommended"],
|
|
64
|
-
"parserOptions": {
|
|
65
|
-
"ecmaVersion": 2021
|
|
66
|
-
},
|
|
67
|
-
"rules": {
|
|
68
|
-
"n/exports-style": ["error", "module.exports"]
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
To setup without the recommended rules you'll need to add the plugin:
|
|
45
|
+
import node from "eslint-plugin-n"
|
|
46
|
+
import {defineConfig} from "eslint/config"
|
|
74
47
|
|
|
75
|
-
|
|
76
|
-
{
|
|
77
|
-
|
|
78
|
-
"
|
|
48
|
+
export default defineConfig([
|
|
49
|
+
plugins: {n: node},
|
|
50
|
+
rules: {
|
|
51
|
+
"n/no-unsupported-features/es-builtins": "error",
|
|
79
52
|
},
|
|
80
|
-
|
|
81
|
-
"rules": {
|
|
82
|
-
"n/exports-style": ["error", "module.exports"]
|
|
83
|
-
}
|
|
84
|
-
}
|
|
53
|
+
])
|
|
85
54
|
```
|
|
86
55
|
|
|
87
56
|
**package.json** (An example)
|
|
@@ -157,7 +126,7 @@ For [Shareable Configs](https://eslint.org/docs/latest/developer-guide/shareable
|
|
|
157
126
|
| [no-restricted-require](docs/rules/no-restricted-require.md) | disallow specified modules when loaded by `require` | | | |
|
|
158
127
|
| [no-sync](docs/rules/no-sync.md) | disallow synchronous methods | | | |
|
|
159
128
|
| [no-top-level-await](docs/rules/no-top-level-await.md) | disallow top-level `await` in published modules | | | |
|
|
160
|
-
| [no-unpublished-bin](docs/rules/no-unpublished-bin.md) | disallow `bin` files that npm ignores |
|
|
129
|
+
| [no-unpublished-bin](docs/rules/no-unpublished-bin.md) | disallow `bin` files that npm ignores | | | |
|
|
161
130
|
| [no-unpublished-import](docs/rules/no-unpublished-import.md) | disallow `import` declarations which import private modules | 🟢 ✅ | | |
|
|
162
131
|
| [no-unpublished-require](docs/rules/no-unpublished-require.md) | disallow `require()` expressions which import private modules | 🟢 ✅ | | |
|
|
163
132
|
| [no-unsupported-features/es-builtins](docs/rules/no-unsupported-features/es-builtins.md) | disallow unsupported ECMAScript built-ins on the specified version | 🟢 ✅ | | |
|
|
@@ -165,9 +134,11 @@ For [Shareable Configs](https://eslint.org/docs/latest/developer-guide/shareable
|
|
|
165
134
|
| [no-unsupported-features/node-builtins](docs/rules/no-unsupported-features/node-builtins.md) | disallow unsupported Node.js built-in APIs on the specified version | 🟢 ✅ | | |
|
|
166
135
|
| [prefer-global/buffer](docs/rules/prefer-global/buffer.md) | enforce either `Buffer` or `require("buffer").Buffer` | | | |
|
|
167
136
|
| [prefer-global/console](docs/rules/prefer-global/console.md) | enforce either `console` or `require("console")` | | | |
|
|
137
|
+
| [prefer-global/crypto](docs/rules/prefer-global/crypto.md) | enforce either `crypto` or `require("crypto").webcrypto` | | | |
|
|
168
138
|
| [prefer-global/process](docs/rules/prefer-global/process.md) | enforce either `process` or `require("process")` | | | |
|
|
169
139
|
| [prefer-global/text-decoder](docs/rules/prefer-global/text-decoder.md) | enforce either `TextDecoder` or `require("util").TextDecoder` | | | |
|
|
170
140
|
| [prefer-global/text-encoder](docs/rules/prefer-global/text-encoder.md) | enforce either `TextEncoder` or `require("util").TextEncoder` | | | |
|
|
141
|
+
| [prefer-global/timers](docs/rules/prefer-global/timers.md) | enforce either global timer functions or `require("timers")` | | | |
|
|
171
142
|
| [prefer-global/url](docs/rules/prefer-global/url.md) | enforce either `URL` or `require("url").URL` | | | |
|
|
172
143
|
| [prefer-global/url-search-params](docs/rules/prefer-global/url-search-params.md) | enforce either `URLSearchParams` or `require("url").URLSearchParams` | | | |
|
|
173
144
|
| [prefer-node-protocol](docs/rules/prefer-node-protocol.md) | enforce using the `node:` protocol when importing Node.js builtin modules. | | 🔧 | |
|
|
@@ -191,10 +162,10 @@ For [Shareable Configs](https://eslint.org/docs/latest/developer-guide/shareable
|
|
|
191
162
|
|
|
192
163
|
About each config:
|
|
193
164
|
|
|
194
|
-
- `recommended`: Considers both CommonJS and ES Modules. If [`"type":"module"` field](https://medium.com/@nodejs/announcing-a-new-experimental-modules-1be8d2d6c2ff#b023) existed in package.json then it considers files as ES Modules. Otherwise it considers files as CommonJS. In addition, it considers `*.mjs` files as ES Modules and `*.cjs` files as CommonJS.
|
|
195
165
|
- `recommended-module`: Considers all files as ES Modules.
|
|
196
166
|
- `recommended-script`: Considers all files as CommonJS.
|
|
197
|
-
- `
|
|
167
|
+
- `recommended`: Considers both CommonJS and ES Modules. If [`"type":"module"` field](https://medium.com/@nodejs/announcing-a-new-experimental-modules-1be8d2d6c2ff#b023) existed in package.json then it considers files as ES Modules. Otherwise it considers files as CommonJS. In addition, it considers `*.mjs` files as ES Modules and `*.cjs` files as CommonJS.
|
|
168
|
+
- `all`: enables all of the rules shipped with the package. This configuration is **not recommended** for production use because it may change with every minor and major version. Use at your own risk.
|
|
198
169
|
|
|
199
170
|
These preset configs:
|
|
200
171
|
|
|
@@ -209,20 +180,17 @@ These preset configs:
|
|
|
209
180
|
- Q: The `no-missing-import` / `no-missing-require` rules don't work with nested folders in SublimeLinter-eslint
|
|
210
181
|
- A: See [context.getFilename() in rule returns relative path](https://github.com/roadhump/SublimeLinter-eslint#contextgetfilename-in-rule-returns-relative-path) in the SublimeLinter-eslint FAQ.
|
|
211
182
|
|
|
212
|
-
- Q: How to use the
|
|
213
|
-
- A: You can use the new exported flat config `
|
|
183
|
+
- Q: How to use the eslint config with mixed commonjs and es modules?
|
|
184
|
+
- A: You can use the new exported flat config `mixed-esm-and-cjs`, an example:
|
|
214
185
|
|
|
215
186
|
```js
|
|
216
|
-
|
|
187
|
+
import node from "eslint-plugin-n"
|
|
188
|
+
import {defineConfig} from "eslint/config"
|
|
217
189
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
"n/exports-style": ["error", "module.exports"],
|
|
223
|
-
},
|
|
224
|
-
},
|
|
225
|
-
]
|
|
190
|
+
export default defineConfig([
|
|
191
|
+
plugins: {n: node},
|
|
192
|
+
extends: ["n/mixed-esm-and-cjs"],
|
|
193
|
+
])
|
|
226
194
|
```
|
|
227
195
|
|
|
228
196
|
## 🚥 Semantic Versioning Policy
|
package/lib/all-rules.js
CHANGED
|
@@ -3,53 +3,96 @@
|
|
|
3
3
|
* @author aladdin-add<weiran.zsd@outlook.com>
|
|
4
4
|
* TODO: maybe auto-generated in the future?
|
|
5
5
|
*/
|
|
6
|
-
"use strict"
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
import callbackReturn from "./rules/callback-return.js"
|
|
8
|
+
import exportsStyle from "./rules/exports-style.js"
|
|
9
|
+
import fileExtensionInImport from "./rules/file-extension-in-import.js"
|
|
10
|
+
import globalRequire from "./rules/global-require.js"
|
|
11
|
+
import handleCallbackErr from "./rules/handle-callback-err.js"
|
|
12
|
+
import noCallbackLiteral from "./rules/no-callback-literal.js"
|
|
13
|
+
import noDeprecatedApi from "./rules/no-deprecated-api.js"
|
|
14
|
+
import noExportsAssign from "./rules/no-exports-assign.js"
|
|
15
|
+
import noExtraneousImport from "./rules/no-extraneous-import.js"
|
|
16
|
+
import noExtraneousRequire from "./rules/no-extraneous-require.js"
|
|
17
|
+
import noMissingImport from "./rules/no-missing-import.js"
|
|
18
|
+
import noMissingRequire from "./rules/no-missing-require.js"
|
|
19
|
+
import noMixedRequires from "./rules/no-mixed-requires.js"
|
|
20
|
+
import noNewRequire from "./rules/no-new-require.js"
|
|
21
|
+
import noPathConcat from "./rules/no-path-concat.js"
|
|
22
|
+
import noProcessEnv from "./rules/no-process-env.js"
|
|
23
|
+
import noProcessExit from "./rules/no-process-exit.js"
|
|
24
|
+
import noRestrictedImport from "./rules/no-restricted-import.js"
|
|
25
|
+
import noRestrictedRequire from "./rules/no-restricted-require.js"
|
|
26
|
+
import noSync from "./rules/no-sync.js"
|
|
27
|
+
import noTopLevelAwait from "./rules/no-top-level-await.js"
|
|
28
|
+
import noUnpublishedBin from "./rules/no-unpublished-bin.js"
|
|
29
|
+
import noUnpublishedImport from "./rules/no-unpublished-import.js"
|
|
30
|
+
import noUnpublishedRequire from "./rules/no-unpublished-require.js"
|
|
31
|
+
import noUnsupportedFeaturesEsBuiltins from "./rules/no-unsupported-features/es-builtins.js"
|
|
32
|
+
import noUnsupportedFeaturesEsSyntax from "./rules/no-unsupported-features/es-syntax.js"
|
|
33
|
+
import noUnsupportedFeaturesNodeBuiltins from "./rules/no-unsupported-features/node-builtins.js"
|
|
34
|
+
import preferGlobalBuffer from "./rules/prefer-global/buffer.js"
|
|
35
|
+
import preferGlobalConsole from "./rules/prefer-global/console.js"
|
|
36
|
+
import preferGlobalCrypto from "./rules/prefer-global/crypto.js"
|
|
37
|
+
import preferGlobalProcess from "./rules/prefer-global/process.js"
|
|
38
|
+
import preferGlobalTextDecoder from "./rules/prefer-global/text-decoder.js"
|
|
39
|
+
import preferGlobalTextEncoder from "./rules/prefer-global/text-encoder.js"
|
|
40
|
+
import preferGlobalUrlSearchParams from "./rules/prefer-global/url-search-params.js"
|
|
41
|
+
import preferGlobalUrl from "./rules/prefer-global/url.js"
|
|
42
|
+
import preferGlobalTimers from "./rules/prefer-global/timers.js"
|
|
43
|
+
import preferNodeProtocol from "./rules/prefer-node-protocol.js"
|
|
44
|
+
import preferPromisesDns from "./rules/prefer-promises/dns.js"
|
|
45
|
+
import preferPromisesFs from "./rules/prefer-promises/fs.js"
|
|
46
|
+
import processExitAsThrow from "./rules/process-exit-as-throw.js"
|
|
47
|
+
import hashbang from "./rules/hashbang.js"
|
|
48
|
+
import noHideCoreModules from "./rules/no-hide-core-modules.js"
|
|
49
|
+
import shebang from "./rules/shebang.js"
|
|
9
50
|
|
|
10
|
-
/** @type {Record<string,
|
|
11
|
-
|
|
12
|
-
"callback-return":
|
|
13
|
-
"exports-style":
|
|
14
|
-
"file-extension-in-import":
|
|
15
|
-
"global-require":
|
|
16
|
-
"handle-callback-err":
|
|
17
|
-
"no-callback-literal":
|
|
18
|
-
"no-deprecated-api":
|
|
19
|
-
"no-exports-assign":
|
|
20
|
-
"no-extraneous-import":
|
|
21
|
-
"no-extraneous-require":
|
|
22
|
-
"no-missing-import":
|
|
23
|
-
"no-missing-require":
|
|
24
|
-
"no-mixed-requires":
|
|
25
|
-
"no-new-require":
|
|
26
|
-
"no-path-concat":
|
|
27
|
-
"no-process-env":
|
|
28
|
-
"no-process-exit":
|
|
29
|
-
"no-restricted-import":
|
|
30
|
-
"no-restricted-require":
|
|
31
|
-
"no-sync":
|
|
32
|
-
"no-top-level-await":
|
|
33
|
-
"no-unpublished-bin":
|
|
34
|
-
"no-unpublished-import":
|
|
35
|
-
"no-unpublished-require":
|
|
36
|
-
"no-unsupported-features/es-builtins":
|
|
37
|
-
"no-unsupported-features/es-syntax":
|
|
38
|
-
"no-unsupported-features/node-builtins":
|
|
39
|
-
"prefer-global/buffer":
|
|
40
|
-
"prefer-global/console":
|
|
41
|
-
"prefer-global/
|
|
42
|
-
"prefer-global/
|
|
43
|
-
"prefer-global/text-
|
|
44
|
-
"prefer-global/
|
|
45
|
-
"prefer-global/url":
|
|
46
|
-
"prefer-
|
|
47
|
-
"prefer-
|
|
48
|
-
"prefer-
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"no-hide-core-modules":
|
|
54
|
-
shebang:
|
|
51
|
+
/** @type {Record<string, import('./rules/rule-module.js').RuleModule>} */
|
|
52
|
+
const allRules = {
|
|
53
|
+
"callback-return": callbackReturn,
|
|
54
|
+
"exports-style": exportsStyle,
|
|
55
|
+
"file-extension-in-import": fileExtensionInImport,
|
|
56
|
+
"global-require": globalRequire,
|
|
57
|
+
"handle-callback-err": handleCallbackErr,
|
|
58
|
+
"no-callback-literal": noCallbackLiteral,
|
|
59
|
+
"no-deprecated-api": noDeprecatedApi,
|
|
60
|
+
"no-exports-assign": noExportsAssign,
|
|
61
|
+
"no-extraneous-import": noExtraneousImport,
|
|
62
|
+
"no-extraneous-require": noExtraneousRequire,
|
|
63
|
+
"no-missing-import": noMissingImport,
|
|
64
|
+
"no-missing-require": noMissingRequire,
|
|
65
|
+
"no-mixed-requires": noMixedRequires,
|
|
66
|
+
"no-new-require": noNewRequire,
|
|
67
|
+
"no-path-concat": noPathConcat,
|
|
68
|
+
"no-process-env": noProcessEnv,
|
|
69
|
+
"no-process-exit": noProcessExit,
|
|
70
|
+
"no-restricted-import": noRestrictedImport,
|
|
71
|
+
"no-restricted-require": noRestrictedRequire,
|
|
72
|
+
"no-sync": noSync,
|
|
73
|
+
"no-top-level-await": noTopLevelAwait,
|
|
74
|
+
"no-unpublished-bin": noUnpublishedBin,
|
|
75
|
+
"no-unpublished-import": noUnpublishedImport,
|
|
76
|
+
"no-unpublished-require": noUnpublishedRequire,
|
|
77
|
+
"no-unsupported-features/es-builtins": noUnsupportedFeaturesEsBuiltins,
|
|
78
|
+
"no-unsupported-features/es-syntax": noUnsupportedFeaturesEsSyntax,
|
|
79
|
+
"no-unsupported-features/node-builtins": noUnsupportedFeaturesNodeBuiltins,
|
|
80
|
+
"prefer-global/buffer": preferGlobalBuffer,
|
|
81
|
+
"prefer-global/console": preferGlobalConsole,
|
|
82
|
+
"prefer-global/crypto": preferGlobalCrypto,
|
|
83
|
+
"prefer-global/process": preferGlobalProcess,
|
|
84
|
+
"prefer-global/text-decoder": preferGlobalTextDecoder,
|
|
85
|
+
"prefer-global/text-encoder": preferGlobalTextEncoder,
|
|
86
|
+
"prefer-global/url-search-params": preferGlobalUrlSearchParams,
|
|
87
|
+
"prefer-global/url": preferGlobalUrl,
|
|
88
|
+
"prefer-global/timers": preferGlobalTimers,
|
|
89
|
+
"prefer-node-protocol": preferNodeProtocol,
|
|
90
|
+
"prefer-promises/dns": preferPromisesDns,
|
|
91
|
+
"prefer-promises/fs": preferPromisesFs,
|
|
92
|
+
"process-exit-as-throw": processExitAsThrow,
|
|
93
|
+
hashbang: hashbang,
|
|
94
|
+
"no-hide-core-modules": noHideCoreModules,
|
|
95
|
+
shebang: shebang,
|
|
55
96
|
}
|
|
97
|
+
|
|
98
|
+
export default allRules
|
package/lib/configs/_commons.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const rules = require("../all-rules")
|
|
1
|
+
import rules from "../all-rules.js"
|
|
4
2
|
|
|
5
3
|
/** @type {import('eslint').Linter.RulesRecord} */
|
|
6
4
|
const recommendeRulesConfig = {}
|
|
@@ -20,5 +18,4 @@ for (const [ruleName, rule] of Object.entries(rules)) {
|
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
exports.allRulesConfig = allRulesConfig
|
|
21
|
+
export { recommendeRulesConfig, allRulesConfig }
|
package/lib/configs/all.js
CHANGED
|
@@ -2,16 +2,15 @@
|
|
|
2
2
|
* @fileoverview config for enabling all rules in the plugin.
|
|
3
3
|
* @author aladdin-add<weiran.zsd@outlook.com>SS
|
|
4
4
|
*/
|
|
5
|
-
"use strict"
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
import { allRulesConfig } from "./_commons.js"
|
|
7
|
+
import * as recommendeConfig from "./recommended.js"
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* https://eslint.org/docs/latest/use/configure/configuration-files-new
|
|
12
11
|
* @type {import('eslint').Linter.FlatConfig}
|
|
13
12
|
*/
|
|
14
|
-
|
|
13
|
+
export const flat = {
|
|
15
14
|
name: "node/flat/all",
|
|
16
15
|
languageOptions: recommendeConfig.flat.languageOptions ?? {},
|
|
17
16
|
rules: allRulesConfig,
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const globals = require("globals")
|
|
4
|
-
const { recommendeRulesConfig } = require("./_commons")
|
|
1
|
+
import globals from "globals"
|
|
2
|
+
import { recommendeRulesConfig } from "./_commons.js"
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* https://eslint.org/docs/latest/use/configure/configuration-files
|
|
8
6
|
* @type {import('eslint').ESLint.ConfigData}
|
|
9
7
|
*/
|
|
10
|
-
|
|
8
|
+
export const eslintrc = {
|
|
11
9
|
env: {
|
|
12
10
|
node: true,
|
|
13
11
|
},
|
|
@@ -37,16 +35,16 @@ module.exports.eslintrc = {
|
|
|
37
35
|
* https://eslint.org/docs/latest/use/configure/configuration-files-new
|
|
38
36
|
* @type {import('eslint').Linter.FlatConfig}
|
|
39
37
|
*/
|
|
40
|
-
|
|
38
|
+
export const flat = {
|
|
41
39
|
name: "node/flat/recommended-module",
|
|
42
40
|
languageOptions: {
|
|
43
41
|
sourceType: "module",
|
|
44
42
|
globals: {
|
|
45
43
|
...globals.node,
|
|
46
|
-
...
|
|
44
|
+
...eslintrc.globals,
|
|
47
45
|
},
|
|
48
46
|
},
|
|
49
47
|
rules:
|
|
50
48
|
/** @type {import('eslint').Linter.RulesRecord} */
|
|
51
|
-
(
|
|
49
|
+
(eslintrc.rules),
|
|
52
50
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const globals = require("globals")
|
|
4
|
-
const { recommendeRulesConfig } = require("./_commons")
|
|
1
|
+
import globals from "globals"
|
|
2
|
+
import { recommendeRulesConfig } from "./_commons.js"
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* https://eslint.org/docs/latest/use/configure/configuration-files
|
|
8
6
|
* @type {import('eslint').ESLint.ConfigData}
|
|
9
7
|
*/
|
|
10
|
-
|
|
8
|
+
export const eslintrc = {
|
|
11
9
|
env: {
|
|
12
10
|
node: true,
|
|
13
11
|
},
|
|
@@ -34,16 +32,16 @@ module.exports.eslintrc = {
|
|
|
34
32
|
* https://eslint.org/docs/latest/use/configure/configuration-files-new
|
|
35
33
|
* @type {import('eslint').Linter.FlatConfig}
|
|
36
34
|
*/
|
|
37
|
-
|
|
35
|
+
export const flat = {
|
|
38
36
|
name: "node/flat/recommended-script",
|
|
39
37
|
languageOptions: {
|
|
40
38
|
sourceType: "commonjs",
|
|
41
39
|
globals: {
|
|
42
40
|
...globals.node,
|
|
43
|
-
...
|
|
41
|
+
...eslintrc.globals,
|
|
44
42
|
},
|
|
45
43
|
},
|
|
46
44
|
rules:
|
|
47
45
|
/** @type {import('eslint').Linter.RulesRecord} */
|
|
48
|
-
(
|
|
46
|
+
(eslintrc.rules),
|
|
49
47
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const moduleConfig = require("./recommended-module")
|
|
5
|
-
const scriptConfig = require("./recommended-script")
|
|
1
|
+
import { getPackageJson } from "../util/get-package-json.js"
|
|
2
|
+
import * as moduleConfig from "./recommended-module.js"
|
|
3
|
+
import * as scriptConfig from "./recommended-script.js"
|
|
6
4
|
|
|
7
5
|
const packageJson = getPackageJson()
|
|
8
6
|
|
|
@@ -17,7 +15,7 @@ const recommendedConfig = isModule ? moduleConfig : scriptConfig
|
|
|
17
15
|
* https://eslint.org/docs/latest/use/configure/configuration-files
|
|
18
16
|
* @type {import('eslint').ESLint.ConfigData}
|
|
19
17
|
*/
|
|
20
|
-
|
|
18
|
+
export const eslintrc = {
|
|
21
19
|
...recommendedConfig.eslintrc,
|
|
22
20
|
overrides: [
|
|
23
21
|
{ files: ["*.cjs", ".*.cjs"], ...scriptConfig.eslintrc },
|
|
@@ -25,4 +23,4 @@ module.exports.eslintrc = {
|
|
|
25
23
|
],
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
export const flat = recommendedConfig.flat
|