Skip to content

Commit

Permalink
fix: Improve config error messages (#18457)
Browse files Browse the repository at this point in the history
* fix: Improve config error messages

* Fix failing test
  • Loading branch information
nzakas committed May 17, 2024
1 parent ceada8c commit 8db0eff
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/eslint/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ async function locateConfigFileToUse({ configFile, cwd }) {
basePath = path.resolve(path.dirname(configFilePath));
} else {
error = new Error("Could not find config file.");
error.messageTemplate = "config-file-missing";
}

}
Expand Down
16 changes: 16 additions & 0 deletions messages/config-file-missing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use strict";

module.exports = function() {
return `
ESLint couldn't find an eslint.config.(js|mjs|cjs) file.
From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:
https://eslint.org/docs/latest/use/configure/migration-guide
If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.
`.trimStart();
};
23 changes: 22 additions & 1 deletion messages/eslintrc-incompat.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ Flat config uses "languageOptions.globals" to define global variables for your f
Please see the following page for information on how to convert your config object into the correct format:
https://eslint.org/docs/latest/use/configure/migration-guide#configuring-language-options
If you're not using "env" directly (it may be coming from a plugin), please see the following:
https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config
`,

extends: `
A config object is using the "extends" key, which is not supported in flat config system.
Instead of "extends", you can include config objects that you'd like to extend from directly in the flat config array.
Please see the following page for more information:
If you're using "extends" in your config file, please see the following:
https://eslint.org/docs/latest/use/configure/migration-guide#predefined-and-shareable-configs
If you're not using "extends" directly (it may be coming from a plugin), please see the following:
https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config
`,

globals: `
Expand All @@ -29,6 +35,9 @@ Flat config uses "languageOptions.globals" to define global variables for your f
Please see the following page for information on how to convert your config object into the correct format:
https://eslint.org/docs/latest/use/configure/migration-guide#configuring-language-options
If you're not using "globals" directly (it may be coming from a plugin), please see the following:
https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config
`,

ignorePatterns: `
Expand All @@ -38,6 +47,9 @@ Flat config uses "ignores" to specify files to ignore.
Please see the following page for information on how to convert your config object into the correct format:
https://eslint.org/docs/latest/use/configure/migration-guide#ignoring-files
If you're not using "ignorePatterns" directly (it may be coming from a plugin), please see the following:
https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config
`,

noInlineConfig: `
Expand All @@ -56,6 +68,9 @@ Flat config is an array that acts like the eslintrc "overrides" array.
Please see the following page for information on how to convert your config object into the correct format:
https://eslint.org/docs/latest/use/configure/migration-guide#glob-based-configs
If you're not using "overrides" directly (it may be coming from a plugin), please see the following:
https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config
`,

parser: `
Expand All @@ -65,6 +80,9 @@ Flat config uses "languageOptions.parser" to override the default parser.
Please see the following page for information on how to convert your config object into the correct format:
https://eslint.org/docs/latest/use/configure/migration-guide#custom-parsers
If you're not using "parser" directly (it may be coming from a plugin), please see the following:
https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config
`,

parserOptions: `
Expand All @@ -74,6 +92,9 @@ Flat config uses "languageOptions.parserOptions" to specify parser options.
Please see the following page for information on how to convert your config object into the correct format:
https://eslint.org/docs/latest/use/configure/migration-guide#configuring-language-options
If you're not using "parserOptions" directly (it may be coming from a plugin), please see the following:
https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config
`,

reportUnusedDisableDirectives: `
Expand Down
2 changes: 1 addition & 1 deletion tests/bin/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ describe("bin/eslint.js", () => {
const stderrPromise = getOutput(child).then(output => {
assert.match(
output.stderr,
/Could not find config file/u
/couldn't find an eslint\.config/u
);
});

Expand Down

0 comments on commit 8db0eff

Please sign in to comment.