feat(react): update complier options for strict mode (#8127)

This commit is contained in:
Noriyuki Shinpuku 2021-12-15 12:31:40 +09:00 committed by GitHub
parent acffd2e689
commit e4f7e2e40b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 15 deletions

View File

@ -19,7 +19,7 @@ describe('app', () => {
name: 'myApp',
linter: Linter.EsLint,
style: 'css',
strict: false,
strict: true,
standaloneConfig: false,
};
@ -76,14 +76,16 @@ describe('app', () => {
path: './tsconfig.spec.json',
},
]);
expect(tsconfig.compilerOptions.strict).not.toBeDefined();
expect(tsconfig.compilerOptions.forceConsistentCasingInFileNames).toEqual(
true
);
expect(tsconfig.compilerOptions.strict).toEqual(true);
expect(tsconfig.compilerOptions.noImplicitOverride).toEqual(true);
expect(
tsconfig.compilerOptions.forceConsistentCasingInFileNames
).not.toBeDefined();
expect(tsconfig.compilerOptions.noImplicitReturns).not.toBeDefined();
expect(
tsconfig.compilerOptions.noFallthroughCasesInSwitch
).not.toBeDefined();
tsconfig.compilerOptions.noPropertyAccessFromIndexSignature
).toEqual(true);
expect(tsconfig.compilerOptions.noImplicitReturns).toEqual(true);
expect(tsconfig.compilerOptions.noFallthroughCasesInSwitch).toEqual(true);
const tsconfigApp = readJson(appTree, 'apps/my-app/tsconfig.app.json');
expect(tsconfigApp.compilerOptions.outDir).toEqual('../../dist/out-tsc');
@ -718,22 +720,26 @@ Object {
});
});
describe('--strict', () => {
it('should update tsconfig.json', async () => {
describe('--no-strict', () => {
it('should not add options for strict mode', async () => {
await applicationGenerator(appTree, {
...schema,
strict: true,
strict: false,
});
const tsconfigJson = readJson(appTree, '/apps/my-app/tsconfig.json');
expect(tsconfigJson.compilerOptions.strict).toBeTruthy();
expect(
tsconfigJson.compilerOptions.forceConsistentCasingInFileNames
).toBeTruthy();
expect(tsconfigJson.compilerOptions.noImplicitReturns).toBeTruthy();
).not.toBeDefined();
expect(tsconfigJson.compilerOptions.strict).not.toBeDefined();
expect(tsconfigJson.compilerOptions.noImplicitOverride).not.toBeDefined();
expect(
tsconfigJson.compilerOptions.noPropertyAccessFromIndexSignature
).not.toBeDefined();
expect(tsconfigJson.compilerOptions.noImplicitReturns).not.toBeDefined();
expect(
tsconfigJson.compilerOptions.noFallthroughCasesInSwitch
).toBeTruthy();
).not.toBeDefined();
});
});

View File

@ -20,6 +20,8 @@ function updateTsConfig(host: Tree, options: NormalizedSchema) {
...json.compilerOptions,
forceConsistentCasingInFileNames: true,
strict: true,
noImplicitOverride: true,
noPropertyAccessFromIndexSignature: true,
noImplicitReturns: true,
noFallthroughCasesInSwitch: true,
};

View File

@ -104,6 +104,10 @@ describe('lib', () => {
tsconfigJson.compilerOptions.forceConsistentCasingInFileNames
).toEqual(true);
expect(tsconfigJson.compilerOptions.strict).toEqual(true);
expect(tsconfigJson.compilerOptions.noImplicitOverride).toEqual(true);
expect(
tsconfigJson.compilerOptions.noPropertyAccessFromIndexSignature
).toEqual(true);
expect(tsconfigJson.compilerOptions.noImplicitReturns).toEqual(true);
expect(tsconfigJson.compilerOptions.noFallthroughCasesInSwitch).toEqual(
true
@ -630,6 +634,10 @@ describe('lib', () => {
tsconfigJson.compilerOptions.forceConsistentCasingInFileNames
).not.toBeDefined();
expect(tsconfigJson.compilerOptions.strict).not.toBeDefined();
expect(tsconfigJson.compilerOptions.noImplicitOverride).not.toBeDefined();
expect(
tsconfigJson.compilerOptions.noPropertyAccessFromIndexSignature
).not.toBeDefined();
expect(tsconfigJson.compilerOptions.noImplicitReturns).not.toBeDefined();
expect(
tsconfigJson.compilerOptions.noFallthroughCasesInSwitch

View File

@ -226,6 +226,8 @@ function updateTsConfig(tree: Tree, options: NormalizedSchema) {
...json.compilerOptions,
forceConsistentCasingInFileNames: true,
strict: true,
noImplicitOverride: true,
noPropertyAccessFromIndexSignature: true,
noImplicitReturns: true,
noFallthroughCasesInSwitch: true,
};