Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions docs/fundamentals/code-analysis/style-rules/ide2000.md
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
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
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)
102 changes: 102 additions & 0 deletions docs/fundamentals/code-analysis/style-rules/ide2001.md
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.

[!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)
132 changes: 132 additions & 0 deletions docs/fundamentals/code-analysis/style-rules/ide2002.md
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)
Loading
Loading