errifscope

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2025 License: MIT Imports: 4 Imported by: 0

README

errifscope

errifscope is linter to find if block that can encapsulate the scope of error variable.

By confining the scope of error to if, it is possible to reduce reassignment to err and avoid creating variables such as err1 and err2.

Installation

go install github.com/otakakot/errifscope/cmd/errifscope@latest

Usage

go vet -vettool=$(which errifscope) ./...

Examples

package main

func f() error {
	return nil
}

func main() {
	err := f()
	if err != nil {
		return
	}
}

Running errifscope on the above code will produce the following output:

./main.go:9:2: can be scoped with if block

You can be rewritten as:

package main

func f() error {
	return nil
}

func main() {
	if err := f(); err != nil {
		return
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "errifscope",
	Doc:  "errifscope is linter to find if block that can encapsulate the scope of error variable.",
	Run:  run,
	Requires: []*analysis.Analyzer{
		inspect.Analyzer,
	},
}

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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