refactor(compile): reduce cognitive complexity of compile_pipeline_inner and compile_all_pipelines#980
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
…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>
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
At a Clippy cognitive-complexity threshold of 15, two functions in
src/compile/mod.rswere the highest-scoring candidates in the codebase:compile_pipeline_innercompile_all_pipelinesNo behaviour was changed. All 1829 tests pass;
cargo clippyis clean.What was extracted
From
compile_pipeline_innerselect_compiler(&CompileTarget) -> Box<dyn Compiler>matchthat also appeared incheck_pipelinemaybe_print_upgrade_note(path, existing_version)if let Some(..) && ..version-bump notemaybe_sync_gitattributes_for_output(sync, path)if sync && let Err(e) =guardlog_pipeline_metadata(&FrontMatter)info!/debug!calls (each expands to anif log_enabled!()branch)perform_source_rewrite_if_neededif !report.changed() { return Ok(false) }so the caller no longer needs the outerif codemod_report.changed()blockFrom
compile_all_pipelinesformat_pipeline_version_status(version, current)if / else if / elseversion-label chain in the listing loopresolve_pipeline_source_path(yaml_path, source, root)if / elsefrom the compile loopbatch_sync_gitattributes(&[DetectedPipeline])if let Some(..) { if let Err(..) { ... } }blockprint_batch_compile_summary(success, skip, fail, rewrote)Bonus deduplication
check_pipelinecontained an identical 4-armCompileTargetmatch. It now also callsselect_compiler, removing the duplicate.Warning
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.