Skip to content

Commit

Permalink
Apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Jul 19, 2023
1 parent 1c26762 commit 8dccf61
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 55 deletions.
28 changes: 16 additions & 12 deletions lib/config/flat-config-schema.js
Expand Up @@ -460,7 +460,7 @@ const sourceTypeSchema = {
* @param {string} key The eslintrc key to create a schema for.
* @returns {ObjectPropertySchema} The schema.
*/
function createEslintrcSchema(key) {
function createEslintrcErrorSchema(key) {
return {
merge: "replace",
validate() {
Expand All @@ -469,23 +469,27 @@ function createEslintrcSchema(key) {
};
}

const eslintrcKeys = [
"env",
"extends",
"globals",
"ignorePatterns",
"noInlineConfig",
"overrides",
"parser",
"parserOptions",
"reportUnusedDisableDirectives",
"root"
];

//-----------------------------------------------------------------------------
// Full schema
//-----------------------------------------------------------------------------

exports.flatConfigSchema = {

// eslintrc-style keys that should warn
env: createEslintrcSchema("env"),
extends: createEslintrcSchema("extends"),
globals: createEslintrcSchema("globals"),
ignorePatterns: createEslintrcSchema("ignorePatterns"),
noInlineConfig: createEslintrcSchema("noInlineConfig"),
overrides: createEslintrcSchema("overrides"),
parser: createEslintrcSchema("parser"),
parserOptions: createEslintrcSchema("parserOptions"),
reportUnusedDisableDirectives: createEslintrcSchema("reportUnusedDisableDirectives"),
root: createEslintrcSchema("root"),
// eslintrc-style keys that should always error
...Object.fromEntries(eslintrcKeys.map(key => [key, createEslintrcErrorSchema(key)])),

// flat config keys
settings: deepObjectAssignSchema,
Expand Down
66 changes: 24 additions & 42 deletions messages/eslintrc-incompat.js
Expand Up @@ -2,115 +2,97 @@

/* eslint consistent-return: 0 -- no default case */

module.exports = function({ key }) {
const messages = {

switch (key) {
case "env":
return `
env: `
A config object is using the "env" key, which is not supported in flat config system.
Flat config uses "languageOptions.globals" to define global variables for your files.
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
`.trim();
`,

case "extends":
return `
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:
https://eslint.org/docs/latest/use/configure/migration-guide#predefined-configs
`.trim();

case "globals":
`,

return `
globals: `
A config object is using the "globals" key, which is not supported in flat config system.
Flat config uses "languageOptions.globals" to define global variables for your files.
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
`.trim();

case "ignorePatterns":
`,

return `
ignorePatterns: `
A config object is using the "ignorePatterns" key, which is not supported in flat config system.
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
`.trim();
`,

case "noInlineConfig":

return `
noInlineConfig: `
A config object is using the "noInlineConfig" key, which is not supported in flat config system.
Flat config uses "linterOptions.noInlineConfig" 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#linter-options
`.trim();

case "overrides":
`,

return `
overrides: `
A config object is using the "overrides" key, which is not supported in flat config system.
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
`.trim();

case "parser":
`,

return `
parser: `
A config object is using the "parser" key, which is not supported in flat config system.
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
`.trim();
`,

case "parserOptions":

return `
parserOptions: `
A config object is using the "parserOptions" key, which is not supported in flat config system.
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
`.trim();

case "reportUnusedDisableDirectives":
`,

return `
reportUnusedDisableDirectives: `
A config object is using the "reportUnusedDisableDirectives" key, which is not supported in flat config system.
Flat config uses "linterOptions.reportUnusedDisableDirectives" 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#linter-options
`.trim();

case "root":
`,

return `
root: `
A config object is using the "root" key, which is not supported in flat config system.
Flat configs always act as if they are the root config file, so this key can be safely removed.
`.trim();
`
};

// no default
}
module.exports = function({ key }) {

return messages[key].trim();
};
2 changes: 1 addition & 1 deletion tests/lib/rule-tester/flat-rule-tester.js
Expand Up @@ -1336,7 +1336,7 @@ describe("FlatRuleTester", () => {
],
invalid: []
});
}, /Unexpected key "env" found./u);
}, /Key "env": This appears to be in eslintrc format rather than flat config format/u);
});

it("should pass-through the tester config to the rule", () => {
Expand Down

0 comments on commit 8dccf61

Please sign in to comment.