From ce260e2bda09ef36b4836b240d5d7459fef15b1c Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Thu, 14 Jan 2021 13:03:20 -0800 Subject: [PATCH 1/5] chore(pkglint): validate the package `maturity` is correct We were missing a few cases where we did not validate that a package had the correct `maturity` set: - A package with L2s could still have a `matuirty` of 'cfn-only' - A package with only L1s could still have a non-'cfn-only' maturity Fix that in the linter, along with the violations discovered. --- packages/@aws-cdk/alexa-ask/README.md | 8 ------- packages/@aws-cdk/alexa-ask/package.json | 2 +- tools/pkglint/lib/rules.ts | 30 ++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/packages/@aws-cdk/alexa-ask/README.md b/packages/@aws-cdk/alexa-ask/README.md index 125b909867ec7..766afeef6d3cd 100644 --- a/packages/@aws-cdk/alexa-ask/README.md +++ b/packages/@aws-cdk/alexa-ask/README.md @@ -9,14 +9,6 @@ > > [CFN Resources]: https://docs.aws.amazon.com/cdk/latest/guide/constructs.html#constructs_lib -![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge) - -> The APIs of higher level constructs in this module are experimental and under active development. -> They are subject to non-backward compatible changes or removal in any future version. These are -> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be -> announced in the release notes. This means that while you may use them, you may need to update -> your source code when upgrading to a newer version of this package. - --- diff --git a/packages/@aws-cdk/alexa-ask/package.json b/packages/@aws-cdk/alexa-ask/package.json index 1233a4a1993ea..7775d413a997b 100644 --- a/packages/@aws-cdk/alexa-ask/package.json +++ b/packages/@aws-cdk/alexa-ask/package.json @@ -91,7 +91,7 @@ "node": ">= 10.13.0 <13 || >=13.7.0" }, "stability": "experimental", - "maturity": "experimental", + "maturity": "cfn-only", "awscdkio": { "announce": false } diff --git a/tools/pkglint/lib/rules.ts b/tools/pkglint/lib/rules.ts index 88688249729a6..d448aaf94154a 100644 --- a/tools/pkglint/lib/rules.ts +++ b/tools/pkglint/lib/rules.ts @@ -284,8 +284,32 @@ export class MaturitySetting extends ValidationRule { maturity = 'deprecated'; } + const packageLevels = this.determinePackageLevels(pkg); + + const hasL1s = packageLevels.findIndex(level => level === 'l1') !== -1; + const hasL2s = packageLevels.findIndex(level => level === 'l2') !== -1; + if (hasL2s) { + // validate that a package that contains L2s does not declare a 'cfn-only' maturity + if (maturity === 'cfn-only') { + pkg.report({ + ruleName: this.name, + message: "Package that contains any L2s cannot declare a 'cfn-only' maturity", + fix: () => pkg.json.maturity = 'experimental', + }); + } + } else if (hasL1s) { + // validate that a package that contains only L1s declares a 'cfn-only' maturity + if (maturity !== 'cfn-only') { + pkg.report({ + ruleName: this.name, + message: "Package that contains only L1s cannot declare a maturity other than 'cfn-only'", + fix: () => pkg.json.maturity = 'cfn-only', + }); + } + } + if (maturity) { - this.validateReadmeHasBanner(pkg, maturity, this.determinePackageLevels(pkg)); + this.validateReadmeHasBanner(pkg, maturity, packageLevels); } } @@ -342,7 +366,9 @@ export class MaturitySetting extends ValidationRule { // to see if this package has L1s. const hasL1 = !!pkg.json['cdk-build']?.cloudformation; - const libFiles = glob.sync('lib/*.ts'); + const libFiles = glob.sync('lib/*.ts', { + ignore: 'lib/*.d.ts', // ignore the generated TS declaration files + }); const hasL2 = libFiles.some(f => !f.endsWith('.generated.ts') && !f.endsWith('index.ts')); return [ From 7b583bf6e1d0c8c7bf94026e375fc8cf9eaee322 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Thu, 14 Jan 2021 13:24:03 -0800 Subject: [PATCH 2/5] Fix @aws-acmpca. --- packages/@aws-cdk/aws-acmpca/README.md | 8 ++++++++ packages/@aws-cdk/aws-acmpca/package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-acmpca/README.md b/packages/@aws-cdk/aws-acmpca/README.md index fd3c39c9f5e4c..04d167836539c 100644 --- a/packages/@aws-cdk/aws-acmpca/README.md +++ b/packages/@aws-cdk/aws-acmpca/README.md @@ -9,6 +9,14 @@ > > [CFN Resources]: https://docs.aws.amazon.com/cdk/latest/guide/constructs.html#constructs_lib +![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge) + +> The APIs of higher level constructs in this module are experimental and under active development. +> They are subject to non-backward compatible changes or removal in any future version. These are +> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be +> announced in the release notes. This means that while you may use them, you may need to update +> your source code when upgrading to a newer version of this package. + --- diff --git a/packages/@aws-cdk/aws-acmpca/package.json b/packages/@aws-cdk/aws-acmpca/package.json index 3baab6e8894b3..3d66f73810462 100644 --- a/packages/@aws-cdk/aws-acmpca/package.json +++ b/packages/@aws-cdk/aws-acmpca/package.json @@ -92,7 +92,7 @@ "node": ">= 10.13.0 <13 || >=13.7.0" }, "stability": "experimental", - "maturity": "cfn-only", + "maturity": "experimental", "awscdkio": { "announce": false } From 6edc4bd1d29d033e25e33030036ba6f194fc6e76 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Thu, 14 Jan 2021 14:21:14 -0800 Subject: [PATCH 3/5] Fix Route53 resolver. --- packages/@aws-cdk/aws-route53resolver/README.md | 8 -------- packages/@aws-cdk/aws-route53resolver/package.json | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/@aws-cdk/aws-route53resolver/README.md b/packages/@aws-cdk/aws-route53resolver/README.md index f6eea77064f22..9cf4ab7748b3d 100644 --- a/packages/@aws-cdk/aws-route53resolver/README.md +++ b/packages/@aws-cdk/aws-route53resolver/README.md @@ -9,14 +9,6 @@ > > [CFN Resources]: https://docs.aws.amazon.com/cdk/latest/guide/constructs.html#constructs_lib -![cdk-constructs: Experimental](https://img.shields.io/badge/cdk--constructs-experimental-important.svg?style=for-the-badge) - -> The APIs of higher level constructs in this module are experimental and under active development. -> They are subject to non-backward compatible changes or removal in any future version. These are -> not subject to the [Semantic Versioning](https://semver.org/) model and breaking changes will be -> announced in the release notes. This means that while you may use them, you may need to update -> your source code when upgrading to a newer version of this package. - --- diff --git a/packages/@aws-cdk/aws-route53resolver/package.json b/packages/@aws-cdk/aws-route53resolver/package.json index 027c64fba0408..f1de5b042dd0e 100644 --- a/packages/@aws-cdk/aws-route53resolver/package.json +++ b/packages/@aws-cdk/aws-route53resolver/package.json @@ -91,7 +91,7 @@ "node": ">= 10.13.0 <13 || >=13.7.0" }, "stability": "experimental", - "maturity": "experimental", + "maturity": "cfn-only", "awscdkio": { "announce": false } From 40f2d12fa7b13a600748c144a119bb23deb3e8a2 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Thu, 14 Jan 2021 14:55:26 -0800 Subject: [PATCH 4/5] Make sure to descend into subdirectories when establishing the level of a package. --- tools/pkglint/lib/rules.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/pkglint/lib/rules.ts b/tools/pkglint/lib/rules.ts index d448aaf94154a..cfc04699d7b6a 100644 --- a/tools/pkglint/lib/rules.ts +++ b/tools/pkglint/lib/rules.ts @@ -366,8 +366,8 @@ export class MaturitySetting extends ValidationRule { // to see if this package has L1s. const hasL1 = !!pkg.json['cdk-build']?.cloudformation; - const libFiles = glob.sync('lib/*.ts', { - ignore: 'lib/*.d.ts', // ignore the generated TS declaration files + const libFiles = glob.sync('lib/**/*.ts', { + ignore: 'lib/**/*.d.ts', // ignore the generated TS declaration files }); const hasL2 = libFiles.some(f => !f.endsWith('.generated.ts') && !f.endsWith('index.ts')); From 18c05e38fc6061dcbbc41f70232f93d02c88cb78 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Fri, 15 Jan 2021 09:04:22 -0800 Subject: [PATCH 5/5] Change findIndex() to some() for finding the level Co-authored-by: Jonathan Goldwasser --- tools/pkglint/lib/rules.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/pkglint/lib/rules.ts b/tools/pkglint/lib/rules.ts index cfc04699d7b6a..8ff807cb44fca 100644 --- a/tools/pkglint/lib/rules.ts +++ b/tools/pkglint/lib/rules.ts @@ -286,8 +286,8 @@ export class MaturitySetting extends ValidationRule { const packageLevels = this.determinePackageLevels(pkg); - const hasL1s = packageLevels.findIndex(level => level === 'l1') !== -1; - const hasL2s = packageLevels.findIndex(level => level === 'l2') !== -1; + const hasL1s = packageLevels.some(level => level === 'l1'); + const hasL2s = packageLevels.some(level => level === 'l2'); if (hasL2s) { // validate that a package that contains L2s does not declare a 'cfn-only' maturity if (maturity === 'cfn-only') {