@@ -645,7 +645,7 @@ function createPlugins(plugins, migration) {
645645/**
646646 * Creates an object expression for the `ignorePatterns` property.
647647 * @param {LegacyConfig } config The config to create the object expression for.
648- * @returns {ObjectExpression } The AST for the object expression.
648+ * @returns {CallExpression } The AST for the object expression.
649649 */
650650function createGlobalIgnores ( config ) {
651651 const ignorePatterns = Array . isArray ( config . ignorePatterns )
@@ -656,8 +656,9 @@ function createGlobalIgnores(config) {
656656 b . literal ( convertIgnorePatternToMinimatch ( pattern ) ) ,
657657 ) ,
658658 ) ;
659- return b . objectExpression ( [
660- b . property ( "init" , b . identifier ( "ignores" ) , ignorePatternsArray ) ,
659+
660+ return b . callExpression ( b . identifier ( "globalIgnores" ) , [
661+ ignorePatternsArray ,
661662 ] ) ;
662663}
663664
@@ -755,40 +756,9 @@ function migrateConfigObject(migration, config) {
755756 ) ;
756757 }
757758
758- // if there are either files or ignores, map so the resulting object has files and ignores
759- if ( files || ignores ) {
760- extendsCallExpression = b . callExpression (
761- b . memberExpression ( extendsCallExpression , b . identifier ( "map" ) ) ,
762- [
763- b . arrowFunctionExpression (
764- [ b . identifier ( "config" ) ] ,
765- b . objectExpression ( [
766- b . spreadElement ( b . identifier ( "config" ) ) ,
767- ...( files
768- ? [
769- b . property (
770- "init" ,
771- b . identifier ( "files" ) ,
772- files ,
773- ) ,
774- ]
775- : [ ] ) ,
776- ...( ignores
777- ? [
778- b . property (
779- "init" ,
780- b . identifier ( "ignores" ) ,
781- ignores ,
782- ) ,
783- ]
784- : [ ] ) ,
785- ] ) ,
786- ) ,
787- ] ,
788- ) ;
789- }
790-
791- configArrayElements . push ( b . spreadElement ( extendsCallExpression ) ) ;
759+ properties . push (
760+ b . property ( "init" , b . identifier ( "extends" ) , extendsCallExpression ) ,
761+ ) ;
792762 }
793763
794764 /*
@@ -878,6 +848,11 @@ export function migrateConfig(
878848 const migration = new Migration ( config ) ;
879849 const body = [ ] ;
880850
851+ // always use defineConfig
852+ migration . imports . set ( "eslint/config" , {
853+ bindings : [ "defineConfig" ] ,
854+ } ) ;
855+
881856 /** @type {Array<CallExpression|ObjectExpression|SpreadElement> } */
882857 const configArrayElements = [
883858 ...migrateConfigObject (
@@ -945,6 +920,7 @@ export function migrateConfig(
945920 }
946921
947922 if ( config . ignorePatterns ) {
923+ migration . imports . get ( "eslint/config" ) . bindings . push ( "globalIgnores" ) ;
948924 configArrayElements . unshift ( createGlobalIgnores ( config ) ) ;
949925 }
950926
@@ -1007,6 +983,11 @@ export function migrateConfig(
1007983 // output any inits
1008984 body . push ( ...migration . inits ) ;
1009985
986+ // the defineConfig() call
987+ const defineConfigNode = b . callExpression ( b . identifier ( "defineConfig" ) , [
988+ b . arrayExpression ( configArrayElements ) ,
989+ ] ) ;
990+
1010991 // output the actual config array to the program
1011992 if ( ! isModule ) {
1012993 body . push (
@@ -1017,14 +998,12 @@ export function migrateConfig(
1017998 b . identifier ( "module" ) ,
1018999 b . identifier ( "exports" ) ,
10191000 ) ,
1020- b . arrayExpression ( configArrayElements ) ,
1001+ defineConfigNode ,
10211002 ) ,
10221003 ) ,
10231004 ) ;
10241005 } else {
1025- body . push (
1026- b . exportDefaultDeclaration ( b . arrayExpression ( configArrayElements ) ) ,
1027- ) ;
1006+ body . push ( b . exportDefaultDeclaration ( defineConfigNode ) ) ;
10281007 }
10291008
10301009 return {
0 commit comments