eslint-plugin-n 17.23.2 → 17.24.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 +2 -0
- package/lib/all-rules.js +2 -0
- package/lib/rules/prefer-global/crypto.js +47 -0
- package/lib/rules/prefer-global/timers.js +66 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -165,9 +165,11 @@ For [Shareable Configs](https://eslint.org/docs/latest/developer-guide/shareable
|
|
|
165
165
|
| [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
166
|
| [prefer-global/buffer](docs/rules/prefer-global/buffer.md) | enforce either `Buffer` or `require("buffer").Buffer` | | | |
|
|
167
167
|
| [prefer-global/console](docs/rules/prefer-global/console.md) | enforce either `console` or `require("console")` | | | |
|
|
168
|
+
| [prefer-global/crypto](docs/rules/prefer-global/crypto.md) | enforce either `crypto` or `require("crypto").webcrypto` | | | |
|
|
168
169
|
| [prefer-global/process](docs/rules/prefer-global/process.md) | enforce either `process` or `require("process")` | | | |
|
|
169
170
|
| [prefer-global/text-decoder](docs/rules/prefer-global/text-decoder.md) | enforce either `TextDecoder` or `require("util").TextDecoder` | | | |
|
|
170
171
|
| [prefer-global/text-encoder](docs/rules/prefer-global/text-encoder.md) | enforce either `TextEncoder` or `require("util").TextEncoder` | | | |
|
|
172
|
+
| [prefer-global/timers](docs/rules/prefer-global/timers.md) | enforce either global timer functions or `require("timers")` | | | |
|
|
171
173
|
| [prefer-global/url](docs/rules/prefer-global/url.md) | enforce either `URL` or `require("url").URL` | | | |
|
|
172
174
|
| [prefer-global/url-search-params](docs/rules/prefer-global/url-search-params.md) | enforce either `URLSearchParams` or `require("url").URLSearchParams` | | | |
|
|
173
175
|
| [prefer-node-protocol](docs/rules/prefer-node-protocol.md) | enforce using the `node:` protocol when importing Node.js builtin modules. | | 🔧 | |
|
package/lib/all-rules.js
CHANGED
|
@@ -38,11 +38,13 @@ module.exports = {
|
|
|
38
38
|
"no-unsupported-features/node-builtins": require("./rules/no-unsupported-features/node-builtins"),
|
|
39
39
|
"prefer-global/buffer": require("./rules/prefer-global/buffer"),
|
|
40
40
|
"prefer-global/console": require("./rules/prefer-global/console"),
|
|
41
|
+
"prefer-global/crypto": require("./rules/prefer-global/crypto"),
|
|
41
42
|
"prefer-global/process": require("./rules/prefer-global/process"),
|
|
42
43
|
"prefer-global/text-decoder": require("./rules/prefer-global/text-decoder"),
|
|
43
44
|
"prefer-global/text-encoder": require("./rules/prefer-global/text-encoder"),
|
|
44
45
|
"prefer-global/url-search-params": require("./rules/prefer-global/url-search-params"),
|
|
45
46
|
"prefer-global/url": require("./rules/prefer-global/url"),
|
|
47
|
+
"prefer-global/timers": require("./rules/prefer-global/timers"),
|
|
46
48
|
"prefer-node-protocol": require("./rules/prefer-node-protocol"),
|
|
47
49
|
"prefer-promises/dns": require("./rules/prefer-promises/dns"),
|
|
48
50
|
"prefer-promises/fs": require("./rules/prefer-promises/fs"),
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Pixel998
|
|
3
|
+
* See LICENSE file in root directory for full license.
|
|
4
|
+
*/
|
|
5
|
+
"use strict"
|
|
6
|
+
|
|
7
|
+
const { READ } = require("@eslint-community/eslint-utils")
|
|
8
|
+
const checkForPreferGlobal = require("../../util/check-prefer-global")
|
|
9
|
+
|
|
10
|
+
const traceMap = {
|
|
11
|
+
globals: {
|
|
12
|
+
crypto: { [READ]: true },
|
|
13
|
+
},
|
|
14
|
+
modules: {
|
|
15
|
+
crypto: { webcrypto: { [READ]: true } },
|
|
16
|
+
"node:crypto": { webcrypto: { [READ]: true } },
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** @type {import('../rule-module').RuleModule} */
|
|
21
|
+
module.exports = {
|
|
22
|
+
meta: {
|
|
23
|
+
docs: {
|
|
24
|
+
description:
|
|
25
|
+
'enforce either `crypto` or `require("crypto").webcrypto`',
|
|
26
|
+
recommended: false,
|
|
27
|
+
url: "https://github.com/eslint-community/eslint-plugin-n/blob/HEAD/docs/rules/prefer-global/crypto.md",
|
|
28
|
+
},
|
|
29
|
+
type: "suggestion",
|
|
30
|
+
fixable: null,
|
|
31
|
+
schema: [{ enum: ["always", "never"] }],
|
|
32
|
+
messages: {
|
|
33
|
+
preferGlobal:
|
|
34
|
+
"Unexpected use of 'require(\"crypto\").webcrypto'. Use the global variable 'crypto' instead.",
|
|
35
|
+
preferModule:
|
|
36
|
+
"Unexpected use of the global variable 'crypto'. Use 'require(\"crypto\").webcrypto' instead.",
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
create(context) {
|
|
41
|
+
return {
|
|
42
|
+
"Program:exit"() {
|
|
43
|
+
checkForPreferGlobal(context, traceMap)
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Pixel998
|
|
3
|
+
* See LICENSE file in root directory for full license.
|
|
4
|
+
*/
|
|
5
|
+
"use strict"
|
|
6
|
+
|
|
7
|
+
const { READ } = require("@eslint-community/eslint-utils")
|
|
8
|
+
const checkForPreferGlobal = require("../../util/check-prefer-global")
|
|
9
|
+
|
|
10
|
+
const traceMap = {
|
|
11
|
+
globals: {
|
|
12
|
+
clearImmediate: { [READ]: true },
|
|
13
|
+
clearInterval: { [READ]: true },
|
|
14
|
+
clearTimeout: { [READ]: true },
|
|
15
|
+
setImmediate: { [READ]: true },
|
|
16
|
+
setInterval: { [READ]: true },
|
|
17
|
+
setTimeout: { [READ]: true },
|
|
18
|
+
},
|
|
19
|
+
modules: {
|
|
20
|
+
timers: {
|
|
21
|
+
clearImmediate: { [READ]: true },
|
|
22
|
+
clearInterval: { [READ]: true },
|
|
23
|
+
clearTimeout: { [READ]: true },
|
|
24
|
+
setImmediate: { [READ]: true },
|
|
25
|
+
setInterval: { [READ]: true },
|
|
26
|
+
setTimeout: { [READ]: true },
|
|
27
|
+
},
|
|
28
|
+
"node:timers": {
|
|
29
|
+
clearImmediate: { [READ]: true },
|
|
30
|
+
clearInterval: { [READ]: true },
|
|
31
|
+
clearTimeout: { [READ]: true },
|
|
32
|
+
setImmediate: { [READ]: true },
|
|
33
|
+
setInterval: { [READ]: true },
|
|
34
|
+
setTimeout: { [READ]: true },
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** @type {import('../rule-module').RuleModule} */
|
|
40
|
+
module.exports = {
|
|
41
|
+
meta: {
|
|
42
|
+
docs: {
|
|
43
|
+
description:
|
|
44
|
+
'enforce either global timer functions or `require("timers")`',
|
|
45
|
+
recommended: false,
|
|
46
|
+
url: "https://github.com/eslint-community/eslint-plugin-n/blob/HEAD/docs/rules/prefer-global/timers.md",
|
|
47
|
+
},
|
|
48
|
+
type: "suggestion",
|
|
49
|
+
fixable: null,
|
|
50
|
+
schema: [{ enum: ["always", "never"] }],
|
|
51
|
+
messages: {
|
|
52
|
+
preferGlobal:
|
|
53
|
+
"Unexpected use of 'require(\"timers\").*'. Use the global variable instead.",
|
|
54
|
+
preferModule:
|
|
55
|
+
"Unexpected use of the global variable. Use 'require(\"timers\").*' instead.",
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
create(context) {
|
|
60
|
+
return {
|
|
61
|
+
"Program:exit"() {
|
|
62
|
+
checkForPreferGlobal(context, traceMap)
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
}
|