Roslyn: 'return value is unused' is overly aggressive

Created on 24 Jan 2019  路  11Comments  路  Source: dotnet/roslyn

I'm getting a warning by default for writing code like this:

image

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:

image

However, i'm now forced to update my code to look much more ugly as:

image

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:

  1. we bulk-fix. but that means if we're actually ignoring something we shouldn't be ignoring, then we're SOL.
  2. we don't have this feature on.

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.

Area-IDE Concept-Continuous Improvement Resolution-By Design

Most helpful comment

Can you try:

# IDE0058
csharp_style_unused_value_expression_statement_preference = discard_variable:none

All 11 comments

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.

image

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:

  1. Diagnostic is hidden by default, so has no visible UI impact: https://github.com/dotnet/roslyn/issues/32721#issuecomment-465759018
  2. Can be easily disabled: https://github.com/dotnet/roslyn/issues/32721#issuecomment-503281258
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ilexp picture ilexp  路  167Comments

mattwar picture mattwar  路  190Comments

gafter picture gafter  路  258Comments

davidroth picture davidroth  路  158Comments

MadsTorgersen picture MadsTorgersen  路  249Comments