diff --git a/packages/eslint/src/generators/utils/eslint-file.spec.ts b/packages/eslint/src/generators/utils/eslint-file.spec.ts index f0428d1bab30b..dce747af9d46b 100644 --- a/packages/eslint/src/generators/utils/eslint-file.spec.ts +++ b/packages/eslint/src/generators/utils/eslint-file.spec.ts @@ -120,6 +120,45 @@ describe('@nx/eslint:lint-file', () => { ]); }); + it('should install necessary dependencies', () => { + // mock eslint version + jest.spyOn(devkitInternals, 'readModulePackageJson').mockReturnValue({ + packageJson: { name: 'eslint', version: '9.0.0' }, + path: '', + }); + tree.write('eslint.config.cjs', 'module.exports = {};'); + tree.write( + 'apps/demo/eslint.config.cjs', + `const baseConfig = require("../../eslint.config.cjs"); + +module.exports = [ + ...baseConfig, + { + files: [ + "**/*.ts", + "**/*.tsx", + "**/*.js", + "**/*.jsx" + ], + rules: {} + }, +];` + ); + + addExtendsToLintConfig(tree, 'apps/demo', { + name: 'plugin:playwright/recommend', + needCompatFixup: true, + }); + + expect(readJson(tree, 'package.json').devDependencies) + .toMatchInlineSnapshot(` + { + "@eslint/compat": "^1.1.1", + "@eslint/eslintrc": "^2.1.1", + } + `); + }); + it('should add extends to flat config', () => { tree.write('eslint.config.cjs', 'module.exports = {};'); tree.write( diff --git a/packages/eslint/src/generators/utils/eslint-file.ts b/packages/eslint/src/generators/utils/eslint-file.ts index 53bcff7095bc0..e560c87d6a194 100644 --- a/packages/eslint/src/generators/utils/eslint-file.ts +++ b/packages/eslint/src/generators/utils/eslint-file.ts @@ -20,7 +20,11 @@ import { useFlatConfig, } from '../../utils/flat-config'; import { getInstalledEslintVersion } from '../../utils/version-utils'; -import { eslint9__eslintVersion, eslintCompat } from '../../utils/versions'; +import { + eslint9__eslintVersion, + eslintCompat, + eslintrcVersion, +} from '../../utils/versions'; import { addBlockToFlatConfigExport, addFlatCompatToFlatConfig, @@ -493,7 +497,7 @@ export function addExtendsToLintConfig( return addDependenciesToPackageJson( tree, {}, - { '@eslint/compat': eslintCompat }, + { '@eslint/compat': eslintCompat, '@eslint/eslintrc': eslintrcVersion }, undefined, true );