dominikh / go-tools

Staticcheck - The advanced Go linter
https://staticcheck.dev
MIT License
6.24k stars 377 forks source link

simple: Warn when a function return signature contains unnecessary variables #78

Open johanbrandhorst opened 7 years ago

johanbrandhorst commented 7 years ago

A couple of times I've come across functions that used to return errors, but for some reason they were refactored so that they no longer return errors and the refactoree forgot to change the signature, ending up with a function that only ever returns the zero value of the error.

As discussed on gophers slack this could probably be extended to any type which is only returned as its zero-value.

It would be nice to warn the user that the function no longer needs to return all the types.

dominikh commented 7 years ago

Another bit of conversation from Slack: We can't apply the check to exported methods because of interfaces. We can't apply them to exported functions because of function types. We can apply them to unexported functions and methods if we can prove that they're not used to implement interfaces in the same package, or to match a function type in the same package, or passed as an argument where the argument type is from another package. The same goes for assignment to variables (including fields, maps and so on)