C#: Add some tests for cs/useless-if-statement.

This commit is contained in:
Michael Nebel
2025-03-05 14:32:41 +01:00
parent 795a2e1175
commit a9d45a2aa2
4 changed files with 36 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
using System;
class FutileConditionalTest
{
public void M(string s)
{
if (s.Length > 0) ; // $ Alert
if (s.Length > 1)
{
} // $ Alert
if (s.Length > 2) // GOOD: because of else-branch
{
}
else
{
Console.WriteLine("hello");
}
if (s.Length > 3)
{
}
else
{
} // $ Alert
}
}

View File

@@ -0,0 +1,3 @@
| FutileConditional.cs:8:9:8:27 | if (...) ... | If-statement with an empty then-branch and no else-branch. |
| FutileConditional.cs:10:9:12:9 | if (...) ... | If-statement with an empty then-branch and no else-branch. |
| FutileConditional.cs:22:9:27:9 | if (...) ... | If-statement with an empty then-branch and no else-branch. |

View File

@@ -0,0 +1,2 @@
query: Useless code/FutileConditional.ql
postprocess: utils/test/InlineExpectationsTestQuery.ql

View File

@@ -0,0 +1,2 @@
semmle-extractor-options: /nostdlib /noconfig
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj