Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use optional chaining for improved readability and maintained functionality #1280

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified apps/generator/cli.js
100755 → 100644
Empty file.
11 changes: 6 additions & 5 deletions apps/generator/lib/generator.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unwanted comments from this file

Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,16 @@ class Generator {
/** @type {Object} The template parameters. The structure for this object is based on each individual template. */
this.templateParams = {};
Object.keys(templateParams).forEach(key => {
const self = this;
Object.defineProperty(this.templateParams, key, {
enumerable: true,
get() {
if (!self.templateConfig.parameters || !self.templateConfig.parameters[key]) {
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.`);
get: () => {
if (this.templateConfig.parameters?.[key] == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here there's one condition also exists !self.templateConfig.parameters pls. add that also in validation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check PR description where I mention the issue that I solved in this PR sonarcloud highlight the issue that Prefer using an optional chain expression instead, as it's more concise and easier to read. that's what I did if i implement one more codition !self.templateConfig.parameters then this PR makes no sense here I hope you understand

This change makes the code more concise and easier to read while maintaining the same functionality. It checks if either the parameters object doesn't exist or if the specific key is not defined within it.

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.`
);
}
return templateParams[key];
}
},
});
});
}
Expand Down
Loading