Source file src/cmd/fix/main.go

     1  // Copyright 2025 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  /*
     6  Fix is a tool executed by "go fix" to update Go programs that use old
     7  features of the language and library and rewrite them to use newer
     8  ones. After you update to a new Go release, fix helps make the
     9  necessary changes to your programs.
    10  
    11  See the documentation for "go fix" for how to run this command.
    12  You can provide an alternative tool using "go fix -fixtool=..."
    13  
    14  Run "go tool fix help" to see the list of analyzers supported by this
    15  program.
    16  
    17  See [golang.org/x/tools/go/analysis] for information on how to write
    18  an analyzer that can suggest fixes.
    19  */
    20  package main
    21  
    22  import (
    23  	"cmd/internal/objabi"
    24  	"cmd/internal/telemetry/counter"
    25  
    26  	"golang.org/x/tools/go/analysis"
    27  	"golang.org/x/tools/go/analysis/passes/buildtag"
    28  	"golang.org/x/tools/go/analysis/passes/hostport"
    29  	"golang.org/x/tools/go/analysis/unitchecker"
    30  )
    31  
    32  func main() {
    33  	// Keep consistent with cmd/vet/main.go!
    34  	counter.Open()
    35  	objabi.AddVersionFlag()
    36  	counter.Inc("fix/invocations")
    37  
    38  	unitchecker.Main(suite...) // (never returns)
    39  }
    40  
    41  // The fix suite analyzers produce fixes that are safe to apply.
    42  // (Diagnostics may not describe actual problems,
    43  // but their fixes must be unambiguously safe to apply.)
    44  var suite = []*analysis.Analyzer{
    45  	buildtag.Analyzer,
    46  	hostport.Analyzer,
    47  	// TODO(adonovan): now the modernize (proposal #75266) and
    48  	// inline (proposal #75267) analyzers are published, revendor
    49  	// x/tools and add them here.
    50  	//
    51  	// TODO(adonovan):add any other vet analyzers whose fixes are always safe.
    52  	// Candidates to audit: sigchanyzer, printf, assign, unreachable.
    53  	// Rejected:
    54  	// - composites: some types (e.g. PointXY{1,2}) don't want field names.
    55  	// - timeformat: flipping MM/DD is a behavior change, but the code
    56  	//    could potentially be a workaround for another bug.
    57  	// - stringintconv: offers two fixes, user input required to choose.
    58  	// - fieldalignment: poor signal/noise; fix could be a regression.
    59  }
    60  

View as plain text