From 4caa34449555d8a680222ec2049d97c59476c11e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 8 May 2023 00:52:27 +0800 Subject: [PATCH] refactor: locateConfigFileToUse returns an Error object (#17159) followup of https://github.com/eslint/eslint/pull/17151#discussion_r1185750069 --- lib/eslint/flat-eslint.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/eslint/flat-eslint.js b/lib/eslint/flat-eslint.js index faf055b265e..8444153076d 100644 --- a/lib/eslint/flat-eslint.js +++ b/lib/eslint/flat-eslint.js @@ -326,7 +326,7 @@ async function loadFlatConfigFile(filePath) { * as override config file is not explicitly set to `false`, it will search * upwards from the cwd for a file named `eslint.config.js`. * @param {import("./eslint").ESLintOptions} options The ESLint instance options. - * @returns {{configFilePath:string,basePath:string,error:boolean}} Location information for + * @returns {{configFilePath:string,basePath:string,error:Error|null}} Location information for * the config file. */ async function locateConfigFileToUse({ configFile, cwd }) { @@ -334,7 +334,7 @@ async function locateConfigFileToUse({ configFile, cwd }) { // determine where to load config file from let configFilePath; let basePath = cwd; - let error = false; + let error = null; if (typeof configFile === "string") { debug(`Override config file path is ${configFile}`); @@ -346,7 +346,7 @@ async function locateConfigFileToUse({ configFile, cwd }) { if (configFilePath) { basePath = path.resolve(path.dirname(configFilePath)); } else { - error = true; + error = new Error("Could not find config file."); } } @@ -385,7 +385,7 @@ async function calculateConfigArray(eslint, { // config file is required to calculate config if (error) { - throw new Error("Could not find config file."); + throw error; } const configs = new FlatConfigArray(baseConfig || [], { basePath, shouldIgnore });