mirror of
https://github.com/github/codeql.git
synced 2026-04-25 16:55:19 +02:00
Merge pull request #13030 from hvitved/csharp/warn-as-error
C#: Never treat warnings as error in the extractor
This commit is contained in:
@@ -130,9 +130,14 @@ namespace Semmle.Extraction.CSharp
|
||||
/// <returns>Modified list of arguments.</returns>
|
||||
private static IEnumerable<string> AddDefaultResponse(string responseFile, IEnumerable<string> args)
|
||||
{
|
||||
return SuppressDefaultResponseFile(args) || !File.Exists(responseFile) ?
|
||||
var ret = SuppressDefaultResponseFile(args) || !File.Exists(responseFile) ?
|
||||
args :
|
||||
new[] { "@" + responseFile }.Concat(args);
|
||||
|
||||
// make sure to never treat warnings as errors in the extractor:
|
||||
// our version of Roslyn may report warnings that the actual build
|
||||
// doesn't
|
||||
return ret.Concat(new[] { "/warnaserror-" });
|
||||
}
|
||||
|
||||
private static bool SuppressDefaultResponseFile(IEnumerable<string> args)
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import csharp
|
||||
import semmle.code.csharp.commons.Diagnostics
|
||||
|
||||
from Diagnostic d
|
||||
where d.getSeverity() >= 3
|
||||
select d
|
||||
@@ -0,0 +1,4 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
Console.WriteLine("Hello, World!");
|
||||
|
||||
var x = "unused";
|
||||
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
7
csharp/ql/integration-tests/posix-only/warn_as_error/build.sh
Executable file
7
csharp/ql/integration-tests/posix-only/warn_as_error/build.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Will fail because of a warning
|
||||
dotnet build
|
||||
|
||||
# Pretend it didn't fail, so extraction succeeds (which doesn't treat warnings as errors)
|
||||
exit 0
|
||||
@@ -0,0 +1,7 @@
|
||||
import os
|
||||
from create_database_utils import *
|
||||
from diagnostics_test_utils import *
|
||||
|
||||
run_codeql_database_create(["./build.sh"], lang="csharp", extra_args=["--extractor-option=cil=false"])
|
||||
|
||||
check_diagnostics()
|
||||
Reference in New Issue
Block a user