Intrange Go Analyzer Development
Guidelines for developing and maintaining the `intrange` static analysis tool, which identifies for loops that can use Go 1.22's integer range feature.
Project Structure
The project is primarily used as a library with the following structure:
**Root directory**: Core logic and source files**Entry point**: Exported global variable `Analyzer`**Binary**: Located in `cmd/intrange`, callable via `go vet`Development Principles
Library-First Design
The primary use case is as a library, not a standalone binaryAll core logic should be in root-level source filesThe `Analyzer` variable is the main integration point for consumersBinary usage via `go vet` is secondaryDependency Management
**Avoid third-party libraries** unless absolutely necessaryUse only the standard library for all core functionalityException: Testing may use external libraries when beneficialTesting Strategy
Use only the standard library for most tests`TestAnalyzer` is the one exception that uses: - `github.com/gostaticanalysis/testutil`
- `golang.org/x/tools/go/analysis/analysistest`
Maintain comprehensive test coverage for analyzer logicPerformance Requirements
**Performance is a primary concern**Design for speed and efficiencyOptimize for minimal overhead in analysis passesConsider the tool will run as part of build/CI pipelinesImplementation Guidelines
When implementing features or fixes:
1. **Start with core logic in root files** - Keep analyzer logic at the repository root
2. **Minimize allocations** - Be conscious of memory usage in hot paths
3. **Test thoroughly** - Use `analysistest` for comprehensive analyzer testing
4. **Document exported APIs** - The `Analyzer` variable and any public APIs must be well-documented
5. **Validate Go 1.22+ compatibility** - Ensure recommendations are valid for the target Go version
Integration Points
Exports `Analyzer` compatible with `golang.org/x/tools/go/analysis`Can be invoked via `go vet -vettool=$(which intrange)`Should integrate cleanly with other static analysis frameworksConstraints
Must work as a standalone analyzerShould not require configuration in typical use casesMust produce actionable, accurate suggestions for integer range conversionsPerformance overhead must be minimal for large codebases