Skip to content

Package redef reports unnecessary variable redefinitions (shadowing) within a Go function or method

License

Notifications You must be signed in to change notification settings

JesseCoretta/go-redef

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-redef

Package redef scans Go code and identifies unnecessary redefinitions of variables within functions and methods.

Synopsis

For example, consider the following pseudocode:

func myFunction() {
	blarg, err := someFunc()
	if err != nil {
		// whatever
	}

	// ... later in the same function ...

	if err := someOtherFunc(); err != nil {
		// whatever
	}
}

As you can see, I needlessly redefined -- or "shadowed" -- my err instance inside myFunction.

This tool looks for, and reports on, such flaws.

Status

This package is highly experimental, and a few quirks still need to be worked out. Use with caution.

Building

This is how I currently build redef:

$ cd /path/to/go-redef/cmd/redef

## Note you can put redef in any folder which is monitored
## by `$PATH` -- this is simply how I do it personally, as
## I have a `bin` directory in my `$HOME`:
$ go build -o ~/bin/redef main.go

NOTE: In the future I'll set up go install for simplicity.

Usage

cd to any Go package directory and run:

$ redef .

Alternatively, one can invoke various options, such as --ignore-err-shadow. See --help for details.

Contributing

Please report any bugs via the Issues tab. The more eyes on this utility, the better for everyone.

Support animal/environmental causes

If you or your organization use my software regularly and find it useful, I only ask that you donate to animal shelters, non-profit environmental entities or similar.

If you cannot afford a monetary contribution to these causes, please volunteer at animal shelters and/or visit kill shelters for the purpose of liberating animals unfairly awaiting execution.

About

Package redef reports unnecessary variable redefinitions (shadowing) within a Go function or method

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Contributors

Languages