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: generate function refactored to reduce cognitive complexity #1047

Merged
merged 3 commits into from
Oct 10, 2023

Conversation

swastiksuvam55
Copy link
Contributor

@swastiksuvam55 swastiksuvam55 commented Oct 8, 2023

generate function refactored to smaller individual functions to reduce cognitive complexity

Related issue(s):
Fixes #1040

Copy link
Contributor

@github-actions github-actions bot left a 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.

Copy link
Member

@jonaslagoni jonaslagoni left a 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 = {}) {
Copy link
Member

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 🙂

lib/generator.js Outdated Show resolved Hide resolved
@jonaslagoni
Copy link
Member

You also have a linting issue 🙂

@swastiksuvam55
Copy link
Contributor Author

@jonaslagoni Thank you for the much-needed feedback, I've made the changes can you please review it again?

Copy link
Member

@jonaslagoni jonaslagoni left a 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
Copy link
Member

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

Copy link
Member

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
Comment on lines 143 to 156
* 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);
* }
Copy link
Member

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
Copy link
Member

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
Comment on lines 235 to 245
/**
* 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.
*/
Copy link
Member

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
Comment on lines 318 to 325
/**
* 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.
*/
Copy link
Member

Choose a reason for hiding this comment

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

Incorrect indentation

@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 9, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

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

Nice @swastiksuvam55 💪

@jonaslagoni
Copy link
Member

/rtm

@asyncapi-bot asyncapi-bot merged commit 4d347f8 into asyncapi:master Oct 10, 2023
18 checks passed
@jonaslagoni
Copy link
Member

@all-contributors please add @swastiksuvam55 for code

@allcontributors
Copy link
Contributor

@jonaslagoni

I've put up a pull request to add @swastiksuvam55! 🎉

@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 1.14.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix cognitive complexity issue
3 participants