Skip to content

Commit 3286fa7

Browse files
Copilotgewarren
andcommitted
Add documentation for IDE2000-2006 newline preference rules
Co-authored-by: gewarren <[email protected]>
1 parent ca04483 commit 3286fa7

File tree

9 files changed

+814
-7
lines changed

9 files changed

+814
-7
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
title: "IDE2000: Avoid multiple blank lines"
3+
description: "Learn about code analysis rule IDE2000: Avoid multiple blank lines"
4+
ms.date: 01/31/2025
5+
f1_keywords:
6+
- IDE2000
7+
helpviewer_keywords:
8+
- IDE2000
9+
author: gewarren
10+
ms.author: gewarren
11+
dev_langs:
12+
- CSharp
13+
- VB
14+
ai-usage: ai-generated
15+
---
16+
# Avoid multiple blank lines (IDE2000)
17+
18+
| Property | Value |
19+
| ------------------------ | ---------------------------------------- |
20+
| **Rule ID** | IDE2000 |
21+
| **Title** | Avoid multiple blank lines |
22+
| **Category** | Style |
23+
| **Subcategory** | Language rules (new-line preferences) |
24+
| **Applicable languages** | C# and Visual Basic |
25+
26+
## Overview
27+
28+
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.
29+
30+
[!INCLUDE [enabled-on-build-never](../includes/enabled-on-build-never.md)]
31+
32+
## Example
33+
34+
```csharp
35+
// Violates IDE2000 - multiple blank lines
36+
public class Example
37+
{
38+
39+
40+
public void Method1()
41+
{
42+
// Code here
43+
}
44+
45+
46+
public void Method2()
47+
{
48+
// Code here
49+
}
50+
}
51+
52+
// Follows IDE2000 - single blank lines for separation
53+
public class Example
54+
{
55+
56+
public void Method1()
57+
{
58+
// Code here
59+
}
60+
61+
public void Method2()
62+
{
63+
// Code here
64+
}
65+
}
66+
```
67+
68+
## Suppress a warning
69+
70+
If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
71+
72+
```csharp
73+
#pragma warning disable IDE2000
74+
// The code that's violating the rule is on this line.
75+
#pragma warning restore IDE2000
76+
```
77+
78+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../configuration-files.md).
79+
80+
```ini
81+
[*.{cs,vb}]
82+
dotnet_diagnostic.IDE2000.severity = none
83+
```
84+
85+
To disable all of the code-style rules, set the severity for the category `Style` to `none` in the [configuration file](../configuration-files.md).
86+
87+
```ini
88+
[*.{cs,vb}]
89+
dotnet_analyzer_diagnostic.category-style.severity = none
90+
```
91+
92+
For more information, see [How to suppress code analysis warnings](../suppress-warnings.md).
93+
94+
## See also
95+
96+
- [New-line preferences](language-rules.md#new-line-preferences)
97+
- [Code style language rules](language-rules.md)
98+
- [Code style rules reference](index.md)
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
title: "IDE2001: Embedded statements must be on their own line"
3+
description: "Learn about code analysis rule IDE2001: Embedded statements must be on their own line"
4+
ms.date: 01/31/2025
5+
f1_keywords:
6+
- IDE2001
7+
helpviewer_keywords:
8+
- IDE2001
9+
author: gewarren
10+
ms.author: gewarren
11+
dev_langs:
12+
- CSharp
13+
- VB
14+
ai-usage: ai-generated
15+
---
16+
# Embedded statements must be on their own line (IDE2001)
17+
18+
| Property | Value |
19+
| ------------------------ | ---------------------------------------- |
20+
| **Rule ID** | IDE2001 |
21+
| **Title** | Embedded statements must be on their own line |
22+
| **Category** | Style |
23+
| **Subcategory** | Language rules (new-line preferences) |
24+
| **Applicable languages** | C# and Visual Basic |
25+
26+
## Overview
27+
28+
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.
29+
30+
[!INCLUDE [enabled-on-build-never](../includes/enabled-on-build-never.md)]
31+
32+
## Example
33+
34+
```csharp
35+
// Violates IDE2001 - embedded statement on same line
36+
if (condition) DoSomething();
37+
while (condition) ProcessItem();
38+
for (int i = 0; i < 10; i++) Console.WriteLine(i);
39+
40+
// Follows IDE2001 - embedded statements on separate lines
41+
if (condition)
42+
DoSomething();
43+
44+
while (condition)
45+
ProcessItem();
46+
47+
for (int i = 0; i < 10; i++)
48+
Console.WriteLine(i);
49+
50+
// Also acceptable with braces
51+
if (condition)
52+
{
53+
DoSomething();
54+
}
55+
```
56+
57+
```vb
58+
' Violates IDE2001 - embedded statement on same line
59+
If condition Then DoSomething()
60+
While condition : ProcessItem() : End While
61+
62+
' Follows IDE2001 - embedded statements on separate lines
63+
If condition Then
64+
DoSomething()
65+
End If
66+
67+
While condition
68+
ProcessItem()
69+
End While
70+
```
71+
72+
## Suppress a warning
73+
74+
If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
75+
76+
```csharp
77+
#pragma warning disable IDE2001
78+
// The code that's violating the rule is on this line.
79+
#pragma warning restore IDE2001
80+
```
81+
82+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../configuration-files.md).
83+
84+
```ini
85+
[*.{cs,vb}]
86+
dotnet_diagnostic.IDE2001.severity = none
87+
```
88+
89+
To disable all of the code-style rules, set the severity for the category `Style` to `none` in the [configuration file](../configuration-files.md).
90+
91+
```ini
92+
[*.{cs,vb}]
93+
dotnet_analyzer_diagnostic.category-style.severity = none
94+
```
95+
96+
For more information, see [How to suppress code analysis warnings](../suppress-warnings.md).
97+
98+
## See also
99+
100+
- [New-line preferences](language-rules.md#new-line-preferences)
101+
- [Code style language rules](language-rules.md)
102+
- [Code style rules reference](index.md)
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
title: "IDE2002: Consecutive braces must not have blank line between them"
3+
description: "Learn about code analysis rule IDE2002: Consecutive braces must not have blank line between them"
4+
ms.date: 01/31/2025
5+
f1_keywords:
6+
- IDE2002
7+
helpviewer_keywords:
8+
- IDE2002
9+
author: gewarren
10+
ms.author: gewarren
11+
dev_langs:
12+
- CSharp
13+
- VB
14+
ai-usage: ai-generated
15+
---
16+
# Consecutive braces must not have blank line between them (IDE2002)
17+
18+
| Property | Value |
19+
| ------------------------ | ---------------------------------------- |
20+
| **Rule ID** | IDE2002 |
21+
| **Title** | Consecutive braces must not have blank line between them |
22+
| **Category** | Style |
23+
| **Subcategory** | Language rules (new-line preferences) |
24+
| **Applicable languages** | C# and Visual Basic |
25+
26+
## Overview
27+
28+
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.
29+
30+
[!INCLUDE [enabled-on-build-never](../includes/enabled-on-build-never.md)]
31+
32+
## Example
33+
34+
```csharp
35+
// Violates IDE2002 - blank line between consecutive braces
36+
public class Example
37+
{
38+
public void Method1()
39+
{
40+
if (condition)
41+
{
42+
DoSomething();
43+
}
44+
45+
}
46+
47+
public void Method2()
48+
{
49+
// Another method
50+
}
51+
52+
}
53+
54+
// Follows IDE2002 - no blank lines between consecutive braces
55+
public class Example
56+
{
57+
public void Method1()
58+
{
59+
if (condition)
60+
{
61+
DoSomething();
62+
}
63+
}
64+
65+
public void Method2()
66+
{
67+
// Another method
68+
}
69+
}
70+
```
71+
72+
```vb
73+
' Violates IDE2002 - blank line between consecutive End statements
74+
Public Class Example
75+
Public Sub Method1()
76+
If condition Then
77+
DoSomething()
78+
End If
79+
80+
End Sub
81+
82+
Public Sub Method2()
83+
' Another method
84+
End Sub
85+
86+
End Class
87+
88+
' Follows IDE2002 - no blank lines between consecutive End statements
89+
Public Class Example
90+
Public Sub Method1()
91+
If condition Then
92+
DoSomething()
93+
End If
94+
End Sub
95+
96+
Public Sub Method2()
97+
' Another method
98+
End Sub
99+
End Class
100+
```
101+
102+
## Suppress a warning
103+
104+
If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
105+
106+
```csharp
107+
#pragma warning disable IDE2002
108+
// The code that's violating the rule is on this line.
109+
#pragma warning restore IDE2002
110+
```
111+
112+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../configuration-files.md).
113+
114+
```ini
115+
[*.{cs,vb}]
116+
dotnet_diagnostic.IDE2002.severity = none
117+
```
118+
119+
To disable all of the code-style rules, set the severity for the category `Style` to `none` in the [configuration file](../configuration-files.md).
120+
121+
```ini
122+
[*.{cs,vb}]
123+
dotnet_analyzer_diagnostic.category-style.severity = none
124+
```
125+
126+
For more information, see [How to suppress code analysis warnings](../suppress-warnings.md).
127+
128+
## See also
129+
130+
- [New-line preferences](language-rules.md#new-line-preferences)
131+
- [Code style language rules](language-rules.md)
132+
- [Code style rules reference](index.md)

0 commit comments

Comments
 (0)