From f737a0d80655e812e882d1dc9043378e75d16de7 Mon Sep 17 00:00:00 2001 From: Cyrille Tuzi Date: Mon, 1 Jun 2020 14:20:55 +0200 Subject: [PATCH 1/2] 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); + }); }); From 7fa3ec7b37e99e6f839152f1178fa97fc1597ed1 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 1 Jun 2020 16:08:10 +0200 Subject: [PATCH 2/2] style: format tslint.json.template --- .../schematics/angular/workspace/files/tslint.json.template | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/schematics/angular/workspace/files/tslint.json.template b/packages/schematics/angular/workspace/files/tslint.json.template index b5eb2d966783..52f376be166a 100644 --- a/packages/schematics/angular/workspace/files/tslint.json.template +++ b/packages/schematics/angular/workspace/files/tslint.json.template @@ -83,7 +83,10 @@ "named": "never" } }, - "typedef": [true, "call-signature"], + "typedef": [ + true, + "call-signature" + ], "typedef-whitespace": { "options": [ {