feat: reduce cognitive complexity#401
Merged
jean-michelet merged 18 commits intofastify:masterfrom Aug 10, 2024
Merged
Conversation
mcollina
reviewed
Jul 29, 2024
Member
Author
|
Just look for my last commit plz, I had missed a previous optimization during refactorisation. |
Member
|
Can you update the workflow to fastify-autoload/.github/workflows/ci.yml Line 20 in 3584972 |
Member
Author
|
I do it in an independent PR @gurgunday : #403 |
Member
Author
|
I would prefer a review from @climba03003 before merging. |
Member
Author
|
Can you review @climba03003 plz or can we merge? |
2 tasks
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is intended to reduce the overall cognitive complexity of the component, which is imho unnecessarily hard to read, although I understand this is subjective. Basically, I've done a bit of refactoring, breaking down huge functions into smaller ones and limiting the use of nested closures.
I put the
findPluginsfunction in its own file to reduce the size ofindex.jsand because it is a clearly separated step.I tried to do the same with
loadPluginsbutvitestfailed to transpile after that... But the two big steps are finding and loading, registering is just a few lines so I think it's ok.I think I've also slightly reduced algorithmic complexity by making a single global iteration on
pluginTree, including plugin loading, hooks and registration. This also makes it possible to benefit from the current iteration context, instead of making distinct tree traversal for hooks and plugins, although this point isn't quite clear to me yet. So it's not a fix of #383.