refactor: reduce complexity of run_analyzers in src/audit/cli.rs#1203
Merged
jamesadevine merged 1 commit intoJun 25, 2026
Merged
Conversation
Extract run_analyzer<T, F> helper that encapsulates the repeated match Ok(val)/Err(e) => warn_and_record pattern used by every analyzer call in run_analyzers and run_agent_output_analyzers. Both functions previously had 6-7 match blocks each, pushing run_analyzers to cognitive complexity 18/15. The helper takes the already-awaited Result<T> and a closure for the success case, replacing every match arm pair with a single descriptive call site. - run_analyzers: complexity 18 → below threshold (no warning) - run_agent_output_analyzers: refactored consistently with same helper Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jamesadevine
approved these changes
Jun 25, 2026
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.
What was complex
run_analyzers(and its siblingrun_agent_output_analyzers) insrc/audit/cli.rscontained 13 identicalmatch ... { Ok(r) => assign, Err(e) => warn_and_record(...) }blocks spread across the two functions — 7 inrun_analyzersand 6 inrun_agent_output_analyzers. Each extramatcharm pushed the cognitive complexity score up, landingrun_analyzersat 18/15.What changed
New helper —
run_analyzer<T, F>:The helper lives next to
warn_and_record. It takes the already-awaitedResult<T>and a closure for the success path, so thematchlives once (in the helper) rather than 13 times across the callers.Refactored callers — every
matchblock in both functions is replaced with arun_analyzer(...)call. Example before/after:Before / after complexity
run_analyzersrun_agent_output_analyzersVerification
cargo build— cleancargo test— all tests passcargo clippy --all-targets --all-features— no new warningscargo clippy ... -W clippy::cognitive_complexityat threshold 15 —src/audit/cli.rsline 312 no longer appearsWarning
Firewall blocked 2 domains
The following domains were blocked by the firewall during workflow execution:
spsprodeus21.vssps.visualstudio.comspsprodweu4.vssps.visualstudio.comSee Network Configuration for more information.