durationcheck

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2019 License: Apache-2.0 Imports: 11 Imported by: 21

README

Duration Check

A Go linter to detect cases where two time.Duration values are being multiplied in possibly erroneous ways.

For example, consider the following snippet:

func waitFor(someDuration time.Duration) {
    timeToWait := someDuration * time.Second
    time.Sleep(timeToWait)
}

Although the above code would compile without any errors, the behaviour is most likely to be incorrect. A caller would reasonably expect waitFor(5 * time.Seconds) to wait for ~5 seconds but they would end up waiting for ~1,388,889 hours.

A majority of these problems would be spotted almost immediately but some could still slip through unnoticed. Hopefully this linter will help catch those rare cases before they cause a production issue.

See the test cases for more examples of the types of errors detected by the linter.

Installation

Requires Go 1.11 or above.

go get -u github.com/charithe/durationcheck/cmd/durationcheck

Usage

Invoke durationcheck with your package name

durationcheck ./...
# or
durationcheck github.com/you/yourproject/...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name:     "durationcheck",
	Doc:      "check for two durations multiplied together",
	Run:      run,
	Requires: []*analysis.Analyzer{inspect.Analyzer},
}

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd
durationcheck command

Jump to

Keyboard shortcuts

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