@@ -11,17 +11,6 @@ import { isPackageTypeModule, installSyncSaveDev, fetchPeerDependencies, findPac
1111import { getShorthandName } from "./utils/naming.js" ;
1212import * as log from "./utils/logging.js" ;
1313
14- // TODO: need to specify the package version - they may export flat configs in the future.
15- const jsStyleGuides = [
16- { message : "Airbnb: https://github.com/airbnb/javascript" , name : "airbnb" , value : { packageName : "eslint-config-airbnb-base" , type : "eslintrc" } } ,
17- { message : "Standard: https://github.com/standard/standard" , name : "standard" , value : { packageName : "eslint-config-standard" , type : "eslintrc" } } ,
18- { message : "XO: https://github.com/xojs/eslint-config-xo" , name : "xo" , value : { packageName : "eslint-config-xo" , type : "eslintrc" } }
19- ] ;
20- const tsStyleGuides = [
21- { message : "Standard: https://github.com/standard/eslint-config-standard-with-typescript" , name : "standard" , value : { packageName : "eslint-config-standard-with-typescript" , type : "eslintrc" } } ,
22- { message : "XO: https://github.com/xojs/eslint-config-xo-typescript" , name : "xo" , value : { packageName : "eslint-config-xo-typescript" , type : "eslintrc" } }
23- ] ;
24-
2514/**
2615 * Class representing a ConfigGenerator.
2716 */
@@ -39,7 +28,7 @@ export class ConfigGenerator {
3928 this . packageJsonPath = options . packageJsonPath || findPackageJson ( this . cwd ) ;
4029 this . answers = options . answers || { } ;
4130 this . result = {
42- devDependencies : [ "eslint" ] ,
31+ devDependencies : [ ] ,
4332 configFilename : "eslint.config.js" ,
4433 configContent : ""
4534 } ;
@@ -58,8 +47,7 @@ export class ConfigGenerator {
5847 initial : 1 ,
5948 choices : [
6049 { message : "To check syntax only" , name : "syntax" } ,
61- { message : "To check syntax and find problems" , name : "problems" } ,
62- { message : "To check syntax, find problems, and enforce code style" , name : "style" }
50+ { message : "To check syntax and find problems" , name : "problems" }
6351 ]
6452 } ,
6553 {
@@ -110,20 +98,6 @@ export class ConfigGenerator {
11098 const answers = await enquirer . prompt ( questions ) ;
11199
112100 Object . assign ( this . answers , answers ) ;
113-
114- if ( answers . purpose === "style" ) {
115-
116- const choices = this . answers . language === "javascript" ? jsStyleGuides : tsStyleGuides ;
117- const styleguideAnswer = await enquirer . prompt ( {
118- type : "select" ,
119- name : "styleguide" ,
120- message : "Which style guide do you want to follow?" ,
121- choices,
122- result : choice => choices . find ( it => it . name === choice ) . value
123- } ) ;
124-
125- Object . assign ( this . answers , styleguideAnswer ) ;
126- }
127101 }
128102
129103 /**
@@ -134,22 +108,9 @@ export class ConfigGenerator {
134108 const isESMModule = isPackageTypeModule ( this . packageJsonPath ) ;
135109
136110 this . result . configFilename = isESMModule ? "eslint.config.js" : "eslint.config.mjs" ;
137- this . answers . styleguide = typeof this . answers . styleguide === "string"
138- ? { packageName : this . answers . styleguide , type : "flat" }
139- : this . answers . styleguide ;
140-
141- // replaced `eslint-config-airbnb-base` with `eslint-config-airbnb`(for react supports)
142- if ( this . answers . styleguide ?. packageName === "eslint-config-airbnb-base" && this . answers . framework === "react" ) {
143- this . answers . styleguide . packageName = "eslint-config-airbnb" ;
144- this . answers . framework = "none" ;
145- }
146-
147- // tseslint should have been a dependency in the shared configs
148- // avoid install tseslint - it may install multi tseslint versions
149- // see https://github.com/eslint/create-config/issues/97
150- if ( this . answers . styleguide && this . answers . language === "typescript" ) {
151- this . answers . language = "javascript" ;
152- }
111+ this . answers . config = typeof this . answers . config === "string"
112+ ? { packageName : this . answers . config , type : "flat" }
113+ : this . answers . config ;
153114
154115 let importContent = "" ;
155116 const helperContent = `import path from "path";
@@ -188,28 +149,6 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug
188149 this . result . devDependencies . push ( "@eslint/js" ) ;
189150 importContent += "import pluginJs from \"@eslint/js\";\n" ;
190151 exportContent += " pluginJs.configs.recommended,\n" ;
191- } else if ( this . answers . purpose === "style" ) {
192- const styleguide = this . answers . styleguide ;
193-
194- this . result . devDependencies . push ( styleguide . packageName ) ;
195-
196- // install peer dependencies - it's needed for most eslintrc-style shared configs.
197- const peers = fetchPeerDependencies ( styleguide . packageName ) ;
198-
199- if ( peers !== null ) {
200- this . result . devDependencies . push ( ...peers ) ;
201- }
202-
203- if ( styleguide . type === "flat" || styleguide . type === void 0 ) {
204- importContent += `import styleGuide from "${ styleguide . packageName } ";\n` ;
205- exportContent += " ...[].concat(styleGuide),\n" ;
206- } else if ( styleguide . type === "eslintrc" ) {
207- needCompatHelper = true ;
208-
209- const shorthandName = getShorthandName ( styleguide . packageName , "eslint-config" ) ;
210-
211- exportContent += ` ...compat.extends("${ shorthandName } "),\n` ;
212- }
213152 }
214153
215154 if ( this . answers . language === "typescript" ) {
@@ -231,10 +170,39 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug
231170 importContent += "import pluginReactConfig from \"eslint-plugin-react/configs/recommended.js\";\n" ;
232171 exportContent += " pluginReactConfig,\n" ;
233172 }
173+ if ( this . answers . config ) {
174+ const config = this . answers . config ;
175+
176+ this . result . devDependencies . push ( config . packageName ) ;
177+
178+ // install peer dependencies - it's needed for most eslintrc-style shared configs.
179+ const peers = fetchPeerDependencies ( config . packageName ) ;
180+
181+ if ( peers !== null ) {
182+ this . result . devDependencies . push ( ...peers ) ;
183+ }
184+
185+ if ( config . type === "flat" || config . type === void 0 ) {
186+ importContent += `import config from "${ config . packageName } ";\n` ;
187+ exportContent += " ...[].concat(config),\n" ;
188+ } else if ( config . type === "eslintrc" ) {
189+ needCompatHelper = true ;
190+
191+ const shorthandName = getShorthandName ( config . packageName , "eslint-config" ) ;
192+
193+ exportContent += ` ...compat.extends("${ shorthandName } "),\n` ;
194+ }
195+ }
234196
235197 if ( needCompatHelper ) {
236198 this . result . devDependencies . push ( "@eslint/eslintrc" , "@eslint/js" ) ;
237199 }
200+
201+ const hasEslint = this . result . devDependencies . some ( dep => ( / ^ e s l i n t ( @ | $ ) / u. test ( dep ) ) ) ;
202+
203+ if ( ! hasEslint ) {
204+ this . result . devDependencies . push ( "eslint" ) ;
205+ }
238206 this . result . configContent = `${ importContent }
239207${ needCompatHelper ? helperContent : "" }
240208export default [\n${ exportContent } ];` ;
0 commit comments