Skip to content

Commit 462d811

Browse files
authoredJan 17, 2025··
MSTest analyzers: document suppressing warning (#44277)
* MSTest analyzers: document suppressing warning * Suppressors cannot be suppressed
1 parent 58988ce commit 462d811

37 files changed

+643
-3
lines changed
 

‎docs/core/testing/mstest-analyzers/mstest0001.md

+13
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,16 @@ To fix a violation of this rule, add `[assembly: Parallelize]` or `[assembly: Do
4444
## When to suppress warnings
4545

4646
Do not suppress a warning from this rule. Many libraries can benefit from a massive performance boost when enabling parallelization. When the test application is designed in a way that prevents parallelization, having the attribute explicitly set helps new developers to understand the limitations of the library.
47+
48+
## Suppress a warning
49+
50+
Violations to this rule cannot be suppressed inline.
51+
52+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../../../fundamentals/code-analysis/configuration-files.md).
53+
54+
```ini
55+
[*.{cs,vb}]
56+
dotnet_diagnostic.MSTEST0001.severity = none
57+
```
58+
59+
For more information, see [How to suppress code analysis warnings](../../../fundamentals/code-analysis/suppress-warnings.md).

‎docs/core/testing/mstest-analyzers/mstest0002.md

+19
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,22 @@ Ensure that the class matches the required layout described above.
4646
## When to suppress warnings
4747

4848
Do not suppress a warning from this rule. Ignoring this rule will result in tests being ignored, because MSTest will not consider this class to be a test class.
49+
50+
## Suppress a warning
51+
52+
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
53+
54+
```csharp
55+
#pragma warning disable MSTEST0002
56+
// The code that's violating the rule is on this line.
57+
#pragma warning restore MSTEST0002
58+
```
59+
60+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../../../fundamentals/code-analysis/configuration-files.md).
61+
62+
```ini
63+
[*.{cs,vb}]
64+
dotnet_diagnostic.MSTEST0002.severity = none
65+
```
66+
67+
For more information, see [How to suppress code analysis warnings](../../../fundamentals/code-analysis/suppress-warnings.md).

‎docs/core/testing/mstest-analyzers/mstest0003.md

+19
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,22 @@ Ensure that the test method matches the required layout described above.
5151
## When to suppress warnings
5252

5353
Do not suppress a warning from this rule. Ignoring this rule will result in tests being ignored, because MSTest will not consider this method to be a test method.
54+
55+
## Suppress a warning
56+
57+
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
58+
59+
```csharp
60+
#pragma warning disable MSTEST0003
61+
// The code that's violating the rule is on this line.
62+
#pragma warning restore MSTEST0003
63+
```
64+
65+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../../../fundamentals/code-analysis/configuration-files.md).
66+
67+
```ini
68+
[*.{cs,vb}]
69+
dotnet_diagnostic.MSTEST0003.severity = none
70+
```
71+
72+
For more information, see [How to suppress code analysis warnings](../../../fundamentals/code-analysis/suppress-warnings.md).

‎docs/core/testing/mstest-analyzers/mstest0004.md

+19
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,22 @@ Change the accessibility of the type to not be `public`.
4242
## When to suppress warnings
4343

4444
You can suppress instances of this diagnostic if the type should remain `public` for compatibility reason.
45+
46+
## Suppress a warning
47+
48+
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
49+
50+
```csharp
51+
#pragma warning disable MSTEST0004
52+
// The code that's violating the rule is on this line.
53+
#pragma warning restore MSTEST0004
54+
```
55+
56+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../../../fundamentals/code-analysis/configuration-files.md).
57+
58+
```ini
59+
[*.{cs,vb}]
60+
dotnet_diagnostic.MSTEST0004.severity = none
61+
```
62+
63+
For more information, see [How to suppress code analysis warnings](../../../fundamentals/code-analysis/suppress-warnings.md).

‎docs/core/testing/mstest-analyzers/mstest0005.md

+19
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,22 @@ Ensure that the `TestContext` property matches the required layout described abo
4848
## When to suppress warnings
4949

5050
Do not suppress a warning from this rule. Ignoring this rule will result in the `TestContext` not being injected by MSTest, thus resulting in `NullReferenceException` or inconsistent state when using the property.
51+
52+
## Suppress a warning
53+
54+
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
55+
56+
```csharp
57+
#pragma warning disable MSTEST0005
58+
// The code that's violating the rule is on this line.
59+
#pragma warning restore MSTEST0005
60+
```
61+
62+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../../../fundamentals/code-analysis/configuration-files.md).
63+
64+
```ini
65+
[*.{cs,vb}]
66+
dotnet_diagnostic.MSTEST0005.severity = none
67+
```
68+
69+
For more information, see [How to suppress code analysis warnings](../../../fundamentals/code-analysis/suppress-warnings.md).

‎docs/core/testing/mstest-analyzers/mstest0006.md

+19
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,22 @@ public class TestClass
9898
}
9999
}
100100
```
101+
102+
## Suppress a warning
103+
104+
If you just want to suppress 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 MSTEST0006
108+
// The code that's violating the rule is on this line.
109+
#pragma warning restore MSTEST0006
110+
```
111+
112+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../../../fundamentals/code-analysis/configuration-files.md).
113+
114+
```ini
115+
[*.{cs,vb}]
116+
dotnet_diagnostic.MSTEST0006.severity = none
117+
```
118+
119+
For more information, see [How to suppress code analysis warnings](../../../fundamentals/code-analysis/suppress-warnings.md).

‎docs/core/testing/mstest-analyzers/mstest0007.md

+19
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,22 @@ To fix a violation of this rule, either convert the method on which you applied
4848
## When to suppress warnings
4949

5050
Do not suppress a warning from this rule. If you ignore this rule, your attributes will be ignored since they are designed for use only in a test context.
51+
52+
## Suppress a warning
53+
54+
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
55+
56+
```csharp
57+
#pragma warning disable MSTEST0007
58+
// The code that's violating the rule is on this line.
59+
#pragma warning restore MSTEST0007
60+
```
61+
62+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../../../fundamentals/code-analysis/configuration-files.md).
63+
64+
```ini
65+
[*.{cs,vb}]
66+
dotnet_diagnostic.MSTEST0007.severity = none
67+
```
68+
69+
For more information, see [How to suppress code analysis warnings](../../../fundamentals/code-analysis/suppress-warnings.md).

‎docs/core/testing/mstest-analyzers/mstest0008.md

+19
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,22 @@ Ensure that the method matches the layout described above.
5050
## When to suppress warnings
5151

5252
Do not suppress a warning from this rule. If you ignore this rule, flagged instances will be either skipped or result in runtime error.
53+
54+
## Suppress a warning
55+
56+
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
57+
58+
```csharp
59+
#pragma warning disable MSTEST0008
60+
// The code that's violating the rule is on this line.
61+
#pragma warning restore MSTEST0008
62+
```
63+
64+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../../../fundamentals/code-analysis/configuration-files.md).
65+
66+
```ini
67+
[*.{cs,vb}]
68+
dotnet_diagnostic.MSTEST0008.severity = none
69+
```
70+
71+
For more information, see [How to suppress code analysis warnings](../../../fundamentals/code-analysis/suppress-warnings.md).

‎docs/core/testing/mstest-analyzers/mstest0009.md

+19
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,22 @@ Ensure that the method matches the layout described above.
5050
## When to suppress warnings
5151

5252
Do not suppress a warning from this rule. If you ignore this rule, flagged instances will be either skipped or result in runtime error.
53+
54+
## Suppress a warning
55+
56+
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
57+
58+
```csharp
59+
#pragma warning disable MSTEST0009
60+
// The code that's violating the rule is on this line.
61+
#pragma warning restore MSTEST0009
62+
```
63+
64+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../../../fundamentals/code-analysis/configuration-files.md).
65+
66+
```ini
67+
[*.{cs,vb}]
68+
dotnet_diagnostic.MSTEST0009.severity = none
69+
```
70+
71+
For more information, see [How to suppress code analysis warnings](../../../fundamentals/code-analysis/suppress-warnings.md).

‎docs/core/testing/mstest-analyzers/mstest0010.md

+19
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,22 @@ Ensure that the method matches the layout described above.
5454
## When to suppress warnings
5555

5656
Do not suppress a warning from this rule. If you ignore this rule, flagged instances will be either skipped or result in runtime error.
57+
58+
## Suppress a warning
59+
60+
If you just want to suppress 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 MSTEST0010
64+
// The code that's violating the rule is on this line.
65+
#pragma warning restore MSTEST0010
66+
```
67+
68+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../../../fundamentals/code-analysis/configuration-files.md).
69+
70+
```ini
71+
[*.{cs,vb}]
72+
dotnet_diagnostic.MSTEST0010.severity = none
73+
```
74+
75+
For more information, see [How to suppress code analysis warnings](../../../fundamentals/code-analysis/suppress-warnings.md).

