Documentation ¶
Overview ¶
Package errcheck is the library used to implement the errcheck command-line tool.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Analyzer = &analysis.Analyzer{ Name: "errcheck", Doc: "check for unchecked errors", Run: runAnalyzer, ResultType: reflect.TypeOf(Result{}), }
var DefaultExcludedSymbols = []string{
"(*bytes.Buffer).Write",
"(*bytes.Buffer).WriteByte",
"(*bytes.Buffer).WriteRune",
"(*bytes.Buffer).WriteString",
"fmt.Print",
"fmt.Printf",
"fmt.Println",
"fmt.Fprint(*bytes.Buffer)",
"fmt.Fprintf(*bytes.Buffer)",
"fmt.Fprintln(*bytes.Buffer)",
"fmt.Fprint(*strings.Builder)",
"fmt.Fprintf(*strings.Builder)",
"fmt.Fprintln(*strings.Builder)",
"fmt.Fprint(os.Stderr)",
"fmt.Fprintf(os.Stderr)",
"fmt.Fprintln(os.Stderr)",
"(*io.PipeReader).CloseWithError",
"(*io.PipeWriter).CloseWithError",
"math/rand.Read",
"(*math/rand.Rand).Read",
"(*strings.Builder).Write",
"(*strings.Builder).WriteByte",
"(*strings.Builder).WriteRune",
"(*strings.Builder).WriteString",
"(hash.Hash).Write",
}
DefaultExcludedSymbols is a list of symbol names that are usually excluded from checks by default.
Note, that they still need to be explicitly copied to Checker.Exclusions.Symbols
var ( // ErrNoGoFiles is returned when CheckPackage is run on a package with no Go source files ErrNoGoFiles = errors.New("package contains no go source files") )
Functions ¶
func ReadExcludes ¶ added in v1.6.1
ReadExcludes reads an excludes file, a newline delimited file that lists patterns for which to allow unchecked errors.
Lines that start with two forward slashes are considered comments and are ignored.
Types ¶
type Checker ¶
type Checker struct { // Exclusions defines code packages, symbols, and other elements that will not be checked. Exclusions Exclusions // Tags are a list of build tags to use. Tags []string // The mod flag for go build. Mod string }
Checker checks that you checked errors.
func (*Checker) CheckPackage ¶
CheckPackage checks packages for errors that have not been checked.
It will exclude specific errors from analysis if the user has configured exclusions.
type Exclusions ¶
type Exclusions struct { // Packages lists paths of excluded packages. Packages []string // SymbolRegexpsByPackage maps individual package paths to regular // expressions that match symbols to be excluded. // // Packages whose paths appear both here and in Packages list will // be excluded entirely. // // This is a legacy input that will be deprecated in errcheck version 2 and // should not be used. SymbolRegexpsByPackage map[string]*regexp.Regexp // Symbols lists patterns that exclude individual package symbols. // // For example: // // "fmt.Errorf" // function // "fmt.Fprintf(os.Stderr)" // function with set argument value // "(hash.Hash).Write" // method // Symbols []string // TestFiles excludes _test.go files. TestFiles bool // GeneratedFiles excludes generated source files. // // Source file is assumed to be generated if its contents // match the following regular expression: // // ^// Code generated .* DO NOT EDIT\\.$ // GeneratedFiles bool // BlankAssignments ignores assignments to blank identifier. BlankAssignments bool // TypeAssertions ignores unchecked type assertions. TypeAssertions bool }
Exclusions define symbols and language elements that will be not checked
type Result ¶
type Result struct { // UncheckedErrors is a list of all the unchecked errors in the package. // Printing an error reports its position within the file and the contents of the line. UncheckedErrors []UncheckedError }
Result is returned from the CheckPackage function, and holds all the errors that were found to be unchecked in a package.
Aggregation can be done using the Append method for users that want to combine results from multiple packages.