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

CodeMaid is not handling conditional compilation on 'Cleanup' document #954

Closed phil000 closed 1 year ago

phil000 commented 1 year ago

Environment

Description

CodeMaid is not handling conditional compilation on 'Cleanup' document.

Current behavior

Shifts code about inappropriately.

Expected behavior

Doesn't shift code about inappropriately.

e.g. Start with:

    private const int MaximumInvoicesScheduleDays = 31;
#if (DEBUG)
    private const int MaximumInvoicesExtractDays = 99999;
#else
    // This will be the absolute maximum for extracting invoices
    private const int MaximumInvoicesExtractDays = 183;
#endif

Perform cleanup.

End up with:

    private const int MaximumInvoicesExtractDays = 99999;
    private const int MaximumInvoicesScheduleDays = 31;
#if (DEBUG)
#else
    // This will be the absolute maximum for extracting invoices
    private const int MaximumInvoicesExtractDays = 183;
#endif
Protiguous commented 1 year ago

Can you test if the #if (DEBUG) versus #if DEBUG makes a difference with CodeMaid?

codecadwallader commented 1 year ago

Thanks for reporting the issue. By default CodeMaid detects preprocessor conditionals and prompts if you want to proceed with a reorganization. When running a reorganization a box like this should(tm) pop up:

image

If you're not seeing that prompt, can you check the setting at CodeMaid->Options->Reorganizing->General->Perform reorganization when preprocessor conditionals are present ?

phil000 commented 1 year ago

Hello,

if (DEBUG) versus #if DEBUG does the same thing.

That setting is turned on.

The behavior is unpredictable, as this

#if DEBUG
    private int z = 5;
#endif
    private int x = 10;
    private int y = 100;

gets cleaned into this:

#if DEBUG
    private int x = 10;
    private int y = 100;
    private int z = 5;
#endif
codecadwallader commented 1 year ago

It sounds like the preprocessor directive detection is failing if you're not seeing the warning prompt. Do you have a minimal solution that reproduces the issue that you can share?

phil000 commented 1 year ago

Hi, Please close this case. I only raised this issue to see if preprocessor directives could actually be handled better. This file and most others we have do need to be cleaned, so we've altered the structure to remove preprocessor directives or place them in a file of their own.

Pinox commented 1 year ago

It sounds like the preprocessor directive detection is failing if you're not seeing the warning prompt. Do you have a minimal solution that reproduces the issue that you can share?

I also see this issue. Although my settings is set to "ask" there is no warning prompt so all conditional statements are reorganized all the time.

In my case it always deletes the " #endif " statement.

image

codecadwallader commented 1 year ago

Thanks for reporting Pinox. Same ask as above, can you please provide a minimal solution that exhibits the issue?