-
-
Notifications
You must be signed in to change notification settings - Fork 239
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
Changes from all commits
a31d964
a5488e7
35a32fd
ec7e381
15e7f0c
d21cb1a
cbaad47
985a80f
e650570
01b92b0
6df7246
6823c6b
14f9f9d
d60d4cc
78192c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here there's one condition also exists There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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]; | ||
} | ||
}, | ||
}); | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
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