I'm getting a warning by default for writing code like this:
This is because i'm not bothering to look at the return value. This is because the return value is pretty irrelevant to me. All it has is:
However, i'm now forced to update my code to look much more ugly as:
Or to suppress the warning. However, the original code was the idiomatic way to just call code and not have to worry about the return value.
It seems like the feature is super aggressive here. In our projects, we see literally thousands of these warnings, and i'm struggling to think how we could deal with them. either:
It seems like the feature needs to be smarter. Perhaps by having an understanding of which APIs it's very much a problem to ignore results from.
Tagging @mavasani
@CyrusNajmabadi The noise was the primary reason we changed the unused expression value diagnostic to be hidden by default, so it basically acts as a refactoring, but with a FixAll ability. I am fine with us converting this to a refactoring as well, and have https://github.com/dotnet/roslyn/issues/32461 track the FixAll functionality if we need bulk change functionality.
This really needs to be done. The experience is so annoying.
Yes. i know i'm not using the value. I don't care about it at all. and needin to say _ = ...
is just so ugly and unnecessary.
@CyrusNajmabadi - this diagnostic is hidden by default. Can you restore it to the original severity so you don't have any user visible impact (no squiggle, suggestions in error list or ... in the editor for the code fix), at which point this is just a refactoring?
I've been unable to make this go away as suggested. What code style rule governs this and what value would I use to make it go away entirely? Even in refactoring mode, it still appears as a lightbulb suggestion (and the short dotted underline that comes with it) on every fluent-api style piece of code or any method with a return value that's unused at least once.
This seems counter-productive and overly-aggressive as suggested by the OP post, unless fluent-api style is no longer a recommended pattern.
Would it be possible to have an additional option under Preference for "Never" as with other options like "Use expression body for ..."?
Would it be possible to have an additional option under Preference for "Never" as with other options like "Use expression body for ..."?
Tools → Options does not have the ability to completely disable analyzers, but the corresponding .editorconfig rules do. In .editorconfig, you can set the severity to none
to disable rules.
Is there a governing rule in .editorconfig for this setting?
Can you try:
# IDE0058
csharp_style_unused_value_expression_statement_preference = discard_variable:none
Exactly what i needed, Should have looked there first. Thanks!
I am going to close this as by design given the following:
Most helpful comment
Can you try: