Edit

Share via


Consecutive braces must not have blank line between them (IDE2002)

Property Value
Rule ID IDE2002
Title Consecutive braces must not have blank line between them
Category Style
Subcategory Language rules (new-line preferences)
Applicable languages C#
Options csharp_style_allow_blank_lines_between_consecutive_braces_experimental

Note

This rule is experimental and subject to change or removal.

Overview

This style rule enforces that consecutive braces should not have blank lines between them. This helps maintain consistent and clean code formatting.

Options

Options specify the behavior that you want the rule to enforce. For information about configuring options, see Option format.

csharp_style_allow_blank_lines_between_consecutive_braces_experimental

Property Value Description
Option name csharp_style_allow_blank_lines_between_consecutive_braces_experimental
Option values true Allow blank lines between consecutive braces
false Don't allow blank lines between consecutive braces
Default option value true

Example

// csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true
public void Method()
{
    if (true)
    {
        DoWork();
    }

}
// csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false
public void Method()
{
    if (true)
    {
        DoWork();
    }
}

Suppress a warning

If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

#pragma warning disable IDE2002
// The code that's violating the rule is on this line.
#pragma warning restore IDE2002

To disable the rule for a file, folder, or project, set its severity to none in the configuration file.

[*.{cs,vb}]
dotnet_diagnostic.IDE2002.severity = none

To disable all of the code-style rules, set the severity for the category Style to none in the configuration file.

[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-style.severity = none

For more information, see How to suppress code analysis warnings.

See also