From b7eb3ba7b0eeb4a988fbd6a8ad068fc97fed75c5 Mon Sep 17 00:00:00 2001 From: kmdrGroch Date: Wed, 11 Sep 2019 18:50:49 +0200 Subject: [PATCH 1/5] fix: edge cases, duplication, log output --- packages/core/src/config/ConfigValidator.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/core/src/config/ConfigValidator.ts b/packages/core/src/config/ConfigValidator.ts index 29f5770c05..017a90da3a 100644 --- a/packages/core/src/config/ConfigValidator.ts +++ b/packages/core/src/config/ConfigValidator.ts @@ -51,8 +51,6 @@ export default class ConfigValidator { private validateThresholds() { const thresholds = this.options.thresholds; - this.validateThresholdsValueExists('high', thresholds.high); - this.validateThresholdsValueExists('low', thresholds.low); this.validateThresholdValue('high', thresholds.high); this.validateThresholdValue('low', thresholds.low); this.validateThresholdValue('break', thresholds.break); @@ -61,14 +59,8 @@ export default class ConfigValidator { } } - private validateThresholdValue(name: keyof MutationScoreThresholds, value: number | null) { - if (typeof value === 'number' && (value < 0 || value > 100)) { - this.invalidate(`Value "${value}" is invalid for \`thresholds.${name}\`. Expected a number between 0 and 100`); - } - } - - private validateThresholdsValueExists(name: keyof MutationScoreThresholds, value: number | undefined) { - if (typeof value !== 'number') { + private validateThresholdValue(name: keyof MutationScoreThresholds, value: any) { + if (typeof value !== 'number' || typeof value === 'number' && (value < 0 || value > 100 || isNaN(value))) { this.invalidate(`Value "${value}" is invalid for \`thresholds.${name}\`. Expected a number between 0 and 100`); } } @@ -77,7 +69,7 @@ export default class ConfigValidator { const logLevel = this.options[logProperty]; const VALID_LOG_LEVEL_VALUES = [LogLevel.Fatal, LogLevel.Error, LogLevel.Warning, LogLevel.Information, LogLevel.Debug, LogLevel.Trace, LogLevel.Off]; if (VALID_LOG_LEVEL_VALUES.indexOf(logLevel) < 0) { - this.invalidate(`Value "${logLevel}" is invalid for \`logLevel\`. Expected one of the following: ${this.joinQuotedList(VALID_LOG_LEVEL_VALUES)}`); + this.invalidate(`Value "${logLevel}" is invalid for \`${logProperty}\`. Expected one of the following: ${this.joinQuotedList(VALID_LOG_LEVEL_VALUES)}`); } } From ce81901d762581b26ff2d0b20522b0e4b55f1568 Mon Sep 17 00:00:00 2001 From: Bartosz Leoniak Date: Wed, 11 Sep 2019 22:01:03 +0200 Subject: [PATCH 2/5] revert some changes --- packages/core/src/config/ConfigValidator.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/core/src/config/ConfigValidator.ts b/packages/core/src/config/ConfigValidator.ts index 017a90da3a..19195e423d 100644 --- a/packages/core/src/config/ConfigValidator.ts +++ b/packages/core/src/config/ConfigValidator.ts @@ -51,6 +51,8 @@ export default class ConfigValidator { private validateThresholds() { const thresholds = this.options.thresholds; + this.validateThresholdsValueExists('high', thresholds.high); + this.validateThresholdsValueExists('low', thresholds.low); this.validateThresholdValue('high', thresholds.high); this.validateThresholdValue('low', thresholds.low); this.validateThresholdValue('break', thresholds.break); @@ -59,8 +61,14 @@ export default class ConfigValidator { } } - private validateThresholdValue(name: keyof MutationScoreThresholds, value: any) { - if (typeof value !== 'number' || typeof value === 'number' && (value < 0 || value > 100 || isNaN(value))) { + private validateThresholdValue(name: keyof MutationScoreThresholds, value: number | null) { + if (value < 0 || value > 100 || isNaN(value)) { + this.invalidate(`Value "${value}" is invalid for \`thresholds.${name}\`. Expected a number between 0 and 100`); + } + } + + private validateThresholdsValueExists(name: keyof MutationScoreThresholds, value: any) { + if (typeof value !== 'number') { this.invalidate(`Value "${value}" is invalid for \`thresholds.${name}\`. Expected a number between 0 and 100`); } } From 3c905cdf79a5262927a17de401c3abc17d0ea729 Mon Sep 17 00:00:00 2001 From: Bartosz Leoniak Date: Wed, 11 Sep 2019 22:01:32 +0200 Subject: [PATCH 3/5] Update ConfigValidator.ts --- packages/core/src/config/ConfigValidator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/config/ConfigValidator.ts b/packages/core/src/config/ConfigValidator.ts index 19195e423d..e130a7253b 100644 --- a/packages/core/src/config/ConfigValidator.ts +++ b/packages/core/src/config/ConfigValidator.ts @@ -66,7 +66,7 @@ export default class ConfigValidator { this.invalidate(`Value "${value}" is invalid for \`thresholds.${name}\`. Expected a number between 0 and 100`); } } - + private validateThresholdsValueExists(name: keyof MutationScoreThresholds, value: any) { if (typeof value !== 'number') { this.invalidate(`Value "${value}" is invalid for \`thresholds.${name}\`. Expected a number between 0 and 100`); From 56f89bd108e1db1c8fe0e242f1aedc4092b1a0ad Mon Sep 17 00:00:00 2001 From: Bartosz Leoniak Date: Wed, 11 Sep 2019 22:01:51 +0200 Subject: [PATCH 4/5] Update ConfigValidator.ts --- packages/core/src/config/ConfigValidator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/config/ConfigValidator.ts b/packages/core/src/config/ConfigValidator.ts index e130a7253b..631457d484 100644 --- a/packages/core/src/config/ConfigValidator.ts +++ b/packages/core/src/config/ConfigValidator.ts @@ -51,7 +51,7 @@ export default class ConfigValidator { private validateThresholds() { const thresholds = this.options.thresholds; - this.validateThresholdsValueExists('high', thresholds.high); + this.validateThresholdsValueExists('high', thresholds.high); this.validateThresholdsValueExists('low', thresholds.low); this.validateThresholdValue('high', thresholds.high); this.validateThresholdValue('low', thresholds.low); From eeb8a927e2a7fbe87fbd0186e8ae923d3ae1e427 Mon Sep 17 00:00:00 2001 From: Bartosz Leoniak Date: Wed, 11 Sep 2019 22:26:31 +0200 Subject: [PATCH 5/5] Update ConfigValidator.ts --- packages/core/src/config/ConfigValidator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/config/ConfigValidator.ts b/packages/core/src/config/ConfigValidator.ts index 631457d484..32c1581e3e 100644 --- a/packages/core/src/config/ConfigValidator.ts +++ b/packages/core/src/config/ConfigValidator.ts @@ -62,7 +62,7 @@ export default class ConfigValidator { } private validateThresholdValue(name: keyof MutationScoreThresholds, value: number | null) { - if (value < 0 || value > 100 || isNaN(value)) { + if (typeof value === 'number' && (value < 0 || value > 100 || isNaN(value))) { this.invalidate(`Value "${value}" is invalid for \`thresholds.${name}\`. Expected a number between 0 and 100`); } }