Skip to content

Commit 2f845b1

Browse files
authored
refactor: use map[T]struct{} for set semantics instead of map[T]bool (#29198)
1 parent 19e2183 commit 2f845b1

3 files changed

Lines changed: 31 additions & 31 deletions

File tree

pkg/sliceutil/sliceutil.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ func Any[T any](slice []T, predicate func(T) bool) bool {
6262
// The order of first occurrence is preserved.
6363
// This is a pure function that does not modify the input slice.
6464
func Deduplicate[T comparable](slice []T) []T {
65-
seen := make(map[T]bool, len(slice))
65+
seen := make(map[T]struct{}, len(slice))
6666
result := make([]T, 0, len(slice))
6767
for _, item := range slice {
68-
if !seen[item] {
69-
seen[item] = true
68+
if _, ok := seen[item]; !ok {
69+
seen[item] = struct{}{}
7070
result = append(result, item)
7171
}
7272
}

pkg/stringutil/sanitize.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,30 @@ var (
1919
pascalCaseSecretPattern = regexp.MustCompile(`\b([A-Z][a-z0-9]*(?:[A-Z][a-z0-9]*)*(?:Token|Key|Secret|Password|Credential|Auth))\b`)
2020

2121
// Common non-sensitive workflow keywords to exclude from redaction
22-
commonWorkflowKeywords = map[string]bool{
23-
"GITHUB": true,
24-
"ACTIONS": true,
25-
"WORKFLOW": true,
26-
"RUNNER": true,
27-
"JOB": true,
28-
"STEP": true,
29-
"MATRIX": true,
30-
"ENV": true,
31-
"PATH": true,
32-
"HOME": true,
33-
"SHELL": true,
34-
"INPUTS": true,
35-
"OUTPUTS": true,
36-
"NEEDS": true,
37-
"STRATEGY": true,
38-
"CONCURRENCY": true,
39-
"IF": true,
40-
"WITH": true,
41-
"USES": true,
42-
"RUN": true,
43-
"WORKING_DIRECTORY": true,
44-
"CONTINUE_ON_ERROR": true,
45-
"TIMEOUT_MINUTES": true,
22+
commonWorkflowKeywords = map[string]struct{}{
23+
"GITHUB": {},
24+
"ACTIONS": {},
25+
"WORKFLOW": {},
26+
"RUNNER": {},
27+
"JOB": {},
28+
"STEP": {},
29+
"MATRIX": {},
30+
"ENV": {},
31+
"PATH": {},
32+
"HOME": {},
33+
"SHELL": {},
34+
"INPUTS": {},
35+
"OUTPUTS": {},
36+
"NEEDS": {},
37+
"STRATEGY": {},
38+
"CONCURRENCY": {},
39+
"IF": {},
40+
"WITH": {},
41+
"USES": {},
42+
"RUN": {},
43+
"WORKING_DIRECTORY": {},
44+
"CONTINUE_ON_ERROR": {},
45+
"TIMEOUT_MINUTES": {},
4646
}
4747
)
4848

@@ -59,7 +59,7 @@ func SanitizeErrorMessage(message string) string {
5959
// Redact uppercase snake_case patterns (e.g., MY_SECRET_KEY, API_TOKEN)
6060
sanitized := secretNamePattern.ReplaceAllStringFunc(message, func(match string) string {
6161
// Don't redact common workflow keywords
62-
if commonWorkflowKeywords[match] {
62+
if _, ok := commonWorkflowKeywords[match]; ok {
6363
return match
6464
}
6565
// Don't redact gh-aw public configuration variables (e.g., GH_AW_SKIP_NPX_VALIDATION)

pkg/workflow/validation_helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ func parseStringSliceAny(raw any, log *logger.Logger) []string {
209209
// validateNoDuplicateIDs checks that all items have unique IDs extracted by idFunc.
210210
// The onDuplicate callback creates the error to return when a duplicate is found.
211211
func validateNoDuplicateIDs[T any](items []T, idFunc func(T) string, onDuplicate func(string) error) error {
212-
seen := make(map[string]bool)
212+
seen := make(map[string]struct{})
213213
for _, item := range items {
214214
id := idFunc(item)
215-
if seen[id] {
215+
if _, ok := seen[id]; ok {
216216
return onDuplicate(id)
217217
}
218-
seen[id] = true
218+
seen[id] = struct{}{}
219219
}
220220
return nil
221221
}

0 commit comments

Comments
 (0)