codecadwallader / codemaid

CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding.
http://www.codemaid.net
GNU Lesser General Public License v3.0
1.88k stars 353 forks source link

Method parameters are indented incorrectly while reorganizing the interface #957

Open tygore587 opened 1 year ago

tygore587 commented 1 year ago

Environment

Description

If you reorganize a class (Ctrl + M, Z) and you are using the following format for methods, the indentation of method parameters is wrong.

Example

Before reorganizing

 internal interface Example
{
    public Task MethodB(
        string parameter1,
        string parameter2,
        string parameter3,
        string parameter4);

    public Task MethodA(string parameter1);
}

After Reorganizing

internal interface Example
{
    public Task MethodA(string parameter1);

    public Task MethodB(
            string parameter1,
        string parameter2,
        string parameter3,
        string parameter4);
}

The indentation of parameter1 in MethodB is wrong. It will be more indented if it is organized lower (so beeing pushed down 2 methods, the result is:

Before

internal interface Example
{
    public Task MethodC(
        string parameter1,
        string parameter2,
        string parameter3,
        string parameter4);

    public Task MethodB(string parameter1);

    public Task MethodA(string parameter1);
}

After

internal interface Example
{
    public Task MethodA(string parameter1);

    public Task MethodB(string parameter1);

    public Task MethodC(
                string parameter1,
        string parameter2,
        string parameter3,
        string parameter4);
}

Steps to recreate

  1. Copy example before reorganizing
  2. Reorganize interface (Ctrl + M, Z)
  3. See result

Expected behavior

Method parameters should not be indented more than the others. They should stay like they are before reorganizing.

codecadwallader commented 1 year ago

Thanks for reporting the issue and the clear examples. I have been able to reproduce it. The reorganization logic contains a number of tricks to try and maintain indentation as it moves elements around but the main fallback for when it can't preserve the indentation is that a cleanup is expected afterwards. Unfortunately, in this example the indentation isn't something CodeMaid would enforce so it isn't resolved by a cleanup.