You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
stylecheck: check for the LHS of a declaration containing a redundant type #551
changed the title [-]staticcheck: add an SA4??? check for the LHS of a declaration containing a redundant type[/-][+]stylecheck: check for the LHS of a declaration containing a redundant type[/+]on Jul 29, 2019
Since golint is being deprecated/removed we're getting rid of it in our org. FWIW I think this is the only useful check we're losing which isn't covered by staticcheck.
We'll add two versions of the check: one in stylecheck and one in quickfix.
The one in stylecheck will be disabled by default, but can be opted into. It will have the following exceptions to reduce false/noisy positives:
// It does not flag variables under the following conditions, to reduce the number of false positives:
// - global variables – these often specify types to aid godoc
// - files that use cgo – the cgo code generation may turn conversions into declarations, and we don't want to flag redundant conversions in this check
//
// It does not flag variables under the following conditions, unless flagHelpfulTypes is true, to reduce the number of noisy positives:
// - packages that import syscall or unsafe – these sometimes use this form of assignment to make sure types are as expected
// - variables named the blank identifier – a pattern used to confirm the types of variables
// - named untyped constants on the rhs – the explicitness might aid readability
This is essentially a better version of what you had in golint.
The one in quickfix will be enabled by default, but only be used inside gopls. It will not underline code or emit warnings, but it will simply grey out redundant types and offer to remove them. It does not have the last 3 exceptions. It will result in a user experience like the following:
Activity
[-]staticcheck: add an SA4??? check for the LHS of a declaration containing a redundant type[/-][+]stylecheck: check for the LHS of a declaration containing a redundant type[/+]dominikh commentedon Jul 29, 2019
It's really more of a style rule, not a matter of correctness.
cespare commentedon Jul 29, 2019
Oh, I see. The SA4??? checks are about "code which isn't really doing anything, so maybe you made a mistake and intended for it to do something"?
dominikh commentedon Jul 29, 2019
That is correct.
cespare commentedon May 10, 2021
Since golint is being deprecated/removed we're getting rid of it in our org. FWIW I think this is the only useful check we're losing which isn't covered by staticcheck.
dominikh commentedon May 14, 2021
We'll add two versions of the check: one in stylecheck and one in quickfix.
The one in stylecheck will be disabled by default, but can be opted into. It will have the following exceptions to reduce false/noisy positives:
This is essentially a better version of what you had in golint.
The one in quickfix will be enabled by default, but only be used inside gopls. It will not underline code or emit warnings, but it will simply grey out redundant types and offer to remove them. It does not have the last 3 exceptions. It will result in a user experience like the following:

dominikh commentedon May 14, 2021
However, this check is probably another one for #938.
cespare commentedon May 19, 2021
Awesome, thanks!
stylecheck, quickfix: flag redundant types in variable declarations