Skip to content

Commit fc63e67

Browse files
authored
Document IDE2000-2006 newline preference rules (#48011)
1 parent 02d57e4 commit fc63e67

File tree

10 files changed

+686
-7
lines changed

10 files changed

+686
-7
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: "IDE2000: Avoid multiple blank lines"
3+
description: "Learn about code analysis rule IDE2000: Avoid multiple blank lines"
4+
ms.date: 08/19/2025
5+
f1_keywords:
6+
- IDE2000
7+
helpviewer_keywords:
8+
- IDE2000
9+
dev_langs:
10+
- CSharp
11+
ai-usage: ai-assisted
12+
---
13+
# Avoid multiple blank lines (IDE2000)
14+
15+
| Property | Value |
16+
|--------------------------|--------------------------------------------------------|
17+
| **Rule ID** | IDE2000 |
18+
| **Title** | Avoid multiple blank lines |
19+
| **Category** | Style |
20+
| **Subcategory** | Language rules (new-line preferences) |
21+
| **Applicable languages** | C# and Visual Basic |
22+
| **Options** | `dotnet_style_allow_multiple_blank_lines_experimental` |
23+
24+
> [!NOTE]
25+
> This rule is experimental and subject to change or removal.
26+
27+
## Overview
28+
29+
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.
30+
31+
## Options
32+
33+
Options specify the behavior that you want the rule to enforce. For information about configuring options, see [Option format](language-rules.md#option-format).
34+
35+
### dotnet_style_allow_multiple_blank_lines_experimental
36+
37+
| Property | Value | Description |
38+
|--------------------------|--------------------------------------------------------|-------------|
39+
| **Option name** | `dotnet_style_allow_multiple_blank_lines_experimental` | |
40+
| **Option values** | `true` | Allow multiple consecutive blank lines |
41+
| | `false` | Don't allow consecutive blank lines |
42+
| **Default option value** | `true` | |
43+
44+
## Example
45+
46+
```csharp
47+
// dotnet_style_allow_multiple_blank_lines_experimental = true
48+
if (true)
49+
{
50+
DoWork();
51+
}
52+
53+
54+
return;
55+
```
56+
57+
```csharp
58+
// dotnet_style_allow_multiple_blank_lines_experimental = false
59+
if (true)
60+
{
61+
DoWork();
62+
}
63+
64+
return;
65+
```
66+
67+
## Suppress a warning
68+
69+
If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
70+
71+
```csharp
72+
#pragma warning disable IDE2000
73+
// The code that's violating the rule is on this line.
74+
#pragma warning restore IDE2000
75+
```
76+
77+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../configuration-files.md).
78+
79+
```ini
80+
[*.{cs,vb}]
81+
dotnet_diagnostic.IDE2000.severity = none
82+
```
83+
84+
To disable all of the code-style rules, set the severity for the category `Style` to `none` in the [configuration file](../configuration-files.md).
85+
86+
```ini
87+
[*.{cs,vb}]
88+
dotnet_analyzer_diagnostic.category-style.severity = none
89+
```
90+
91+
For more information, see [How to suppress code analysis warnings](../suppress-warnings.md).
92+
93+
## See also
94+
95+
- [New-line preferences](language-rules.md#new-line-preferences)
96+
- [Code style language rules](language-rules.md)
97+
- [Code style rules reference](index.md)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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: 08/19/2025
5+
f1_keywords:
6+
- IDE2001
7+
helpviewer_keywords:
8+
- IDE2001
9+
dev_langs:
10+
- CSharp
11+
- VB
12+
ai-usage: ai-assisted
13+
---
14+
# Embedded statements must be on their own line (IDE2001)
15+
16+
| Property | Value |
17+
|--------------------------|--------------------------------------------------------------------|
18+
| **Rule ID** | IDE2001 |
19+
| **Title** | Embedded statements must be on their own line |
20+
| **Category** | Style |
21+
| **Subcategory** | Language rules (new-line preferences) |
22+
| **Applicable languages** | C# |
23+
| **Options** | `csharp_style_allow_embedded_statements_on_same_line_experimental` |
24+
25+
> [!NOTE]
26+
> This rule is experimental and subject to change or removal.
27+
28+
## Overview
29+
30+
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.
31+
32+
## Options
33+
34+
Options specify the behavior that you want the rule to enforce. For information about configuring options, see [Option format](language-rules.md#option-format).
35+
36+
### csharp_style_allow_embedded_statements_on_same_line_experimental
37+
38+
| Property | Value | Description |
39+
|--------------------------|----------------------------------------------|-------------|
40+
| **Option name** | `csharp_style_allow_embedded_statements_on_same_line_experimental` | |
41+
| **Option values** | `true` | Allow embedded statements on same line as control keyword |
42+
| | `false` | Require embedded statements to be on their own line |
43+
| **Default option value** | `true` | |
44+
45+
## Example
46+
47+
```csharp
48+
// csharp_style_allow_embedded_statements_on_same_line_experimental = true
49+
for (int i = 0; i < 10; i++) Console.WriteLine(i);
50+
```
51+
52+
```csharp
53+
// csharp_style_allow_embedded_statements_on_same_line_experimental = false
54+
for (int i = 0; i < 10; i++)
55+
Console.WriteLine(i);
56+
```
57+
58+
## Suppress a warning
59+
60+
If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
61+
62+
```csharp
63+
#pragma warning disable IDE2001
64+
// The code that's violating the rule is on this line.
65+
#pragma warning restore IDE2001
66+
```
67+
68+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../configuration-files.md).
69+
70+
```ini
71+
[*.{cs,vb}]
72+
dotnet_diagnostic.IDE2001.severity = none
73+
```
74+
75+
To disable all of the code-style rules, set the severity for the category `Style` to `none` in the [configuration file](../configuration-files.md).
76+
77+
```ini
78+
[*.{cs,vb}]
79+
dotnet_analyzer_diagnostic.category-style.severity = none
80+
```
81+
82+
For more information, see [How to suppress code analysis warnings](../suppress-warnings.md).
83+
84+
## See also
85+
86+
- [New-line preferences](language-rules.md#new-line-preferences)
87+
- [Code style language rules](language-rules.md)
88+
- [Code style rules reference](index.md)
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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: 08/19/2025
5+
f1_keywords:
6+
- IDE2002
7+
helpviewer_keywords:
8+
- IDE2002
9+
dev_langs:
10+
- CSharp
11+
ai-usage: ai-assisted
12+
---
13+
# Consecutive braces must not have blank line between them (IDE2002)
14+
15+
| Property | Value |
16+
|--------------------------|--------------------------------------------------------------------------|
17+
| **Rule ID** | IDE2002 |
18+
| **Title** | Consecutive braces must not have blank line between them |
19+
| **Category** | Style |
20+
| **Subcategory** | Language rules (new-line preferences) |
21+
| **Applicable languages** | C# |
22+
| **Options** | `csharp_style_allow_blank_lines_between_consecutive_braces_experimental` |
23+
24+
> [!NOTE]
25+
> This rule is experimental and subject to change or removal.
26+
27+
## Overview
28+
29+
This style rule enforces that consecutive braces should not have blank lines between them. This helps maintain consistent and clean code formatting.
30+
31+
## Options
32+
33+
Options specify the behavior that you want the rule to enforce. For information about configuring options, see [Option format](language-rules.md#option-format).
34+
35+
### csharp_style_allow_blank_lines_between_consecutive_braces_experimental
36+
37+
| Property | Value | Description |
38+
|--------------------------|----------------------------------------------|-------------|
39+
| **Option name** | `csharp_style_allow_blank_lines_between_consecutive_braces_experimental` | |
40+
| **Option values** | `true` | Allow blank lines between consecutive braces |
41+
| | `false` | Don't allow blank lines between consecutive braces |
42+
| **Default option value** | `true` | |
43+
44+
## Example
45+
46+
```csharp
47+
// csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true
48+
public void Method
49+
{
50+
if (true)
51+
{
52+
DoWork();
53+
}
54+
55+
}
56+
```
57+
58+
```csharp
59+
// csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false
60+
public void Method
61+
{
62+
if (true)
63+
{
64+
DoWork();
65+
}
66+
}
67+
```
68+
69+
## Suppress a warning
70+
71+
If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
72+
73+
```csharp
74+
#pragma warning disable IDE2002
75+
// The code that's violating the rule is on this line.
76+
#pragma warning restore IDE2002
77+
```
78+
79+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../configuration-files.md).
80+
81+
```ini
82+
[*.{cs,vb}]
83+
dotnet_diagnostic.IDE2002.severity = none
84+
```
85+
86+
To disable all of the code-style rules, set the severity for the category `Style` to `none` in the [configuration file](../configuration-files.md).
87+
88+
```ini
89+
[*.{cs,vb}]
90+
dotnet_analyzer_diagnostic.category-style.severity = none
91+
```
92+
93+
For more information, see [How to suppress code analysis warnings](../suppress-warnings.md).
94+
95+
## See also
96+
97+
- [New-line preferences](language-rules.md#new-line-preferences)
98+
- [Code style language rules](language-rules.md)
99+
- [Code style rules reference](index.md)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: "IDE2003: Blank line required between block and subsequent statement"
3+
description: "Learn about code analysis rule IDE2003: Blank line required between block and subsequent statement"
4+
ms.date: 08/19/2025
5+
f1_keywords:
6+
- IDE2003
7+
helpviewer_keywords:
8+
- IDE2003
9+
dev_langs:
10+
- CSharp
11+
ai-usage: ai-assisted
12+
---
13+
# Blank line required between block and subsequent statement (IDE2003)
14+
15+
| Property | Value |
16+
|--------------------------|---------------------------------------------------------------------|
17+
| **Rule ID** | IDE2003 |
18+
| **Title** | Blank line required between block and subsequent statement |
19+
| **Category** | Style |
20+
| **Subcategory** | Language rules (new-line preferences) |
21+
| **Applicable languages** | C# and Visual Basic |
22+
| **Options** | `dotnet_style_allow_statement_immediately_after_block_experimental` |
23+
24+
> [!NOTE]
25+
> This rule is experimental and subject to change or removal.
26+
27+
## Overview
28+
29+
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.
30+
31+
## Options
32+
33+
Options specify the behavior that you want the rule to enforce. For information about configuring options, see [Option format](language-rules.md#option-format).
34+
35+
### dotnet_style_allow_statement_immediately_after_block_experimental
36+
37+
| Property | Value | Description |
38+
|--------------------------|----------------------------------------------|-------------|
39+
| **Option name** | `dotnet_style_allow_statement_immediately_after_block_experimental` | |
40+
| **Option values** | `true` | Allow subsequent statement to immediately follow block statement without a blank line in between |
41+
| | `false` | Require a blank line between a block statement and the subsequent statement |
42+
| **Default option value** | `true` | |
43+
44+
## Example
45+
46+
```csharp
47+
// dotnet_style_allow_statement_immediately_after_block_experimental = true
48+
if (true)
49+
{
50+
DoWork();
51+
}
52+
return;
53+
```
54+
55+
```csharp
56+
// dotnet_style_allow_statement_immediately_after_block_experimental = false
57+
if (true)
58+
{
59+
DoWork();
60+
}
61+
62+
return;
63+
```
64+
65+
## Suppress a warning
66+
67+
If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
68+
69+
```csharp
70+
#pragma warning disable IDE2003
71+
// The code that's violating the rule is on this line.
72+
#pragma warning restore IDE2003
73+
```
74+
75+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../configuration-files.md).
76+
77+
```ini
78+
[*.{cs,vb}]
79+
dotnet_diagnostic.IDE2003.severity = none
80+
```
81+
82+
To disable all of the code-style rules, set the severity for the category `Style` to `none` in the [configuration file](../configuration-files.md).
83+
84+
```ini
85+
[*.{cs,vb}]
86+
dotnet_analyzer_diagnostic.category-style.severity = none
87+
```
88+
89+
For more information, see [How to suppress code analysis warnings](../suppress-warnings.md).
90+
91+
## See also
92+
93+
- [New-line preferences](language-rules.md#new-line-preferences)
94+
- [Code style language rules](language-rules.md)
95+
- [Code style rules reference](index.md)

0 commit comments

Comments
 (0)