Refactor (script/raw-changelog.ts: 198>): Function with high complexity (count = 24): format; Split up format() function - #97
Open
mchen1820 wants to merge 2 commits into
Conversation
Decreased the complexity of the format() function by dividing up the function into several helper functions, including createGroups(), formatCommit(), groupCommits(), sectionHasEntries(), formatSection(), and formatContributors()
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.
Decreased the complexity of the format() function by dividing up the function into several helper functions, including createGroups(), formatCommit(), groupCommits(), sectionHasEntries(), formatSection(), and formatContributors()
P1B: Starter Task: Refactoring PR
1. Issue
Link to the associated GitHub issue: #81
Full path to the refactored file: script/raw-changelog.ts
This file seems to generate and format changelog notes for the opencode repository.
Only the format() function was altered, with more helper functions added above the format() function.
This refactoring addressed the following Qlty-reported issue: Function with high complexity (count = 24): format
2. Refactoring
The high complexity issue I chose impacted the codebase's maintainability by making the format() code hard to read, and thus harder to test or change in the future.
To resolve this issue, I divided some of the complex subtasks of the format() function into smaller helper functions, making the format() function itself much shorter while performing the same tasks.
My changes improve maintainability by making the format() function much easier to read and understand. The format() function mostly consists of simple helper function calls that are very understandable since they are appropriately named after their subtask. This improves maintainability by making it easy for future contributors to understand and adjust the format() function or its subtasks as necessary as future changes are made to the overall codebase.
3. Validation
I validated that my changes were correct by making sure bun lint and bun test passed locally, creating new tests in raw-changelog.test.ts and checking they passed, and checking that the Qlty smell was reduced.
bun lint passing:

bun test passing (with new raw-changelog.test.ts tests):

Qlty smell for script/raw-changelog.ts reduced:
