-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jsii-diff): extend reporting options (#547)
jsii-diff now prints all changes, can report changes over experimental packages as errors, and has the ability to load a set of ignore rules from a file.
- Loading branch information
Showing
10 changed files
with
324 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Stability } from "jsii-spec"; | ||
import { ApiMismatch, Mismatches } from "./types"; | ||
|
||
export enum DiagLevel { | ||
Error = 0, | ||
Warning = 1, | ||
Skipped = 2, | ||
} | ||
|
||
const LEVEL_PREFIX = { | ||
[DiagLevel.Error]: 'err ', | ||
[DiagLevel.Warning]: 'warn', | ||
[DiagLevel.Skipped]: 'skip', | ||
}; | ||
|
||
export interface Diagnostic { | ||
level: DiagLevel; | ||
message: string; | ||
suppressionKey: string; | ||
} | ||
|
||
export function formatDiagnostic(diag: Diagnostic, includeSuppressionKey = false) { | ||
return [ | ||
LEVEL_PREFIX[diag.level], | ||
'-', | ||
diag.message, | ||
...(includeSuppressionKey ? [`[${diag.suppressionKey}]`] : []), | ||
].join(' '); | ||
} | ||
|
||
export function hasErrors(diags: Diagnostic[]) { | ||
return diags.some(diag => diag.level === DiagLevel.Error); | ||
} | ||
|
||
/** | ||
* Classify API mismatches into a set of warnings and errors | ||
*/ | ||
export function classifyDiagnostics(mismatches: Mismatches, experimentalErrors: boolean, skipFilter: Set<string>): Diagnostic[] { | ||
const ret = mismatches.mismatches.map(mis => ({ level: level(mis), message: mis.message, suppressionKey: mis.violationKey })); | ||
ret.sort((a, b) => a.level - b.level); | ||
return ret; | ||
|
||
function level(mis: ApiMismatch) { | ||
if (skipFilter.has(mis.violationKey)) { return DiagLevel.Skipped; } | ||
if (mis.stability === Stability.Stable || (mis.stability === Stability.Experimental && experimentalErrors)) { return DiagLevel.Error; } | ||
return DiagLevel.Warning; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.