eslint-plugin-n 17.17.0 → 17.18.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/lib/rules/no-deprecated-api.js +7 -0
- package/lib/rules/no-unpublished-import.js +3 -0
- package/lib/rules/prefer-node-protocol.js +55 -11
- package/lib/rules/prefer-promises/dns.js +7 -0
- package/lib/rules/prefer-promises/fs.js +7 -0
- package/lib/unsupported-features/node-builtins-modules/https.js +5 -5
- package/lib/unsupported-features/node-builtins.js +1 -0
- package/lib/util/check-prefer-global.js +7 -0
- package/lib/util/check-unsupported-builtins.js +7 -0
- package/lib/util/iterate-process-get-builtin-module-references.js +56 -0
- package/package.json +1 -1
|
@@ -16,6 +16,9 @@ const getSemverRange = require("../util/get-semver-range")
|
|
|
16
16
|
const extendTrackmapWithNodePrefix = require("../util/extend-trackmap-with-node-prefix")
|
|
17
17
|
const unprefixNodeColon = require("../util/unprefix-node-colon")
|
|
18
18
|
const { getScope } = require("../util/eslint-compat")
|
|
19
|
+
const {
|
|
20
|
+
iterateProcessGetBuiltinModuleReferences,
|
|
21
|
+
} = require("../util/iterate-process-get-builtin-module-references")
|
|
19
22
|
|
|
20
23
|
/** @typedef {import('../unsupported-features/types.js').DeprecatedInfo} DeprecatedInfo */
|
|
21
24
|
/**
|
|
@@ -842,6 +845,10 @@ module.exports = {
|
|
|
842
845
|
}
|
|
843
846
|
for (const report of [
|
|
844
847
|
...tracker.iterateCjsReferences(modules),
|
|
848
|
+
...iterateProcessGetBuiltinModuleReferences(
|
|
849
|
+
tracker,
|
|
850
|
+
modules
|
|
851
|
+
),
|
|
845
852
|
...tracker.iterateEsmReferences(modules),
|
|
846
853
|
]) {
|
|
847
854
|
const { node, path, type, info } = report
|
|
@@ -9,6 +9,7 @@ const getAllowModules = require("../util/get-allow-modules")
|
|
|
9
9
|
const getConvertPath = require("../util/get-convert-path")
|
|
10
10
|
const getResolvePaths = require("../util/get-resolve-paths")
|
|
11
11
|
const getResolverConfig = require("../util/get-resolver-config")
|
|
12
|
+
const getTryExtensions = require("../util/get-try-extensions")
|
|
12
13
|
const visitImport = require("../util/visit-import")
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -18,6 +19,7 @@ const visitImport = require("../util/visit-import")
|
|
|
18
19
|
* convertPath?: import('../util/get-convert-path').ConvertPath;
|
|
19
20
|
* resolvePaths?: import('../util/get-resolve-paths').ResolvePaths;
|
|
20
21
|
* resolverConfig?: import('../util/get-resolver-config').ResolverConfig;
|
|
22
|
+
* tryExtensions?: import('../util/get-try-extensions').TryExtensions;
|
|
21
23
|
* ignoreTypeImport?: boolean;
|
|
22
24
|
* ignorePrivate?: boolean;
|
|
23
25
|
* }?
|
|
@@ -42,6 +44,7 @@ module.exports = {
|
|
|
42
44
|
convertPath: getConvertPath.schema,
|
|
43
45
|
resolvePaths: getResolvePaths.schema,
|
|
44
46
|
resolverConfig: getResolverConfig.schema,
|
|
47
|
+
tryExtensions: getTryExtensions.schema,
|
|
45
48
|
ignoreTypeImport: { type: "boolean", default: false },
|
|
46
49
|
ignorePrivate: { type: "boolean", default: true },
|
|
47
50
|
},
|
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
"use strict"
|
|
6
6
|
|
|
7
|
-
const {
|
|
7
|
+
const {
|
|
8
|
+
getStringIfConstant,
|
|
9
|
+
getPropertyName,
|
|
10
|
+
} = require("@eslint-community/eslint-utils")
|
|
8
11
|
|
|
9
12
|
const { Range } = require("semver")
|
|
10
13
|
|
|
@@ -15,6 +18,10 @@ const {
|
|
|
15
18
|
NodeBuiltinModules,
|
|
16
19
|
} = require("../unsupported-features/node-builtins.js")
|
|
17
20
|
|
|
21
|
+
/**
|
|
22
|
+
* @typedef { 'import' | 'require' | 'getBuiltinModule' } ModuleStyle
|
|
23
|
+
*/
|
|
24
|
+
|
|
18
25
|
/**
|
|
19
26
|
* @param {string} name The name of the node module
|
|
20
27
|
* @returns {boolean}
|
|
@@ -38,10 +45,15 @@ function isStringLiteral(node) {
|
|
|
38
45
|
|
|
39
46
|
/**
|
|
40
47
|
* @param {import('eslint').Rule.RuleContext} context
|
|
41
|
-
* @param {
|
|
48
|
+
* @param {ModuleStyle} moduleStyle
|
|
42
49
|
* @returns {boolean}
|
|
43
50
|
*/
|
|
44
51
|
function isEnablingThisRule(context, moduleStyle) {
|
|
52
|
+
// The availability of `process.getBuiltinModule()` means that `node:` protocol is supported.
|
|
53
|
+
if (moduleStyle === "getBuiltinModule") {
|
|
54
|
+
return true
|
|
55
|
+
}
|
|
56
|
+
|
|
45
57
|
const version = getConfiguredNodeVersion(context)
|
|
46
58
|
|
|
47
59
|
// Only check Node.js version because this rule is meaningless if configured Node.js version doesn't match semver range.
|
|
@@ -81,7 +93,7 @@ function isValidRequireArgument(node) {
|
|
|
81
93
|
/**
|
|
82
94
|
* @param {import('estree').Node | null | undefined} node
|
|
83
95
|
* @param {import('eslint').Rule.RuleContext} context
|
|
84
|
-
* @param {
|
|
96
|
+
* @param {ModuleStyle} moduleStyle
|
|
85
97
|
*/
|
|
86
98
|
function validate(node, context, moduleStyle) {
|
|
87
99
|
if (node == null) {
|
|
@@ -96,7 +108,10 @@ function validate(node, context, moduleStyle) {
|
|
|
96
108
|
return
|
|
97
109
|
}
|
|
98
110
|
|
|
99
|
-
if (
|
|
111
|
+
if (
|
|
112
|
+
(moduleStyle === "require" || moduleStyle === "getBuiltinModule") &&
|
|
113
|
+
!isValidRequireArgument(node)
|
|
114
|
+
) {
|
|
100
115
|
return
|
|
101
116
|
}
|
|
102
117
|
|
|
@@ -126,6 +141,25 @@ function validate(node, context, moduleStyle) {
|
|
|
126
141
|
})
|
|
127
142
|
}
|
|
128
143
|
|
|
144
|
+
/**
|
|
145
|
+
* @param {import('estree').Expression | import('estree').Super} node
|
|
146
|
+
*/
|
|
147
|
+
function isProcess(node) {
|
|
148
|
+
if (node.type === "Identifier" && node.name === "process") {
|
|
149
|
+
return true
|
|
150
|
+
}
|
|
151
|
+
if (node.type === "MemberExpression") {
|
|
152
|
+
if (getPropertyName(node) !== "process") {
|
|
153
|
+
return false
|
|
154
|
+
}
|
|
155
|
+
return (
|
|
156
|
+
node.object.type === "Identifier" &&
|
|
157
|
+
node.object.name === "globalThis"
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
return false
|
|
161
|
+
}
|
|
162
|
+
|
|
129
163
|
/** @type {import('./rule-module').RuleModule} */
|
|
130
164
|
module.exports = {
|
|
131
165
|
meta: {
|
|
@@ -158,15 +192,25 @@ module.exports = {
|
|
|
158
192
|
}
|
|
159
193
|
|
|
160
194
|
if (
|
|
161
|
-
node.optional
|
|
162
|
-
node.arguments.length
|
|
163
|
-
node.callee.type
|
|
164
|
-
node.callee.name
|
|
195
|
+
!node.optional &&
|
|
196
|
+
node.arguments.length === 1 &&
|
|
197
|
+
node.callee.type === "Identifier" &&
|
|
198
|
+
node.callee.name === "require"
|
|
165
199
|
) {
|
|
166
|
-
return
|
|
200
|
+
return validate(node.arguments[0], context, "require")
|
|
201
|
+
}
|
|
202
|
+
if (
|
|
203
|
+
node.arguments.length >= 1 &&
|
|
204
|
+
node.callee.type === "MemberExpression" &&
|
|
205
|
+
isProcess(node.callee.object) &&
|
|
206
|
+
getPropertyName(node.callee) === "getBuiltinModule"
|
|
207
|
+
) {
|
|
208
|
+
return validate(
|
|
209
|
+
node.arguments[0],
|
|
210
|
+
context,
|
|
211
|
+
"getBuiltinModule"
|
|
212
|
+
)
|
|
167
213
|
}
|
|
168
|
-
|
|
169
|
-
return validate(node.arguments[0], context, "require")
|
|
170
214
|
},
|
|
171
215
|
|
|
172
216
|
ExportAllDeclaration(node) {
|
|
@@ -10,6 +10,9 @@ const {
|
|
|
10
10
|
ReferenceTracker,
|
|
11
11
|
} = require("@eslint-community/eslint-utils")
|
|
12
12
|
const { getScope } = require("../../util/eslint-compat")
|
|
13
|
+
const {
|
|
14
|
+
iterateProcessGetBuiltinModuleReferences,
|
|
15
|
+
} = require("../../util/iterate-process-get-builtin-module-references")
|
|
13
16
|
|
|
14
17
|
/** @type {import('@eslint-community/eslint-utils').TraceMap<boolean>} */
|
|
15
18
|
const dns = {
|
|
@@ -63,6 +66,10 @@ module.exports = {
|
|
|
63
66
|
const tracker = new ReferenceTracker(scope, { mode: "legacy" })
|
|
64
67
|
const references = [
|
|
65
68
|
...tracker.iterateCjsReferences(traceMap),
|
|
69
|
+
...iterateProcessGetBuiltinModuleReferences(
|
|
70
|
+
tracker,
|
|
71
|
+
traceMap
|
|
72
|
+
),
|
|
66
73
|
...tracker.iterateEsmReferences(traceMap),
|
|
67
74
|
]
|
|
68
75
|
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
const { CALL, ReferenceTracker } = require("@eslint-community/eslint-utils")
|
|
8
8
|
const { getScope } = require("../../util/eslint-compat")
|
|
9
|
+
const {
|
|
10
|
+
iterateProcessGetBuiltinModuleReferences,
|
|
11
|
+
} = require("../../util/iterate-process-get-builtin-module-references")
|
|
9
12
|
|
|
10
13
|
/** @type {import('@eslint-community/eslint-utils').TraceMap<boolean>} */
|
|
11
14
|
const traceMap = {
|
|
@@ -61,6 +64,10 @@ module.exports = {
|
|
|
61
64
|
const tracker = new ReferenceTracker(scope, { mode: "legacy" })
|
|
62
65
|
const references = [
|
|
63
66
|
...tracker.iterateCjsReferences(traceMap),
|
|
67
|
+
...iterateProcessGetBuiltinModuleReferences(
|
|
68
|
+
tracker,
|
|
69
|
+
traceMap
|
|
70
|
+
),
|
|
64
71
|
...tracker.iterateEsmReferences(traceMap),
|
|
65
72
|
]
|
|
66
73
|
|
|
@@ -5,7 +5,7 @@ const { READ } = require("@eslint-community/eslint-utils")
|
|
|
5
5
|
/**
|
|
6
6
|
* @satisfies {import('../types.js').SupportVersionTraceMap}
|
|
7
7
|
*/
|
|
8
|
-
const
|
|
8
|
+
const https = {
|
|
9
9
|
globalAgent: { [READ]: { supported: ["0.5.9"] } },
|
|
10
10
|
createServer: { [READ]: { supported: ["0.3.4"] } },
|
|
11
11
|
get: { [READ]: { supported: ["0.3.6"] } },
|
|
@@ -18,12 +18,12 @@ const http = {
|
|
|
18
18
|
* @satisfies {import('../types.js').SupportVersionTraceMap}
|
|
19
19
|
*/
|
|
20
20
|
module.exports = {
|
|
21
|
-
|
|
21
|
+
https: {
|
|
22
22
|
[READ]: { supported: ["0.3.4"] },
|
|
23
|
-
...
|
|
23
|
+
...https,
|
|
24
24
|
},
|
|
25
|
-
"node:
|
|
25
|
+
"node:https": {
|
|
26
26
|
[READ]: { supported: ["14.13.1", "12.20.0"] },
|
|
27
|
-
...
|
|
27
|
+
...https,
|
|
28
28
|
},
|
|
29
29
|
}
|
|
@@ -37,6 +37,7 @@ const NodeBuiltinModules = {
|
|
|
37
37
|
...require("./node-builtins-modules/sea.js"),
|
|
38
38
|
...require("./node-builtins-modules/stream.js"),
|
|
39
39
|
...require("./node-builtins-modules/string_decoder.js"),
|
|
40
|
+
...require("./node-builtins-modules/sqlite.js"),
|
|
40
41
|
...require("./node-builtins-modules/test.js"),
|
|
41
42
|
...require("./node-builtins-modules/timers.js"),
|
|
42
43
|
...require("./node-builtins-modules/tls.js"),
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
const { ReferenceTracker } = require("@eslint-community/eslint-utils")
|
|
8
8
|
const { getScope } = require("../util/eslint-compat")
|
|
9
|
+
const {
|
|
10
|
+
iterateProcessGetBuiltinModuleReferences,
|
|
11
|
+
} = require("../util/iterate-process-get-builtin-module-references")
|
|
9
12
|
/**
|
|
10
13
|
* @typedef TraceMap
|
|
11
14
|
* @property {import('@eslint-community/eslint-utils').TraceMap<boolean>} globals
|
|
@@ -43,6 +46,10 @@ class Verifier {
|
|
|
43
46
|
|
|
44
47
|
for (const { node } of [
|
|
45
48
|
...tracker.iterateCjsReferences(traceMap.modules),
|
|
49
|
+
...iterateProcessGetBuiltinModuleReferences(
|
|
50
|
+
tracker,
|
|
51
|
+
traceMap.modules
|
|
52
|
+
),
|
|
46
53
|
...tracker.iterateEsmReferences(traceMap.modules),
|
|
47
54
|
]) {
|
|
48
55
|
context.report({ node, messageId: "preferGlobal" })
|
|
@@ -11,6 +11,9 @@ const getSemverRange = require("./get-semver-range")
|
|
|
11
11
|
const unprefixNodeColon = require("./unprefix-node-colon")
|
|
12
12
|
const semverRangeSubset = require("semver/ranges/subset")
|
|
13
13
|
const { getScope } = require("../util/eslint-compat")
|
|
14
|
+
const {
|
|
15
|
+
iterateProcessGetBuiltinModuleReferences,
|
|
16
|
+
} = require("./iterate-process-get-builtin-module-references")
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
19
|
* Parses the options.
|
|
@@ -158,6 +161,10 @@ module.exports.checkUnsupportedBuiltins = function checkUnsupportedBuiltins(
|
|
|
158
161
|
const tracker = new ReferenceTracker(scope, { mode: "legacy" })
|
|
159
162
|
const references = [
|
|
160
163
|
...tracker.iterateCjsReferences(traceMap.modules ?? {}),
|
|
164
|
+
...iterateProcessGetBuiltinModuleReferences(
|
|
165
|
+
tracker,
|
|
166
|
+
traceMap.modules ?? {}
|
|
167
|
+
),
|
|
161
168
|
...tracker.iterateEsmReferences(traceMap.modules ?? {}),
|
|
162
169
|
...tracker.iterateGlobalReferences(traceMap.globals ?? {}),
|
|
163
170
|
]
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
const {
|
|
3
|
+
CALL,
|
|
4
|
+
getStringIfConstant,
|
|
5
|
+
READ,
|
|
6
|
+
} = require("@eslint-community/eslint-utils")
|
|
7
|
+
const processGetBuiltinModuleCall = {
|
|
8
|
+
process: {
|
|
9
|
+
getBuiltinModule: {
|
|
10
|
+
[CALL]: true,
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Iterate the references of process.getBuiltinModule() modules.
|
|
16
|
+
* @template Info
|
|
17
|
+
* @param {import("@eslint-community/eslint-utils").ReferenceTracker} tracker The reference tracker.
|
|
18
|
+
* @param {import("@eslint-community/eslint-utils").TraceMap<Info>} traceMap The trace map.
|
|
19
|
+
* @returns {IterableIterator<import("@eslint-community/eslint-utils").Reference<Info>>} The iterator.
|
|
20
|
+
*/
|
|
21
|
+
function* iterateProcessGetBuiltinModuleReferences(tracker, traceMap) {
|
|
22
|
+
for (const { node } of tracker.iterateGlobalReferences(
|
|
23
|
+
processGetBuiltinModuleCall
|
|
24
|
+
)) {
|
|
25
|
+
if (node.type !== "CallExpression") continue
|
|
26
|
+
const key = node.arguments[0] && getStringIfConstant(node.arguments[0])
|
|
27
|
+
if (key == null) {
|
|
28
|
+
continue
|
|
29
|
+
}
|
|
30
|
+
const nextTraceMap = Object.hasOwn(traceMap, key) && traceMap[key]
|
|
31
|
+
if (!nextTraceMap) {
|
|
32
|
+
continue
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (nextTraceMap[READ]) {
|
|
36
|
+
yield {
|
|
37
|
+
node,
|
|
38
|
+
path: [key],
|
|
39
|
+
type: READ,
|
|
40
|
+
info: nextTraceMap[READ],
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for (const ref of tracker.iteratePropertyReferences(
|
|
45
|
+
node,
|
|
46
|
+
nextTraceMap
|
|
47
|
+
)) {
|
|
48
|
+
yield {
|
|
49
|
+
...ref,
|
|
50
|
+
path: [key, ...ref.path],
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = { iterateProcessGetBuiltinModuleReferences }
|