Analysis of commit 86aa220
Assignee: @copilot
Summary
pkg/linters repeats the same analyzer-registration and run-bootstrap scaffold across a large portion of the custom linter packages. The repeated block is not just a few lines of boilerplate: it includes the analyzer declaration, default dependency list, URL construction pattern, and the first-pass inspector setup in each run function.
Duplication Details
Pattern: repeated analyzer declaration and inspector bootstrap
- Severity: Medium
- Occurrences: 65 repeated
Analyzer declarations and 58 repeated insp, err := astutil.Inspector(pass) bootstraps across pkg/linters/*.go
- Locations:
pkg/linters/appendbytestring/appendbytestring.go (lines 19-28)
pkg/linters/stringsjoinone/stringsjoinone.go (lines 19-28)
pkg/linters/mapclearloop/mapclearloop.go (lines 20-29)
- Code Sample:
var Analyzer = &analysis.Analyzer{
Name: "appendbytestring",
Doc: "reports append(b, []byte(s)...) calls where s is a string that can be simplified to append(b, s...)",
URL: "https://github.com/github/gh-aw/tree/main/pkg/linters/appendbytestring",
Requires: []*analysis.Analyzer{inspect.Analyzer, nolint.Analyzer, filecheck.Analyzer},
Run: run,
}
func run(pass *analysis.Pass) (any, error) {
insp, err := astutil.Inspector(pass)
Impact Analysis
- Maintainability: Any change to default analyzer wiring, dependency ordering, URL conventions, or run bootstrap behavior requires sweeping edits across dozens of packages.
- Bug Risk: Small drift between linters is easy to introduce when one package updates the scaffold and others do not.
- Code Bloat: The same 8-10 lines are copied into most linter packages before the linter-specific logic even starts.
Refactoring Recommendations
-
Extract a shared analyzer factory
- Extract common functionality to:
pkg/linters/internal/analyzerutil
- Estimated effort: Medium (4-6 hours)
- Benefits: One place to define common
Requires, URL construction, and analyzer metadata conventions
-
Wrap the inspector bootstrap
- Extract common functionality to:
pkg/linters/internal/analyzerutil
- Estimated effort: Medium (2-4 hours)
- Benefits: Reduces repeated
astutil.Inspector(pass) / error handling and makes the linter-specific traversal logic stand out
Implementation Checklist
Analysis Metadata
- Analyzed Files: 1576 eligible non-test
.go and .cjs files in the shallow checkout snapshot
- Detection Method: Serena semantic code analysis plus targeted pattern search
- Commit:
86aa22071639b26f15d43f429bcb5e74c5cd4638
- Analysis Date:
2026-08-05T22:17:32Z
References:
Generated by 🔍 Duplicate Code Detector · gpt54 · 120.2 AIC · ⌖ 11.7 AIC · ⊞ 12.8K · ◷
Analysis of commit 86aa220
Assignee:
@copilotSummary
pkg/lintersrepeats the same analyzer-registration and run-bootstrap scaffold across a large portion of the custom linter packages. The repeated block is not just a few lines of boilerplate: it includes the analyzer declaration, default dependency list, URL construction pattern, and the first-pass inspector setup in eachrunfunction.Duplication Details
Pattern: repeated analyzer declaration and inspector bootstrap
Analyzerdeclarations and 58 repeatedinsp, err := astutil.Inspector(pass)bootstraps acrosspkg/linters/*.gopkg/linters/appendbytestring/appendbytestring.go(lines 19-28)pkg/linters/stringsjoinone/stringsjoinone.go(lines 19-28)pkg/linters/mapclearloop/mapclearloop.go(lines 20-29)Impact Analysis
Refactoring Recommendations
Extract a shared analyzer factory
pkg/linters/internal/analyzerutilRequires, URL construction, and analyzer metadata conventionsWrap the inspector bootstrap
pkg/linters/internal/analyzerutilastutil.Inspector(pass)/ error handling and makes the linter-specific traversal logic stand outImplementation Checklist
Analysis Metadata
.goand.cjsfiles in the shallow checkout snapshot86aa22071639b26f15d43f429bcb5e74c5cd46382026-08-05T22:17:32ZReferences: