Author Semgrep rules as validated YAML fragments#19
Merged
Conversation
Adding a rule now means dropping one fragment under analyzers/semgrep/rules/ and running go generate, instead of editing the room.yml godfile. The bundler validates signal metadata, rejects duplicate ids and ambiguous YAML (anchors, aliases, merge keys, duplicate keys, non-integer confidence), sorts canonically, and rewrites room.yml atomically so the checked-in bundle stays a regular file. CI regenerates and fails on drift, keeping the config_sha256 receipt binding intact.
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.
Summary
room.ymlgodfile into one-rule-per-file fragments underanalyzers/semgrep/rules/, bundled by a deterministic Go generator (cmd/semgrep-rule-bundler+internal/semgrepbundle) viago generate ./analyzers/semgrep.room_signal, integerroom_confidence_basis_pointsin 1..10000, and no ambiguous YAML (anchors, aliases, merge keys, duplicate or non-string mapping keys). Output is canonically sorted, carries a DO-NOT-EDIT header, and is written atomically — a symlinkedroom.ymlis replaced, never followed.room.yml(and itsconfig_sha256receipt binding) always matches the authored fragments. Contributor workflow documented indocs/analyzer.md.Test plan
go test ./...— unit tests for deterministic ordering, invalid fragments (duplicate ids/keys, anchors, aliases, merge keys, float/exponent/quoted confidence), symlink rejection, and atomic write semanticsgo generate ./analyzers/semgrepreproduces checked-inroom.ymlbyte-for-byte (sha2562a4073e1…)semgrep --validate --strict— 8 rules, 0 errorsROOM_SEMGREP_CORE=… go test -tags=semgrep_integration ./cmd/room-semgrep— realsemgrep-core1.139.0 suite passesactionlint .github/workflows/ci.yml,go vet ./...,gofmt,git diff --checkall clean