Skip to content

A Go (golang) tool for detecting defers that attempt to modify a non-named return value

License

Notifications You must be signed in to change notification settings

simplylib/defermodafterreturn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

defermodafterreturn

A Go (golang) tool for detecting defers that attempt to modify a non-named return value

Installing

go install github.com/simplylib/defermodafterreturn@latest

Usage

defermodafterreturn detects uses of a defer that attempts to modify return values in a function without named returns

Usage: defermodafterreturn [flags] <dir/file>

Ex: defermodafterreturn -v -t 8 . // recursively find all go files in current directory and scan for defers

Flags:
  -t int
        how many files to work on at once (default is number of cpu threads)
  -v    be verbose about operations

Example

Running defermodafterreturn linter/testdata/bad.go inside of this repo on this file

linter/testdata/bad.go:11:8 function literal in defer assigns to non-named return in parent function
defer func() {
        err2 := w.Close()
        if err2 != nil && err != nil {
                err = err2
        }
}()

About

A Go (golang) tool for detecting defers that attempt to modify a non-named return value

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages