Skip to content

Commit

Permalink
add one more condition as reviewer suggested
Browse files Browse the repository at this point in the history
  • Loading branch information
thebedigupta committed Oct 8, 2024
1 parent 6df7246 commit 6823c6b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 14 deletions.
1 change: 0 additions & 1 deletion apps/generator/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,4 @@ async function watcherHandler(changedFiles) {
showError(e);
}
}

process.on('unhandledRejection', showErrorAndExit);
14 changes: 1 addition & 13 deletions apps/generator/lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

/**
Expand Down

0 comments on commit 6823c6b

Please sign in to comment.