fix

package
v0.13.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package fix provides SuggestedFix generation for gormreuse violations.

Fix Strategy

The fix generation follows a two-phase approach:

  1. Phase 1 (Reassignment): Add reassignment to non-finisher uses - q.Where("a") → q = q.Where("a")

  2. Phase 2 (Session): Simulate Phase 1 and add Session to roots that still have multiple uses after reassignment - q = q.Where("a") → q = q.Where("a").Session(&gorm.Session{})

Example

// Before
q := db.Where("base")
q.Where("a")           // non-finisher
q.Where("b").Find()    // finisher
q.Where("c")           // non-finisher
q.Where("d").Find()    // finisher

// After Phase 1 (reassignment)
q := db.Where("base")
q = q.Where("a")       // ← added reassignment
q.Where("b").Find()
q = q.Where("c")       // ← added reassignment
q.Where("d").Find()

// After Phase 2 (Session)
q := db.Where("base")
q = q.Where("a").Session(&gorm.Session{})  // ← added Session (q_2 has 2 uses)
q.Where("b").Find()
q = q.Where("c")
q.Where("d").Find()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator generates SuggestedFix for a violation.

func New

func New(pass *analysis.Pass) *Generator

New creates a new fix Generator.

func (*Generator) Generate

Generate generates SuggestedFix for a violation. Returns nil if the violation cannot be auto-fixed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL