-
-
Notifications
You must be signed in to change notification settings - Fork 172
/
fs.js
167 lines (164 loc) · 5.75 KB
/
fs.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
160
161
162
163
164
165
166
167
/**
* @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/fs")
new RuleTester({
parserOptions: {
ecmaVersion: 2015,
sourceType: "module",
},
globals: {
require: false,
},
}).run("prefer-promises/fs", rule, {
valid: [
"const fs = require('fs'); fs.createReadStream()",
"const fs = require('fs'); fs.accessSync()",
"const fs = require('fs'); fs.promises.access()",
"const {promises} = require('fs'); promises.access()",
"const {promises: fs} = require('fs'); fs.access()",
"const {promises: {access}} = require('fs'); access()",
"import fs from 'fs'; fs.promises.access()",
"import * as fs from 'fs'; fs.promises.access()",
"import {promises} from 'fs'; promises.access()",
"import {promises as fs} from 'fs'; fs.access()",
],
invalid: [
{
code: "const fs = require('fs'); fs.access()",
errors: [{ messageId: "preferPromises", data: { name: "access" } }],
},
{
code: "const {access} = require('fs'); access()",
errors: [{ messageId: "preferPromises", data: { name: "access" } }],
},
{
code: "import fs from 'fs'; fs.access()",
errors: [{ messageId: "preferPromises", data: { name: "access" } }],
},
{
code: "import * as fs from 'fs'; fs.access()",
errors: [{ messageId: "preferPromises", data: { name: "access" } }],
},
{
code: "import {access} from 'fs'; access()",
errors: [{ messageId: "preferPromises", data: { name: "access" } }],
},
// Other members
{
code: "const fs = require('fs'); fs.copyFile()",
errors: [
{ messageId: "preferPromises", data: { name: "copyFile" } },
],
},
{
code: "const fs = require('fs'); fs.open()",
errors: [{ messageId: "preferPromises", data: { name: "open" } }],
},
{
code: "const fs = require('fs'); fs.rename()",
errors: [{ messageId: "preferPromises", data: { name: "rename" } }],
},
{
code: "const fs = require('fs'); fs.truncate()",
errors: [
{ messageId: "preferPromises", data: { name: "truncate" } },
],
},
{
code: "const fs = require('fs'); fs.rmdir()",
errors: [{ messageId: "preferPromises", data: { name: "rmdir" } }],
},
{
code: "const fs = require('fs'); fs.mkdir()",
errors: [{ messageId: "preferPromises", data: { name: "mkdir" } }],
},
{
code: "const fs = require('fs'); fs.readdir()",
errors: [
{ messageId: "preferPromises", data: { name: "readdir" } },
],
},
{
code: "const fs = require('fs');fs.readlink()",
errors: [
{ messageId: "preferPromises", data: { name: "readlink" } },
],
},
{
code: "const fs = require('fs'); fs.symlink()",
errors: [
{ messageId: "preferPromises", data: { name: "symlink" } },
],
},
{
code: "const fs = require('fs'); fs.lstat()",
errors: [{ messageId: "preferPromises", data: { name: "lstat" } }],
},
{
code: "const fs = require('fs'); fs.stat()",
errors: [{ messageId: "preferPromises", data: { name: "stat" } }],
},
{
code: "const fs = require('fs'); fs.link()",
errors: [{ messageId: "preferPromises", data: { name: "link" } }],
},
{
code: "const fs = require('fs'); fs.unlink()",
errors: [{ messageId: "preferPromises", data: { name: "unlink" } }],
},
{
code: "const fs = require('fs'); fs.chmod()",
errors: [{ messageId: "preferPromises", data: { name: "chmod" } }],
},
{
code: "const fs = require('fs'); fs.lchmod()",
errors: [{ messageId: "preferPromises", data: { name: "lchmod" } }],
},
{
code: "const fs = require('fs'); fs.lchown()",
errors: [{ messageId: "preferPromises", data: { name: "lchown" } }],
},
{
code: "const fs = require('fs'); fs.chown()",
errors: [{ messageId: "preferPromises", data: { name: "chown" } }],
},
{
code: "const fs = require('fs'); fs.utimes()",
errors: [{ messageId: "preferPromises", data: { name: "utimes" } }],
},
{
code: "const fs = require('fs'); fs.realpath()",
errors: [
{ messageId: "preferPromises", data: { name: "realpath" } },
],
},
{
code: "const fs = require('fs'); fs.mkdtemp()",
errors: [
{ messageId: "preferPromises", data: { name: "mkdtemp" } },
],
},
{
code: "const fs = require('fs'); fs.writeFile()",
errors: [
{ messageId: "preferPromises", data: { name: "writeFile" } },
],
},
{
code: "const fs = require('fs'); fs.appendFile()",
errors: [
{ messageId: "preferPromises", data: { name: "appendFile" } },
],
},
{
code: "const fs = require('fs'); fs.readFile()",
errors: [
{ messageId: "preferPromises", data: { name: "readFile" } },
],
},
],
})