-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add SARIF 2.1.0 report output with shared reporting layer #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a653f18
Initial plan
Copilot 7969cbb
feat: add SARIF report output support with shared RuleSeverity/RuleMe…
Copilot b67695c
refactor: address PR review comments
Copilot 87a9890
refactor: address second round of PR review comments
Copilot 024cddb
refactor: address third round of PR review comments
Copilot 32195bb
refactor: address fourth round of PR review comments
Copilot 61baa80
fix: correct Visual Studio SARIF viewer - requires extension, not bui…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,7 @@ | ||
| namespace JulianVerdurmen.SlnxValidator.Core.Reporting; | ||
|
|
||
| public sealed record Rule( | ||
| string Id, | ||
304NotModified marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| string Name, | ||
| string Description, | ||
| RuleSeverity DefaultSeverity); | ||
This file contains hidden or 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,60 @@ | ||
| using JulianVerdurmen.SlnxValidator.Core.ValidationResults; | ||
|
|
||
| namespace JulianVerdurmen.SlnxValidator.Core.Reporting; | ||
|
|
||
| public static class RuleProvider | ||
| { | ||
| private static (ValidationErrorCode Key, Rule Rule) Create( | ||
| ValidationErrorCode code, string name, string description, | ||
| RuleSeverity severity = RuleSeverity.MAJOR) => | ||
| (code, new Rule(code.ToCode(), name, description, severity)); | ||
|
|
||
| private static readonly Dictionary<ValidationErrorCode, Rule> Rules = | ||
| new (ValidationErrorCode Key, Rule Rule)[] | ||
| { | ||
| Create(ValidationErrorCode.FileNotFound, | ||
| "SLNX file not found", | ||
| "The specified .slnx file does not exist."), | ||
|
|
||
| Create(ValidationErrorCode.InvalidExtension, | ||
| "Invalid solution file extension", | ||
| "The input file does not have a .slnx extension.", | ||
| RuleSeverity.MINOR), | ||
|
|
||
| Create(ValidationErrorCode.NotATextFile, | ||
| "SLNX file is not a text file", | ||
| "The file is binary and cannot be parsed as XML."), | ||
|
|
||
| Create(ValidationErrorCode.InvalidXml, | ||
| "Invalid XML", | ||
| "The .slnx file is not valid XML."), | ||
|
|
||
| Create(ValidationErrorCode.ReferencedFileNotFound, | ||
| "Referenced file not found", | ||
| "A file referenced in a <File Path=\"...\"> element does not exist on disk."), | ||
|
|
||
| Create(ValidationErrorCode.InvalidWildcardUsage, | ||
| "Invalid wildcard usage", | ||
| "A <File Path=\"...\"> element contains a wildcard pattern, which is not supported.", | ||
| RuleSeverity.MINOR), | ||
|
|
||
| Create(ValidationErrorCode.XsdViolation, | ||
| "XSD schema violation", | ||
| "The XML structure violates the .slnx schema."), | ||
|
|
||
| Create(ValidationErrorCode.RequiredFileDoesntExistOnSystem, | ||
| "Required file does not exist on the system", | ||
| "A file required by '--required-files' does not exist on the file system."), | ||
|
|
||
| Create(ValidationErrorCode.RequiredFileNotReferencedInSolution, | ||
| "Required file not referenced in solution", | ||
| "A file required by '--required-files' exists on the file system but is not referenced as a <File> element in the solution."), | ||
| }.ToDictionary(e => e.Key, e => e.Rule); | ||
|
|
||
| public static Rule Get(ValidationErrorCode code) | ||
| { | ||
| if (Rules.TryGetValue(code, out var rule)) | ||
| return rule; | ||
| throw new ArgumentOutOfRangeException(nameof(code), code, null); | ||
| } | ||
| } |
This file contains hidden or 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,16 @@ | ||
| namespace JulianVerdurmen.SlnxValidator.Core.Reporting; | ||
|
|
||
| /// <summary>Universal severity level used across the entire validator pipeline.</summary> | ||
| public enum RuleSeverity | ||
| { | ||
| /// <summary>SARIF: <c>error</c> — causes exit code 1.</summary> | ||
| BLOCKER, | ||
| /// <summary>SARIF: <c>error</c> — causes exit code 1.</summary> | ||
| CRITICAL, | ||
304NotModified marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// <summary>SARIF: <c>error</c> — causes exit code 1. Default severity for most rules.</summary> | ||
| MAJOR, | ||
| /// <summary>SARIF: <c>warning</c> — does not cause exit code 1.</summary> | ||
| MINOR, | ||
| /// <summary>SARIF: <c>note</c> — does not cause exit code 1.</summary> | ||
| INFO | ||
| } | ||
This file contains hidden or 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,13 @@ | ||
| using JulianVerdurmen.SlnxValidator.Core.Reporting; | ||
| using JulianVerdurmen.SlnxValidator.Core.ValidationResults; | ||
|
|
||
| namespace JulianVerdurmen.SlnxValidator.Core.SarifReporting; | ||
|
|
||
| public interface ISarifReporter | ||
| { | ||
| Task WriteReportAsync(IReadOnlyList<FileValidationResult> results, string outputPath, | ||
| IReadOnlyDictionary<ValidationErrorCode, RuleSeverity?>? severityOverrides = null); | ||
|
|
||
| Task WriteReportAsync(IReadOnlyList<FileValidationResult> results, Stream outputStream, | ||
| IReadOnlyDictionary<ValidationErrorCode, RuleSeverity?>? severityOverrides = null); | ||
| } |
6 changes: 6 additions & 0 deletions
6
src/SLNX-validator.Core/SarifReporting/SarifArtifactLocation.cs
This file contains hidden or 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,6 @@ | ||
| namespace JulianVerdurmen.SlnxValidator.Core.SarifReporting; | ||
|
|
||
| internal sealed record SarifArtifactLocation | ||
| { | ||
| public required string Uri { get; init; } | ||
| } |
6 changes: 6 additions & 0 deletions
6
src/SLNX-validator.Core/SarifReporting/SarifDefaultConfiguration.cs
This file contains hidden or 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,6 @@ | ||
| namespace JulianVerdurmen.SlnxValidator.Core.SarifReporting; | ||
|
|
||
| internal sealed record SarifDefaultConfiguration | ||
| { | ||
| public required string Level { get; init; } | ||
| } |
This file contains hidden or 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,6 @@ | ||
| namespace JulianVerdurmen.SlnxValidator.Core.SarifReporting; | ||
|
|
||
| internal sealed record SarifLocation | ||
| { | ||
| public required SarifPhysicalLocation PhysicalLocation { get; init; } | ||
| } |
This file contains hidden or 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,13 @@ | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace JulianVerdurmen.SlnxValidator.Core.SarifReporting; | ||
|
|
||
| internal sealed record SarifLog | ||
| { | ||
| [JsonPropertyName("$schema")] | ||
| public required string Schema { get; init; } | ||
|
|
||
| public required string Version { get; init; } | ||
|
|
||
| public required List<SarifRun> Runs { get; init; } | ||
| } |
This file contains hidden or 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,6 @@ | ||
| namespace JulianVerdurmen.SlnxValidator.Core.SarifReporting; | ||
|
|
||
| internal sealed record SarifMessage | ||
| { | ||
| public required string Text { get; init; } | ||
| } |
11 changes: 11 additions & 0 deletions
11
src/SLNX-validator.Core/SarifReporting/SarifPhysicalLocation.cs
This file contains hidden or 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,11 @@ | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace JulianVerdurmen.SlnxValidator.Core.SarifReporting; | ||
|
|
||
| internal sealed record SarifPhysicalLocation | ||
| { | ||
| public required SarifArtifactLocation ArtifactLocation { get; init; } | ||
|
|
||
| [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||
| public SarifRegion? Region { get; init; } | ||
| } |
This file contains hidden or 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,6 @@ | ||
| namespace JulianVerdurmen.SlnxValidator.Core.SarifReporting; | ||
|
|
||
| internal sealed record SarifRegion | ||
| { | ||
| public required int StartLine { get; init; } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.