Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dotnet-diff-coverage.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"**/*.targets",
"**/*.config"
],
"threshold": 0
"threshold": 0,
"sarifLevel": "note"
}
4 changes: 2 additions & 2 deletions src/DotnetDiffCoverage/Commands/RootCommandBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,12 @@
var sarifReporter = services.GetRequiredService<SarifReporter>();
if (outputSarif.Name == "-")
{
await sarifReporter.WriteAsync(result, Console.OpenStandardOutput());
await sarifReporter.WriteAsync(result, Console.OpenStandardOutput(), config.SarifLevel);
}
else
{
using var stream = outputSarif.Open(FileMode.Create);
await sarifReporter.WriteAsync(result, stream);
await sarifReporter.WriteAsync(result, stream, config.SarifLevel);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/DotnetDiffCoverage/Config/ToolConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/// <summary>Glob patterns for non-source files to exclude from diff analysis entirely.</summary>
public IReadOnlyList<string> ExcludePatterns { get; init; } = DefaultExcludePatterns;

/// <summary>Coverage threshold (0â100). Exit code 1 if uncovered % exceeds this.</summary>
/// <summary>Coverage threshold (0–100). Exit code 1 if uncovered % exceeds this.</summary>
public double Threshold { get; init; } = 0.0;

/// <summary>Default coverage format if not specified on CLI.</summary>
Expand All @@ -21,6 +21,9 @@
/// <summary>Prefix to strip from coverage file paths before matching against diff paths.</summary>
public string? CoveragePathPrefix { get; init; }

/// <summary>SARIF result level for uncovered lines. Valid values: "error", "warning", "note", "none".</summary>
public string SarifLevel { get; init; } = "warning";

Comment on lines +25 to +26
public static readonly IReadOnlyList<string> DefaultTestFilePatterns = new[]
{
"tests/**",
Expand Down
4 changes: 2 additions & 2 deletions src/DotnetDiffCoverage/Output/SarifReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
[property: JsonPropertyName("$schema")] string Schema,
object[] Runs);

public async Task WriteAsync(CrossReferenceResult result, Stream stream)
public async Task WriteAsync(CrossReferenceResult result, Stream stream, string level = "warning")
{
var results = result.Files
.SelectMany(f => f.UncoveredRanges.Select(range => new
{
ruleId = "DC001",
level = "warning",
level,
message = new
{
text = range.Start == range.End
Expand Down
Loading