Skip to content

[fp-enhancer] Improve pkg/cli: immutability and functional initialization#18469

Merged
pelikhan merged 2 commits intomainfrom
fp/pkg-cli-immutability-9fef174f497c9d74
Feb 26, 2026
Merged

[fp-enhancer] Improve pkg/cli: immutability and functional initialization#18469
pelikhan merged 2 commits intomainfrom
fp/pkg-cli-immutability-9fef174f497c9d74

Conversation

@github-actions
Copy link
Contributor

Applies moderate, tasteful functional/immutability improvements to the pkg/cli package 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/console

Summary 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:

var toolNames []string
for name := range toolStats {
    toolNames = append(toolNames, name)
}

After:

toolNames := slices.Collect(maps.Keys(toolStats))

2. Default-Value Initialization (copilot_setup.go)

Replaced a var declaration with dual-branch assignment with a cleaner default-then-override pattern, eliminating the uninitialized variable declaration.

Before:

var stepsToInsert []CopilotWorkflowStep
if actionMode.IsRelease() {
    stepsToInsert = []CopilotWorkflowStep{checkoutStep, installStep}
} else {
    stepsToInsert = []CopilotWorkflowStep{installStep}
}

After:

stepsToInsert := []CopilotWorkflowStep{installStep}
if actionMode.IsRelease() {
    stepsToInsert = []CopilotWorkflowStep{checkoutStep, installStep}
}

Benefits

  • Clarity: slices.Collect(maps.Keys(...)) clearly expresses intent without imperative noise
  • Immutability: Variables initialized directly rather than via var + mutation
  • Conciseness: 4 lines → 1 line for map-key extraction

Testing

  • ✅ All targeted tests pass (TestInjectExtensionInstallStep, TestListToolsForMCP)
  • make fmt passes
  • make lint passes
  • ✅ No behavioral changes — functionality is identical

References: §22435661535

Generated by Functional Pragmatist

  • expires on Feb 27, 2026, 9:34 AM UTC

- 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 dsyme marked this pull request as ready for review February 26, 2026 12:45
Copilot AI review requested due to automatic review settings February 26, 2026 12:45
@dsyme dsyme closed this Feb 26, 2026
@dsyme dsyme reopened this Feb 26, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 pelikhan merged commit 2368d98 into main Feb 26, 2026
48 checks passed
@pelikhan pelikhan deleted the fp/pkg-cli-immutability-9fef174f497c9d74 branch February 26, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants