Go fix
- 'errors.As' can be replaced with 'errors.AsType'
Reports calls to errors.As that can be replaced with errors.AsType.
- 'HasPrefix' and 'TrimPrefix' can use 'strings.CutPrefix'
Reports code that checks a prefix with strings.HasPrefix and then removes the same prefix with strings.TrimPrefix.
- 'interface{}' can be replaced with 'any'
Reports type declarations that use interface{} and can be simplified by using any.
- 'Len()'/'At()' loop can be replaced with iterator
Reports index-based loops over standard library types where the loop body only accesses elements by index, such as x.At(i).
- 'omitempty' tag on a struct field can be changed
Reports JSON struct tags that use ,omitempty on struct-typed fields.
- 'reflect.TypeOf' can be replaced with ‘reflect.TypeFor’
Reports uses of reflect.TypeOf where the type is known at compile time, such as reflect.TypeOf(T{}) and reflect.TypeOf((*T)(nil)).Elem().
- 'sort.Slice' can be replaced with 'slices.Sort'
Reports calls to sort.Slice where the comparison function only compares elements with the < operator.
- 'strings.Index' and slicing can use 'strings.Cut'
Reports code that uses strings.Index to find a separator and then slices the string manually.
- 'strings.Split' or 'strings.Fields' loop can use a 'Seq' variant
Reports loops that range over strings.Split or strings.Fields.
- Address can be built with 'net.JoinHostPort'
Reports addresses built with fmt.Sprintf("%s:%d", host, port) or fmt.Sprintf("%s:%s", host, port).
- Apply 'atomictypes' go fix
Reports opportunities found by go fix -json -atomictypes.
- Apply 'buildtag' go fix
Reports opportunities found by go fix -json -buildtag.
- Apply 'fmtappendf' go fix
Reports opportunities found by go fix -json -fmtappendf.
- Apply 'unsafefuncs' go fix
Reports opportunities found by go fix -json -unsafefuncs.
- Backward slice loop can use 'slices.Backward'
Reports reverse index loops over slices that can be replaced with slices.Backward.
- Conditional assignment can be replaced with 'min' or 'max'
Syntax update: replace conditional assignment with min or max Reports if statements that assign one of two values to the same variable and can be replaced with the built-in min or max function (Go 1.21 or later).
- Counted loop can be replaced with range over integer
Reports three-clause for loops of the form for i := 0; i < n; i++ that can be replaced with for i := range n (Go 1.22 or later).
- Declaration marked with '//go:fix inline' can be inlined
Reports references to functions or constants marked with //go:fix inline.
- Map loop can be replaced with the 'maps' function
Reports loops that copy a map or collect its keys or values and can be replaced with maps.Copy, maps.Keys, or maps.Values.
- Nested embedded field literals can be removed
Reports composite literals that initialize a promoted field through an embedded struct literal.
- Obsolete '+build' line
Reports // +build lines that are no longer needed because the file already contains a matching //go:build directive.
- Pointer helper call can be replaced with 'new()'
Reports calls to pointer helper functions that return the address of a parameter, such as IntPtr(x) returning &x, and can be replaced with new(...).
- Redundant range variable shadowing
Reports redundant variable shadowing inside a for range loop, such as x := x, that was previously used to capture the loop variable for a goroutine or closure.
- Slice search loop can be replaced with 'slices.Contains'
Reports loops that check whether a slice contains a value by comparing each element with ==.
- String concatenation can use 'strings.Builder'
Reports index-based loops over standard library types where the loop body only accesses elements by index, such as x.At(i).
- Test context cancellation can use 't.Context()'
Reports test code that creates a cancellable context with context.WithCancel(context.Background()) and immediately defers cancel().
- WaitGroup goroutine pattern can use 'WaitGroup.Go'
Reports the common WaitGroup pattern that uses wg.Add(1), starts a goroutine, and defers wg.Done().