Skip to content

Commit aeb85a4

Browse files
committed
docs(cli): clarified info and changes applied
1 parent 5f33c1b commit aeb85a4

13 files changed

+32
-19
lines changed

docs/guides/2-cli.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Heres an example of this scoringFile config file:
112112
"E":0
113113
},
114114
"threshold":50,
115-
"warningsSubtract": true,
115+
"onlySubtractHigherSeverityLevel": true,
116116
"uniqueErrors": false
117117
}
118118
```
@@ -121,8 +121,21 @@ Where:
121121

122122
- 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
123123
- scoringLetter : An object with key/value pairs with scoring letter and scoring percentage, that the result must be greater, for this letter
124-
- threshold : A number with minimum percentage value to provide valid the file we are checking
125-
- warningsSubtract : A boolean to accumulate the result types to less than the scoring percentage or to stop counting on most critical result types
124+
- 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.
125+
- 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.
126+
127+
See sample:
128+
129+
true
130+
131+
API with Errors and Warnings, only Errors substract from scoring
132+
API with Warnings, Warnings substract from scoring
133+
134+
false
135+
136+
API with Errors and Warnings, Errors and Warnings substracts from scoring
137+
API with Warnings, Warnings substract from scoring
138+
126139
- 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
127140

128141
Example:

packages/cli/src/commands/lint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ const scoringThresholdNotEnough = (results: IRuleResult[], scoringConfig: Scorin
308308
getScoringLevel(
309309
getCountsBySeverity(groupedUniqueResults),
310310
scoringConfig.scoringSubtract,
311-
scoringConfig.warningsSubtract,
311+
scoringConfig.onlySubtractHigherSeverityLevel
312312
)
313313
);
314314
}

packages/cli/src/formatters/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type ScoringConfig = {
1515
scoringSubtract: ScoringTable[];
1616
scoringLetter: ScoringLevel[];
1717
threshold: number;
18-
warningsSubtract: boolean;
18+
onlySubtractHigherSeverityLevel: boolean;
1919
uniqueErrors: boolean;
2020
};
2121

packages/cli/src/formatters/utils/getScoring.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ export const getScoringLevel = (
2424
[DiagnosticSeverity.Hint]: number;
2525
},
2626
scoringSubtract: ScoringTable[],
27-
warningsSubtract: boolean,
27+
onlySubtractHigherSeverityLevel: boolean,
2828
): number => {
2929
let scoring = 100;
3030
Object.keys(issuesCount).forEach(key => {
3131
const scoringKey = Object.keys(SEVERITY_MAP).filter(mappedKey => SEVERITY_MAP[mappedKey] == key)[0];
3232
if (scoringSubtract[scoringKey] !== void 0) {
33-
if (scoring < 100 && !warningsSubtract) return;
33+
if (scoring < 100 && !onlySubtractHigherSeverityLevel) return;
3434
let subtractValue = 0;
3535
Object.keys(scoringSubtract[scoringKey] as ScoringSubtract[]).forEach((subtractKey: string): void => {
3636
subtractValue = (
@@ -42,7 +42,7 @@ export const getScoringLevel = (
4242
scoring -= subtractValue;
4343
}
4444
});
45-
return scoring;
45+
return scoring > 0 ? scoring : 0;
4646
};
4747

4848
export const getScoringText = (
@@ -54,8 +54,8 @@ export const getScoringText = (
5454
},
5555
scoringConfig: ScoringConfig,
5656
): string => {
57-
const { scoringSubtract, scoringLetter, warningsSubtract } = scoringConfig;
58-
const scoring = getScoringLevel(issuesCount, scoringSubtract, warningsSubtract);
57+
const { scoringSubtract, scoringLetter, onlySubtractHigherSeverityLevel } = scoringConfig;
58+
const scoring = getScoringLevel(issuesCount, scoringSubtract, onlySubtractHigherSeverityLevel);
5959
let scoringLevel: string = Object.keys(scoringLetter)[Object.keys(scoringLetter).length - 1];
6060
Object.keys(scoringLetter)
6161
.reverse()

packages/cli/src/services/__tests__/__fixtures__/scoring-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
"E": 0
2828
},
2929
"threshold": 50,
30-
"warningsSubtract": true,
30+
"onlySubtractHigherSeverityLevel": true,
3131
"uniqueErrors": false
3232
}

packages/cli/src/services/__tests__/output.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const scoringConfig = {
2828
E: 0,
2929
} as unknown as ScoringLevel[],
3030
threshold: 50,
31-
warningsSubtract: true,
31+
onlySubtractHigherSeverityLevel: true,
3232
uniqueErrors: false,
3333
};
3434

test-harness/scenarios/formats/results-default-format-scoring-json.scenario

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ info:
7979
"E": 0
8080
},
8181
"threshold": 50,
82-
"warningsSubtract": true,
82+
"onlySubtractHigherSeverityLevel": true,
8383
"uniqueErrors": false
8484
}
8585
====command====

test-harness/scenarios/formats/results-default-scoring.scenario

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ info:
7979
"E": 0
8080
},
8181
"threshold": 50,
82-
"warningsSubtract": true,
82+
"onlySubtractHigherSeverityLevel": true,
8383
"uniqueErrors": false
8484
}
8585
====command====

test-harness/scenarios/formats/results-format-stylish-scoring.scenario

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ paths: {}
8080
"E": 0
8181
},
8282
"threshold": 50,
83-
"warningsSubtract": true,
83+
"onlySubtractHigherSeverityLevel": true,
8484
"uniqueErrors": false
8585
}
8686
====command====

test-harness/scenarios/overrides/aliases-scoring.scenario

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ module.exports = {
9393
"E": 0
9494
},
9595
"threshold": 50,
96-
"warningsSubtract": true,
96+
"onlySubtractHigherSeverityLevel": true,
9797
"uniqueErrors": false
9898
}
9999
====asset:v2/document.json====

test-harness/scenarios/severity/fail-on-error-no-error-scoring.scenario

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Will only fail if there is an error, and there is not. Can still see all warning
4747
"E": 0
4848
},
4949
"threshold": 50,
50-
"warningsSubtract": true,
50+
"onlySubtractHigherSeverityLevel": true,
5151
"uniqueErrors": false
5252
}
5353
====command====

test-harness/scenarios/severity/fail-on-error-scoring.scenario

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Will fail and return 1 as exit code because errors exist with scoring data
5858
"E": 0
5959
},
6060
"threshold": 50,
61-
"warningsSubtract": true,
61+
"onlySubtractHigherSeverityLevel": true,
6262
"uniqueErrors": false
6363
}
6464
====command-nix====

test-harness/scenarios/valid-no-errors.oas2-scoring.scenario

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = oas;
4747
"E": 0
4848
},
4949
"threshold": 50,
50-
"warningsSubtract": true,
50+
"onlySubtractHigherSeverityLevel": true,
5151
"uniqueErrors": false
5252
}
5353
====command====

0 commit comments

Comments
 (0)