Add lookup table lint analyzer - #22
Conversation
📝 WalkthroughWalkthroughAdds a new Go static analysis pass ChangesLookup Table Lint Analyzer
Estimated code review effort: 4 (Complex) | ~60 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
lookuptablelint/testdata/src/a/a.go (1)
56-126: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a boundary test for exactly 64 entries.
tooLargehas 65 entries (000–064), which correctly exceeds the default-max_entries=64. However, there's no positive test for a map with exactly 64 entries. If the boundary comparison accidentally changes from<=to<, no test would catch the regression.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lookuptablelint/testdata/src/a/a.go` around lines 56 - 126, Add a boundary test in the lookuptablelint testdata around the tooLarge/tooSmall maps to cover a map with exactly 64 entries and verify it is accepted; this will protect the max_entries check from regressing from <= to <. Use the existing tooLarge fixture in a.go as the location to derive a 64-entry case, and ensure the test clearly exercises the lookup-table limit boundary.lookuptablelint/analyzer.go (1)
302-313: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
ast.IsGenerated(file)here. The standard helper matches the generated-code convention directly and avoids the loose substring scan. Remove the now-unusedstringsimport too.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lookuptablelint/analyzer.go` around lines 302 - 313, Replace the custom generated-code detection in generated(file *ast.File) with the standard ast.IsGenerated(file) helper so the analyzer uses the official convention instead of scanning comments manually. After switching, remove the now-unused strings import from analyzer.go and make sure any remaining references to the old substring check are eliminated.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@lookuptablelint/analyzer.go`:
- Around line 302-313: Replace the custom generated-code detection in
generated(file *ast.File) with the standard ast.IsGenerated(file) helper so the
analyzer uses the official convention instead of scanning comments manually.
After switching, remove the now-unused strings import from analyzer.go and make
sure any remaining references to the old substring check are eliminated.
In `@lookuptablelint/testdata/src/a/a.go`:
- Around line 56-126: Add a boundary test in the lookuptablelint testdata around
the tooLarge/tooSmall maps to cover a map with exactly 64 entries and verify it
is accepted; this will protect the max_entries check from regressing from <= to
<. Use the existing tooLarge fixture in a.go as the location to derive a
64-entry case, and ensure the test clearly exercises the lookup-table limit
boundary.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b737526b-b0ab-43f4-acc5-89cf155d0416
⛔ Files ignored due to path filters (2)
go.workis excluded by!**/*.worklookuptablelint/go.sumis excluded by!**/*.sum
📒 Files selected for processing (6)
lookuptablelint/analyzer.golookuptablelint/analyzer_test.golookuptablelint/cmd/lookuptablelint/main.golookuptablelint/doc.golookuptablelint/go.modlookuptablelint/testdata/src/a/a.go
Summary
lookuptablelint, a go/analysis analyzer for small static lookup mapsmap[k]bool/map[k]struct{}lookup tables that should be predicate helpers with single-case switcheslookuptablelintsinglechecker command and analysistest coverageNotes
-max_entries; local benchmarks showed switches faster through thousands of same-length string cases, but 64 keeps the lint focused on obvious lookup tablesValidation
PATH=/opt/homebrew/bin:$PATH ./scripts/test-all.shSummary by CodeRabbit
New Features
Documentation
Chores