Skip to content

Commit

Permalink
fix(angular): ensure @typescript-eslint/utils is used with eslint fla…
Browse files Browse the repository at this point in the history
…t config (#28267)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
Eslint 9 is installed for new angular workspace but v7 of
@typescript-eslint/utils package is being installed and is incompatible


## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Esnure v8 of @typescript-eslint/utils is installed

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #

---------

Co-authored-by: Leosvel Pérez Espinosa <[email protected]>
  • Loading branch information
Coly010 and leosvelperez authored Oct 3, 2024
1 parent 9797475 commit 874fad0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
17 changes: 16 additions & 1 deletion packages/angular/src/generators/add-linting/add-linting.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'nx/src/internal-testing-utils/mock-project-graph';

import {
ProjectConfiguration,
Tree,
Expand Down Expand Up @@ -56,6 +55,22 @@ describe('addLinting generator', () => {
expect(devDependencies['@angular-eslint/template-parser']).toBeDefined();
});

it('should use flat config and install correct dependencies when using it', async () => {
process.env.ESLINT_USE_FLAT_CONFIG = 'true';
await addLintingGenerator(tree, {
prefix: 'myOrg',
projectName: appProjectName,
projectRoot: appProjectRoot,
skipFormat: true,
});

const { devDependencies } = readJson(tree, 'package.json');
expect(devDependencies['@typescript-eslint/utils']).toMatchInlineSnapshot(
`"^8.0.0"`
);
delete process.env.ESLINT_USE_FLAT_CONFIG;
});

it('should correctly generate the .eslintrc.json file', async () => {
await addLintingGenerator(tree, {
prefix: 'myOrg',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import {
type GeneratorCallback,
type Tree,
} from '@nx/devkit';
import { useFlatConfig } from '@nx/eslint/src/utils/flat-config';
import { eslint9__typescriptESLintVersion } from '@nx/eslint/src/utils/versions';
import { versions } from '../../utils/version-utils';
import { isBuildableLibraryProject } from './buildable-project';
import { useFlatConfig } from '@nx/eslint/src/utils/flat-config';

export function addAngularEsLintDependencies(
tree: Tree,
projectName: string
): GeneratorCallback {
const compatVersions = versions(tree);
const angularEslintVersionToInstall = compatVersions.angularEslintVersion;
const devDependencies = useFlatConfig(tree)
const usesEslintFlatConfig = useFlatConfig(tree);
const devDependencies = usesEslintFlatConfig
? {
'angular-eslint': angularEslintVersionToInstall,
}
Expand All @@ -24,8 +26,9 @@ export function addAngularEsLintDependencies(
};

if ('typescriptEslintVersion' in compatVersions) {
devDependencies['@typescript-eslint/utils'] =
compatVersions.typescriptEslintVersion;
devDependencies['@typescript-eslint/utils'] = usesEslintFlatConfig
? eslint9__typescriptESLintVersion
: compatVersions.typescriptEslintVersion;
}

if (isBuildableLibraryProject(tree, projectName)) {
Expand Down

0 comments on commit 874fad0

Please sign in to comment.