Package redef scans Go code and identifies unnecessary redefinitions of variables within functions and methods.
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.
This package is highly experimental, and a few quirks still need to be worked out. Use with caution.
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.goNOTE: In the future I'll set up go install for simplicity.
cd to any Go package directory and run:
$ redef .Alternatively, one can invoke various options, such as --ignore-err-shadow. See --help for details.
Please report any bugs via the Issues tab. The more eyes on this utility, the better for everyone.
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.