Skip to content

refactor(compile): reduce cognitive complexity of compile_pipeline_inner and compile_all_pipelines#980

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-compile-mod-a0c2969a36d9e9d3
Draft

refactor(compile): reduce cognitive complexity of compile_pipeline_inner and compile_all_pipelines#980
github-actions[bot] wants to merge 1 commit into
mainfrom
refactor/reduce-complexity-compile-mod-a0c2969a36d9e9d3

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

At a Clippy cognitive-complexity threshold of 15, two functions in src/compile/mod.rs were the highest-scoring candidates in the codebase:

Function Before After
compile_pipeline_inner 23 < 15 (no warning)
compile_all_pipelines 18 < 15 (no warning)

No behaviour was changed. All 1829 tests pass; cargo clippy is clean.

What was extracted

From compile_pipeline_inner

New helper What it does
select_compiler(&CompileTarget) -> Box<dyn Compiler> Removes duplicate 4-arm match that also appeared in check_pipeline
maybe_print_upgrade_note(path, existing_version) Extracts the if let Some(..) && .. version-bump note
maybe_sync_gitattributes_for_output(sync, path) Flattens the compound if sync && let Err(e) = guard
log_pipeline_metadata(&FrontMatter) Groups 7 info!/debug! calls (each expands to an if log_enabled!() branch)
Guard folded into perform_source_rewrite_if_needed Adds an early if !report.changed() { return Ok(false) } so the caller no longer needs the outer if codemod_report.changed() block

From compile_all_pipelines

New helper What it does
format_pipeline_version_status(version, current) Replaces the if / else if / else version-label chain in the listing loop
resolve_pipeline_source_path(yaml_path, source, root) Removes the source-path-candidate if / else from the compile loop
batch_sync_gitattributes(&[DetectedPipeline]) Encapsulates the nested if let Some(..) { if let Err(..) { ... } } block
print_batch_compile_summary(success, skip, fail, rewrote) Extracts the conditional summary-line print

Bonus deduplication

check_pipeline contained an identical 4-arm CompileTarget match. It now also calls select_compiler, removing the duplicate.

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • spsprodeus21.vssps.visualstudio.com
  • spsprodweu4.vssps.visualstudio.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "spsprodeus21.vssps.visualstudio.com"
    - "spsprodweu4.vssps.visualstudio.com"

See Network Configuration for more information.

Generated by Cyclomatic Complexity Reducer · sonnet46 7.5M ·

…ner and compile_all_pipelines

Extract helper functions to reduce cognitive complexity:

- select_compiler(): removes duplicate 4-arm CompileTarget match from
  both compile_pipeline_inner and check_pipeline
- maybe_print_upgrade_note(): extracts the if-let-&& version comparison
  block from compile_pipeline_inner
- maybe_sync_gitattributes_for_output(): flattens the compound
  'if sync && let Err(e) =' guard into a clearly-named helper
  expands to an 'if log_enabled!()' branch) into a dedicated function
- format_pipeline_version_status(): extracts the if/else-if/else
  version label from compile_all_pipelines' listing loop
- resolve_pipeline_source_path(): removes the path-candidate if/else
  from compile_all_pipelines' compile loop
- batch_sync_gitattributes(): encapsulates the nested if-let blocks for
  post-batch .gitattributes sync
- print_batch_compile_summary(): extracts the rewrote_count conditional
  summary print from compile_all_pipelines
  guard, removing the outer 'if codemod_report.changed()' from the caller

Complexity reductions (threshold 15):
- compile_pipeline_inner: 23 -> below 15 (no longer flagged)
- compile_all_pipelines: 18 -> below 15 (no longer flagged)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants