-
-
Notifications
You must be signed in to change notification settings - Fork 768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New rule: Warn on ignored return value #2239
Comments
Related topics: The annotation I think that force to handle all the returns values is overkill. It works perfect for a pure-function world but in the real world you are going to add far to much On the other hand, a rule that checks the |
Thanks @bbaldino for the rule suggestion (and first contribution PR!) and @BraisGabin for your comments, which I 100% agree with. Limiting this to functions annotated with |
Of course I'll defer to what you guys think is best, but I'll admit I actually think more often than not a function which returns something whose value is ignored is a bug, though I don't have any data to back that up. I'm doing some tests against the my actual project to try and see what the results are like, but the rule logic still needs further refinement. |
The rule or changes you're looking for might have already been suggested!
Please search in the issues before creating a new one.
Expected Behavior of the rule
If a method which returns a value is called and the return value is ignored, detekt should issue a warning.
Example:
It would be easy for someone to call
myByte.putBit(1, true)
and think it would be modified in place, but actually it returns the new value. A failure to handle this return value will almost certainly result in a bug.Context
In many (most?) cases, the failure to observe a value returned by a function will result in a bug, but it can be an easy thing for a developer to forget. A warning will help catch instances where the return value should be handled. Cases which don't fall under this condition can suppress the warning (which also serves to explicitly document that it was intended).
I plan on taking a look at implementing this rule myself when I get a chance.
The text was updated successfully, but these errors were encountered: