[fp-enhancer] Improve pkg/cli - functional/immutability enhancements (round 1)#23658
Closed
github-actions[bot] wants to merge 1 commit intomainfrom
Closed
[fp-enhancer] Improve pkg/cli - functional/immutability enhancements (round 1)#23658github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
- tool_graph.go: replace manual map-to-slice loop + sort.Strings with slices.Sorted(maps.Keys(...)) for declarative, immutable initialization - tool_graph.go: pre-allocate transitions slice with make([]T, 0, len(map)) to avoid unnecessary reallocations - tool_graph.go: replace sort.Slice with slices.SortFunc using typed comparison function (eliminates index-based access, more readable) - actionlint.go: pre-allocate relPaths slice with known capacity Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Collaborator
|
/q update prompt to avoid calling make with a length, it triggers codeql violations. |
Contributor
Author
|
🎩 Mission equipment ready! Q has optimized your workflow. Use wisely, 007! 🔫 |
Contributor
Author
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.
This PR applies moderate, tasteful functional/immutability techniques to the
pkg/clipackage to improve code clarity and maintainability.Round-Robin Progress: First package processed. Next run will process:
pkg/consoleSummary of Changes
1. Declarative Slice Initialization (
tool_graph.go)Replaced a manual 4-line loop +
sort.Stringswith a single declarative expression:This pattern is already used elsewhere in
pkg/cli(e.g.,run_workflow_validation.go), making this consistent with existing codebase style.2. Pre-allocated Slice (
tool_graph.go)Pre-allocate
transitionsslice with known capacity to avoid incremental growth:3. Type-safe Sort (
tool_graph.go)Replaced
sort.Slice(index-based, untyped) withslices.SortFunc(typed comparison):Side effect: the
"sort"import is replaced with"maps"and"slices"(standard library packages).4. Pre-allocated Slice (
actionlint.go)Pre-allocate
relPathswith known capacity fromlen(lockFiles):Testing
TestToolGraph,TestToolGraphMultipleSequences,TestToolGraphEmptySequencesall passgo build ./pkg/cli/succeedsmake fmtpassesBenefits
slices.Sorted(maps.Keys(...))communicates intent in one linerun_workflow_validation.goslices.SortFuncis type-safe vs index-basedsort.SliceAutomated by Functional Pragmatist — processing
pkg/cli(round 1 of N). Next:pkg/console