unused

package
v0.0.0-...-5156ccc Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2023 License: BSD-3-Clause, MIT Imports: 16 Imported by: 0

Documentation

Overview

Package unused contains code for finding unused code.

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &lint.Analyzer{
	Doc: &lint.Documentation{
		Title: "Unused code",
	},
	Analyzer: &analysis.Analyzer{
		Name:       "U1000",
		Doc:        "Unused code",
		Run:        Run,
		Requires:   []*analysis.Analyzer{generated.Analyzer, directives.Analyzer},
		ResultType: reflect.TypeOf(Result{}),
	},
}
View Source
var Debug io.Writer
View Source
var DefaultOptions = Options{
	FieldWritesAreUses:     true,
	PostStatementsAreReads: false,
	ExportedIsUsed:         true,
	ExportedFieldsAreUsed:  true,
	ParametersAreUsed:      true,
	LocalVariablesAreUsed:  true,
	GeneratedIsUsed:        true,
}

Functions

func Run

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

Types

type Node

type Node struct {
	ID  NodeID
	Obj Object

	// using slices instead of maps here helps make merging of graphs simpler and more efficient, because we can rewrite
	// IDs in place instead of having to build new maps.
	Uses []NodeID
	Owns []NodeID
}

func Graph

func Graph(fset *token.FileSet,
	files []*ast.File,
	pkg *types.Package,
	info *types.Info,
	directives []lint.Directive,
	generated map[string]generated.Generator,
	opts Options,
) []Node

type NodeID

type NodeID uint64

OPT(dh): 32 bits would be plenty, but the Node struct would end up with padding, anyway.

type Object

type Object struct {
	Name      string
	ShortName string
	// OPT(dh): use an enum for the kind
	Kind            string
	Path            ObjectPath
	Position        token.Position
	DisplayPosition token.Position
}

type ObjectPath

type ObjectPath struct {
	PkgPath string
	ObjPath objectpath.Path
}

type Options

type Options struct {
	FieldWritesAreUses     bool
	PostStatementsAreReads bool
	ExportedIsUsed         bool
	ExportedFieldsAreUsed  bool
	ParametersAreUsed      bool
	LocalVariablesAreUsed  bool
	GeneratedIsUsed        bool
}

type Result

type Result struct {
	Used   []Object
	Unused []Object
	Quiet  []Object
}

TODO(dh): should we return a map instead of two slices?

type SerializedGraph

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

func (*SerializedGraph) Dot

func (g *SerializedGraph) Dot() string

Dot formats a graph in Graphviz dot format.

func (*SerializedGraph) Merge

func (g *SerializedGraph) Merge(nodes []Node)

func (*SerializedGraph) Results

func (g *SerializedGraph) Results() Result

Jump to

Keyboard shortcuts

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