dotnet/roslyn

Code fix for IDE0059 "Remove unnecessary assignment" removes empty lines or reorders code

オープン

#45,421 opened on 2020/06/24

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

Repository metrics

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

説明

Version Used: 16.6.2

Steps to Reproduce:

public class Test
{
    public long M(bool flag)
    {
        long a = 0; // IDE0059
        long b = 0; // IDE0059
        long c = 0; // IDE0059

        if (flag)
        {
            a = 1;
            b = 1;
            c = 1;
        }
        else
        {
            a = 2;
            b = 2;
            c = 2;
        }

        return a + b + c;
    }
}
  1. Run "Remove unnecessary assignment" for c
  2. Run "Remove unnecessary assignment" for b

Expected Behavior:

In both steps, the = 0 characters should be removed

         long a = 0; // IDE0059
-        long b = 0; // IDE0059
-        long c = 0; // IDE0059
+        long b; // IDE0059
+        long c; // IDE0059
 
         if (flag)

Actual Behavior:

After running "Remove unnecessary assignment" for c, the empty line below the declaration and the comment is also removed:

         long a = 0; // IDE0059
         long b = 0; // IDE0059
-        long c = 0; // IDE0059
-
+        long c;
         if (flag)

After then running "Remove unnecessary assignment" for b , the b and c declarations are reordered and the comment is removed:

         long a = 0; // IDE0059
-        long b = 0; // IDE0059
-        long c = 0; // IDE0059
-
+        long c;
+        long b;
         if (flag)

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