nilpointer

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 6 Imported by: 0

README

nilpointer

nilpointer checks for return of nil if pointer type is included in multiple return values.

nilpointer was created under the influence of nilerr.

Powerd by skeleton.

How to use

go install github.com/uh-zz/nilpointer/cmd/nilpointer@latest
go vet -vettool=`which nilpointer` ./...

Analyze

Checks for return of nil if pointer type is included in multiple return values.

func do() (*int, error) {
	if err != nil {
		return nil, nil // NG
	}

	i1 := 1
	return &i1, nil // OK
}

Not checked if return value is one.

type Something struct {
    E error
}

func do() *Something {
    if err := something(); err != nil {
        return &Something{E: err}
    }
    return nil // OK
}

if err := do(); err != nil {
    return err
}

nilpointer ignores code which has a miss with ignore comment.

func do() (*int, error) {
	if err != nil {
        //lint:ignore nilpointer reason
		return nil, nil // ignore
	}

	i1 := 1
	return &i1, nil // OK
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: "nilpointer",
	Doc:  doc,
	Run:  run,
	Requires: []*analysis.Analyzer{
		commentmap.Analyzer,
		buildssa.Analyzer,
	},
}

Analyzer is ...

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