Skip to content

Commit

Permalink
fix(linter): install @eslint/eslintrc package as necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Feb 7, 2025
1 parent 33352bc commit 793da4c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
39 changes: 39 additions & 0 deletions packages/eslint/src/generators/utils/eslint-file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 6 additions & 2 deletions packages/eslint/src/generators/utils/eslint-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -493,7 +497,7 @@ export function addExtendsToLintConfig(
return addDependenciesToPackageJson(
tree,
{},
{ '@eslint/compat': eslintCompat },
{ '@eslint/compat': eslintCompat, '@eslint/eslintrc': eslintrcVersion },
undefined,
true
);
Expand Down

0 comments on commit 793da4c

Please sign in to comment.