-
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 2 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,98 @@ | ||
| --- | ||
| title: "IDE2000: Avoid multiple blank lines" | ||
| description: "Learn about code analysis rule IDE2000: Avoid multiple blank lines" | ||
| ms.date: 01/31/2025 | ||
| f1_keywords: | ||
| - IDE2000 | ||
| helpviewer_keywords: | ||
| - IDE2000 | ||
| author: gewarren | ||
| ms.author: gewarren | ||
| dev_langs: | ||
| - CSharp | ||
| - VB | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ai-usage: ai-generated | ||
| --- | ||
| # 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 | | ||
|
|
||
| ## 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. | ||
|
|
||
| [!INCLUDE [enabled-on-build-never](../includes/enabled-on-build-never.md)] | ||
|
|
||
| ## Example | ||
|
|
||
| ```csharp | ||
| // Violates IDE2000 - multiple blank lines | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public class Example | ||
| { | ||
|
|
||
|
|
||
| public void Method1() | ||
| { | ||
| // Code here | ||
| } | ||
|
|
||
|
|
||
| public void Method2() | ||
| { | ||
| // Code here | ||
| } | ||
| } | ||
|
|
||
| // Follows IDE2000 - single blank lines for separation | ||
| public class Example | ||
| { | ||
|
|
||
| public void Method1() | ||
| { | ||
| // Code here | ||
| } | ||
|
|
||
| public void Method2() | ||
| { | ||
| // Code here | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## 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,102 @@ | ||
| --- | ||
| 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: 01/31/2025 | ||
| f1_keywords: | ||
| - IDE2001 | ||
| helpviewer_keywords: | ||
| - IDE2001 | ||
| author: gewarren | ||
| ms.author: gewarren | ||
| dev_langs: | ||
| - CSharp | ||
| - VB | ||
| ai-usage: ai-generated | ||
| --- | ||
| # 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# and Visual Basic | | ||
|
|
||
| ## Overview | ||
|
|
||
| This style rule enforces that embedded statements (statements that are part of control flow constructs like `if`, `while`, `for`, etc.) must be placed on their own line rather than on the same line as the control keyword. | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| [!INCLUDE [enabled-on-build-never](../includes/enabled-on-build-never.md)] | ||
|
|
||
| ## Example | ||
|
|
||
| ```csharp | ||
| // Violates IDE2001 - embedded statement on same line | ||
| if (condition) DoSomething(); | ||
| while (condition) ProcessItem(); | ||
| for (int i = 0; i < 10; i++) Console.WriteLine(i); | ||
|
|
||
| // Follows IDE2001 - embedded statements on separate lines | ||
| if (condition) | ||
| DoSomething(); | ||
|
|
||
| while (condition) | ||
| ProcessItem(); | ||
|
|
||
| for (int i = 0; i < 10; i++) | ||
| Console.WriteLine(i); | ||
|
|
||
| // Also acceptable with braces | ||
| if (condition) | ||
| { | ||
| DoSomething(); | ||
| } | ||
| ``` | ||
|
|
||
| ```vb | ||
| ' Violates IDE2001 - embedded statement on same line | ||
| If condition Then DoSomething() | ||
| While condition : ProcessItem() : End While | ||
|
|
||
| ' Follows IDE2001 - embedded statements on separate lines | ||
| If condition Then | ||
| DoSomething() | ||
| End If | ||
|
|
||
| While condition | ||
| ProcessItem() | ||
| End While | ||
| ``` | ||
|
|
||
| ## 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,132 @@ | ||
| --- | ||
| 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: 01/31/2025 | ||
| f1_keywords: | ||
| - IDE2002 | ||
| helpviewer_keywords: | ||
| - IDE2002 | ||
| author: gewarren | ||
| ms.author: gewarren | ||
| dev_langs: | ||
| - CSharp | ||
| - VB | ||
| ai-usage: ai-generated | ||
| --- | ||
| # 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# and Visual Basic | | ||
|
|
||
| ## Overview | ||
|
|
||
| This style rule enforces that consecutive closing and opening braces should not have blank lines between them. This helps maintain consistent and clean code formatting. | ||
|
|
||
| [!INCLUDE [enabled-on-build-never](../includes/enabled-on-build-never.md)] | ||
|
|
||
| ## Example | ||
|
|
||
| ```csharp | ||
| // Violates IDE2002 - blank line between consecutive braces | ||
| public class Example | ||
| { | ||
| public void Method1() | ||
| { | ||
| if (condition) | ||
| { | ||
| DoSomething(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public void Method2() | ||
| { | ||
| // Another method | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // Follows IDE2002 - no blank lines between consecutive braces | ||
| public class Example | ||
| { | ||
| public void Method1() | ||
| { | ||
| if (condition) | ||
| { | ||
| DoSomething(); | ||
| } | ||
| } | ||
|
|
||
| public void Method2() | ||
| { | ||
| // Another method | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ```vb | ||
| ' Violates IDE2002 - blank line between consecutive End statements | ||
| Public Class Example | ||
| Public Sub Method1() | ||
| If condition Then | ||
| DoSomething() | ||
| End If | ||
|
|
||
| End Sub | ||
|
|
||
| Public Sub Method2() | ||
| ' Another method | ||
| End Sub | ||
|
|
||
| End Class | ||
|
|
||
| ' Follows IDE2002 - no blank lines between consecutive End statements | ||
| Public Class Example | ||
| Public Sub Method1() | ||
| If condition Then | ||
| DoSomething() | ||
| End If | ||
| End Sub | ||
|
|
||
| Public Sub Method2() | ||
| ' Another method | ||
| End Sub | ||
| End Class | ||
| ``` | ||
|
|
||
| ## 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) |
Oops, something went wrong.
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.