Skip to content

Commit

Permalink
Rule S2701: Literal boolean values should not be used in assertions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
michalb-sonar authored Aug 25, 2017
1 parent feb4016 commit ffd6451
Show file tree
Hide file tree
Showing 12 changed files with 5,575 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"issues": [
{
"id": "S2701",
"message": "Remove or correct this assertion.",
"location": {
"uri": "sources\Nancy\src\Nancy.Testing.Tests\BrowserFixture.cs",
"region": {
"startLine": 462,
"startColumn": 13,
"endLine": 462,
"endColumn": 56
}
}
},
{
"id": "S2701",
"message": "Remove or correct this assertion.",
"location": {
"uri": "sources\Nancy\src\Nancy.Testing.Tests\BrowserFixture.cs",
"region": {
"startLine": 484,
"startColumn": 13,
"endLine": 484,
"endColumn": 56
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"issues": [
{
"id": "S2701",
"message": "Remove or correct this assertion.",
"location": {
"uri": "sources\Nancy\src\Nancy.Tests.Functional\Tests\SerializeTests.cs",
"region": {
"startLine": 44,
"startColumn": 13,
"endLine": 44,
"endColumn": 56
}
}
},
{
"id": "S2701",
"message": "Remove or correct this assertion.",
"location": {
"uri": "sources\Nancy\src\Nancy.Tests.Functional\Tests\SerializeTests.cs",
"region": {
"startLine": 66,
"startColumn": 13,
"endLine": 66,
"endColumn": 56
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"issues": [
{
"id": "S2701",
"message": "Remove or correct this assertion.",
"location": {
"uri": "sources\akka.net\src\core\Akka.Cluster.Tests\MetricsCollectorSpec.cs",
"region": {
"startLine": 57,
"startColumn": 25,
"endLine": 57,
"endColumn": 82
}
}
},
{
"id": "S2701",
"message": "Remove or correct this assertion.",
"location": {
"uri": "sources\akka.net\src\core\Akka.Cluster.Tests\MetricsCollectorSpec.cs",
"region": {
"startLine": 75,
"startColumn": 25,
"endLine": 75,
"endColumn": 82
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"issues": [
{
"id": "S2701",
"message": "Remove or correct this assertion.",
"location": {
"uri": "sources\akka.net\src\core\Akka.Tests\Configuration\ConfigurationSpec.cs",
"region": {
"startLine": 43,
"startColumn": 13,
"endLine": 43,
"endColumn": 66
}
}
},
{
"id": "S2701",
"message": "Remove or correct this assertion.",
"location": {
"uri": "sources\akka.net\src\core\Akka.Tests\Configuration\HoconTests.cs",
"region": {
"startLine": 119,
"startColumn": 13,
"endLine": 119,
"endColumn": 60
}
}
},
{
"id": "S2701",
"message": "Remove or correct this assertion.",
"location": {
"uri": "sources\akka.net\src\core\Akka.Tests\Configuration\HoconTests.cs",
"region": {
"startLine": 152,
"startColumn": 13,
"endLine": 152,
"endColumn": 63
}
}
},
{
"id": "S2701",
"message": "Remove or correct this assertion.",
"location": {
"uri": "sources\akka.net\src\core\Akka.Tests\Configuration\HoconTests.cs",
"region": {
"startLine": 153,
"startColumn": 13,
"endLine": 153,
"endColumn": 76
}
}
},
{
"id": "S2701",
"message": "Remove or correct this assertion.",
"location": {
"uri": "sources\akka.net\src\core\Akka.Tests\Configuration\HoconTests.cs",
"region": {
"startLine": 187,
"startColumn": 13,
"endLine": 187,
"endColumn": 63
}
}
},
{
"id": "S2701",
"message": "Remove or correct this assertion.",
"location": {
"uri": "sources\akka.net\src\core\Akka.Tests\Configuration\HoconTests.cs",
"region": {
"startLine": 188,
"startColumn": 13,
"endLine": 188,
"endColumn": 76
}
}
},
{
"id": "S2701",
"message": "Remove or correct this assertion.",
"location": {
"uri": "sources\akka.net\src\core\Akka.Tests\Configuration\HoconTests.cs",
"region": {
"startLine": 358,
"startColumn": 13,
"endLine": 358,
"endColumn": 88
}
}
},
{
"id": "S2701",
"message": "Remove or correct this assertion.",
"location": {
"uri": "sources\akka.net\src\core\Akka.Tests\Configuration\HoconTests.cs",
"region": {
"startLine": 360,
"startColumn": 13,
"endLine": 360,
"endColumn": 89
}
}
},
{
"id": "S2701",
"message": "Remove or correct this assertion.",
"location": {
"uri": "sources\akka.net\src\core\Akka.Tests\Configuration\HoconTests.cs",
"region": {
"startLine": 363,
"startColumn": 13,
"endLine": 363,
"endColumn": 88
}
}
},
{
"id": "S2701",
"message": "Remove or correct this assertion.",
"location": {
"uri": "sources\akka.net\src\core\Akka.Tests\Configuration\HoconTests.cs",
"region": {
"startLine": 365,
"startColumn": 13,
"endLine": 365,
"endColumn": 89
}
}
}
]
}
10 changes: 10 additions & 0 deletions sonaranalyzer-dotnet/rspec/cs/S2701_c#.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p>There's no reason to use literal boolean values in assertions. Doing so is at best confusing for maintainers, and at worst a bug.</p>
<h2>Noncompliant Code Example</h2>
<pre>
bool b = true;
NUnit.Framework.Assert.AreEqual(true, b);
Xunit.Assert.NotSame(true, b);
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(true, b);
System.Diagnostics.Debug.Assert(true);
</pre>

13 changes: 13 additions & 0 deletions sonaranalyzer-dotnet/rspec/cs/S2701_c#.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"title": "Literal boolean values should not be used in assertions",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"tests"
],
"defaultSeverity": "Critical"
}
27 changes: 27 additions & 0 deletions sonaranalyzer-dotnet/src/SonarAnalyzer.CSharp/RspecStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3615,6 +3615,33 @@
<data name="S2699_Type" xml:space="preserve">
<value>CODE_SMELL</value>
</data>
<data name="S2701_Category" xml:space="preserve">
<value>Sonar Code Smell</value>
</data>
<data name="S2701_Description" xml:space="preserve">
<value>There's no reason to use literal boolean values in assertions. Doing so is at best confusing for maintainers, and at worst a bug.</value>
</data>
<data name="S2701_IsActivatedByDefault" xml:space="preserve">
<value>False</value>
</data>
<data name="S2701_Remediation" xml:space="preserve">
<value>Constant/Issue</value>
</data>
<data name="S2701_RemediationCost" xml:space="preserve">
<value>5min</value>
</data>
<data name="S2701_Severity" xml:space="preserve">
<value>Critical</value>
</data>
<data name="S2701_Tags" xml:space="preserve">
<value>tests</value>
</data>
<data name="S2701_Title" xml:space="preserve">
<value>Literal boolean values should not be used in assertions</value>
</data>
<data name="S2701_Type" xml:space="preserve">
<value>CODE_SMELL</value>
</data>
<data name="S2737_Category" xml:space="preserve">
<value>Sonar Code Smell</value>
</data>
Expand Down
Loading

0 comments on commit ffd6451

Please sign in to comment.