-
-
Notifications
You must be signed in to change notification settings - Fork 171
/
dns.js
74 lines (69 loc) · 2.31 KB
/
dns.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* @author Toru Nagashima
* See LICENSE file in root directory for full license.
*/
"use strict"
const { CALL, CONSTRUCT, ReferenceTracker } = require("eslint-utils")
const trackMap = {
dns: {
lookup: { [CALL]: true },
lookupService: { [CALL]: true },
Resolver: { [CONSTRUCT]: true },
getServers: { [CALL]: true },
resolve: { [CALL]: true },
resolve4: { [CALL]: true },
resolve6: { [CALL]: true },
resolveAny: { [CALL]: true },
resolveCname: { [CALL]: true },
resolveMx: { [CALL]: true },
resolveNaptr: { [CALL]: true },
resolveNs: { [CALL]: true },
resolvePtr: { [CALL]: true },
resolveSoa: { [CALL]: true },
resolveSrv: { [CALL]: true },
resolveTxt: { [CALL]: true },
reverse: { [CALL]: true },
setServers: { [CALL]: true },
},
}
module.exports = {
meta: {
docs: {
description: 'enforce `require("dns").promises`',
category: "Stylistic Issues",
recommended: false,
url:
"https://github.com/mysticatea/eslint-plugin-node/blob/v11.1.0/docs/rules/prefer-promises/dns.md",
},
fixable: null,
messages: {
preferPromises: "Use 'dns.promises.{{name}}()' instead.",
preferPromisesNew: "Use 'new dns.promises.{{name}}()' instead.",
},
schema: [],
type: "suggestion",
},
create(context) {
return {
"Program:exit"() {
const scope = context.getScope()
const tracker = new ReferenceTracker(scope, { mode: "legacy" })
const references = [
...tracker.iterateCjsReferences(trackMap),
...tracker.iterateEsmReferences(trackMap),
]
for (const { node, path } of references) {
const name = path[path.length - 1]
const isClass = name[0] === name[0].toUpperCase()
context.report({
node,
messageId: isClass
? "preferPromisesNew"
: "preferPromises",
data: { name },
})
}
},
}
},
}