Skip to content

Commit

Permalink
docs(cli): clarified info and changes applied
Browse files Browse the repository at this point in the history
  • Loading branch information
PagoNxt-Trade committed Jan 23, 2023
1 parent 5f33c1b commit 9f35840
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
19 changes: 16 additions & 3 deletions docs/guides/2-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Heres an example of this scoringFile config file:
"E":0
},
"threshold":50,
"warningsSubtract": true,
"onlySubtractHigherSeverityLevel": true,
"uniqueErrors": false
}
```
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/formatters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type ScoringConfig = {
scoringSubtract: ScoringTable[];
scoringLetter: ScoringLevel[];
threshold: number;
warningsSubtract: boolean;
onlySubtractHigherSeverityLevel: boolean;
uniqueErrors: boolean;
};

Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/formatters/utils/getScoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -42,7 +42,7 @@ export const getScoringLevel = (
scoring -= subtractValue;
}
});
return scoring;
return scoring > 0 ? scoring : 0;
};

export const getScoringText = (
Expand All @@ -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()
Expand Down

0 comments on commit 9f35840

Please sign in to comment.