unparam icon indicating copy to clipboard operation
unparam copied to clipboard

Remove the "always receives X" check entirely

Open mvdan opened this issue 7 years ago • 12 comments

We made it more conservative in #14, but it's still prone to false positives.

I've gone through all the warnings from this linter that I have applied, and this kind were almost non-existent.

Does anyone find it useful? Does anyone find it annoying? Input welcome.

mvdan avatar Jul 21 '18 18:07 mvdan

I don't like it too

kostyaVyrodov avatar Oct 09 '18 12:10 kostyaVyrodov

Does anyone find it useful?

I don't remember the last time I've seen it. I might've fixed all instances and not introduced new ones.

As a result, it's hard for me to say, but it sounds useful.

Does anyone find it annoying?

I do not.

dmitshur avatar Oct 19 '18 03:10 dmitshur

It is. annoying.

edulopezTriv avatar Oct 15 '19 13:10 edulopezTriv

I think I remember a couple of times where this check improved my code. They were mostly cases arising after refactorings, when boolean (or constant) flags of functions or methods become always-true or always-false after some removals and code moves.

I can also see it potentially preventing bugs where you add such flag, add it to an old function call, copy-paste that call into a new location, and forget to switch the flag.

For me personally it would be a pity to lose this check.

ainar-g avatar Oct 15 '19 21:10 ainar-g

The results so far are pretty much 50/50. Usually, that would mean that the check isn't generally useful, as I try to keep my linters as precise as possible.

Having said that, something has changed recently - gopls will start supporting different severities depending on the analyzer. So, when refactoring unparam to use go/analysis (which I need to do anyway), I can split up the tool into multiple analyzers:

  • parameter X is unused (error severity, because this is often a bug like forgetting to use a parameter)
  • result X is never used (lower severity, because it's just a simplification)
  • parameter/result X is always value Y (lower severity, because it's just a simplification)

So I think we can keep all the features, while ensuring that the "error severity" has a far lower false positive rate.

mvdan avatar Apr 26 '20 15:04 mvdan

We're using this linter through golangci-lint, mainly for the "unused parameter" check which is extremely useful. In our particular codebase, "always receives X" is always an annoyance. Would be nice to remove or disable it. The comments above have left me confused. Is it possible yet? (Edit: nolint: unparam works, but is extra effort with various downsides.)

mitranim avatar Sep 05 '21 08:09 mitranim

@mitranim it's not configurable right now.

mvdan avatar Sep 12 '21 14:09 mvdan

This is the reason why I had the disable the (otherwise useful) unparam linter completely.

I disagree with the premise of this linter: sometimes it's simply better style to pass a value as an argument, even if it's always the same.

jdemeyer avatar Jan 19 '22 08:01 jdemeyer

It'd be nice to have a way to disable a feature if it's annoying so many folks.

kucherenkovova avatar Jan 19 '22 20:01 kucherenkovova

boolean (or constant) flags of functions or methods become always-true or always-false after some removals and code moves.

I get this argument and it may be a good compromise to limit this check to booleans only.

jdemeyer avatar Jan 20 '22 07:01 jdemeyer

I think detection is a good feature, but I also think it is excessive. I don't think it should be detected when it currently just happens to be the same value.

I think it should at least be an option.

I can't even implement it to CI because of this.

yuki2006 avatar Apr 02 '22 20:04 yuki2006

I'd like to be able to disable the check for "parameter/result X is always value Y" as well. As mentioned before, it can be useful to declare parameters that are constant now but might be variable in the future. It makes a function more generic and easier to understand

mthaak avatar Sep 19 '22 09:09 mthaak