Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/eslint/eslint into eslint.c…
Browse files Browse the repository at this point in the history
…onfig.ts
  • Loading branch information
aryaemami59 committed Feb 29, 2024
2 parents 9b630ea + af6e170 commit ac08d46
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/src/integrate/nodejs-api.md
Expand Up @@ -128,7 +128,7 @@ The `ESLint` constructor takes an `options` object. If you omit the `options` ob
* `options.globInputPaths` (`boolean`)<br>
Default is `true`. If `false` is present, the [`eslint.lintFiles()`][eslint-lintfiles] method doesn't interpret glob patterns.
* `options.ignore` (`boolean`)<br>
Default is `true`. If `false` is present, the [`eslint.lintFiles()`][eslint-lintfiles] method doesn't respect `.eslintignore` files or `ignorePatterns` in your configuration.
Default is `true`. If `false` is present, the [`eslint.lintFiles()`][eslint-lintfiles] method doesn't respect `ignorePatterns` in your configuration.
* `options.ignorePatterns` (`string[] | null`)<br>
Default is `null`. Ignore file patterns to use in addition to config ignores. These patterns are relative to `cwd`.
* `options.passOnNoPatterns` (`boolean`)<br>
Expand Down
9 changes: 8 additions & 1 deletion lib/eslint/eslint.js
Expand Up @@ -879,6 +879,7 @@ class ESLint {
configs,
errorOnUnmatchedPattern
});
const controller = new AbortController();

debug(`${filePaths.length} files found in: ${Date.now() - startTime}ms`);

Expand Down Expand Up @@ -947,9 +948,12 @@ class ESLint {
fixer = message => shouldMessageBeFixed(message, config, fixTypesSet) && originalFix(message);
}

return fs.readFile(filePath, "utf8")
return fs.readFile(filePath, { encoding: "utf8", signal: controller.signal })
.then(text => {

// fail immediately if an error occurred in another file
controller.signal.throwIfAborted();

// do the linting
const result = verifyText({
text,
Expand All @@ -973,6 +977,9 @@ class ESLint {
}

return result;
}).catch(error => {
controller.abort(error);
throw error;
});

})
Expand Down
35 changes: 35 additions & 0 deletions tests/lib/eslint/eslint.js
Expand Up @@ -16,6 +16,7 @@ const fs = require("fs");
const fsp = fs.promises;
const os = require("os");
const path = require("path");
const timers = require("node:timers/promises");
const escapeStringRegExp = require("escape-string-regexp");
const fCache = require("file-entry-cache");
const sinon = require("sinon");
Expand Down Expand Up @@ -4445,6 +4446,40 @@ describe("ESLint", () => {
});
});

it("should stop linting files if a rule crashes", async () => {

const cwd = getFixturePath("files");
let createCallCount = 0;

eslint = new ESLint({
cwd,
plugins: {
boom: {
rules: {
boom: {
create() {
createCallCount++;
throw Error("Boom!");
}
}
}
}
},
baseConfig: {
rules: {
"boom/boom": "error"
}
}
});

await assert.rejects(eslint.lintFiles("*.js"));

// Wait until all files have been closed.
while (process.getActiveResourcesInfo().includes("CloseReq")) {
await timers.setImmediate();
}
assert.strictEqual(createCallCount, 1);
});

});

Expand Down

0 comments on commit ac08d46

Please sign in to comment.