-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Document IDE2000-2006 newline preference rules #48011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ca04483
Initial plan
Copilot 3286fa7
Add documentation for IDE2000-2006 newline preference rules
Copilot 5c5c80f
Address PR feedback: update dates, fix dev_langs, add periods to comm…
Copilot 1002c7e
add options
gewarren 8d0bf44
add to toc
gewarren 1434378
add experimental note
gewarren 6dcabb1
respond to feedback
gewarren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| --- | ||
| title: "IDE2000: Avoid multiple blank lines" | ||
| description: "Learn about code analysis rule IDE2000: Avoid multiple blank lines" | ||
| ms.date: 08/19/2025 | ||
| f1_keywords: | ||
| - IDE2000 | ||
| helpviewer_keywords: | ||
| - IDE2000 | ||
| dev_langs: | ||
| - CSharp | ||
| ai-usage: ai-assisted | ||
| --- | ||
| # Avoid multiple blank lines (IDE2000) | ||
|
|
||
| | Property | Value | | ||
| |--------------------------|--------------------------------------------------------| | ||
| | **Rule ID** | IDE2000 | | ||
| | **Title** | Avoid multiple blank lines | | ||
| | **Category** | Style | | ||
| | **Subcategory** | Language rules (new-line preferences) | | ||
| | **Applicable languages** | C# and Visual Basic | | ||
| | **Options** | `dotnet_style_allow_multiple_blank_lines_experimental` | | ||
|
|
||
| > [!NOTE] | ||
| > This rule is experimental and subject to change or removal. | ||
|
|
||
| ## Overview | ||
|
|
||
| This style rule flags the presence of multiple consecutive blank lines in source code. Having multiple blank lines can reduce code readability and is generally considered poor formatting practice. | ||
|
|
||
| ## Options | ||
|
|
||
| Options specify the behavior that you want the rule to enforce. For information about configuring options, see [Option format](language-rules.md#option-format). | ||
|
|
||
| ### dotnet_style_allow_multiple_blank_lines_experimental | ||
|
|
||
| | Property | Value | Description | | ||
| |--------------------------|--------------------------------------------------------|-------------| | ||
| | **Option name** | `dotnet_style_allow_multiple_blank_lines_experimental` | | | ||
| | **Option values** | `true` | Allow multiple consecutive blank lines | | ||
| | | `false` | Don't allow consecutive blank lines | | ||
| | **Default option value** | `true` | | | ||
|
|
||
| ## Example | ||
|
|
||
| ```csharp | ||
| // dotnet_style_allow_multiple_blank_lines_experimental = true | ||
| if (true) | ||
| { | ||
| DoWork(); | ||
| } | ||
|
|
||
|
|
||
| return; | ||
| ``` | ||
|
|
||
| ```csharp | ||
| // dotnet_style_allow_multiple_blank_lines_experimental = false | ||
| if (true) | ||
| { | ||
| DoWork(); | ||
| } | ||
|
|
||
| return; | ||
| ``` | ||
|
|
||
| ## 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. | ||
|
|
||
| ```csharp | ||
| #pragma warning disable IDE2000 | ||
| // The code that's violating the rule is on this line. | ||
| #pragma warning restore IDE2000 | ||
| ``` | ||
|
|
||
| To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../configuration-files.md). | ||
|
|
||
| ```ini | ||
| [*.{cs,vb}] | ||
| dotnet_diagnostic.IDE2000.severity = none | ||
| ``` | ||
|
|
||
| To disable all of the code-style rules, set the severity for the category `Style` to `none` in the [configuration file](../configuration-files.md). | ||
|
|
||
| ```ini | ||
| [*.{cs,vb}] | ||
| dotnet_analyzer_diagnostic.category-style.severity = none | ||
| ``` | ||
|
|
||
| For more information, see [How to suppress code analysis warnings](../suppress-warnings.md). | ||
|
|
||
| ## See also | ||
|
|
||
| - [New-line preferences](language-rules.md#new-line-preferences) | ||
| - [Code style language rules](language-rules.md) | ||
| - [Code style rules reference](index.md) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| --- | ||
| title: "IDE2001: Embedded statements must be on their own line" | ||
| description: "Learn about code analysis rule IDE2001: Embedded statements must be on their own line" | ||
| ms.date: 08/19/2025 | ||
| f1_keywords: | ||
| - IDE2001 | ||
| helpviewer_keywords: | ||
| - IDE2001 | ||
| dev_langs: | ||
| - CSharp | ||
| - VB | ||
| ai-usage: ai-assisted | ||
| --- | ||
| # Embedded statements must be on their own line (IDE2001) | ||
|
|
||
| | Property | Value | | ||
| |--------------------------|--------------------------------------------------------------------| | ||
| | **Rule ID** | IDE2001 | | ||
| | **Title** | Embedded statements must be on their own line | | ||
| | **Category** | Style | | ||
| | **Subcategory** | Language rules (new-line preferences) | | ||
| | **Applicable languages** | C# | | ||
| | **Options** | `csharp_style_allow_embedded_statements_on_same_line_experimental` | | ||
|
|
||
| > [!NOTE] | ||
| > This rule is experimental and subject to change or removal. | ||
|
|
||
| ## Overview | ||
|
|
||
| This style rule enforces that embedded statements (statements that are part of control flow constructs like `if`, `while`, and `for`) must be placed on their own line rather than on the same line as the control keyword. | ||
|
|
||
| ## Options | ||
|
|
||
| Options specify the behavior that you want the rule to enforce. For information about configuring options, see [Option format](language-rules.md#option-format). | ||
|
|
||
| ### csharp_style_allow_embedded_statements_on_same_line_experimental | ||
|
|
||
| | Property | Value | Description | | ||
| |--------------------------|----------------------------------------------|-------------| | ||
| | **Option name** | `csharp_style_allow_embedded_statements_on_same_line_experimental` | | | ||
| | **Option values** | `true` | Allow embedded statements on same line as control keyword | | ||
| | | `false` | Require embedded statements to be on their own line | | ||
| | **Default option value** | `true` | | | ||
|
|
||
| ## Example | ||
|
|
||
| ```csharp | ||
| // csharp_style_allow_embedded_statements_on_same_line_experimental = true | ||
| for (int i = 0; i < 10; i++) Console.WriteLine(i); | ||
| ``` | ||
|
|
||
| ```csharp | ||
| // csharp_style_allow_embedded_statements_on_same_line_experimental = false | ||
| for (int i = 0; i < 10; i++) | ||
| Console.WriteLine(i); | ||
| ``` | ||
|
|
||
| ## 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. | ||
|
|
||
| ```csharp | ||
| #pragma warning disable IDE2001 | ||
| // The code that's violating the rule is on this line. | ||
| #pragma warning restore IDE2001 | ||
| ``` | ||
|
|
||
| To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../configuration-files.md). | ||
|
|
||
| ```ini | ||
| [*.{cs,vb}] | ||
| dotnet_diagnostic.IDE2001.severity = none | ||
| ``` | ||
|
|
||
| To disable all of the code-style rules, set the severity for the category `Style` to `none` in the [configuration file](../configuration-files.md). | ||
|
|
||
| ```ini | ||
| [*.{cs,vb}] | ||
| dotnet_analyzer_diagnostic.category-style.severity = none | ||
| ``` | ||
|
|
||
| For more information, see [How to suppress code analysis warnings](../suppress-warnings.md). | ||
|
|
||
| ## See also | ||
|
|
||
| - [New-line preferences](language-rules.md#new-line-preferences) | ||
| - [Code style language rules](language-rules.md) | ||
| - [Code style rules reference](index.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| --- | ||
| title: "IDE2002: Consecutive braces must not have blank line between them" | ||
| description: "Learn about code analysis rule IDE2002: Consecutive braces must not have blank line between them" | ||
| ms.date: 08/19/2025 | ||
| f1_keywords: | ||
| - IDE2002 | ||
| helpviewer_keywords: | ||
| - IDE2002 | ||
| dev_langs: | ||
| - CSharp | ||
| ai-usage: ai-assisted | ||
| --- | ||
| # 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](language-rules.md#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 | ||
| // csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true | ||
| public void Method | ||
| { | ||
| if (true) | ||
| { | ||
| DoWork(); | ||
| } | ||
|
|
||
| } | ||
| ``` | ||
|
|
||
| ```csharp | ||
| // 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. | ||
|
|
||
| ```csharp | ||
| #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](../configuration-files.md). | ||
|
|
||
| ```ini | ||
| [*.{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](../configuration-files.md). | ||
|
|
||
| ```ini | ||
| [*.{cs,vb}] | ||
| dotnet_analyzer_diagnostic.category-style.severity = none | ||
| ``` | ||
|
|
||
| For more information, see [How to suppress code analysis warnings](../suppress-warnings.md). | ||
|
|
||
| ## See also | ||
|
|
||
| - [New-line preferences](language-rules.md#new-line-preferences) | ||
| - [Code style language rules](language-rules.md) | ||
| - [Code style rules reference](index.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| --- | ||
| title: "IDE2003: Blank line required between block and subsequent statement" | ||
| description: "Learn about code analysis rule IDE2003: Blank line required between block and subsequent statement" | ||
| ms.date: 08/19/2025 | ||
| f1_keywords: | ||
| - IDE2003 | ||
| helpviewer_keywords: | ||
| - IDE2003 | ||
| dev_langs: | ||
| - CSharp | ||
| ai-usage: ai-assisted | ||
| --- | ||
| # Blank line required between block and subsequent statement (IDE2003) | ||
|
|
||
| | Property | Value | | ||
| |--------------------------|---------------------------------------------------------------------| | ||
| | **Rule ID** | IDE2003 | | ||
| | **Title** | Blank line required between block and subsequent statement | | ||
| | **Category** | Style | | ||
| | **Subcategory** | Language rules (new-line preferences) | | ||
| | **Applicable languages** | C# and Visual Basic | | ||
| | **Options** | `dotnet_style_allow_statement_immediately_after_block_experimental` | | ||
|
|
||
| > [!NOTE] | ||
| > This rule is experimental and subject to change or removal. | ||
|
|
||
| ## Overview | ||
|
|
||
| This style rule enforces that there should be a blank line between a block statement and any subsequent statement at the same scope level. This improves code readability by visually separating different logical sections of code. | ||
|
|
||
| ## Options | ||
|
|
||
| Options specify the behavior that you want the rule to enforce. For information about configuring options, see [Option format](language-rules.md#option-format). | ||
|
|
||
| ### dotnet_style_allow_statement_immediately_after_block_experimental | ||
|
|
||
| | Property | Value | Description | | ||
| |--------------------------|----------------------------------------------|-------------| | ||
| | **Option name** | `dotnet_style_allow_statement_immediately_after_block_experimental` | | | ||
| | **Option values** | `true` | Allow subsequent statement to immediately follow block statement without a blank line in between | | ||
| | | `false` | Require a blank line between a block statement and the subsequent statement | | ||
| | **Default option value** | `true` | | | ||
|
|
||
| ## Example | ||
|
|
||
| ```csharp | ||
| // dotnet_style_allow_statement_immediately_after_block_experimental = true | ||
| if (true) | ||
| { | ||
| DoWork(); | ||
| } | ||
| return; | ||
| ``` | ||
|
|
||
| ```csharp | ||
| // dotnet_style_allow_statement_immediately_after_block_experimental = false | ||
| if (true) | ||
| { | ||
| DoWork(); | ||
| } | ||
|
|
||
| return; | ||
| ``` | ||
|
|
||
| ## 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. | ||
|
|
||
| ```csharp | ||
| #pragma warning disable IDE2003 | ||
| // The code that's violating the rule is on this line. | ||
| #pragma warning restore IDE2003 | ||
| ``` | ||
|
|
||
| To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../configuration-files.md). | ||
|
|
||
| ```ini | ||
| [*.{cs,vb}] | ||
| dotnet_diagnostic.IDE2003.severity = none | ||
| ``` | ||
|
|
||
| To disable all of the code-style rules, set the severity for the category `Style` to `none` in the [configuration file](../configuration-files.md). | ||
|
|
||
| ```ini | ||
| [*.{cs,vb}] | ||
| dotnet_analyzer_diagnostic.category-style.severity = none | ||
| ``` | ||
|
|
||
| For more information, see [How to suppress code analysis warnings](../suppress-warnings.md). | ||
|
|
||
| ## See also | ||
|
|
||
| - [New-line preferences](language-rules.md#new-line-preferences) | ||
| - [Code style language rules](language-rules.md) | ||
| - [Code style rules reference](index.md) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.