From a446c6c4efac38b7a4da88153d371f3bf35ef16d Mon Sep 17 00:00:00 2001 From: AWS CDK Automation <43080478+aws-cdk-automation@users.noreply.github.com> Date: Wed, 18 Dec 2024 01:15:53 -0800 Subject: [PATCH] fix: use maps instead of literals in `configureCategories` (backport #1598) (#1601) # Backport This will backport the following commits from `main` to `maintenance/v5.6`: - [fix: use maps instead of literals in `configureCategories` (#1598)](https://github.com/aws/jsii-compiler/pull/1598) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) Co-authored-by: Eli Polonsky --- src/jsii-diagnostic.ts | 11 ++++++----- test/jsii-diagnostic.test.ts | 6 ++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/jsii-diagnostic.ts b/src/jsii-diagnostic.ts index bf9e6087..d60a1892 100644 --- a/src/jsii-diagnostic.ts +++ b/src/jsii-diagnostic.ts @@ -86,13 +86,13 @@ export class Code = new Map(); + private static readonly byName: Map = new Map(); // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility readonly #defaultCategory: ts.DiagnosticCategory; @@ -126,7 +126,8 @@ export class Code { code.category = DiagnosticCategory.Suggestion; }); + test('throws on __proto__ key', () => { + expect(() => configureCategories(JSON.parse('{"__proto__":{"pollutedKey":123}}'))).toThrow( + `Unrecognized diagnostic code '__proto__'`, + ); + }); + test('diagnostic by name', () => { configureCategories({ 'metadata/package-json-missing-description': DiagnosticCategory.Error,