From 283ed02c64f827161edba3e11c3cead3b54b7ee9 Mon Sep 17 00:00:00 2001 From: Neta Nir Date: Tue, 20 Apr 2021 17:21:11 -0700 Subject: [PATCH] chore: ban @experimental (#14070) 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 https://github.com/aws/aws-cdk/pull/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* --- packages/awslint/lib/rules/docs.ts | 20 ++++++++++++++++++++ tools/cfn2ts/lib/codegen.ts | 1 - 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/awslint/lib/rules/docs.ts b/packages/awslint/lib/rules/docs.ts index fda92170bd80a..8c5107d8450ac 100644 --- a/packages/awslint/lib/rules/docs.ts +++ b/packages/awslint/lib/rules/docs.ts @@ -1,3 +1,4 @@ +import { Stability } from '@jsii/spec'; import * as reflect from 'jsii-reflect'; import { Linter } from '../linter'; import { CoreTypes } from './core-types'; @@ -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': @@ -97,6 +113,10 @@ function isCfnType(ctx: DocsLinterContext) { } } +function isModuleExperimental(assembly: reflect.Assembly) { + return assembly.spec.docs?.stability === Stability.Experimental; +} + function flatMap(array: readonly T[], callbackfn: (value: T, index: number, array: readonly T[]) => U[]): U[] { return Array.prototype.concat(...array.map(callbackfn)); } diff --git a/tools/cfn2ts/lib/codegen.ts b/tools/cfn2ts/lib/codegen.ts index c06fce32e10ff..f952bb34a832e 100644 --- a/tools/cfn2ts/lib/codegen.ts +++ b/tools/cfn2ts/lib/codegen.ts @@ -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);`);