refactor: reduce cyclomatic complexity in high-complexity functions#4
Merged
leonardomso merged 1 commit intomasterfrom Jan 1, 2026
Merged
Conversation
Refactored 4 functions flagged by gocyclo for exceeding complexity threshold of 15: cmd/check.go - runCheck() (26 → ~7): - Extract exitOnError() for consistent error handling - Extract scanFiles() for file scanning phase - Extract parseAndFilterLinks() for parsing phase - Extract checkLinks() for URL checking phase - Extract routeOutput() for output routing cmd/check_output.go - outputText() (20 → ~7): - Extract printSummaryLine() for summary output - Extract getEmptyResultsMessage() for empty state handling - Extract shouldGroupResults() for display mode decision - Extract outputGroupedResults() and outputFlatResults() - Extract maybeShowIgnored() for conditional ignored display internal/output/markdown.go - Format() (20 → ~4): - Extract writeHeader() for report header - Extract writeSummaryTable() for summary stats - Extract writeDeadLinksSection() with table and details helpers - Extract writeWarningsSection() with table and redirect details - Extract writeDuplicatesSection() for duplicates table - Extract writeIgnoredSection() for ignored URLs - Use fmt.Fprintf() instead of b.WriteString(fmt.Sprintf()) internal/fixer/fixer.go - FindFixes() (17 → ~5): - Extract buildURLToLinksMap() for URL lookup map creation - Extract isFixableRedirect() for eligibility check - Extract addOrUpdateFix() for fix map management - Extract createFix() for fix object creation - Extract applyRefInfo() for reference info detection All 197 tests passing, 0 linter issues.
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.
Summary
Refactored 4 functions flagged by gocyclo for exceeding the complexity threshold of 15, improving code maintainability and readability.
Complexity Reductions
runCheck()outputText()Format()FindFixes()Changes
cmd/check.go -
runCheck()(26 → ~7)exitOnError()for consistent error handlingscanFiles()for file scanning phaseparseAndFilterLinks()for parsing phasecheckLinks()for URL checking phaserouteOutput()for output routingcmd/check_output.go -
outputText()(20 → ~7)printSummaryLine()for summary outputgetEmptyResultsMessage()for empty state handlingshouldGroupResults()for display mode decisionoutputGroupedResults()andoutputFlatResults()maybeShowIgnored()for conditional ignored displayinternal/output/markdown.go -
Format()(20 → ~4)writeHeader()for report headerwriteSummaryTable()for summary statswriteDeadLinksSection()with table and details helperswriteWarningsSection()with table and redirect detailswriteDuplicatesSection()for duplicates tablewriteIgnoredSection()for ignored URLsfmt.Fprintf()instead ofb.WriteString(fmt.Sprintf())internal/fixer/fixer.go -
FindFixes()(17 → ~5)buildURLToLinksMap()for URL lookup map creationisFixableRedirect()for eligibility checkaddOrUpdateFix()for fix map managementcreateFix()for fix object creationapplyRefInfo()for reference info detectionTesting
gocyclo -over 15 .- no flagged functions from original scopeGo Report Card
This PR addresses the gocyclo warnings from Go Report Card, improving the project's code quality score.