From fc468a582bed1bce978df6adba9beb0c969285da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Jona=C5=A1?= Date: Mon, 30 Oct 2023 16:57:59 +0100 Subject: [PATCH] fix(linter): fix flat config migration (#19742) --- packages/eslint/src/generators/init/init-migration.ts | 1 - .../src/generators/utils/flat-config/ast-utils.ts | 10 ++++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/eslint/src/generators/init/init-migration.ts b/packages/eslint/src/generators/init/init-migration.ts index 918d54023ed7d..a4da8e7804d59 100644 --- a/packages/eslint/src/generators/init/init-migration.ts +++ b/packages/eslint/src/generators/init/init-migration.ts @@ -99,7 +99,6 @@ function migrateEslintFile(projectEslintPath: string, tree: Tree) { 'plugin:@nrwl/typescript', 'plugin:@nrwl/javascript', ]); - console.warn('Flat eslint config is not supported yet for migration'); tree.write(projectEslintPath, config); } else { updateJson(tree, projectEslintPath, (json) => { diff --git a/packages/eslint/src/generators/utils/flat-config/ast-utils.ts b/packages/eslint/src/generators/utils/flat-config/ast-utils.ts index 6e74612d62161..9da68e403799e 100644 --- a/packages/eslint/src/generators/utils/flat-config/ast-utils.ts +++ b/packages/eslint/src/generators/utils/flat-config/ast-utils.ts @@ -335,18 +335,24 @@ export function addBlockToFlatConfigExport( }); const insert = printer.printNode(ts.EmitHint.Expression, config, source); if (options.insertAtTheEnd) { + const index = + exportsArray.length > 0 + ? exportsArray.at(exportsArray.length - 1).end + : exportsArray.pos; return applyChangesToString(content, [ { type: ChangeType.Insert, - index: exportsArray[exportsArray.length - 1].end, + index, text: `,\n${insert}`, }, ]); } else { + const index = + exportsArray.length > 0 ? exportsArray.at(0).pos : exportsArray.pos; return applyChangesToString(content, [ { type: ChangeType.Insert, - index: exportsArray[0].pos, + index, text: `\n${insert},`, }, ]);