composite

Imports

Imports #

"fmt"
"go/ast"
"go/types"
"strings"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/internal/typeparams"

Constants & Variables

Analyzer var #

var Analyzer = *ast.UnaryExpr

Doc const #

const Doc = `check for unkeyed composite literals

This analyzer reports a diagnostic for composite literals of struct
types imported from another package that do not use the field-keyed
syntax. Such literals are fragile because the addition of a new field
(even if unexported) to the struct will cause compilation to fail.

As an example,

	err = &net.DNSConfigError{err}

should be replaced by:

	err = &net.DNSConfigError{Err: err}
`

unkeyedLiteral var #

unkeyedLiteral is a white list of types in the standard packages that are used with unkeyed literals we deem to be acceptable.

var unkeyedLiteral = map[string]bool{...}

whitelist var #

var whitelist = true

Functions

init function #

func init()

isLocalType function #

isLocalType reports whether typ belongs to the same package as pass. TODO(adonovan): local means "internal to a function"; rename to isSamePackageType.

func isLocalType(pass *analysis.Pass, typ types.Type) bool

run function #

runUnkeyedLiteral checks if a composite literal is a struct literal with unkeyed fields.

func run(pass *analysis.Pass) (interface{}, error)

Generated with Arrow