From cbc755ca824dee93f91110fb49aedb00455b39bb Mon Sep 17 00:00:00 2001 From: Cyrille Tuzi Date: Mon, 1 Jun 2020 14:20:55 +0200 Subject: [PATCH] feat(@schematics/angular): add tslint no-any and typedef rules when in strict mode --- .../angular/workspace/files/tslint.json.template | 4 +++- .../schematics/angular/workspace/index_spec.ts | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/schematics/angular/workspace/files/tslint.json.template b/packages/schematics/angular/workspace/files/tslint.json.template index def88d1c87aa..b5eb2d966783 100644 --- a/packages/schematics/angular/workspace/files/tslint.json.template +++ b/packages/schematics/angular/workspace/files/tslint.json.template @@ -42,7 +42,8 @@ "instance-method" ] } - ], + ],<% if (strict) { %> + "no-any": true,<% } %> "no-console": [ true, "debug", @@ -82,6 +83,7 @@ "named": "never" } }, + "typedef": [true, "call-signature"], "typedef-whitespace": { "options": [ { diff --git a/packages/schematics/angular/workspace/index_spec.ts b/packages/schematics/angular/workspace/index_spec.ts index 2f6d3b222113..6dd48e092842 100644 --- a/packages/schematics/angular/workspace/index_spec.ts +++ b/packages/schematics/angular/workspace/index_spec.ts @@ -81,10 +81,22 @@ describe('Workspace Schematic', () => { expect(angularCompilerOptions).toBeUndefined(); }); - it('should not add strict compiler options when true', async () => { + it('should add strict compiler options when true', async () => { const tree = await schematicRunner.runSchematicAsync('workspace', { ...defaultOptions, strict: true }).toPromise(); const { compilerOptions, angularCompilerOptions } = JSON.parse(tree.readContent('/tsconfig.base.json')); expect(compilerOptions.strict).toBe(true); expect(angularCompilerOptions.strictTemplates).toBe(true); }); + + it('should not add strict lint options when false', async () => { + const tree = await schematicRunner.runSchematicAsync('workspace', { ...defaultOptions, strict: false }).toPromise(); + const { rules } = JSON.parse(tree.readContent('/tslint.json')); + expect(rules['no-any']).toBeUndefined(); + }); + + it('should add strict lint options when true', async () => { + const tree = await schematicRunner.runSchematicAsync('workspace', { ...defaultOptions, strict: true }).toPromise(); + const { rules } = JSON.parse(tree.readContent('/tslint.json')); + expect(rules['no-any']).toBe(true); + }); });