fix(linter): check existence of eslintrc.json before running migration (#6335)
This commit is contained in:
parent
6ef8afbfd9
commit
35d77a1b2a
@ -5,7 +5,7 @@ import {
|
|||||||
writeJson,
|
writeJson,
|
||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
|
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';
|
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);
|
writeJson(tree, 'libs/workspace-lib/.eslintrc.json', projectEslintConfig2);
|
||||||
|
|
||||||
await remoteESLintProjectConfigIfNoTypeCheckingRules(tree);
|
await removeESLintProjectConfigIfNoTypeCheckingRules(tree);
|
||||||
|
|
||||||
// No change
|
// No change
|
||||||
expect(readJson(tree, 'apps/react-app/.eslintrc.json')).toEqual(
|
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);
|
writeJson(tree, 'libs/workspace-lib/.eslintrc.json', projectEslintConfig2);
|
||||||
|
|
||||||
await remoteESLintProjectConfigIfNoTypeCheckingRules(tree);
|
await removeESLintProjectConfigIfNoTypeCheckingRules(tree);
|
||||||
|
|
||||||
// No change - uses rule requiring type-checking
|
// No change - uses rule requiring type-checking
|
||||||
expect(readJson(tree, 'apps/react-app/.eslintrc.json')).toEqual(
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -24,6 +24,10 @@ function updateProjectESLintConfigs(host: Tree) {
|
|||||||
export default async function removeESLintProjectConfigIfNoTypeCheckingRules(
|
export default async function removeESLintProjectConfigIfNoTypeCheckingRules(
|
||||||
host: Tree
|
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
|
// 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');
|
const rootESLintConfig = readJson(host, '.eslintrc.json');
|
||||||
if (hasRulesRequiringTypeChecking(rootESLintConfig)) {
|
if (hasRulesRequiringTypeChecking(rootESLintConfig)) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user