Repository navigation
feat: --sarif writes architecture rule violations as SARIF 2.1.0 - #76
Merged
Merged
Conversation
`codeshot --architecture ... --sarif codeshot.sarif` writes every --forbid and --rules violation as a SARIF result, for GitHub code scanning: the depending file at its first call-site line (from the codegraph index, a snapshot edge's line, or the SCIP index's first reference; line 1 when unknown), the depended-on file as a related location, and a fingerprint from the rule and the two files so an alert survives the line moving. Written on every run, with an empty results list when nothing breaks a rule, and with --check. Line numbers are looked up only for violations, so the diagram path is unchanged. P5a of the program.
golangci-lint v2.15.0 (CI) flags SA1019 on the test that covers indexers writing the deprecated packed range; that coverage is on purpose.
- F1: codeshot's hash goes in primaryLocationLineHash, the key GitHub tracks alerts by (upload-sarif keeps a given one); it includes the rule's wording, and an exact duplicate result is written once. - F2: artifact URIs are percent-encoded per segment; absolute paths are file:// URIs. - F3/F4: a real call line wins over the caller's start line, for codegraph and snapshots alike; 0 is no line. - F6: --sarif needs --forbid or --rules (an empty log would close every open alert). - A3/A4/F9: rules carry help text; the no-lines warning names the source and an old index plainly; one smallest-line helper.
Open
11 tasks
- V1: the fingerprint is the rule id, the rule and the two files; the --rules path as typed and the reason no longer reopen alerts. - V2: a --sarif run whose scan --max-symbols cut writes nothing and exits 1, since a partial log would close the alerts of violations past it. - V3: --sarif refuses a rules file that checks nothing. - V5: a ':' in a relative path's first segment is %3A; a Windows drive path is a file:///C:/ URI. - V6/V10/V11: an index without edge lines still gives start lines; the multi-source warning is about that source's results only; exact call lines beat start-line fallbacks across sources.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
--architecturecan now write its rule violations as SARIF 2.1.0, the format GitHub code scanning reads:codeshot --architecture --path . --rules .codeshot.yaml --sarif codeshot.sarif --format svg --out arch.svg--forbidand--rulesviolation becomes oneerrorresult, with the same message as the stderr report (including the reason, the layer names and which sources saw the edge).primaryLocationLineHash, the key GitHub tracks alerts by) comes from the rule and the two files, not the line, so moving the call doesn't open a new alert.--check. Exit codes don't change.--sarifneeds a rule to check, and refuses a scan--max-symbolscut.This is P5a of the program.
How
SiteLinerinterface on each source. The code that builds the diagram is untouched.--architecturedraws (imports and file targets aside). It takes the smallest edge line, or the calling function's start line when codegraph stored none for that edge.lineon a drawn-kind edge between the two files (the field is optional in snapshot v1).codeshot/forbid(flags and file forbid rules) andcodeshot/layers.encoding/jsonandcrypto/sha256.Measured (base
0bf0de4vsedda666, Linux, Go 1.26.5)jsonschema4.26.0, outside the test suite. The runs, on this repo with thecoreandsourceslayers swapped so there are violations:.codeshot.yaml: 0 results.internal/codeshot/diff_test.go:67is that file's first use of a codegraph type (*codegraph.Response). The SCIP index'sdiff_test.go:14isx.Name, a field of codegraph'sNode.rangefield, and scip-go 0.2.8 writes only the typed one, so every SCIP-only result fell back to line 1. It now reads both through the bindings'SourceRange, with a regression test for the typed field.--sarif(verified): 5 runs (no rules, the real rules, failing rules,--forbidwith--group-depth, symbol mode) give identical DOT, stderr and exit code on base and this branch.--sarifrefused outside--architecture.go test ./...ok; golangci-lint0 issues.; gofmt and go vet clean; both diagram--checkruns exit 0 (fresh clone, fork v1.6.2-em.44).Changes since review (2026-11-18)
Round 1 (
/code-review+ a code-reviewer agent on0384dab; the agent read GitHub's SARIF docs and the codeql-action fingerprint code), fixed infe1bca3:primaryLocationLineHashand computes it from the line's text when it's missing. The first version put codeshot's hash under its own key, which GitHub ignores, and two different rules on one edge (a--forbidflag and the same rule in the file) shared it. codeshot's hash, which now includes the rule's wording, goes inprimaryLocationLineHash(upload-sarif keeps a given one), and an exact duplicate result is written once.#,%or a non-ASCII name was written raw, so a URI parser read part of it as a fragment and codeql-action's decoder turned%20into a space. Each segment is now percent-encoded, and an absolute path is afile://URI.--sarifwithout--forbidor--rulesis refused: it would upload an empty log and close every open alert.helptext, and the no-lines warning names the source and says plainly when an index predates the line columns.--sarif, 5 runs matchmaster.go test ./...ok; golangci-lint v2.15.00 issues.Round 2 (verify on
fe1bca3): the round-1 fixes held (13 runs without--sarifmatchedmaster; 11 outputs validated). Fixed in17b1e69:--rulespath as typed and the rule's reason, so--rules ./r.yamlinstead of--rules r.yaml, or a reworded reason, reopened every alert. It is now the rule id, the rule and the two files.--sarif, a scan that--max-symbolscut exits 1 and writes nothing, naming the value to rerun with: a partial log would close the alerts of violations past the cut. (Before: exit 0 and a partial log.)--sarif, like no rules at all.:in a relative path's first segment is%3A(it read as a scheme), and a Windows drive path is afile:///C:/URI.go test ./...ok; golangci-lint v2.15.00 issues.; 5 outputs validate with 0 errors (all results lined, unique fingerprints); without--sarif, 5 runs matchmaster.Known limits
--path .); with a snapshot or SCIP index whose paths start elsewhere, results point at the wrong file.security-events: writeon the diagrams job and is a separate decision.--checkdrift, symbol mode or--diff.