@@ -123,6 +123,16 @@ export class ConfigGenerator {
123123 const purpose = this . answers . purpose ;
124124 const useTs = this . answers . useTs ;
125125
126+ if ( purpose === "syntax" ) {
127+
128+ // no need to install any plugin
129+ } else if ( purpose === "problems" ) {
130+ this . result . devDependencies . push ( "@eslint/js" ) ;
131+ importContent += "import js from \"@eslint/js\";\n" ;
132+ exportContent += ` { files: ["${ extensions } "], plugins: { js }, extends: ["js/recommended"] },\n` ;
133+ }
134+
135+ // language = javascript/typescript
126136 if ( languages . includes ( "javascript" ) ) {
127137 if ( this . answers . moduleType === "commonjs" || this . answers . moduleType === "script" ) {
128138 exportContent += ` { files: ["**/*.js"], languageOptions: { sourceType: "${ this . answers . moduleType } " } },\n` ;
@@ -139,74 +149,71 @@ export class ConfigGenerator {
139149
140150 exportContent += ` { files: ["${ extensions } "], languageOptions: { ${ envContent [ this . answers . env . join ( "," ) ] } } },\n` ;
141151 }
142- }
143-
144- if ( purpose === "syntax" ) {
152+ if ( useTs ) {
153+ this . result . devDependencies . push ( "typescript-eslint" ) ;
154+ importContent += "import tseslint from \"typescript-eslint\";\n" ;
155+ exportContent += " tseslint.configs.recommended,\n" ;
156+ }
145157
146- // no need to install any plugin
147- } else if ( purpose === "problems" ) {
148- this . result . devDependencies . push ( "@eslint/js" ) ;
149- importContent += "import js from \"@eslint/js\";\n" ;
150- exportContent += ` { files: ["${ extensions } "], plugins: { js }, extends: ["js/recommended"] },\n` ;
151- }
158+ if ( this . answers . framework === "vue" ) {
159+ this . result . devDependencies . push ( "eslint-plugin-vue" ) ;
160+ importContent += "import pluginVue from \"eslint-plugin-vue\";\n" ;
161+ exportContent += " pluginVue.configs[\"flat/essential\"],\n" ;
152162
153- if ( useTs ) {
154- this . result . devDependencies . push ( "typescript-eslint" ) ;
155- importContent += "import tseslint from \"typescript-eslint\";\n" ;
156- exportContent += " tseslint.configs.recommended,\n" ;
157- }
158-
159- if ( this . answers . framework === "vue" ) {
160- this . result . devDependencies . push ( "eslint-plugin-vue" ) ;
161- importContent += "import pluginVue from \"eslint-plugin-vue\";\n" ;
162- exportContent += " pluginVue.configs[\"flat/essential\"],\n" ;
163+ // https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser
164+ if ( this . answers . language === "typescript" ) {
165+ exportContent += " { files: [\"**/*.vue\"], languageOptions: { parserOptions: { parser: tseslint.parser } } },\n" ;
166+ }
167+ }
163168
164- // https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser
165- if ( this . answers . language === "typescript" ) {
166- exportContent += " { files: [\"**/*.vue\"], languageOptions: { parserOptions: { parser: tseslint.parser } } },\n" ;
169+ if ( this . answers . framework === "react" ) {
170+ this . result . devDependencies . push ( "eslint-plugin-react" ) ;
171+ importContent += "import pluginReact from \"eslint-plugin-react\";\n" ;
172+ exportContent += " pluginReact.configs.flat.recommended,\n" ;
167173 }
168- }
169174
170- if ( this . answers . framework === "react" ) {
171- this . result . devDependencies . push ( "eslint-plugin-react" ) ;
172- importContent += "import pluginReact from \"eslint-plugin-react\";\n" ;
173- exportContent += " pluginReact.configs.flat.recommended,\n" ;
175+ if ( needCompatHelper ) {
176+ this . result . devDependencies . push ( "@eslint/eslintrc" , "@eslint/js" ) ;
177+ }
174178 }
175179
180+ // language = json/jsonc/json5
176181 if ( languages . some ( item => item . startsWith ( "json" ) ) ) {
177182 this . result . devDependencies . push ( "@eslint/json" ) ;
178183 importContent += "import json from \"@eslint/json\";\n" ;
179- }
180- if ( languages . includes ( "json" ) ) {
181- const config = purpose === "syntax"
182- ? " {files: [\"**/*.json\"], plugins: {json}, language: \"json/json\"},\n"
183- : " {files: [\"**/*.json\"], language: \"json/json\", ...json.configs.recommended},\n" ;
184184
185- exportContent += config ;
186- }
187- if ( languages . includes ( "jsonc" ) ) {
188- const config = purpose === "syntax"
189- ? " {files: [\"**/*.jsonc\"], plugins: {json}, language: \"json/jsonc\"},\n"
190- : " {files: [\"**/*.jsonc\"], language: \"json/jsonc\", ...json.configs.recommended},\n" ;
185+ if ( languages . includes ( "json" ) ) {
186+ const config = purpose === "syntax"
187+ ? " { files: [\"**/*.json\"], plugins: { json }, language: \"json/json\" },\n"
188+ : " { files: [\"**/*.json\"], language: \"json/json\", ...json.configs.recommended},\n" ;
191189
192- exportContent += config ;
193- }
194- if ( languages . includes ( "json5 " ) ) {
195- const config = purpose === "syntax"
196- ? " {files: [\"**/*.json5 \"], plugins: {json}, language: \"json/json5\" },\n"
197- : " {files: [\"**/*.json5 \"], language: \"json/json5 \", ...json.configs.recommended},\n" ;
190+ exportContent += config ;
191+ }
192+ if ( languages . includes ( "jsonc " ) ) {
193+ const config = purpose === "syntax"
194+ ? " { files: [\"**/*.jsonc \"], plugins: { json }, language: \"json/jsonc\" },\n"
195+ : " { files: [\"**/*.jsonc \"], language: \"json/jsonc \", ...json.configs.recommended },\n" ;
198196
199- exportContent += config ;
197+ exportContent += config ;
198+ }
199+ if ( languages . includes ( "json5" ) ) {
200+ const config = purpose === "syntax"
201+ ? " { files: [\"**/*.json5\"], plugins: { json }, language: \"json/json5\" },\n"
202+ : " { files: [\"**/*.json5\"], language: \"json/json5\", ...json.configs.recommended },\n" ;
203+
204+ exportContent += config ;
205+ }
200206 }
201207
208+ // language = markdown
202209 if ( languages . includes ( "md" ) ) {
203210 this . result . devDependencies . push ( "@eslint/markdown" ) ;
204211 importContent += "import markdown from \"@eslint/markdown\";\n" ;
205212
206213 if ( purpose === "syntax" ) {
207214 const config = this . answers . mdType === "commonmark"
208- ? " {files: [\"**/*.md\"], plugins: {markdown}, language: \"markdown/commonmark\"},\n"
209- : " {files: [\"**/*.md\"], plugins: {markdown}, language: \"markdown/gfm\"},\n" ;
215+ ? " { files: [\"**/*.md\"], plugins: {markdown}, language: \"markdown/commonmark\" },\n"
216+ : " { files: [\"**/*.md\"], plugins: {markdown}, language: \"markdown/gfm\" },\n" ;
210217
211218 exportContent += config ;
212219 } else if ( purpose === "problems" ) {
@@ -215,11 +222,12 @@ export class ConfigGenerator {
215222 if ( this . answers . mdType === "gfm" ) {
216223
217224 // the default is commonmark
218- exportContent += " {files: [\"**/*.md\"], language: \"markdown/gfm\"},\n" ;
225+ exportContent += " { files: [\"**/*.md\"], language: \"markdown/gfm\" },\n" ;
219226 }
220227 }
221228 }
222229
230+ // passed `--config`
223231 if ( this . answers . config ) {
224232 const config = this . answers . config ;
225233
@@ -256,14 +264,6 @@ export class ConfigGenerator {
256264 }
257265 }
258266
259- if ( needCompatHelper ) {
260- this . result . devDependencies . push ( "@eslint/eslintrc" , "@eslint/js" ) ;
261- }
262-
263- const lintFilesConfig = ` { files: ["${ extensions } "] },\n` ;
264-
265- exportContent = `${ lintFilesConfig } ${ exportContent } ` ;
266-
267267 this . result . configContent = `${ importContent }
268268${ needCompatHelper ? helperContent : "" }
269269export default defineConfig([\n${ exportContent || " {}\n" } ]);` ; // defaults to `[{}]` to avoid empty config warning
0 commit comments