defers

package
v0.9.2202 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: BSD-3-Clause, BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package defers defines an Analyzer that checks for common mistakes in defer statements.

Analyzer defers

defers: report common mistakes in defer statements

The defers analyzer reports a diagnostic when a defer statement would result in a non-deferred call to time.Since, as experience has shown that this is nearly always a mistake.

For example:

start := time.Now()
...
defer recordLatency(time.Since(start)) // error: call to time.Since is not deferred

The correct code is:

defer func() { recordLatency(time.Since(start)) }()

Index

Constants

This section is empty.

Variables

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

Analyzer is the defers analyzer.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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