Skip to content

Commit 3feaba5

Browse files
authored
Merge pull request dotnet#20986 from mavasani/RemainingRUles
Document remaining IDExxxx rules
2 parents ab090ad + 5b6189d commit 3feaba5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1972
-88
lines changed

.openpublishing.redirection.json

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,43 +2874,67 @@
28742874
},
28752875
{
28762876
"source_path": "docs/fundamentals/code-analysis/style-rules/ide0003.md",
2877-
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0003-ide0009.md"
2877+
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0003-ide0009"
28782878
},
28792879
{
28802880
"source_path": "docs/fundamentals/code-analysis/style-rules/ide0007.md",
2881-
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0007-ide0008.md"
2881+
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0007-ide0008"
28822882
},
28832883
{
28842884
"source_path": "docs/fundamentals/code-analysis/style-rules/ide0008.md",
2885-
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0007-ide0008.md"
2885+
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0007-ide0008"
28862886
},
28872887
{
28882888
"source_path": "docs/fundamentals/code-analysis/style-rules/ide0009.md",
2889-
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0003-ide0009.md"
2889+
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0003-ide0009"
2890+
},
2891+
{
2892+
"source_path": "docs/fundamentals/code-analysis/style-rules/ide0020.md",
2893+
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0020-ide0038"
28902894
},
28912895
{
28922896
"source_path": "docs/fundamentals/code-analysis/style-rules/ide0023.md",
2893-
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0023-ide0024.md"
2897+
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0023-ide0024"
28942898
},
28952899
{
28962900
"source_path": "docs/fundamentals/code-analysis/style-rules/ide0024.md",
2897-
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0023-ide0024.md"
2901+
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0023-ide0024"
2902+
},
2903+
{
2904+
"source_path": "docs/fundamentals/code-analysis/style-rules/ide0029.md",
2905+
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0029-ide0030"
2906+
},
2907+
{
2908+
"source_path": "docs/fundamentals/code-analysis/style-rules/ide0030.md",
2909+
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0029-ide0030"
2910+
},
2911+
{
2912+
"source_path": "docs/fundamentals/code-analysis/style-rules/ide0038.md",
2913+
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0020-ide0038"
28982914
},
28992915
{
29002916
"source_path": "docs/fundamentals/code-analysis/style-rules/ide0047.md",
2901-
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0047-ide0048.md"
2917+
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0047-ide0048"
29022918
},
29032919
{
29042920
"source_path": "docs/fundamentals/code-analysis/style-rules/ide0048.md",
2905-
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0047-ide0048.md"
2921+
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0047-ide0048"
2922+
},
2923+
{
2924+
"source_path": "docs/fundamentals/code-analysis/style-rules/ide0054.md",
2925+
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0054-ide0074"
29062926
},
29072927
{
29082928
"source_path": "docs/fundamentals/code-analysis/style-rules/ide0055.md",
2909-
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/formatting-rules.md"
2929+
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/formatting-rules"
2930+
},
2931+
{
2932+
"source_path": "docs/fundamentals/code-analysis/style-rules/ide0074.md",
2933+
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0054-ide0074"
29102934
},
29112935
{
29122936
"source_path": "docs/fundamentals/code-analysis/style-rules/ide1006.md",
2913-
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/naming-rules.md"
2937+
"redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/naming-rules"
29142938
},
29152939
{
29162940
"source_path": "docs/fundamentals/productivity/code-analysis.md",

docs/fundamentals/code-analysis/code-style-rule-options.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Code style rules are divided into following subcategories:
2020

2121
- [Language rules](style-rules/language-rules.md)
2222

23+
- [Unnecessary code rules](style-rules/unnecessary-code-rules.md)
24+
2325
- [Formatting rules](style-rules/formatting-rules.md)
2426

2527
- [Naming rules](style-rules/naming-rules.md)

docs/fundamentals/code-analysis/style-rules/expression-level-preferences.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@ dev_langs:
1515

1616
The style rules in this section concern the following expression-level preferences that are common to C# and Visual Basic:
1717

18+
- [Add missing cases to switch statement (IDE0010)](ide0010.md)
1819
- [Use object initializers (IDE0017)](ide0017.md)
1920
- [Use collection initializers (IDE0028)](ide0028.md)
2021
- [Use auto property (IDE0032)](ide0032.md)
2122
- [Use explicitly provided tuple name (IDE0033)](ide0033.md)
2223
- [Use inferred member name (IDE0037)](ide0037.md)
2324
- [Use conditional expression for assignment (IDE0045)](ide0045.md)
2425
- [Use conditional expression for return (IDE0046)](ide0046.md)
25-
- [Use compound assignment (IDE0054)](ide0054.md)
26-
- [Unnecessary value assignment (IDE0059)](ide0059.md)
27-
- [Unused expression value (IDE0058)](ide0058.md)
26+
- [Convert anonymous type to tuple (IDE0050)](ide0050.md)
27+
- [Use compound assignment (IDE0054 and IDE0074)](ide0054-ide0074.md)
28+
- [Use 'System.HashCode.Combine' (IDE0070)](ide0070.md)
29+
- [Simplify interpolation (IDE0071)](ide0071.md)
30+
- [Simplify conditional expression (IDE0075)](ide0075.md)
31+
- [Convert 'typeof' to 'nameof' (IDE0082)](ide0082.md)
2832

2933
## C# expression-level preferences
3034

@@ -36,6 +40,8 @@ The style rules in this section concern the following expression-level preferenc
3640
- [Deconstruct variable declaration (IDE0042)](ide0042.md)
3741
- [Use index operator (IDE0056)](ide0056.md)
3842
- [Use range operator (IDE0057)](ide0057.md)
43+
- [Add missing cases to switch expression (IDE0072)](ide0072.md)
44+
- [Simplify 'new' expression (IDE0090)](ide0090.md)
3945

4046
## See also
4147

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: "IDE0001: Simplify name"
3+
description: "Learn about code analysis rule IDE0001: Simplify name"
4+
ms.date: 09/30/2020
5+
ms.topic: reference
6+
f1_keywords:
7+
- IDE0001
8+
helpviewer_keywords:
9+
- IDE0001
10+
author: gewarren
11+
ms.author: gewarren
12+
dev_langs:
13+
- CSharp
14+
- VB
15+
---
16+
# Simplify name (IDE0001)
17+
18+
|Property|Value|
19+
|-|-|
20+
| **Rule ID** | IDE0001 |
21+
| **Title** | Simplify name |
22+
| **Category** | Style |
23+
| **Subcategory** | Unnecessary code rules |
24+
| **Applicable languages** | C# and Visual Basic |
25+
26+
## Overview
27+
28+
This rule concerns the use of simplified type names in declarations and executable code, when possible. Unnecessary name qualification can be removed to simplify code and improve readability. This rule has no associated code style option.
29+
30+
## Example
31+
32+
```csharp
33+
using System.IO;
34+
class C
35+
{
36+
// IDE0001: 'System.IO.FileInfo' can be simplified to 'FileInfo'
37+
System.IO.FileInfo file;
38+
39+
// Fixed code
40+
FileInfo file;
41+
}
42+
```
43+
44+
```vb
45+
Imports System.IO
46+
Class C
47+
' IDE0001: 'System.IO.FileInfo' can be simplified to 'FileInfo'
48+
Private file As System.IO.FileInfo
49+
50+
' Fixed code
51+
Private file As FileInfo
52+
End Class
53+
```
54+
55+
## See also
56+
57+
- [Simplify member access (IDE0002)](ide0002.md)
58+
- [Unnecessary code rules](unnecessary-code-rules.md)
59+
- [Code style rules reference](index.md)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: "IDE0002: Simplify member access"
3+
description: "Learn about code analysis rule IDE0002: Simplify member access"
4+
ms.date: 09/30/2020
5+
ms.topic: reference
6+
f1_keywords:
7+
- IDE0002
8+
helpviewer_keywords:
9+
- IDE0002
10+
author: gewarren
11+
ms.author: gewarren
12+
dev_langs:
13+
- CSharp
14+
- VB
15+
---
16+
# Simplify member access (IDE0002)
17+
18+
|Property|Value|
19+
|-|-|
20+
| **Rule ID** | IDE0002 |
21+
| **Title** | Simplify member access |
22+
| **Category** | Style |
23+
| **Subcategory** | Unnecessary code rules |
24+
| **Applicable languages** | C# and Visual Basic |
25+
26+
## Overview
27+
28+
This rule concerns use of simplified type member access in declarations and executable code, when possible. Unnecessary qualification can be removed to simplify code and improve readability. This rule has no associated code style option.
29+
30+
## Example
31+
32+
```csharp
33+
static void M1() { }
34+
static void M2()
35+
{
36+
// IDE0002: 'C.M1' can be simplified to 'M1'
37+
C.M1();
38+
39+
// Fixed code
40+
M1();
41+
}
42+
```
43+
44+
```vb
45+
Shared Sub M1()
46+
End Sub
47+
48+
Shared Sub M2()
49+
' IDE0002: 'C.M1' can be simplified to 'M1'
50+
C.M1()
51+
52+
' Fixed code
53+
M1()
54+
End Sub
55+
```
56+
57+
## See also
58+
59+
- [Simplify name (IDE0001)](ide0001.md)
60+
- [Unnecessary code rules](unnecessary-code-rules.md)
61+
- [Code style rules reference](index.md)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: "IDE0004: Remove unnecessary cast"
3+
description: "Learn about code analysis rule IDE0004: Remove unnecessary cast"
4+
ms.date: 09/30/2020
5+
ms.topic: reference
6+
f1_keywords:
7+
- IDE0004
8+
helpviewer_keywords:
9+
- IDE0004
10+
author: gewarren
11+
ms.author: gewarren
12+
dev_langs:
13+
- CSharp
14+
- VB
15+
---
16+
# Remove unnecessary cast (IDE0004)
17+
18+
|Property|Value|
19+
|-|-|
20+
| **Rule ID** | IDE0004 |
21+
| **Title** | Remove unnecessary cast |
22+
| **Category** | Style |
23+
| **Subcategory** | Unnecessary code rules |
24+
| **Applicable languages** | C# and Visual Basic |
25+
26+
## Overview
27+
28+
This rule flags unnecessary [type cast](../../../csharp/programming-guide/types/casting-and-type-conversions.md). A cast expression is unnecessary if the code semantics would be identical with or without it. This rule has no associated code style option.
29+
30+
## Example
31+
32+
```csharp
33+
// Code with violations
34+
int v = (int)0;
35+
36+
// Fixed code
37+
int v = 0;
38+
```
39+
40+
```vb
41+
' Code with violations
42+
Dim v As Integer = CType(0, Integer)
43+
44+
' Fixed code
45+
Dim v As Integer = 0
46+
```
47+
48+
## See also
49+
50+
- [Type cast and conversions](../../../csharp/programming-guide/types/casting-and-type-conversions.md)
51+
- [Unnecessary code rules](unnecessary-code-rules.md)
52+
- [Code style rules reference](index.md)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
title: "IDE0005: Remove unnecessary import"
3+
description: "Learn about code analysis rule IDE0005: Remove unnecessary import"
4+
ms.date: 09/30/2020
5+
ms.topic: reference
6+
f1_keywords:
7+
- IDE0005
8+
helpviewer_keywords:
9+
- IDE0005
10+
author: gewarren
11+
ms.author: gewarren
12+
dev_langs:
13+
- CSharp
14+
- VB
15+
---
16+
# Remove unnecessary import (IDE0005)
17+
18+
|Property|Value|
19+
|-|-|
20+
| **Rule ID** | IDE0005 |
21+
| **Title** | Remove unnecessary import |
22+
| **Category** | Style |
23+
| **Subcategory** | Unnecessary code rules |
24+
| **Applicable languages** | C# and Visual Basic |
25+
26+
## Overview
27+
28+
This rule flags the following unnecessary constructs:
29+
30+
- C# unnecessary [using directive](../../../csharp/language-reference/keywords/using-directive.md).
31+
- C# unnecessary [using static directive](../../../csharp/language-reference/keywords/using-static.md).
32+
- Visual Basic unnecessary [Import](../../../visual-basic/language-reference/statements/imports-statement-net-namespace-and-type.md) statement.
33+
34+
These unnecessary constructs can be removed without changing the semantics of the code. This rule has no associated code style option.
35+
36+
> [!NOTE]
37+
> To enable this [rule on build](../overview.md#code-style-analysis), you need to enable [XML documentation comments](../../../csharp/codedoc.md) for the project. See [this issue](https://github.com/dotnet/roslyn/issues/41640) for more details.
38+
39+
## Example
40+
41+
```csharp
42+
// Code with violations
43+
using System;
44+
using System.IO; // IDE0005: Using directive is unnecessary
45+
class C
46+
{
47+
public static void M()
48+
{
49+
Console.WriteLine("Hello");
50+
}
51+
}
52+
53+
// Fixed code
54+
using System;
55+
class C
56+
{
57+
public static void M()
58+
{
59+
Console.WriteLine("Hello");
60+
}
61+
}
62+
```
63+
64+
```vb
65+
' Code with violations
66+
Imports System.IO ' IDE0005: Imports statement is unnecessary
67+
Class C
68+
Public Shared Sub M()
69+
Console.WriteLine("Hello")
70+
End Sub
71+
End Class
72+
73+
' Fixed code
74+
Class C
75+
Public Shared Sub M()
76+
Console.WriteLine("Hello")
77+
End Sub
78+
End Class
79+
```
80+
81+
## See also
82+
83+
- [C# using directive](../../../csharp/language-reference/keywords/using-directive.md)
84+
- [C# using static directive](../../../csharp/language-reference/keywords/using-static.md)
85+
- [Visual Basic Import statement](../../../visual-basic/language-reference/statements/imports-statement-net-namespace-and-type.md)
86+
- [Unnecessary code rules](unnecessary-code-rules.md)
87+
- [Code style rules reference](index.md)

0 commit comments

Comments
 (0)