Skip to content

nilpointer checks for nil returning if the multiple return value contains pointer types.

License

Notifications You must be signed in to change notification settings

uh-zz/nilpointer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
}

About

nilpointer checks for nil returning if the multiple return value contains pointer types.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages