feat: Add SARIF 2.1.0 report output with shared reporting layer#56
feat: Add SARIF 2.1.0 report output with shared reporting layer#56304NotModified merged 7 commits intomainfrom
Conversation
…tadata layer - Rename SonarRuleSeverity → RuleSeverity in Core/Reporting/ - Add RuleMetadata record and RuleMetadataProvider static class - Add SarifReporter with SARIF 2.1.0 DTOs (no external NuGet deps) - Add --sarif-report-file CLI option and wire into ValidatorRunner - Update all SonarRuleSeverity references to RuleSeverity - Add SarifReporterTests with snapshot tests - Update README with SARIF docs and GitHub Code Scanning example Agent-Logs-Url: https://github.com/304NotModified/SLNX-validator/sessions/5d6c6f75-d638-45f6-a4ec-d404d306a102 Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
- Split SarifModels.cs into individual files per class - Add XML doc comments to RuleSeverity enum with SARIF/SonarQube mapping - Move --sarif-report-file section before --continue-on-error in README - Remove unclear .sarif.json tip line from README - Update severity override flags table to include SARIF level column - Add short SARIF explanation to GitHub Code Scanning section Agent-Logs-Url: https://github.com/304NotModified/SLNX-validator/sessions/c8bac85a-7f8b-43c1-911f-a7724715655c Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
- Rename RuleMetadata -> Rule, RuleMetadataProvider -> RuleProvider - Convert switch expression in RuleProvider to private dictionary - Remove <remarks> block from RuleSeverity (keep per-value <summary>) - README: expand --sarif-report-file section with SARIF intro, benefits, links, viewers - README: add internal links in severity mapping section - README: update severity override description to mention console + SQ + SARIF Agent-Logs-Url: https://github.com/304NotModified/SLNX-validator/sessions/24076cbf-30ba-4777-8367-61481287936c Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
| { | ||
| private static readonly Dictionary<ValidationErrorCode, Rule> Rules = new() | ||
| { | ||
| [ValidationErrorCode.FileNotFound] = new( |
There was a problem hiding this comment.
Create a helper to dedup. Use smart default to reduce duplications.
There was a problem hiding this comment.
Added a private Create() helper with RuleSeverity.MAJOR as the default parameter. All 7 MAJOR entries no longer repeat code.ToCode() or the explicit severity, and only the 2 MINOR entries pass an override. (024cddb)
- RuleProvider: add Create() helper with default MAJOR severity to eliminate repeated code.ToCode() and explicit MAJOR - README: replace VS Code -> Visual Studio Code, VS -> Visual Studio throughout - README: fix out-of-the-box claim (Visual Studio built-in, VS Code/Azure DevOps need extensions) - README: fix Visual Studio link to SARIF viewer docs (was Roslyn analyzers) - README: fix Azure DevOps link to SARIF SAST Scans Tab extension (was code coverage docs) Agent-Logs-Url: https://github.com/304NotModified/SLNX-validator/sessions/f238c504-01a4-4790-a858-136add863e89 Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
- RuleProvider: dedup error codes by having Create() return (Key, Rule) tuple, build dictionary via .ToDictionary() so each ValidationErrorCode only appears once - RuleProvider: rename rules: "Input file not found" -> "SLNX file not found", "Invalid file extension" -> "Invalid solution file extension", "File is not a text file" -> "SLNX file is not a text file" - Update snapshot tests to match new rule names - README: link "Visual Studio" in benefits bullet to official SARIF viewer docs - README: viewers section - Visual Studio/Code/Azure DevOps no longer hyperlinks; only the extension/docs links are clickable, no duplicate links Agent-Logs-Url: https://github.com/304NotModified/SLNX-validator/sessions/e6c871f9-f7c6-4137-9c1d-716db710bb21 Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
…lt-in The previously linked docs URL returned 404. Visual Studio does not have a built-in SARIF viewer; it requires the Microsoft SARIF Viewer extension. - Benefits bullet: removed "built-in" claim, now says "via extensions for Visual Studio, Visual Studio Code, and Azure DevOps" - Viewers list: Visual Studio entry now links to the correct Marketplace extension (WDGIS.MicrosoftSarifViewer2022) Agent-Logs-Url: https://github.com/304NotModified/SLNX-validator/sessions/273158ae-504a-46bd-9190-2e9f6a642aa7 Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
304NotModified
left a comment
There was a problem hiding this comment.
Links give 404. See open code comments
Fixed in 61baa80 — the 404 link ( |
Core/Reporting/RuleSeverity.cs(renamed from SonarRuleSeverity)Core/Reporting/Rule.cs(renamed from RuleMetadata)Core/Reporting/RuleProvider.cs(renamed from RuleMetadataProvider,Create()returns tuple to eliminate duplicate error code keys, default MAJOR severity)SonarReporter.GetRuleDefinition()to useRuleProviderCore/SarifReporting/with individual files per DTO, ISarifReporter.cs, SarifReporter.cs<remarks>from RuleSeverity; keep per-value<summary>with SARIF mappingOriginal prompt
Goal
Add SARIF (Static Analysis Results Interchange Format) report output support to slnx-validator, following "Option A" — extracting shared rule metadata and severity into a common reporting layer so there is zero duplication between the SonarQube and SARIF reporters.
Architecture changes
1. Extract shared reporting layer
Rename
SonarRuleSeverity→RuleSeverity(the enum is already used as the universal severity across the entire app — inValidatorRunnerOptions,SeverityOverridesParser,ValidationReporter,ValidatorRunner.IsFailingError()— so the rename is justified).Create a new shared namespace/folder
Core/Reporting/with:RuleSeverity.cs— the renamed enum (values: BLOCKER, CRITICAL, MAJOR, MINOR, INFO)RuleMetadata.cs— a record holding the format-agnostic rule info:Id(string, e.g. "SLNX011"),Name(string),Description(string),DefaultSeverity(RuleSeverity)RuleMetadataProvider.cs— a static class with aGet(ValidationErrorCode)method containing the switch expression currently inSonarReporter.GetRuleDefinition(), but returning only the shared fields (no SonarQube-specific fields like CleanCodeAttribute, Type, Impacts)Update all references from
SonarRuleSeveritytoRuleSeverityacross the entire codebase:ValidatorRunnerOptions.csSeverityOverridesParser.csValidationReporter.csValidatorRunner.csISonarReporter.csSonarReporter.csSonarRule.cs(keep a SonarQube-specific Severity property, but typed asRuleSeverity)SonarRuleSeverity2. Update SonarReporter to use shared provider
SonarReporter.GetRuleDefinition()should useRuleMetadataProvider.Get(code)for the shared fields (Id, Name, Description, default Severity) and only add the SonarQube-specific fields itself (EngineId, CleanCodeAttribute, Type, Impacts).The
IsIgnored()helper logic is also needed by the SARIF reporter. Either extract it to a shared place, or keep it simple and let each reporter have its own trivial one-liner.3. Add SARIF reporter
Create a new namespace/folder
Core/SarifReporting/with:SarifReporter.cs— implements a newISarifReporterinterface. UsesRuleMetadataProviderfor rule metadata. MapsRuleSeverityto SARIF levels:"error""warning""note"SarifLogwith$schema("https://json.schemastore.org/sarif-2.1.0.json"),version("2.1.0"),runsarraySarifRunwithtoolandresultsSarifToolwithdriverSarifToolComponent(driver) withname("slnx-validator"),informationUri,rulesarraySarifReportingDescriptor(rule) withid,shortDescription,fullDescription,defaultConfiguration(withlevel)SarifResultwithruleId,level,message,locationsSarifLocation,SarifPhysicalLocation,SarifArtifactLocation,SarifRegionSarifMessagewithtextISarifReporter.cs— interface mirroringISonarReporterpattern:The file-writing pattern (create directory, open stream) should follow the same pattern as
SonarReporter.4. Wire up CLI
In
Program.cs, add:Add it to the root command and pass it through to
ValidatorRunnerOptions.In
ValidatorRunnerOptions.cs, addstring? SarifReportPath.In
ValidatorRunner.RunAsync(), add the SARIF report writing block (same pattern as the SonarQube block):In
ServiceCollectionExtensions.cs, registerISarifReporter→SarifReporter.5. Tests
Add
SarifReporterTests.csin the test project, covering at minimum:6. Update README.md docum...
This pull request was created from Copilot chat.