[fp-enhancer] Improve pkg/cli: immutability and functional initialization#18469
Merged
[fp-enhancer] Improve pkg/cli: immutability and functional initialization#18469
Conversation
- Replace manual map-key extraction loops with slices.Collect(maps.Keys(...)) in audit.go and run_workflow_validation.go - Simplify conditional slice initialization in copilot_setup.go using default value pattern instead of var declaration Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dsyme
approved these changes
Feb 26, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR applies functional programming improvements to the pkg/cli package, modernizing code patterns to reduce mutation and improve clarity. The changes replace imperative map-key extraction loops with the idiomatic slices.Collect(maps.Keys(...)) pattern and refactor a variable initialization to use a default-then-override approach.
Changes:
- Replaced 4-line map-key extraction loops with
slices.Collect(maps.Keys(...))one-liners in two files - Refactored conditional slice initialization to use a default-value pattern
- Added imports for Go 1.23+ stdlib packages (
maps,slices)
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/cli/run_workflow_validation.go | Replaced imperative map-key extraction with slices.Collect(maps.Keys(workflowInputs)) for workflow input validation |
| pkg/cli/copilot_setup.go | Refactored step insertion initialization to use default-then-override pattern |
| pkg/cli/audit.go | Replaced imperative map-key extraction with slices.Collect(maps.Keys(toolStats)) for audit report generation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
pelikhan
approved these changes
Feb 26, 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.
Applies moderate, tasteful functional/immutability improvements to the
pkg/clipackage to reduce unnecessary mutation and improve clarity.Round-Robin Progress: This is part of a systematic package-by-package refactoring. Next package to process:
pkg/consoleSummary of Changes
1. Functional Map-Key Extraction (
audit.go,run_workflow_validation.go)Replaced 4-line imperative map-key extraction loops with the idiomatic
slices.Collect(maps.Keys(...))one-liner, using stdlib packages (maps,slices) from Go 1.23+.Before:
After:
2. Default-Value Initialization (
copilot_setup.go)Replaced a
vardeclaration with dual-branch assignment with a cleaner default-then-override pattern, eliminating the uninitialized variable declaration.Before:
After:
Benefits
slices.Collect(maps.Keys(...))clearly expresses intent without imperative noisevar+ mutationTesting
TestInjectExtensionInstallStep,TestListToolsForMCP)make fmtpassesmake lintpassesReferences: §22435661535