-
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): also check stability transitions (#592)
Once an API element is marked @stable, it is not allowed to retract that stability guarantee anymore by changing it back to @experimental. This is now verified by `jsii-diff`. This was always intended to be checked, but was missed as an oversight in the initial implementation.
- Loading branch information
Showing
4 changed files
with
79 additions
and
0 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,45 @@ | ||
import reflect = require('jsii-reflect'); | ||
import spec = require('jsii-spec'); | ||
import { ApiElement, ComparisonContext } from './types'; | ||
|
||
export function compareStabilities(original: reflect.Documentable & ApiElement, updated: reflect.Documentable, context: ComparisonContext) { | ||
// Nothing to do in these cases | ||
if (original.docs.stability === undefined || original.docs.stability === updated.docs.stability) { return; } | ||
|
||
// Not allowed to disavow stability | ||
if (updated.docs.stability === undefined) { | ||
context.mismatches.report({ | ||
ruleKey: 'removed-stability', | ||
message: `stability was '${original.docs.stability}', has been removed`, | ||
violator: original, | ||
}); | ||
return; | ||
} | ||
|
||
const allowed = allowedTransitions(original.docs.stability); | ||
if (!allowed.includes(updated.docs.stability)) { | ||
context.mismatches.report({ | ||
ruleKey: 'changed-stability', | ||
message: `stability not allowed to go from '${original.docs.stability}' to '${updated.docs.stability}'`, | ||
violator: original, | ||
}); | ||
} | ||
} | ||
|
||
function allowedTransitions(start: spec.Stability): spec.Stability[] { | ||
switch (start) { | ||
// Experimental can go to stable or be deprecated | ||
case spec.Stability.Experimental: | ||
return [spec.Stability.Stable, spec.Stability.Deprecated]; | ||
|
||
// Stable can be deprecated | ||
case spec.Stability.Stable: | ||
return [spec.Stability.Deprecated]; | ||
|
||
// Deprecated can be reinstated | ||
case spec.Stability.Deprecated: | ||
return [spec.Stability.Stable]; | ||
} | ||
|
||
throw new Error(`Unrecognized stability: ${start}`); | ||
} |
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