Writing Custom Rules
Encode your team's security conventions, internal API usage patterns, and domain-specific checks using Gritcadence's YAML rule format. Available on Pro and Team plans.
Rule schema
Each custom rule is a YAML file placed in a directory specified by rules.custom_rules_dir in your .gritcadence.yaml config.
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique rule identifier. Recommend GRCD-CUSTOM-XXX-NNN convention. |
severity | enum | Yes | critical / high / medium / low |
language | string | Yes | python / javascript / typescript / go / java / ruby / rust |
message | string | Yes | Short description shown in PR comment. Max 120 chars. |
paths.include | string[] | No | Glob patterns to restrict which files this rule applies to. |
paths.exclude | string[] | No | Glob patterns to exclude from this rule. |
pattern | string | No* | Single pattern to match. Use ... as wildcard for arguments. |
pattern-either | string[] | No* | List of patterns — fires if any match. |
pattern-all | string[] | No* | List of patterns — fires only if all match in same context. |
fix | string | No | Optional suggested fix shown in PR comment. |
* At least one of pattern, pattern-either, or pattern-all is required.
Test harness
Validate custom rules locally before pushing with the grcd test-rules CLI command (available on Pro/Team plans):
Fixture files use YAML frontmatter to declare expected outcomes:
Shared rule libraries (Team plan)
On the Team plan, push custom rules to an org/rules repository and they apply across all repositories in your organization. No per-repo config needed. Rules in the shared library are versioned and auditable.