Update code for new behavior of ESLint rule n/prefer-promises/fs.

This commit is contained in:
David Anson 2023-08-22 21:39:09 -07:00
parent 8c8841e7b1
commit 523eeee3bb
3 changed files with 77 additions and 82 deletions

View file

@ -2807,6 +2807,7 @@ function readConfig(file, parsers, fs, callback) {
} }
// Read file // Read file
file = helpers.expandTildePath(file, __webpack_require__(/*! node:os */ "?e6c4")); file = helpers.expandTildePath(file, __webpack_require__(/*! node:os */ "?e6c4"));
// eslint-disable-next-line n/prefer-promises/fs
fs.readFile(file, "utf8", function (err, content) { fs.readFile(file, "utf8", function (err, content) {
if (err) { if (err) {
// @ts-ignore // @ts-ignore

View file

@ -1176,6 +1176,7 @@ function readConfig(file, parsers, fs, callback) {
} }
// Read file // Read file
file = helpers.expandTildePath(file, require("node:os")); file = helpers.expandTildePath(file, require("node:os"));
// eslint-disable-next-line n/prefer-promises/fs
fs.readFile(file, "utf8", (err, content) => { fs.readFile(file, "utf8", (err, content) => {
if (err) { if (err) {
// @ts-ignore // @ts-ignore

View file

@ -412,19 +412,16 @@ test("enableTagMixedCase", (t) => new Promise((resolve) => {
}); });
})); }));
test("styleFiles", (t) => new Promise((resolve) => { test("styleFiles", async(t) => {
t.plan(9); t.plan(8);
fs.readdir("./style", function readdir(err, files) { const files = await fs.promises.readdir("./style");
t.falsy(err);
for (const file of files) { for (const file of files) {
t.truthy(require(path.join("../style", file)), "Unable to load/parse."); t.truthy(require(path.join("../style", file)), "Unable to load/parse.");
const exportValue = `./style/${file}`; const exportValue = `./style/${file}`;
const exportKey = exportValue.replace(/\.json$/, ""); const exportKey = exportValue.replace(/\.json$/, "");
t.is(packageExports[exportKey], exportValue); t.is(packageExports[exportKey], exportValue);
} }
resolve();
}); });
}));
test("styleAll", (t) => new Promise((resolve) => { test("styleAll", (t) => new Promise((resolve) => {
t.plan(2); t.plan(2);
@ -839,8 +836,8 @@ test("customFileSystemAsync", (t) => new Promise((resolve) => {
}); });
})); }));
test("readme", (t) => new Promise((resolve) => { test("readme", async(t) => {
t.plan(125); t.plan(124);
const tagToRules = {}; const tagToRules = {};
for (const rule of rules) { for (const rule of rules) {
for (const tag of rule.tags) { for (const tag of rule.tags) {
@ -849,9 +846,7 @@ test("readme", (t) => new Promise((resolve) => {
tagToRules[tag] = tagRules; tagToRules[tag] = tagRules;
} }
} }
fs.readFile("README.md", "utf8", const contents = await fs.promises.readFile("README.md", "utf8");
function readFile(err, contents) {
t.falsy(err);
const rulesLeft = [ ...rules ]; const rulesLeft = [ ...rules ];
let seenRelated = false; let seenRelated = false;
let seenReferences = false; let seenReferences = false;
@ -914,9 +909,7 @@ test("readme", (t) => new Promise((resolve) => {
(ruleLeft || "[NO RULE]").toString() + "."); (ruleLeft || "[NO RULE]").toString() + ".");
const tagLeft = Object.keys(tagToRules).shift(); const tagLeft = Object.keys(tagToRules).shift();
t.true(!tagLeft, "Undocumented tag " + tagLeft + "."); t.true(!tagLeft, "Undocumented tag " + tagLeft + ".");
resolve();
}); });
}));
test("validateJsonUsingConfigSchemaStrict", (t) => { test("validateJsonUsingConfigSchemaStrict", (t) => {
t.plan(159); t.plan(159);