119 lines
3.8 KiB
JavaScript
119 lines
3.8 KiB
JavaScript
/**
|
||
* Convert a brooks-lint Markdown report into a SARIF 2.1.0 log.
|
||
*
|
||
* SARIF is what GitHub Code Scanning ingests, so emitting it lets brooks-lint
|
||
* findings appear inline on the PR "Files changed" tab. Findings are parsed by
|
||
* report-parse.mjs; severity maps to SARIF levels (critical→error,
|
||
* warning→warning, suggestion→note). File locations are best-effort: a finding
|
||
* whose Symptom names a file gets a physicalLocation, otherwise it lands at the
|
||
* run level with no location (still listed, just not pinned to a line).
|
||
*/
|
||
|
||
import { parseFindings, RISK_CATALOG } from "./report-parse.mjs";
|
||
|
||
const INFO_URI = "https://github.com/hyhmrright/brooks-lint";
|
||
// The field guide only publishes the six production-risk anchors (#r1–#r6);
|
||
// test risks live in the source file, so route T-codes there to avoid a dead link.
|
||
const GUIDE_URI = "https://hyhmrright.github.io/brooks-lint/guide.html";
|
||
const TEST_RISKS_URI =
|
||
"https://github.com/hyhmrright/brooks-lint/blob/main/skills/_shared/test-decay-risks.md";
|
||
|
||
const LEVEL_BY_SEVERITY = {
|
||
critical: "error",
|
||
warning: "warning",
|
||
suggestion: "note",
|
||
};
|
||
|
||
function helpUri(code) {
|
||
return code.startsWith("T") ? TEST_RISKS_URI : `${GUIDE_URI}#${code.toLowerCase()}`;
|
||
}
|
||
|
||
/** PascalCase a risk name for use as a SARIF rule name. */
|
||
function ruleName(name) {
|
||
return name.replace(/[^A-Za-z0-9]+/g, " ").trim().split(/\s+/).join("");
|
||
}
|
||
|
||
/** Stable, run-independent fingerprint so re-runs dedupe instead of stacking. */
|
||
function fingerprint(parts) {
|
||
let hash = 5381;
|
||
const str = parts.join(" |