-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add ClassicModel Analyzer/CodeFixes for Postive and Negative * Add ClassicModel Analyzer/CodeFixes for (Not)AssignableFrom * "Fix" markdown long lines * Code review changes
- Loading branch information
1 parent
405d2c4
commit b2f4e68
Showing
22 changed files
with
2,047 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# NUnit2051 | ||
|
||
## Consider using Assert.That(expr, Is.Positive) instead of ClassicAssert.Positive(expr) | ||
|
||
| Topic | Value | ||
| :-- | :-- | ||
| Id | NUnit2051 | ||
| Severity | Info | ||
| Enabled | True | ||
| Category | Assertion | ||
| Code | [ClassicModelAssertUsageAnalyzer](https://github.com/nunit/nunit.analyzers/blob/master/src/nunit.analyzers/ClassicModelAssertUsage/ClassicModelAssertUsageAnalyzer.cs) | ||
|
||
## Description | ||
|
||
Consider using the constraint model, `Assert.That(expr, Is.Positive)`, instead of the classic model, | ||
`ClassicAssert.Positive(expr)`. | ||
|
||
## Motivation | ||
|
||
The classic Assert model contains less flexibility than the constraint model, | ||
so this analyzer marks usages of `ClassicAssert.Positive` from the classic Assert model. | ||
|
||
```csharp | ||
[Test] | ||
public void Test() | ||
{ | ||
ClassicAssert.Positive(expression); | ||
} | ||
``` | ||
|
||
## How to fix violations | ||
|
||
The analyzer comes with a code fix that will replace `ClassicAssert.Positive(expression)` with | ||
`Assert.That(expression, Is.Positive)`. So the code block above will be changed into. | ||
|
||
```csharp | ||
[Test] | ||
public void Test() | ||
{ | ||
Assert.That(expression, Is.Positive); | ||
} | ||
``` | ||
|
||
<!-- start generated config severity --> | ||
## Configure severity | ||
|
||
### Via ruleset file | ||
|
||
Configure the severity per project, for more info see | ||
[MSDN](https://learn.microsoft.com/en-us/visualstudio/code-quality/using-rule-sets-to-group-code-analysis-rules?view=vs-2022). | ||
|
||
### Via .editorconfig file | ||
|
||
```ini | ||
# NUnit2051: Consider using Assert.That(expr, Is.Positive) instead of ClassicAssert.Positive(expr) | ||
dotnet_diagnostic.NUnit2051.severity = chosenSeverity | ||
``` | ||
|
||
where `chosenSeverity` can be one of `none`, `silent`, `suggestion`, `warning`, or `error`. | ||
|
||
### Via #pragma directive | ||
|
||
```csharp | ||
#pragma warning disable NUnit2051 // Consider using Assert.That(expr, Is.Positive) instead of ClassicAssert.Positive(expr) | ||
Code violating the rule here | ||
#pragma warning restore NUnit2051 // Consider using Assert.That(expr, Is.Positive) instead of ClassicAssert.Positive(expr) | ||
``` | ||
|
||
Or put this at the top of the file to disable all instances. | ||
|
||
```csharp | ||
#pragma warning disable NUnit2051 // Consider using Assert.That(expr, Is.Positive) instead of ClassicAssert.Positive(expr) | ||
``` | ||
|
||
### Via attribute `[SuppressMessage]` | ||
|
||
```csharp | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Assertion", | ||
"NUnit2051:Consider using Assert.That(expr, Is.Positive) instead of ClassicAssert.Positive(expr)", | ||
Justification = "Reason...")] | ||
``` | ||
<!-- end generated config severity --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# NUnit2052 | ||
|
||
## Consider using Assert.That(expr, Is.Negative) instead of ClassicAssert.Negative(expr) | ||
|
||
| Topic | Value | ||
| :-- | :-- | ||
| Id | NUnit2052 | ||
| Severity | Info | ||
| Enabled | True | ||
| Category | Assertion | ||
| Code | [ClassicModelAssertUsageAnalyzer](https://github.com/nunit/nunit.analyzers/blob/master/src/nunit.analyzers/ClassicModelAssertUsage/ClassicModelAssertUsageAnalyzer.cs) | ||
|
||
## Description | ||
|
||
Consider using the constraint model, `Assert.That(expr, Is.Negative)`, instead of the classic model, | ||
`ClassicAssert.Negative(expr)`. | ||
|
||
## Motivation | ||
|
||
The classic Assert model contains less flexibility than the constraint model, | ||
so this analyzer marks usages of `ClassicAssert.Negative` from the classic Assert model. | ||
|
||
```csharp | ||
[Test] | ||
public void Test() | ||
{ | ||
ClassicAssert.Negative(expression); | ||
} | ||
``` | ||
|
||
## How to fix violations | ||
|
||
The analyzer comes with a code fix that will replace `ClassicAssert.Negative(expression)` with | ||
`Assert.That(expression, Is.Negative)`. So the code block above will be changed into. | ||
|
||
```csharp | ||
[Test] | ||
public void Test() | ||
{ | ||
Assert.That(expression, Is.Negative); | ||
} | ||
``` | ||
|
||
<!-- start generated config severity --> | ||
## Configure severity | ||
|
||
### Via ruleset file | ||
|
||
Configure the severity per project, for more info see | ||
[MSDN](https://learn.microsoft.com/en-us/visualstudio/code-quality/using-rule-sets-to-group-code-analysis-rules?view=vs-2022). | ||
|
||
### Via .editorconfig file | ||
|
||
```ini | ||
# NUnit2052: Consider using Assert.That(expr, Is.Negative) instead of ClassicAssert.Negative(expr) | ||
dotnet_diagnostic.NUnit2052.severity = chosenSeverity | ||
``` | ||
|
||
where `chosenSeverity` can be one of `none`, `silent`, `suggestion`, `warning`, or `error`. | ||
|
||
### Via #pragma directive | ||
|
||
```csharp | ||
#pragma warning disable NUnit2052 // Consider using Assert.That(expr, Is.Negative) instead of ClassicAssert.Negative(expr) | ||
Code violating the rule here | ||
#pragma warning restore NUnit2052 // Consider using Assert.That(expr, Is.Negative) instead of ClassicAssert.Negative(expr) | ||
``` | ||
|
||
Or put this at the top of the file to disable all instances. | ||
|
||
```csharp | ||
#pragma warning disable NUnit2052 // Consider using Assert.That(expr, Is.Negative) instead of ClassicAssert.Negative(expr) | ||
``` | ||
|
||
### Via attribute `[SuppressMessage]` | ||
|
||
```csharp | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Assertion", | ||
"NUnit2052:Consider using Assert.That(expr, Is.Negative) instead of ClassicAssert.Negative(expr)", | ||
Justification = "Reason...")] | ||
``` | ||
<!-- end generated config severity --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# NUnit2053 | ||
|
||
## Consider using Assert.That(actual, Is.AssignableFrom(expected)) instead of ClassicAssert.IsAssignableFrom(expected, actual) | ||
|
||
| Topic | Value | ||
| :-- | :-- | ||
| Id | NUnit2053 | ||
| Severity | Info | ||
| Enabled | True | ||
| Category | Assertion | ||
| Code | [ClassicModelAssertUsageAnalyzer](https://github.com/nunit/nunit.analyzers/blob/master/src/nunit.analyzers/ClassicModelAssertUsage/ClassicModelAssertUsageAnalyzer.cs) | ||
|
||
## Description | ||
|
||
Consider using the constraint model, `Assert.That(actual, Is.AssignableFrom(expected))`, instead of the classic model, | ||
`ClassicAssert.IsAssignableFrom(expected, actual)`. | ||
|
||
## Motivation | ||
|
||
The assert `ClassicAssert.IsAssignableFrom` from the classic Assert model makes it easy to confuse the `expected` and the | ||
`actual` argument, so this analyzer marks usages of `ClassicAssert.IsAssignableFrom`. | ||
|
||
```csharp | ||
[Test] | ||
public void Test() | ||
{ | ||
ClassicAssert.IsAssignableFrom(expected, actual); | ||
} | ||
``` | ||
|
||
## How to fix violations | ||
|
||
The analyzer comes with a code fix that will replace `ClassicAssert.IsAssignableFrom(expected, actual)` with | ||
`Assert.That(actual, Is.AssignableFrom(expected))`. So the code block above will be changed into. | ||
|
||
```csharp | ||
[Test] | ||
public void Test() | ||
{ | ||
Assert.That(actual, Is.AssignableFrom(expected)); | ||
} | ||
``` | ||
|
||
<!-- start generated config severity --> | ||
## Configure severity | ||
|
||
### Via ruleset file | ||
|
||
Configure the severity per project, for more info see | ||
[MSDN](https://learn.microsoft.com/en-us/visualstudio/code-quality/using-rule-sets-to-group-code-analysis-rules?view=vs-2022). | ||
|
||
### Via .editorconfig file | ||
|
||
```ini | ||
# NUnit2053: Consider using Assert.That(actual, Is.AssignableFrom(expected)) instead of ClassicAssert.IsAssignableFrom(expected, actual) | ||
dotnet_diagnostic.NUnit2053.severity = chosenSeverity | ||
``` | ||
|
||
where `chosenSeverity` can be one of `none`, `silent`, `suggestion`, `warning`, or `error`. | ||
|
||
### Via #pragma directive | ||
|
||
```csharp | ||
#pragma warning disable NUnit2053 // Consider using Assert.That(actual, Is.AssignableFrom(expected)) instead of ClassicAssert.IsAssignableFrom(expected, actual) | ||
Code violating the rule here | ||
#pragma warning restore NUnit2053 // Consider using Assert.That(actual, Is.AssignableFrom(expected)) instead of ClassicAssert.IsAssignableFrom(expected, actual) | ||
``` | ||
|
||
Or put this at the top of the file to disable all instances. | ||
|
||
```csharp | ||
#pragma warning disable NUnit2053 // Consider using Assert.That(actual, Is.AssignableFrom(expected)) instead of ClassicAssert.IsAssignableFrom(expected, actual) | ||
``` | ||
|
||
### Via attribute `[SuppressMessage]` | ||
|
||
```csharp | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Assertion", | ||
"NUnit2053:Consider using Assert.That(actual, Is.AssignableFrom(expected)) instead of ClassicAssert.IsAssignableFrom(expected, actual)", | ||
Justification = "Reason...")] | ||
``` | ||
<!-- end generated config severity --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# NUnit2054 | ||
|
||
<!-- markdownlint-disable-next-line MD013 --> | ||
## Consider using Assert.That(actual, Is.Not.AssignableFrom(expected)) instead of ClassicAssert.IsNotAssignableFrom(expected, actual) | ||
|
||
| Topic | Value | ||
| :-- | :-- | ||
| Id | NUnit2054 | ||
| Severity | Info | ||
| Enabled | True | ||
| Category | Assertion | ||
| Code | [ClassicModelAssertUsageAnalyzer](https://github.com/nunit/nunit.analyzers/blob/master/src/nunit.analyzers/ClassicModelAssertUsage/ClassicModelAssertUsageAnalyzer.cs) | ||
|
||
## Description | ||
|
||
Consider using the constraint model, `Assert.That(actual, Is.Not.AssignableFrom(expected))`, instead of the classic model, | ||
`ClassicAssert.IsNotAssignableFrom(expected, actual)`. | ||
|
||
## Motivation | ||
|
||
The assert `ClassicAssert.IsNotAssignableFrom` from the classic Assert model makes it easy to confuse the `expected` | ||
and the `actual` argument, so this analyzer marks usages of `ClassicAssert.IsNotAssignableFrom`. | ||
|
||
```csharp | ||
[Test] | ||
public void Test() | ||
{ | ||
ClassicAssert.IsNotAssignableFrom(expected, actual); | ||
} | ||
``` | ||
|
||
## How to fix violations | ||
|
||
The analyzer comes with a code fix that will replace `ClassicAssert.IsNotAssignableFrom(expected, actual)` with | ||
`Assert.That(actual, Is.Not.AssignableFrom(expected))`. So the code block above will be changed into. | ||
|
||
```csharp | ||
[Test] | ||
public void Test() | ||
{ | ||
Assert.That(actual, Is.Not.AssignableFrom(expected)); | ||
} | ||
``` | ||
|
||
<!-- start generated config severity --> | ||
## Configure severity | ||
|
||
### Via ruleset file | ||
|
||
Configure the severity per project, for more info see | ||
[MSDN](https://learn.microsoft.com/en-us/visualstudio/code-quality/using-rule-sets-to-group-code-analysis-rules?view=vs-2022). | ||
|
||
### Via .editorconfig file | ||
|
||
```ini | ||
# NUnit2054: Consider using Assert.That(actual, Is.Not.AssignableFrom(expected)) instead of ClassicAssert.IsNotAssignableFrom(expected, actual) | ||
dotnet_diagnostic.NUnit2054.severity = chosenSeverity | ||
``` | ||
|
||
where `chosenSeverity` can be one of `none`, `silent`, `suggestion`, `warning`, or `error`. | ||
|
||
### Via #pragma directive | ||
|
||
```csharp | ||
#pragma warning disable NUnit2054 // Consider using Assert.That(actual, Is.Not.AssignableFrom(expected)) instead of ClassicAssert.IsNotAssignableFrom(expected, actual) | ||
Code violating the rule here | ||
#pragma warning restore NUnit2054 // Consider using Assert.That(actual, Is.Not.AssignableFrom(expected)) instead of ClassicAssert.IsNotAssignableFrom(expected, actual) | ||
``` | ||
|
||
Or put this at the top of the file to disable all instances. | ||
|
||
```csharp | ||
#pragma warning disable NUnit2054 // Consider using Assert.That(actual, Is.Not.AssignableFrom(expected)) instead of ClassicAssert.IsNotAssignableFrom(expected, actual) | ||
``` | ||
|
||
### Via attribute `[SuppressMessage]` | ||
|
||
```csharp | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Assertion", | ||
"NUnit2054:Consider using Assert.That(actual, Is.Not.AssignableFrom(expected)) instead of ClassicAssert.IsNotAssignableFrom(expected, actual)", | ||
Justification = "Reason...")] | ||
``` | ||
<!-- end generated config severity --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.