Blank Lines around Preprocessor Directives

I love the formatting styles available in ReSharper, but I cannot seem to prevent certain blank lines around preprocessor directives from being removed. 

For example, I have a class with the following fields and types:

      private const string DateFormat = "yyyy-MM-dd";

#pragma warning disable 649

private bool useTestDate;

private string testDate;

#pragma warning restore 649

public enum Season
{
Easter = 0,

Halloween = 1,

Thanksgiving = 2,

Christmas = 3
}

Note the blank lines above and below the "disable" and "restore" pragmas. When the code is auto-formatted, I cannot seem to keep the blank lines above the "disable" pragma.

      private const string DateFormat = "yyyy-MM-dd";
#pragma warning disable 649

private bool useTestDate;

private string testDate;

#pragma warning restore 649

public enum Season
{
Easter = 0,

Halloween = 1,

Thanksgiving = 2,

Christmas = 3
}

Oddly enough, the blank lines above and below the "restore" pragma are retained, but the blank line above the "disable" is always removed. Even when the allowed blank lines between fields is set to 2, the line above and below the pragma will get auto-formatted with 0 above and 2 below.

It would be great if there was an option to specifically allow X number of blank lines around preprocessor directives, including #pragma, #if, #else, #endif, and the rest.

 

Ideally, I want to limit the number of consecutive blank lines throughout all code to 1, but I also prefer there be a blank line surrounding most preprocessor directive. The only exception I can think of would be directives immediately inside a code block, however I wouldn't mind if the extra blank line was present:

   public class TestClass
{
#pragma warning disable 649

private bool useTestDate;

private string testDate;

#pragma warning restore 649
}

 

0
2 comments

Hello Michael!

 

Sorry for delay in responding.

Unfortunately I couldn't reproduce the specified behavior.

Could you please share your code sample and dotsettings files from all layers (https://www.jetbrains.com/help/resharper/Sharing_Configuration_Options.html#managing) using 'Submit a request' form.

Thank you.

0

Angelina,

I've just submitted a new request with the code sample and dotsettings files attached.

Thanks!

0

Please sign in to leave a comment.