diff --git a/packages/linter/src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules.spec.ts b/packages/linter/src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules.spec.ts index 1960be4818..dc47c2ec61 100644 --- a/packages/linter/src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules.spec.ts +++ b/packages/linter/src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules.spec.ts @@ -5,7 +5,7 @@ import { writeJson, } from '@nrwl/devkit'; import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; -import remoteESLintProjectConfigIfNoTypeCheckingRules from './remove-eslint-project-config-if-no-type-checking-rules'; +import removeESLintProjectConfigIfNoTypeCheckingRules from './remove-eslint-project-config-if-no-type-checking-rules'; const KNOWN_RULE_REQUIRING_TYPE_CHECKING = '@typescript-eslint/await-thenable'; @@ -100,7 +100,7 @@ describe('Remove ESLint parserOptions.project config if no rules requiring type- }; writeJson(tree, 'libs/workspace-lib/.eslintrc.json', projectEslintConfig2); - await remoteESLintProjectConfigIfNoTypeCheckingRules(tree); + await removeESLintProjectConfigIfNoTypeCheckingRules(tree); // No change expect(readJson(tree, 'apps/react-app/.eslintrc.json')).toEqual( @@ -157,7 +157,7 @@ describe('Remove ESLint parserOptions.project config if no rules requiring type- }; writeJson(tree, 'libs/workspace-lib/.eslintrc.json', projectEslintConfig2); - await remoteESLintProjectConfigIfNoTypeCheckingRules(tree); + await removeESLintProjectConfigIfNoTypeCheckingRules(tree); // No change - uses rule requiring type-checking expect(readJson(tree, 'apps/react-app/.eslintrc.json')).toEqual( @@ -184,4 +184,8 @@ describe('Remove ESLint parserOptions.project config if no rules requiring type- } `); }); + + it('should not error if .eslintrc.json does not exist', async () => { + await removeESLintProjectConfigIfNoTypeCheckingRules(tree); + }); }); diff --git a/packages/linter/src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules.ts b/packages/linter/src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules.ts index 5f6423fe6f..6f8b2ed9f4 100644 --- a/packages/linter/src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules.ts +++ b/packages/linter/src/migrations/update-12-4-0/remove-eslint-project-config-if-no-type-checking-rules.ts @@ -24,6 +24,10 @@ function updateProjectESLintConfigs(host: Tree) { export default async function removeESLintProjectConfigIfNoTypeCheckingRules( host: Tree ) { + if (!host.exists('.eslintrc.json')) { + return; + } + // If the root level config uses at least one rule requiring type-checking, do not migrate any project configs const rootESLintConfig = readJson(host, '.eslintrc.json'); if (hasRulesRequiringTypeChecking(rootESLintConfig)) {