-
-
Notifications
You must be signed in to change notification settings - Fork 171
/
dns.js
159 lines (156 loc) · 5.21 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**
* @author Toru Nagashima
* See LICENSE file in root directory for full license.
*/
"use strict"
const RuleTester = require("eslint").RuleTester
const rule = require("../../../../lib/rules/prefer-promises/dns")
new RuleTester({
parserOptions: {
ecmaVersion: 2015,
sourceType: "module",
},
globals: {
require: false,
},
}).run("prefer-promises/dns", rule, {
valid: [
"const dns = require('dns'); dns.lookupSync()",
"const dns = require('dns'); dns.promises.lookup()",
"const {promises} = require('dns'); promises.lookup()",
"const {promises: dns} = require('dns'); dns.lookup()",
"const {promises: {lookup}} = require('dns'); lookup()",
"import dns from 'dns'; dns.promises.lookup()",
"import * as dns from 'dns'; dns.promises.lookup()",
"import {promises} from 'dns'; promises.lookup()",
"import {promises as dns} from 'dns'; dns.lookup()",
],
invalid: [
{
code: "const dns = require('dns'); dns.lookup()",
errors: [{ messageId: "preferPromises", data: { name: "lookup" } }],
},
{
code: "const {lookup} = require('dns'); lookup()",
errors: [{ messageId: "preferPromises", data: { name: "lookup" } }],
},
{
code: "import dns from 'dns'; dns.lookup()",
errors: [{ messageId: "preferPromises", data: { name: "lookup" } }],
},
{
code: "import * as dns from 'dns'; dns.lookup()",
errors: [{ messageId: "preferPromises", data: { name: "lookup" } }],
},
{
code: "import {lookup} from 'dns'; lookup()",
errors: [{ messageId: "preferPromises", data: { name: "lookup" } }],
},
// Other members
{
code: "const dns = require('dns'); dns.lookupService()",
errors: [
{
messageId: "preferPromises",
data: { name: "lookupService" },
},
],
},
{
code: "const dns = require('dns'); new dns.Resolver()",
errors: [
{ messageId: "preferPromisesNew", data: { name: "Resolver" } },
],
},
{
code: "const dns = require('dns'); dns.getServers()",
errors: [
{ messageId: "preferPromises", data: { name: "getServers" } },
],
},
{
code: "const dns = require('dns'); dns.resolve()",
errors: [
{ messageId: "preferPromises", data: { name: "resolve" } },
],
},
{
code: "const dns = require('dns'); dns.resolve4()",
errors: [
{ messageId: "preferPromises", data: { name: "resolve4" } },
],
},
{
code: "const dns = require('dns'); dns.resolve6()",
errors: [
{ messageId: "preferPromises", data: { name: "resolve6" } },
],
},
{
code: "const dns = require('dns'); dns.resolveAny()",
errors: [
{ messageId: "preferPromises", data: { name: "resolveAny" } },
],
},
{
code: "const dns = require('dns'); dns.resolveCname()",
errors: [
{ messageId: "preferPromises", data: { name: "resolveCname" } },
],
},
{
code: "const dns = require('dns'); dns.resolveMx()",
errors: [
{ messageId: "preferPromises", data: { name: "resolveMx" } },
],
},
{
code: "const dns = require('dns'); dns.resolveNaptr()",
errors: [
{ messageId: "preferPromises", data: { name: "resolveNaptr" } },
],
},
{
code: "const dns = require('dns'); dns.resolveNs()",
errors: [
{ messageId: "preferPromises", data: { name: "resolveNs" } },
],
},
{
code: "const dns = require('dns'); dns.resolvePtr()",
errors: [
{ messageId: "preferPromises", data: { name: "resolvePtr" } },
],
},
{
code: "const dns = require('dns'); dns.resolveSoa()",
errors: [
{ messageId: "preferPromises", data: { name: "resolveSoa" } },
],
},
{
code: "const dns = require('dns'); dns.resolveSrv()",
errors: [
{ messageId: "preferPromises", data: { name: "resolveSrv" } },
],
},
{
code: "const dns = require('dns'); dns.resolveTxt()",
errors: [
{ messageId: "preferPromises", data: { name: "resolveTxt" } },
],
},
{
code: "const dns = require('dns'); dns.reverse()",
errors: [
{ messageId: "preferPromises", data: { name: "reverse" } },
],
},
{
code: "const dns = require('dns'); dns.setServers()",
errors: [
{ messageId: "preferPromises", data: { name: "setServers" } },
],
},
],
})