Skip to content

Commit

Permalink
feat: show an explicit message when undefined is included as a config
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Apr 5, 2024
1 parent e0cbc50 commit af9507e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/eslint/eslint.js
Expand Up @@ -395,6 +395,10 @@ async function calculateConfigArray(eslint, {
const fileConfig = await loadFlatConfigFile(configFilePath);

if (Array.isArray(fileConfig)) {
if (fileConfig.includes(void 0)) {
throw new Error("You have included `undefined` in your array of configs - this is commonly the result of trying to use a config from a plugin that does not exist; make sure you have not typo'd the name!");
}

configs.push(...fileConfig);
} else {
configs.push(fileConfig);
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/undefined-config/a.js
@@ -0,0 +1 @@
var foo = "bar";
14 changes: 14 additions & 0 deletions tests/fixtures/undefined-config/eslint.config.js
@@ -0,0 +1,14 @@
// as in '= require("eslint-plugin-mine")'
const myPlugin = {
configs: { recommended: {} }
}

module.exports = [
{
rules: {
quotes: ["error", "single"]
}
},
// 'whoops, this should really be "recommended"'
myPlugin.configs.eslint_recommended
]
10 changes: 10 additions & 0 deletions tests/lib/eslint/eslint.js
Expand Up @@ -1222,6 +1222,16 @@ describe("ESLint", () => {
assert.strictEqual(results[0].messages[0].ruleId, "quotes");
});

it("should error early with config files that include an undefined", async () => {
eslint = new ESLint({
cwd: getFixturePath("undefined-config")
});

await assert.rejects(async () => {
await eslint.lintFiles(["a*.js"]);
}, /You have included `undefined` in your array of configs - this is commonly the result of trying to use a config from a plugin that does not exist; make sure you have not typo'd the name!/u);
});

// https://github.com/eslint/eslint/issues/16265
describe("Dot files in searches", () => {

Expand Down

0 comments on commit af9507e

Please sign in to comment.