From a6fbee6865d93e655575dbc1476644a6ec429ffd Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Tue, 27 Aug 2019 19:24:58 +0200 Subject: [PATCH] style: add `no-invalid-await` and `prefer-promise-shorthand` lint rules (#15450) Add these two lint rules for a better code quality and readability --- .../architect/src/index_spec.ts | 2 +- .../src/experimental/jobs/strategy_spec.ts | 24 +++++++++---------- scripts/validate.ts | 2 +- tslint.json | 2 ++ 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/angular_devkit/architect/src/index_spec.ts b/packages/angular_devkit/architect/src/index_spec.ts index cac45b39de5e..109481a7af9b 100644 --- a/packages/angular_devkit/architect/src/index_spec.ts +++ b/packages/angular_devkit/architect/src/index_spec.ts @@ -177,7 +177,7 @@ describe('architect', () => { it('reports errors in the builder (async)', async () => { testArchitectHost.addBuilder('package:error', createBuilder(() => { - return new Promise((_, reject) => reject(new Error('Error async'))); + return Promise.reject(new Error('Error async')); })); let run: BuilderRun | undefined = undefined; diff --git a/packages/angular_devkit/core/src/experimental/jobs/strategy_spec.ts b/packages/angular_devkit/core/src/experimental/jobs/strategy_spec.ts index b0b575bec755..63bbd20ef2ec 100644 --- a/packages/angular_devkit/core/src/experimental/jobs/strategy_spec.ts +++ b/packages/angular_devkit/core/src/experimental/jobs/strategy_spec.ts @@ -39,8 +39,8 @@ describe('strategy.serialize()', () => { name: 'add', }); - const job1 = await scheduler.schedule('add', [1, 2, 3, 4]); - const job2 = await scheduler.schedule('add', [1, 2, 3, 4, 5]); + const job1 = scheduler.schedule('add', [1, 2, 3, 4]); + const job2 = scheduler.schedule('add', [1, 2, 3, 4, 5]); expect(started).toBe(0); expect(finished).toBe(0); @@ -102,8 +102,8 @@ describe('strategy.serialize()', () => { name: 'add100', }); - const job1 = await scheduler.schedule('add', [1, 2, 3, 4]); - const job2 = await scheduler.schedule('add100', [1, 2, 3, 4, 5]); + const job1 = scheduler.schedule('add', [1, 2, 3, 4]); + const job2 = scheduler.schedule('add100', [1, 2, 3, 4, 5]); expect(started).toBe(0); expect(finished).toBe(0); @@ -159,8 +159,8 @@ describe('strategy.reuse()', () => { name: 'add', }); - const job1 = await scheduler.schedule('add', [1, 2, 3, 4]); - const job2 = await scheduler.schedule('add', []); + const job1 = scheduler.schedule('add', [1, 2, 3, 4]); + const job2 = scheduler.schedule('add', []); expect(started).toBe(0); expect(finished).toBe(0); @@ -179,8 +179,8 @@ describe('strategy.reuse()', () => { expect(job1.state).toBe(JobState.Ended); expect(job2.state).toBe(JobState.Ended); - const job3 = await scheduler.schedule('add', [1, 2, 3, 4, 5]); - const job4 = await scheduler.schedule('add', []); + const job3 = scheduler.schedule('add', [1, 2, 3, 4, 5]); + const job4 = scheduler.schedule('add', []); job3.output.subscribe(); expect(started).toBe(2); expect(finished).toBe(1); @@ -226,10 +226,10 @@ describe('strategy.memoize()', () => { name: 'add', }); - const job1 = await scheduler.schedule('add', [1, 2, 3, 4]); - const job2 = await scheduler.schedule('add', [1, 2, 3, 4]); - const job3 = await scheduler.schedule('add', [1, 2, 3, 4, 5]); - const job4 = await scheduler.schedule('add', [1, 2, 3, 4, 5]); + const job1 = scheduler.schedule('add', [1, 2, 3, 4]); + const job2 = scheduler.schedule('add', [1, 2, 3, 4]); + const job3 = scheduler.schedule('add', [1, 2, 3, 4, 5]); + const job4 = scheduler.schedule('add', [1, 2, 3, 4, 5]); expect(started).toBe(0); expect(finished).toBe(0); diff --git a/scripts/validate.ts b/scripts/validate.ts index 8be68d916f3c..a69828945a8f 100644 --- a/scripts/validate.ts +++ b/scripts/validate.ts @@ -42,7 +42,7 @@ export default async function (options: { verbose: boolean }, logger: logging.Lo logger.info(''); logger.info('Running commit validation...'); - error = await validateCommits({}, logger.createChild('validate-commits')) != 0 + error = validateCommits({}, logger.createChild('validate-commits')) != 0 || error; logger.info(''); diff --git a/tslint.json b/tslint.json index 984fb344304f..9ff4affde825 100644 --- a/tslint.json +++ b/tslint.json @@ -35,6 +35,8 @@ "no-unthrown-error": true, "no-use-of-empty-return-value": true, "no-useless-increment": true, + "no-invalid-await": true, + "prefer-promise-shorthand": true, //These rules are part of the code smell detection section of tslint-sonarts "no-dead-store": true,