Skip to content

Commit

Permalink
chore: ban @experimental (#14070)
Browse files Browse the repository at this point in the history
Add a lint rule that disallow the use of @experimental in stable module. Ideally we would do the same for experimental modules, but for these, jsii marks all properties as experimental. Since we only care about stable modules, this is sufficient. Im open to other suggestion as well. 

Should only be merged after #14071 which removes all experimental API.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
NetaNir committed Apr 21, 2021
1 parent d4a1c28 commit 283ed02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/awslint/lib/rules/docs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Stability } from '@jsii/spec';
import * as reflect from 'jsii-reflect';
import { Linter } from '../linter';
import { CoreTypes } from './core-types';
Expand Down Expand Up @@ -71,6 +72,21 @@ docsLinter.add({
},
});

docsLinter.add({
code: 'no-experimental-apis',
message: 'The use of @experimental in not allowed',
eval: e => {
if (!isPublic(e.ctx)) { return; }
// technically we should ban the use of @experimental in the codebase. Since jsii marks all symbols
// of experimental modules as experimental we can't.
if (isModuleExperimental(e.ctx.assembly)) {
return;
}
const sym = e.ctx.documentable;
e.assert(sym.docs.docs.stability !== Stability.Experimental, e.ctx.errorKey);
},
});

function isPublic(ctx: DocsLinterContext) {
switch (ctx.kind) {
case 'class-property':
Expand All @@ -97,6 +113,10 @@ function isCfnType(ctx: DocsLinterContext) {
}
}

function isModuleExperimental(assembly: reflect.Assembly) {
return assembly.spec.docs?.stability === Stability.Experimental;
}

function flatMap<T, U>(array: readonly T[], callbackfn: (value: T, index: number, array: readonly T[]) => U[]): U[] {
return Array.prototype.concat(...array.map(callbackfn));
}
1 change: 0 additions & 1 deletion tools/cfn2ts/lib/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ export default class CodeGenerator {
this.code.line(' *');
this.code.line(' * @param inspector - tree inspector to collect and process attributes');
this.code.line(' *');
this.code.line(' * @stability experimental');
this.code.line(' */');
this.code.openBlock(`public inspect(inspector: ${CORE}.TreeInspector)`);
this.code.line(`inspector.addAttribute("${TreeAttributes.CFN_TYPE}", ${resource.className}.CFN_RESOURCE_TYPE_NAME);`);
Expand Down

0 comments on commit 283ed02

Please sign in to comment.