From 636cd77002acf26a25e777fe7c1160923eb92398 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Mon, 18 Nov 2024 16:38:44 -0500 Subject: [PATCH] fix(linter): remove legacy dependencies during convert to flat config (#28981) ## Current Behavior `@typescript-eslint/eslint-plugin` and `@typescript-eslint/parser` are left at old versions after converting to flat config. ## Expected Behavior `@typescript-eslint/eslint-plugin` and `@typescript-eslint/parser` are removed when converting to flat config. ## Related Issue(s) Fixes # --- .../convert-to-flat-config/generator.spec.ts | 26 +++++++++++++++++++ .../convert-to-flat-config/generator.ts | 7 +++++ 2 files changed, 33 insertions(+) diff --git a/packages/eslint/src/generators/convert-to-flat-config/generator.spec.ts b/packages/eslint/src/generators/convert-to-flat-config/generator.spec.ts index 45a1ed54543d9..9eda076ba6a50 100644 --- a/packages/eslint/src/generators/convert-to-flat-config/generator.spec.ts +++ b/packages/eslint/src/generators/convert-to-flat-config/generator.spec.ts @@ -47,6 +47,32 @@ describe('convert-to-flat-config generator', () => { }); }); + it('should update dependencies', async () => { + await lintProjectGenerator(tree, { + skipFormat: false, + linter: Linter.EsLint, + project: 'test-lib', + setParserOptionsProject: false, + }); + await convertToFlatConfigGenerator(tree, options); + + expect(tree.read('package.json', 'utf-8')).toMatchInlineSnapshot(` + "{ + "name": "@proj/source", + "dependencies": {}, + "devDependencies": { + "@eslint/eslintrc": "^2.1.1", + "@nx/eslint": "0.0.1", + "@nx/eslint-plugin": "0.0.1", + "eslint": "^9.8.0", + "eslint-config-prettier": "^9.0.0", + "typescript-eslint": "^8.0.0" + } + } + " + `); + }); + it('should convert json successfully', async () => { await lintProjectGenerator(tree, { skipFormat: false, diff --git a/packages/eslint/src/generators/convert-to-flat-config/generator.ts b/packages/eslint/src/generators/convert-to-flat-config/generator.ts index 795b97b6c91fa..5e68663fda610 100644 --- a/packages/eslint/src/generators/convert-to-flat-config/generator.ts +++ b/packages/eslint/src/generators/convert-to-flat-config/generator.ts @@ -8,6 +8,7 @@ import { ProjectConfiguration, readJson, readNxJson, + removeDependenciesFromPackageJson, Tree, updateJson, updateProjectConfiguration, @@ -240,4 +241,10 @@ function processConvertedConfig( } addDependenciesToPackageJson(tree, {}, devDependencies); + + removeDependenciesFromPackageJson( + tree, + ['@typescript-eslint/eslint-plugin', '@typescript-eslint/parser'], + ['@typescript-eslint/eslint-plugin', '@typescript-eslint/parser'] + ); }