From 6823c6b15191f7693bef7644bbed62bb1f7fba5f Mon Sep 17 00:00:00 2001 From: bedi gupta Date: Tue, 8 Oct 2024 14:52:38 +0530 Subject: [PATCH] add one more condition as reviewer suggested --- apps/generator/cli.js | 1 - apps/generator/lib/generator.js | 14 +------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/apps/generator/cli.js b/apps/generator/cli.js index 0fd464b10..9a2c1f645 100644 --- a/apps/generator/cli.js +++ b/apps/generator/cli.js @@ -194,5 +194,4 @@ async function watcherHandler(changedFiles) { showError(e); } } - process.on('unhandledRejection', showErrorAndExit); \ No newline at end of file diff --git a/apps/generator/lib/generator.js b/apps/generator/lib/generator.js index c9080edae..93fe3611a 100644 --- a/apps/generator/lib/generator.js +++ b/apps/generator/lib/generator.js @@ -133,27 +133,15 @@ class Generator { Object.defineProperty(this.templateParams, key, { enumerable: true, get: () => { - if (this.templateConfig.parameters?.[key] == null) { + if (!this.templateConfig.parameters || this.templateConfig.parameters[key] == null) { throw new Error( `Template parameter "${key}" has not been defined in the package.json file under generator property. Please make sure it's listed there before you use it in your template.` ); } - // If we got here, the parameter exists, so just return it return templateParams[key]; }, }); }); - // CHANGES EXPLAINED: - // 1. Removed 'self' variable: Arrow function in the getter automatically binds 'this' - // to the correct context, eliminating the need for 'const self = this'. - // 2. Simplified null check: Using '?.' and '== null' checks for both null and undefined - // in a more concise way. - // 3. Improved readability: The code is now more compact and easier to understand at a glance. - // 4. Maintained functionality: Despite the changes, the core logic remains the same, - // ensuring backwards compatibility. - - // NOTE: This refactoring addresses the SonarCloud suggestion to use optional chaining - // and improves overall code quality by using modern JavaScript features. } /**