33const RuleTester = require ( 'eslint' ) . RuleTester ;
44const tester = new RuleTester ( {
55 parserOptions : {
6- ecmaVersion : 6 ,
6+ ecmaVersion : 13 ,
77 sourceType : 'module' ,
88 } ,
99} ) ;
@@ -24,6 +24,37 @@ tester.run(ruleName, require(`../rules/${ruleName}`), {
2424 code : `var something = require('fs').readFile, readFile = require('foo').readFile;
2525 readFile(c);` ,
2626 } ,
27+ {
28+ code : `
29+ import { promises as fsp } from 'fs';
30+ import fs from 'fs';
31+ import path from 'path';
32+
33+ const index = await fsp.readFile(path.resolve(__dirname, './index.html'), 'utf-8');
34+ const key = fs.readFileSync(path.join(__dirname, './ssl.key'));
35+ await fsp.writeFile(path.resolve(__dirname, './sitemap.xml'), sitemap);` ,
36+ globals : {
37+ __dirname : 'readonly' ,
38+ } ,
39+ } ,
40+ {
41+ code : `
42+ import fs from 'fs';
43+ import path from 'path';
44+ const dirname = path.dirname(__filename)
45+ const key = fs.readFileSync(path.resolve(dirname, './index.html'));` ,
46+ globals : {
47+ __filename : 'readonly' ,
48+ } ,
49+ } ,
50+ {
51+ code : `
52+ import fs from 'fs';
53+ const key = fs.readFileSync(\`\${process.cwd()}/path/to/foo.json\`);` ,
54+ globals : {
55+ process : 'readonly' ,
56+ } ,
57+ } ,
2758 ] ,
2859 invalid : [
2960 /// requires
@@ -141,5 +172,15 @@ tester.run(ruleName, require(`../rules/${ruleName}`), {
141172 code : "var fs = require('fs');\nfunction foo () {\nvar { readFile: something } = fs.promises;\nsomething(filename);\n}" ,
142173 errors : [ { message : 'Found readFile from package "fs" with non literal argument at index 0' } ] ,
143174 } ,
175+ {
176+ code : `
177+ import fs from 'fs';
178+ import path from 'path';
179+ const key = fs.readFileSync(path.resolve(__dirname, foo));` ,
180+ globals : {
181+ __filename : 'readonly' ,
182+ } ,
183+ errors : [ { message : 'Found readFileSync from package "fs" with non literal argument at index 0' } ] ,
184+ } ,
144185 ] ,
145186} ) ;
0 commit comments