diff --git a/lib/config-generator.js b/lib/config-generator.js index 3dd216e..9785442 100644 --- a/lib/config-generator.js +++ b/lib/config-generator.js @@ -80,8 +80,9 @@ export class ConfigGenerator { let importContent = ""; let exportContent = ""; let needCompatHelper = false; + const languages = this.answers.languages; - if (this.answers.languages?.includes("javascript")) { + if (languages?.includes("javascript")) { if (this.answers.moduleType === "commonjs" || this.answers.moduleType === "script") { exportContent += ` {files: ["**/*.js"], languageOptions: {sourceType: "${this.answers.moduleType}"}},\n`; } @@ -138,6 +139,32 @@ export class ConfigGenerator { exportContent += " pluginReact.configs.flat.recommended,\n"; } } + + if (languages?.some(item => item.startsWith("json"))) { + this.result.devDependencies.push("@eslint/json"); + importContent += "import json from \"@eslint/json\";\n"; + } + if (languages?.includes("json")) { + exportContent += " {files: [\"**/*.json\"], language: \"json/json\", ...json.configs.recommended},\n"; + } + if (languages?.includes("jsonc")) { + exportContent += " {files: [\"**/*.jsonc\"], language: \"json/jsonc\", ...json.configs.recommended},\n"; + } + if (languages?.includes("json5")) { + exportContent += " {files: [\"**/*.json5\"], language: \"json/json5\", ...json.configs.recommended},\n"; + } + + if (languages?.includes("md")) { + this.result.devDependencies.push("@eslint/markdown"); + importContent += "import markdown from \"@eslint/markdown\";\n"; + exportContent += " ...markdown.configs.recommended,\n"; + if (this.answers.mdType === "gfm") { + + // the default is commonmark + exportContent += " {files: [\"**/*.md\"], language: \"markdown/gfm\"},\n"; + } + } + if (this.answers.config) { const config = this.answers.config;