fillreturns

package
v0.21.0-pre.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

Package fillreturns defines an Analyzer that will attempt to automatically fill in a return statement that has missing values with zero value elements.

Analyzer fillreturns

fillreturns: suggest fixes for errors due to an incorrect number of return values

This checker provides suggested fixes for type errors of the type "wrong number of return values (want %d, got %d)". For example:

func m() (int, string, *bool, error) {
	return
}

will turn into

func m() (int, string, *bool, error) {
	return 0, "", nil, nil
}

This functionality is similar to https://github.com/sqs/goreturns.

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name:             "fillreturns",
	Doc:              analyzerutil.MustExtractDoc(doc, "fillreturns"),
	Requires:         []*analysis.Analyzer{inspect.Analyzer},
	Run:              run,
	RunDespiteErrors: true,
	URL:              "https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/fillreturns",
}

Functions

func MatchingIdents

func MatchingIdents(typs []types.Type, node ast.Node, pos token.Pos, info *types.Info, pkg *types.Package) map[types.Type][]string

MatchingIdents finds the names of all identifiers in 'node' that match any of the given types. 'pos' represents the position at which the identifiers may be inserted. 'pos' must be within the scope of each of identifier we select. Otherwise, we will insert a variable at 'pos' that is unrecognized.

This function is shared with the 'fillstruct' analyzer.

Types

This section is empty.

Jump to

Keyboard shortcuts

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