eslint-plugin-n 17.24.0 → 18.0.1
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 +27 -61
- package/configs/recommended-module.js +2 -3
- package/configs/recommended-script.js +2 -2
- package/lib/all-rules.js +90 -49
- 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 +5 -7
- 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 +17 -31
- 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 | 🟢 ✅ | | |
|
|
@@ -193,10 +162,10 @@ For [Shareable Configs](https://eslint.org/docs/latest/developer-guide/shareable
|
|
|
193
162
|
|
|
194
163
|
About each config:
|
|
195
164
|
|
|
196
|
-
- `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.
|
|
197
165
|
- `recommended-module`: Considers all files as ES Modules.
|
|
198
166
|
- `recommended-script`: Considers all files as CommonJS.
|
|
199
|
-
- `
|
|
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.
|
|
200
169
|
|
|
201
170
|
These preset configs:
|
|
202
171
|
|
|
@@ -211,20 +180,17 @@ These preset configs:
|
|
|
211
180
|
- Q: The `no-missing-import` / `no-missing-require` rules don't work with nested folders in SublimeLinter-eslint
|
|
212
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.
|
|
213
182
|
|
|
214
|
-
- Q: How to use the
|
|
215
|
-
- 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:
|
|
216
185
|
|
|
217
186
|
```js
|
|
218
|
-
|
|
187
|
+
import node from "eslint-plugin-n"
|
|
188
|
+
import {defineConfig} from "eslint/config"
|
|
219
189
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
"n/exports-style": ["error", "module.exports"],
|
|
225
|
-
},
|
|
226
|
-
},
|
|
227
|
-
]
|
|
190
|
+
export default defineConfig([
|
|
191
|
+
plugins: {n: node},
|
|
192
|
+
extends: ["n/mixed-esm-and-cjs"],
|
|
193
|
+
])
|
|
228
194
|
```
|
|
229
195
|
|
|
230
196
|
## 🚥 Semantic Versioning Policy
|
package/lib/all-rules.js
CHANGED
|
@@ -3,55 +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/crypto":
|
|
42
|
-
"prefer-global/process":
|
|
43
|
-
"prefer-global/text-decoder":
|
|
44
|
-
"prefer-global/text-encoder":
|
|
45
|
-
"prefer-global/url-search-params":
|
|
46
|
-
"prefer-global/url":
|
|
47
|
-
"prefer-global/timers":
|
|
48
|
-
"prefer-node-protocol":
|
|
49
|
-
"prefer-promises/dns":
|
|
50
|
-
"prefer-promises/fs":
|
|
51
|
-
"process-exit-as-throw":
|
|
52
|
-
hashbang:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"no-hide-core-modules": require("./rules/no-hide-core-modules"),
|
|
56
|
-
shebang: require("./rules/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,
|
|
57
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
|
package/lib/eslint-utils.d.ts
CHANGED
|
@@ -1,81 +1,146 @@
|
|
|
1
|
-
declare module "eslint-plugin-es-x" {
|
|
2
|
-
export const rules: NonNullable<import('eslint').ESLint.Plugin["rules"]>;
|
|
3
|
-
}
|
|
1
|
+
declare module "eslint-plugin-es-x" {}
|
|
4
2
|
|
|
5
3
|
declare module "@eslint-community/eslint-utils" {
|
|
6
|
-
import * as estree from
|
|
7
|
-
import * as eslint from
|
|
4
|
+
import * as estree from "estree"
|
|
5
|
+
import * as eslint from "eslint"
|
|
8
6
|
|
|
9
|
-
type Node = estree.Node | estree.Expression
|
|
7
|
+
type Node = estree.Node | estree.Expression
|
|
10
8
|
|
|
11
|
-
export const READ: unique symbol
|
|
12
|
-
export const CALL: unique symbol
|
|
13
|
-
export const CONSTRUCT: unique symbol
|
|
14
|
-
export const ESM: unique symbol
|
|
9
|
+
export const READ: unique symbol
|
|
10
|
+
export const CALL: unique symbol
|
|
11
|
+
export const CONSTRUCT: unique symbol
|
|
12
|
+
export const ESM: unique symbol
|
|
15
13
|
export class ReferenceTracker {
|
|
16
|
-
constructor(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
constructor(
|
|
15
|
+
globalScope: eslint.Scope.Scope,
|
|
16
|
+
{
|
|
17
|
+
mode,
|
|
18
|
+
globalObjectNames,
|
|
19
|
+
}?:
|
|
20
|
+
| {
|
|
21
|
+
mode?: "legacy" | "strict" | undefined
|
|
22
|
+
globalObjectNames?: string[] | undefined
|
|
23
|
+
}
|
|
24
|
+
| undefined
|
|
25
|
+
)
|
|
26
|
+
variableStack: eslint.Scope.Variable[]
|
|
27
|
+
globalScope: eslint.Scope.Scope
|
|
28
|
+
mode: "legacy" | "strict"
|
|
29
|
+
globalObjectNames: string[]
|
|
30
|
+
iterateGlobalReferences<Info extends unknown>(
|
|
31
|
+
traceMap: TraceMap<Info>
|
|
32
|
+
): IterableIterator<Reference<Info>>
|
|
33
|
+
iterateCjsReferences<Info extends unknown>(
|
|
34
|
+
traceMap: TraceMap<Info>
|
|
35
|
+
): IterableIterator<Reference<Info>>
|
|
36
|
+
iterateEsmReferences<Info extends unknown>(
|
|
37
|
+
traceMap: TraceMap<Info>
|
|
38
|
+
): IterableIterator<Reference<Info>>
|
|
39
|
+
iteratePropertyReferences<Info extends unknown>(
|
|
40
|
+
node: estree.Expression,
|
|
41
|
+
traceMap: TraceMap<Info>
|
|
42
|
+
): IterableIterator<Reference<Info>>
|
|
28
43
|
}
|
|
29
44
|
export namespace ReferenceTracker {
|
|
30
|
-
export { READ }
|
|
31
|
-
export { CALL }
|
|
32
|
-
export { CONSTRUCT }
|
|
33
|
-
export { ESM }
|
|
45
|
+
export { READ }
|
|
46
|
+
export { CALL }
|
|
47
|
+
export { CONSTRUCT }
|
|
48
|
+
export { ESM }
|
|
34
49
|
}
|
|
35
|
-
type ReferenceType = typeof READ | typeof CALL | typeof CONSTRUCT
|
|
50
|
+
type ReferenceType = typeof READ | typeof CALL | typeof CONSTRUCT
|
|
36
51
|
type TraceMap<Info extends unknown> = {
|
|
37
|
-
[READ]?: Info
|
|
38
|
-
[CALL]?: Info
|
|
39
|
-
[CONSTRUCT]?: Info
|
|
40
|
-
[key: string]: TraceMap<Info> | undefined
|
|
52
|
+
[READ]?: Info
|
|
53
|
+
[CALL]?: Info
|
|
54
|
+
[CONSTRUCT]?: Info
|
|
55
|
+
[key: string]: TraceMap<Info> | undefined
|
|
41
56
|
}
|
|
42
|
-
type RichNode = eslint.Rule.Node | Node
|
|
57
|
+
type RichNode = eslint.Rule.Node | Node
|
|
43
58
|
type Reference<Info extends unknown> = {
|
|
44
|
-
node: RichNode
|
|
45
|
-
path: string[]
|
|
46
|
-
type: ReferenceType
|
|
47
|
-
info: Info
|
|
48
|
-
}
|
|
59
|
+
node: RichNode
|
|
60
|
+
path: string[]
|
|
61
|
+
type: ReferenceType
|
|
62
|
+
info: Info
|
|
63
|
+
}
|
|
49
64
|
|
|
50
|
-
export function findVariable(
|
|
65
|
+
export function findVariable(
|
|
66
|
+
initialScope: eslint.Scope.Scope,
|
|
67
|
+
nameOrNode: string | Node
|
|
68
|
+
): eslint.Scope.Variable | null
|
|
51
69
|
|
|
52
|
-
export function getFunctionHeadLocation(
|
|
53
|
-
|
|
54
|
-
|
|
70
|
+
export function getFunctionHeadLocation(
|
|
71
|
+
node: Extract<
|
|
72
|
+
eslint.Rule.Node,
|
|
73
|
+
{
|
|
74
|
+
type:
|
|
75
|
+
| "FunctionDeclaration"
|
|
76
|
+
| "FunctionExpression"
|
|
77
|
+
| "ArrowFunctionExpression"
|
|
78
|
+
}
|
|
79
|
+
>,
|
|
80
|
+
sourceCode: eslint.SourceCode
|
|
81
|
+
): eslint.AST.SourceLocation | null
|
|
55
82
|
|
|
56
|
-
export function getFunctionNameWithKind(
|
|
57
|
-
|
|
58
|
-
|
|
83
|
+
export function getFunctionNameWithKind(
|
|
84
|
+
node: Extract<
|
|
85
|
+
eslint.Rule.Node,
|
|
86
|
+
{
|
|
87
|
+
type:
|
|
88
|
+
| "FunctionDeclaration"
|
|
89
|
+
| "FunctionExpression"
|
|
90
|
+
| "ArrowFunctionExpression"
|
|
91
|
+
}
|
|
92
|
+
>,
|
|
93
|
+
sourceCode?: eslint.SourceCode | undefined
|
|
94
|
+
): string
|
|
59
95
|
|
|
60
|
-
export function getInnermostScope(
|
|
96
|
+
export function getInnermostScope(
|
|
97
|
+
initialScope: eslint.Scope.Scope,
|
|
98
|
+
node: Node
|
|
99
|
+
): eslint.Scope.Scope
|
|
61
100
|
|
|
62
|
-
export function getPropertyName(
|
|
63
|
-
|
|
64
|
-
|
|
101
|
+
export function getPropertyName(
|
|
102
|
+
node: Extract<
|
|
103
|
+
Node,
|
|
104
|
+
{
|
|
105
|
+
type:
|
|
106
|
+
| "MemberExpression"
|
|
107
|
+
| "Property"
|
|
108
|
+
| "MethodDefinition"
|
|
109
|
+
| "PropertyDefinition"
|
|
110
|
+
}
|
|
111
|
+
>,
|
|
112
|
+
initialScope?: eslint.Scope.Scope | undefined
|
|
113
|
+
): string | null
|
|
65
114
|
|
|
66
|
-
export function getStaticValue(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
115
|
+
export function getStaticValue(
|
|
116
|
+
node: Node,
|
|
117
|
+
initialScope?: eslint.Scope.Scope | null | undefined
|
|
118
|
+
):
|
|
119
|
+
| {
|
|
120
|
+
value: unknown
|
|
121
|
+
optional?: never
|
|
122
|
+
}
|
|
123
|
+
| {
|
|
124
|
+
value: undefined
|
|
125
|
+
optional?: true
|
|
126
|
+
}
|
|
127
|
+
| null
|
|
73
128
|
|
|
74
|
-
export function getStringIfConstant(
|
|
129
|
+
export function getStringIfConstant(
|
|
130
|
+
node: Node,
|
|
131
|
+
initialScope?: eslint.Scope.Scope | null | undefined
|
|
132
|
+
): string | null
|
|
75
133
|
|
|
76
|
-
export function hasSideEffect(
|
|
134
|
+
export function hasSideEffect(
|
|
135
|
+
node: eslint.Rule.Node,
|
|
136
|
+
sourceCode: eslint.SourceCode,
|
|
137
|
+
{
|
|
138
|
+
considerGetters,
|
|
139
|
+
considerImplicitTypeConversion,
|
|
140
|
+
}?: VisitOptions | undefined
|
|
141
|
+
): boolean
|
|
77
142
|
type VisitOptions = {
|
|
78
|
-
considerGetters?: boolean | undefined
|
|
79
|
-
considerImplicitTypeConversion?: boolean | undefined
|
|
80
|
-
}
|
|
143
|
+
considerGetters?: boolean | undefined
|
|
144
|
+
considerImplicitTypeConversion?: boolean | undefined
|
|
145
|
+
}
|
|
81
146
|
}
|