tolowerequalfold: detect local ToLower/ToUpper aliases in literal comparisons - #37496
Merged
Merged
Conversation
5 tasks
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix tolowerfold linter false negative for local variable comparisons
tolowerequalfold: detect local ToLower/ToUpper aliases in literal comparisons
Jun 7, 2026
pelikhan
marked this pull request as ready for review
June 7, 2026 05:54
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR updates several string comparisons to use strings.EqualFold for case-insensitive equality and enhances the tolowerequalfold linter to detect comparisons against variables that alias strings.ToLower/ToUpper(...).
Changes:
- Replaced some
==checks (and someToLower(...) == ...patterns) withstrings.EqualFold(...). - Extended the
tolowerequalfoldanalyzer to recognize local alias variables assigned fromstrings.ToLower/ToUpper(...). - Added analyzer testdata covering the new alias-detection behavior.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/runs_on_validation.go | Uses EqualFold in runner label validation logic. |
| pkg/workflow/features.go | Uses EqualFold for deprecated feature flag handling. |
| pkg/workflow/error_recovery.go | Uses EqualFold in validation severity classification. |
| pkg/parser/yaml_import.go | Switches setup-steps filename checks to EqualFold on the basename. |
| pkg/linters/tolowerequalfold/tolowerequalfold.go | Adds alias tracking so the analyzer catches lower := strings.ToLower(x); lower == "...". |
| pkg/linters/tolowerequalfold/testdata/src/tolowerequalfold/tolowerequalfold.go | Adds testdata for alias-based comparisons. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 6/6 changed files
- Comments generated: 7
| for _, label := range labels { | ||
| lower := strings.ToLower(label) | ||
| if strings.HasPrefix(lower, "macos-") || lower == "macos" { | ||
| if strings.HasPrefix(lower, "macos-") || strings.EqualFold(lower, "macos") { |
| // Inline sub-agents are now enabled by default and the corresponding | ||
| // frontmatter flag is deprecated/no-op. | ||
| if flagLower == "inline-agents" { | ||
| if strings.EqualFold(flagLower, "inline-agents") { |
|
|
||
| switch { | ||
| case lowerField == "engine" || strings.Contains(lowerReason, "invalid engine"): | ||
| case strings.EqualFold(lowerField, "engine") || strings.Contains(lowerReason, "invalid engine"): |
| base := filepath.Base(filePath) | ||
| lower := strings.ToLower(base) | ||
| return lower == "copilot-setup-steps.yml" || lower == "copilot-setup-steps.yaml" | ||
| return strings.EqualFold(base, "copilot-setup-steps.yml") || strings.EqualFold(base, "copilot-setup-steps.yaml") |
Comment on lines
+117
to
+135
| switch stmt.Tok { | ||
| case token.DEFINE: | ||
| if obj.Pos() != ident.Pos() { | ||
| delete(aliases, obj) | ||
| continue | ||
| } | ||
| rhs, ok := rhsExprForIndex(stmt.Rhs, i) | ||
| if !ok { | ||
| delete(aliases, obj) | ||
| continue | ||
| } | ||
| if arg, ok := caseConvArg(rhs); ok { | ||
| aliases[obj] = arg | ||
| } else { | ||
| delete(aliases, obj) | ||
| } | ||
| case token.ASSIGN: | ||
| delete(aliases, obj) | ||
| } |
Comment on lines
+81
to
+89
| func collectCaseConvAliases(pass *analysis.Pass) map[types.Object]ast.Expr { | ||
| aliases := make(map[types.Object]ast.Expr) | ||
| for _, file := range pass.Files { | ||
| ast.Inspect(file, func(node ast.Node) bool { | ||
| switch n := node.(type) { | ||
| case *ast.AssignStmt: | ||
| collectAliasesFromAssignStmt(pass, n, aliases) | ||
| case *ast.ValueSpec: | ||
| collectAliasesFromValueSpec(pass, n, aliases) |
Comment on lines
+16
to
+17
| lower := strings.ToLower(name) | ||
| _ = lower == "alice" // want `use strings\.EqualFold` |
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.
tolowerequalfoldonly reported directstrings.ToLower/ToUpper(...) == ...patterns and missed the same idiom when the case-converted value was first assigned to a local variable. This created inconsistent enforcement and left equivalent case-insensitive comparisons unflagged.Analyzer: add one-level local alias detection
strings.ToLower(...)/strings.ToUpper(...).==/!=checks.Analyzer: preserve self-compare safety
v := strings.ToLower(x); v == xis not reported.Test fixtures: cover new behavior
Call-site cleanup for known missed cases
strings.EqualFold(...)in:pkg/parser/yaml_import.gopkg/workflow/features.gopkg/workflow/runs_on_validation.gopkg/workflow/error_recovery.go