-
-
Notifications
You must be signed in to change notification settings - Fork 238
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: generate function refactored to reduce cognitive complexity #1047
Conversation
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.
Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.
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.
Just a few comments 💪
lib/generator.js
Outdated
@@ -160,7 +160,7 @@ class Generator { | |||
* @return {Promise} | |||
*/ | |||
// eslint-disable-next-line sonarjs/cognitive-complexity | |||
async generate(asyncapiDocument, parseOptions = {}) { | |||
/* async generate(asyncapiDocument, parseOptions = {}) { |
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.
Please remove any commented out code 🙂
You also have a linting issue 🙂 |
@jonaslagoni Thank you for the much-needed feedback, I've made the changes can you please review it again? |
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.
Few more changes is needed 🙂
lib/generator.js
Outdated
@@ -136,67 +136,174 @@ class Generator { | |||
}); | |||
} | |||
|
|||
// eslint-disable-next-line sonarjs/cognitive-complexity |
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.
Please remove this 🙂
lib/generator.js
Outdated
*/ | ||
// eslint-disable-next-line sonarjs/cognitive-complexity | ||
|
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.
No new lines between the jsdoc and function 🙂
lib/generator.js
Outdated
* generator | ||
* .generate(myAsyncAPIdocument) | ||
* .then(() => { | ||
* console.log('Done!'); | ||
* }) | ||
* .catch(console.error); | ||
* | ||
* @example <caption>Using async/await</caption> | ||
* try { | ||
* await generator.generate(myAsyncAPIdocument); | ||
* console.log('Done!'); | ||
* } catch (e) { | ||
* console.error(e); | ||
* } |
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.
You can leave the different examples, no need to remove it 🙂
lib/generator.js
Outdated
|
||
// Setup the output based on the configured options |
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.
No need for this.
lib/generator.js
Outdated
/** | ||
* Installs and sets up the template for code generation. | ||
* | ||
* This function installs the specified template using the provided installation option, | ||
* sets up the necessary directory paths, loads the template configuration, and returns | ||
* information about the installed template. | ||
* | ||
* @async | ||
* @returns {Promise<{ templatePkgName: string, templatePkgPath: string }>} | ||
* A promise that resolves to an object containing the name and path of the installed template. | ||
*/ |
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.
Incorrect indentation 🙂
lib/generator.js
Outdated
/** | ||
* Executes the 'generate:after' hook. | ||
* | ||
* Launches the after-hook to perform additional actions after code generation. | ||
* | ||
* @async | ||
* @returns {Promise<void>} A promise that resolves when the after-hook execution is completed. | ||
*/ |
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.
Incorrect indentation
Kudos, SonarCloud Quality Gate passed! |
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.
Nice @swastiksuvam55 💪
/rtm |
@all-contributors please add @swastiksuvam55 for code |
I've put up a pull request to add @swastiksuvam55! 🎉 |
🎉 This PR is included in version 1.14.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
generate
function refactored to smaller individual functions to reduce cognitive complexityRelated issue(s):
Fixes #1040