dotnet/roslyn

wrong "Remove unnecessary suppression" warning

Open

#59,837 opened on Mar 1, 2022

View on GitHub
 (3 comments) (1 reaction) (0 assignees)C# (4,257 forks)batch import
Area-IDEBugDeveloper CommunityFeature - IDE0079IDE-CodeStylehelp wanted

Repository metrics

Stars
 (20,414 stars)
PR merge metrics
 (Avg merge 6d 17h) (256 merged PRs in 30d)

Description

This issue has been moved from a ticket on Developer Community.


VS 2022 shows 2 contradicting warnings.

First, VS wants me to convert an if statement into a conditional expression.

I don't want to do that, because I feel the if statement is better readable. So I added "#pragma warning disable IDE0046 // Convert to conditional expression":

public static string? GetFrameWorkElementName(FrameworkElement frameworkElement) {
  if (! IsTracingOn) return null;

#pragma warning disable IDE0046 // Convert to conditional expression
  if (frameworkElement is ITraceName iTraceName && iTraceName.TraceName!=null && iTraceName.TraceName.Length>0) {
  #pragma warning restore IDE0046
    return iTraceName.TraceName;
  }

return frameworkElement.Name!=null && frameworkElement.Name.Length>0 ? frameworkElement.Name : 
    frameworkElement.GetType(). ToString();
}

! [image.png] (https://aka.ms/dc/image?name=B6325bdf53a8d4318ac09beb436634904637816120209707038_20220228-102701-image.png&tid=6325bdf53a8d4318ac09beb436634904637816120209707038)

The lightbulb displays 2 contradicting warnings:

  1. Use conditional expression for return (IDE0046)
  2. Remove unnecessary suppression (IDE0079)

However, they contradict each other, not both can be true at the same time !!!!!!!!!!!!!

I like that VS tries to tell me there might be a problem. But there MUST be a way to tell VS that at this place it is not a problem and VS needs to stop warning me here. My goal is to have 0 warnings. If I have some untrue warnings here and there, the warnings become useless, because I can no longer easily see that all warnings are resolved.


Original Comments

Feedback Bot on 2/28/2022, 01:44 AM:

Feedback Bot on 2/28/2022, 00:24 PM:


Original Solutions

(no solutions)

Contributor guide