Skip to content

[duplicate-code] Duplicate linter analyzer scaffolding across pkg/linters #50697

Description

@github-actions

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

  1. 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
  2. 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

  • Review duplication findings
  • Prioritize refactoring tasks
  • Create refactoring plan
  • Implement changes
  • Update tests
  • Verify no functionality broken

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 ·

  • expires on Aug 7, 2026, 2:20 PM UTC-08:00

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions