diff --git a/docs/guides/2-cli.md b/docs/guides/2-cli.md index b7b75e724d..897e8ffb94 100644 --- a/docs/guides/2-cli.md +++ b/docs/guides/2-cli.md @@ -112,7 +112,7 @@ Heres an example of this scoringFile config file: "E":0 }, "threshold":50, - "warningsSubtract": true, + "onlySubtractHigherSeverityLevel": true, "uniqueErrors": false } ``` @@ -121,8 +121,21 @@ Where: - scoringSubtract : An object with key/value pair objects for every result level we want to subtract percentage, with the percentage to subtract from number of results on every result type - scoringLetter : An object with key/value pairs with scoring letter and scoring percentage, that the result must be greater, for this letter -- threshold : A number with minimum percentage value to provide valid the file we are checking -- warningsSubtract : A boolean to accumulate the result types to less than the scoring percentage or to stop counting on most critical result types +- threshold : A number with minimum percentage value to provide valid the file we are checking. Any scoring below this thresold will mark the API as a failure in the scoring. +- onlySubtractHigherSeverityLevel : A boolean to decide if only the higher severity level who appears in the results for the API to analize, are subtracted from scoring or every severity level are subtracted from scoring. + +See sample: + + true + + API with Errors and Warnings, only Errors substract from scoring + API with Warnings, Warnings substract from scoring + + false + + API with Errors and Warnings, Errors and Warnings substracts from scoring + API with Warnings, Warnings substract from scoring + - uniqueErrors : A boolean to count unique errors or all errors. An error is considered unique if its code and message have not been seen yet Example: diff --git a/packages/cli/src/formatters/types.ts b/packages/cli/src/formatters/types.ts index 795cc61ea2..5b020a4a39 100644 --- a/packages/cli/src/formatters/types.ts +++ b/packages/cli/src/formatters/types.ts @@ -15,7 +15,7 @@ export type ScoringConfig = { scoringSubtract: ScoringTable[]; scoringLetter: ScoringLevel[]; threshold: number; - warningsSubtract: boolean; + onlySubtractHigherSeverityLevel: boolean; uniqueErrors: boolean; }; diff --git a/packages/cli/src/formatters/utils/getScoring.ts b/packages/cli/src/formatters/utils/getScoring.ts index b6099df055..9846225562 100644 --- a/packages/cli/src/formatters/utils/getScoring.ts +++ b/packages/cli/src/formatters/utils/getScoring.ts @@ -24,13 +24,13 @@ export const getScoringLevel = ( [DiagnosticSeverity.Hint]: number; }, scoringSubtract: ScoringTable[], - warningsSubtract: boolean, + onlySubtractHigherSeverityLevel: boolean, ): number => { let scoring = 100; Object.keys(issuesCount).forEach(key => { const scoringKey = Object.keys(SEVERITY_MAP).filter(mappedKey => SEVERITY_MAP[mappedKey] == key)[0]; if (scoringSubtract[scoringKey] !== void 0) { - if (scoring < 100 && !warningsSubtract) return; + if (scoring < 100 && !onlySubtractHigherSeverityLevel) return; let subtractValue = 0; Object.keys(scoringSubtract[scoringKey] as ScoringSubtract[]).forEach((subtractKey: string): void => { subtractValue = ( @@ -42,7 +42,7 @@ export const getScoringLevel = ( scoring -= subtractValue; } }); - return scoring; + return scoring > 0 ? scoring : 0; }; export const getScoringText = ( @@ -54,8 +54,8 @@ export const getScoringText = ( }, scoringConfig: ScoringConfig, ): string => { - const { scoringSubtract, scoringLetter, warningsSubtract } = scoringConfig; - const scoring = getScoringLevel(issuesCount, scoringSubtract, warningsSubtract); + const { scoringSubtract, scoringLetter, onlySubtractHigherSeverityLevel } = scoringConfig; + const scoring = getScoringLevel(issuesCount, scoringSubtract, onlySubtractHigherSeverityLevel); let scoringLevel: string = Object.keys(scoringLetter)[Object.keys(scoringLetter).length - 1]; Object.keys(scoringLetter) .reverse()