codemaid icon indicating copy to clipboard operation
codemaid copied to clipboard

CodeMaid adding tabs that shouldn't be there

Open jws305 opened this issue 3 years ago • 6 comments

Environment

  • Visual Studio version: 2022 Professional
  • CodeMaid version: 12.0
  • Code language: C#

Description

Cleanup Active Document causes block to add an indent every time it is run, i.e. if I run the task 5 times, I get 5 tabs in front of the block.

Steps to recreate

  1. Clone https://github.com/jws305/CodeMaidIndentIssue
  2. Run Cleanup Active Document on Program.cs

Current behavior

Erroneous tabs added

Expected behavior

The result of the cleanup should be deterministic.

jws305 avatar Nov 08 '21 20:11 jws305

Me too but codemaid adding spaces

AndreiYakovlev avatar Nov 09 '21 06:11 AndreiYakovlev

Thanks for reporting the issue. I am able to reproduce it and that is unexpected. I suspect it is something specific with this code segment:

        private static Lazy<int> Item { get; } = new Lazy<int>(() =>
        {
            return 1;
        });

codecadwallader avatar Nov 10 '21 00:11 codecadwallader

It looks to be tied to the insert explicit access modifiers logic on properties. If that option is turned off the behavior stops.

codecadwallader avatar Nov 10 '21 01:11 codecadwallader

It goes without saying, this is also affecting VS 2019 (16.11.4).

DamianSuess avatar Nov 11 '21 22:11 DamianSuess

To validate, this is the symptom of the bug, correct? The example is from our ViewModel using Prism Library, which as you can imagine uses a lot of DelegateCommand Properties.

Before:

    public DelegateCommand OnShowMain => new DelegateCommand(async () =>
    {
        await NavigationService.NavigateAsync($"../{nameof(MainView)}");
    });

After: (note single space indention after Ctrl+M+Space)

    public DelegateCommand OnShowMain => new DelegateCommand(async () =>
     {
         await NavigationService.NavigateAsync($"../{nameof(MainView)}");
     });

DamianSuess avatar Feb 23 '22 13:02 DamianSuess

Yes, I believe if you disable the options around inserting explicit access modifiers that will bypass the SDK bug and avoid the issue.

codecadwallader avatar Mar 11 '22 13:03 codecadwallader

Yes, I believe if you disable the options around inserting explicit access modifiers that will bypass the SDK bug and avoid the issue.

thanks, solve my problem.

wx0322 avatar Nov 18 '22 01:11 wx0322