‎docs/core/testing/mstest-analyzers/mstest0011.md

+19
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,22 @@ Ensure that the method matches the layout described above.
5454
## When to suppress warnings
5555

5656
Do not suppress a warning from this rule. If you ignore this rule, flagged instances will be either skipped or result in runtime error.
57+
58+
## Suppress a warning
59+
60+
If you just want to suppress 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 MSTEST0011
64+
// The code that's violating the rule is on this line.
65+
#pragma warning restore MSTEST0011
66+
```
67+
68+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../../../fundamentals/code-analysis/configuration-files.md).
69+
70+
```ini
71+
[*.{cs,vb}]
72+
dotnet_diagnostic.MSTEST0011.severity = none
73+
```
74+
75+
For more information, see [How to suppress code analysis warnings](../../../fundamentals/code-analysis/suppress-warnings.md).

‎docs/core/testing/mstest-analyzers/mstest0012.md

+19
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,22 @@ Ensure that the method matches the layout described above.
5656
## When to suppress warnings
5757

5858
Do not suppress a warning from this rule. If you ignore this rule, flagged instances will be either skipped or result in runtime error.
59+
60+
## Suppress a warning
61+
62+
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
63+
64+
```csharp
65+
#pragma warning disable MSTEST0012
66+
// The code that's violating the rule is on this line.
67+
#pragma warning restore MSTEST0012
68+
```
69+
70+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../../../fundamentals/code-analysis/configuration-files.md).
71+
72+
```ini
73+
[*.{cs,vb}]
74+
dotnet_diagnostic.MSTEST0012.severity = none
75+
```
76+
77+
For more information, see [How to suppress code analysis warnings](../../../fundamentals/code-analysis/suppress-warnings.md).

‎docs/core/testing/mstest-analyzers/mstest0013.md

+19
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,22 @@ Ensure that the method matches the layout described above.
5656
## When to suppress warnings
5757

5858
Do not suppress a warning from this rule. If you ignore this rule, flagged instances will be either skipped or result in runtime error.
59+
60+
## Suppress a warning
61+
62+
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
63+
64+
```csharp
65+
#pragma warning disable MSTEST0013
66+
// The code that's violating the rule is on this line.
67+
#pragma warning restore MSTEST0013
68+
```
69+
70+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../../../fundamentals/code-analysis/configuration-files.md).
71+
72+
```ini
73+
[*.{cs,vb}]
74+
dotnet_diagnostic.MSTEST0013.severity = none
75+
```
76+
77+
For more information, see [How to suppress code analysis warnings](../../../fundamentals/code-analysis/suppress-warnings.md).

‎docs/core/testing/mstest-analyzers/mstest0014.md

+19
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,22 @@ Ensure that the `DataRow` instance matches the required layout described above.
4343
## When to suppress warnings
4444

4545
Do not suppress a warning from this rule. If you ignore this rule, flagged instances will be either skipped or result in runtime error.
46+
47+
## Suppress a warning
48+
49+
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
50+
51+
```csharp
52+
#pragma warning disable MSTEST0014
53+
// The code that's violating the rule is on this line.
54+
#pragma warning restore MSTEST0014
55+
```
56+
57+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../../../fundamentals/code-analysis/configuration-files.md).
58+
59+
```ini
60+
[*.{cs,vb}]
61+
dotnet_diagnostic.MSTEST0014.severity = none
62+
```
63+
64+
For more information, see [How to suppress code analysis warnings](../../../fundamentals/code-analysis/suppress-warnings.md).

‎docs/core/testing/mstest-analyzers/mstest0015.md

+19
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,22 @@ Ensure that the test method isn't ignored.
3939
## When to suppress warnings
4040

4141
Do not suppress a warning from this rule. If you ignore this rule, test method will be ignored.
42+
43+
## Suppress a warning
44+
45+
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
46+
47+
```csharp
48+
#pragma warning disable MSTEST0015
49+
// The code that's violating the rule is on this line.
50+
#pragma warning restore MSTEST0015
51+
```
52+
53+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../../../fundamentals/code-analysis/configuration-files.md).
54+
55+
```ini
56+
[*.{cs,vb}]
57+
dotnet_diagnostic.MSTEST0015.severity = none
58+
```
59+
60+
For more information, see [How to suppress code analysis warnings](../../../fundamentals/code-analysis/suppress-warnings.md).

‎docs/core/testing/mstest-analyzers/mstest0016.md

+19
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,22 @@ Ensure that the test class has a test method or is `static` and has methods attr
3939
## When to suppress warnings
4040

4141
Do not suppress a warning from this rule. If you ignore this rule, test class will be ignored.
42+
43+
## Suppress a warning
44+
45+
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
46+
47+
```csharp
48+
#pragma warning disable MSTEST0016
49+
// The code that's violating the rule is on this line.
50+
#pragma warning restore MSTEST0016
51+
```
52+
53+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../../../fundamentals/code-analysis/configuration-files.md).
54+
55+
```ini
56+
[*.{cs,vb}]
57+
dotnet_diagnostic.MSTEST0016.severity = none
58+
```
59+
60+
For more information, see [How to suppress code analysis warnings](../../../fundamentals/code-analysis/suppress-warnings.md).

‎docs/core/testing/mstest-analyzers/mstest0017.md

+19
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,22 @@ Ensure that that `actual` and `expected`/`notExpected` arguments are passed in t
4646
## When to suppress warnings
4747

4848
Do not suppress a warning from this rule as it would result to misleading output.
49+
50+
## Suppress a warning
51+
52+
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
53+
54+
```csharp
55+
#pragma warning disable MSTEST0017
56+
// The code that's violating the rule is on this line.
57+
#pragma warning restore MSTEST0017
58+
```
59+
60+
To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../../../fundamentals/code-analysis/configuration-files.md).
61+
62+
```ini
63+
[*.{cs,vb}]
64+
dotnet_diagnostic.MSTEST0017.severity = none
65+
```
66+
67+
For more information, see [How to suppress code analysis warnings](../../../fundamentals/code-analysis/suppress-warnings.md).

0 commit comments

Comments
 (0)
Please sign in to comment.