Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDE0063 code fixer deletes comments nearby using statement or curly braces #48586

Closed
Tan90909090 opened this issue Oct 14, 2020 · 3 comments · Fixed by #48806
Closed

IDE0063 code fixer deletes comments nearby using statement or curly braces #48586

Tan90909090 opened this issue Oct 14, 2020 · 3 comments · Fixed by #48806
Labels
Area-IDE Concept-Continuous Improvement help wanted The issue is "up for grabs" - add a comment if you are interested in working on it IDE-CodeStyle Built-in analyzers, fixes, and refactorings
Milestone

Comments

@Tan90909090
Copy link

Version Used: Visual Studio 2019 Version 16.7.5

Steps to Reproduce:

  1. Write a following code, which has an IDE0063 'using' statement can be simplified:
using System;
using System.IO;

class C
{
    static void Main()
    {
        using (var s = new MemoryStream()) // foo
        { // bar
            Console.WriteLine(s.CanRead); // Only this comment remains.
        } // baz
    }
}
  1. Apply the Use simple 'using' statement

Expected Behavior:
All comments remain like this:

using System;
using System.IO;

class C
{
    static void Main()
    {
        using var s = new MemoryStream(); // foo
        // bar
        Console.WriteLine(s.CanRead); // Only this comment remains.
        // baz
    }
}

Actual Behavior:
"foo", "bar", "baz" comments are deleted:

using System;
using System.IO;

class C
{
    static void Main()
    {
        using var s = new MemoryStream();
        Console.WriteLine(s.CanRead); // Only this comment remains.
    }
}
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 14, 2020
@CyrusNajmabadi CyrusNajmabadi added help wanted The issue is "up for grabs" - add a comment if you are interested in working on it IDE-CodeStyle Built-in analyzers, fixes, and refactorings and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 14, 2020
@CyrusNajmabadi
Copy link
Member

We would take a targetted PR that updated things to have this behavior.

@louis-z
Copy link
Contributor

louis-z commented Oct 18, 2020

I can take a look at it.

@louis-z
Copy link
Contributor

louis-z commented Oct 21, 2020

Expected Behavior:
All comments remain like this:

using System;
using System.IO;

class C
{
    static void Main()
    {
        using var s = new MemoryStream(); // foo
        // bar
        Console.WriteLine(s.CanRead); // Only this comment remains.
        // baz
    }
}

Ok, so I managed to resolve the issue, but instead I get aligned comments as follows:

using System;
using System.IO;

class C
{
    static void Main()
    {
        using var s = new MemoryStream(); // foo
                                          // bar
        Console.WriteLine(s.CanRead); // Only this comment remains.
                                      // baz
    }
}

If that sounds acceptable, I'll gladly submit a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Concept-Continuous Improvement help wanted The issue is "up for grabs" - add a comment if you are interested in working on it IDE-CodeStyle Built-in analyzers, fixes, and refactorings
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants