Skip to content

Commit

Permalink
Handle file system race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Sep 23, 2021
1 parent 2766795 commit 14c6845
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
5 changes: 3 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "@nabla/vite-plugin-eslint",
"version": "1.3.1",
"version": "1.3.2",
"license": "MIT",
"description": "Plugs ESLint into Vite dev server",
"homepage": "https://github.com/nabla/vite-plugin-eslint#readme",
Expand All @@ -14,7 +14,8 @@
},
"keywords": [
"vite",
"eslint"
"eslint",
"vite-plugin"
],
"main": "index.js",
"dependencies": {
Expand Down
51 changes: 33 additions & 18 deletions worker.js
Expand Up @@ -9,24 +9,39 @@ const formatterPromise = workerData.formatter
: undefined;

parentPort.on("message", (path) => {
eslint.isPathIgnored(path).then(async (ignored) => {
if (ignored) return;
const [report] = await eslint.lintFiles(path);
if (report.messages.length === 0) return;
if (formatterPromise) {
const formatter = await formatterPromise;
console.log(formatter.format([report]));
} else {
report.messages.forEach((m) => {
const prettyPath = path.slice(path.indexOf("/src/") + 1);
const location = `${prettyPath}(${m.line},${m.column})`;
const rule = m.ruleId ? ` ${m.ruleId}` : "";
eslint
.isPathIgnored(path)
.then(async (ignored) => {
if (ignored) return;
const [report] = await eslint.lintFiles(path);
if (report.messages.length === 0) return;
if (formatterPromise) {
const formatter = await formatterPromise;
console.log(formatter.format([report]));
} else {
report.messages.forEach((m) => {
const prettyPath = path.slice(path.indexOf("/src/") + 1);
const location = `${prettyPath}(${m.line},${m.column})`;
const rule = m.ruleId ? ` ${m.ruleId}` : "";
console.log(
`${location}: ${chalk[m.severity === 2 ? "red" : "yellow"](
m.message
)}${rule}`
);
});
}
})
.catch((e) => {
if (e.messageTemplate === "file-not-found" && e.messageData?.pattern) {
// Can happen when the file is deleted or moved
console.log(
`${location}: ${chalk[m.severity === 2 ? "red" : "yellow"](
`${m.message}`
)}${rule}`
`${chalk.yellow(`[eslint] File not found`)} ${chalk.dim(
e.messageData.pattern
)}`
);
});
}
});
} else {
// Otherwise log the full error
console.error(e);
}
});
});

0 comments on commit 14c6845

Please sign in to comment.