refactor: split util.js to reduce total and per-function complexity#310
Merged
Conversation
…g buildMetadataHeader Agent-Logs-Url: https://github.com/albe/node-event-storage/sessions/841f5b4b-68ed-4165-abb2-5460a0c1207c Co-authored-by: albe <4259532+albe@users.noreply.github.com>
…tion Agent-Logs-Url: https://github.com/albe/node-event-storage/sessions/841f5b4b-68ed-4165-abb2-5460a0c1207c Co-authored-by: albe <4259532+albe@users.noreply.github.com>
Agent-Logs-Url: https://github.com/albe/node-event-storage/sessions/eeb3b469-4cd2-4180-b83b-f193620604e5 Co-authored-by: albe <4259532+albe@users.noreply.github.com>
Contributor
Author
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.
CodeQL flagged
scanForFilesat cyclomatic complexity 24 andutil.jstotal complexity at 75. Both stem from a single overloaded utility file and one deeply nested recursive function.scanForFilescomplexity (24 → ~3)Extracted four module-level helpers so each unit of work is a flat, named function:
Total util.js complexity
Relocated cohesive groups to more specific modules:
src/fsUtil.js(new) —ensureDirectory,scanForFiles, and their extracted helpers.scanForFilesSyncwas removed as it had no remaining callers after the async storage open change.src/metadataUtil.js(existing) —buildMetadataHeaderadded here; it already owned the rest of the metadata serialization surfaceAll import sites across
src/updated accordingly;src/fsUtil.jsadded topackage.jsonfiles.