dotnet/roslyn

wrong "Remove unnecessary suppression" warning

オープン

#59,837 opened on 2022/03/01

 (3 件のコメント) (1 件のリアクション) (0 人の担当者)C# (4,257 件のフォーク)batch import
Area-IDEBugDeveloper CommunityFeature - IDE0079IDE-CodeStylehelp wanted

Repository metrics

Stars
 (20,414 個のスター)
PR merge metrics
 (平均マージ 6d 17h) (30d で 256 merged PRs)

説明

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)

コントリビューターガイド