Enforce Rego formatting and bug linting#183
Merged
Merged
Conversation
|
🎯 Code Coverage (details) 🔗 Commit SHA: e7dc9ee | Docs | Datadog PR Page | Give us feedback! |
whitemerch
force-pushed
the
chakib.hamie/enforce_regal_and_opa_fmt
branch
4 times, most recently
from
June 12, 2026 15:35
49cb221 to
923d88e
Compare
whitemerch
force-pushed
the
chakib.hamie/enforce_regal_and_opa_fmt
branch
from
June 12, 2026 15:38
923d88e to
52c010e
Compare
whitemerch
marked this pull request as ready for review
June 12, 2026 16:10
ChouraquiBen
previously approved these changes
Jun 15, 2026
| - main | ||
| paths: | ||
| - "**/*.rego" | ||
| - ".regal/config.yaml" |
Contributor
There was a problem hiding this comment.
The sound of the concurrency limits rule
| *.out | ||
|
|
||
| /.idea/ | ||
| /.vscode/ |
Contributor
There was a problem hiding this comment.
nit: why though? I'm pretty sure that will lead to committing the folder 🤔
ChouraquiBen
approved these changes
Jun 15, 2026
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.
Motivation
With the Rego library files now free of linter-detected bugs, this PR adds tooling to keep them that way. It covers every
.regofile in the repo, not just the libraries directory, and provides three layers of enforcement: a CI gate, an opt-in pre-commit hook, and format-on-save for VS Code and Cursor.Changes
CI (
lint-rego.yml)A new workflow triggers on any PR or push to
mainthat touches a.regofile or the Regal config. It checks formatting withopa fmt --failacross the whole repo, then runsregal lintrestricted to thebugscategory. Style, idiomatic, performance, import, and testing findings are suppressed so the gate stays focused on correctness.Pre-commit hooks (
.pre-commit-config.yaml)Two local hooks cover all staged
.regofiles:opa fmt --fail— blocks the commit if any file is not properly formatted.regal lint --fail-level errorwith non-bug categories disabled — blocks only on real correctness issues.Install with
pip install pre-commit && pre-commit install.Editor formatting (
.vscode/settings.json)The workspace settings file sets
opa fmtas the default Rego formatter and enables format-on-save. This applies automatically in VS Code and Cursor for anyone with the OPA extension installed..vscode/is unignored so this ships with the repo.Regal config (
.regal/config.yaml)Added suppression for
testing/test-outside-test-packagesince library tests intentionally live alongside their library files rather than in a separate test package.QA Instruction
cd assets/libraries && opa test . -v— all library tests pass.opa fmt --fail .— exits 0.regal lint --fail-level error --disable-category style --disable-category idiomatic --disable-category performance --disable-category imports --disable-category testing .— exits 0.lint-regoCI job to go green.Impact
No runtime behavior changes. CI gains a new required job for all Rego files; the pre-commit hook is opt-in. Contributors using VS Code or Cursor get automatic Rego formatting on save.
Future work
This PR intentionally starts with the
bugscategory only. Follow-up PRs will turn the rest of Regal back on for CI and pre-commit by dropping the matching--disable-categoryflags (and any other temporary suppressions) once the corresponding findings are cleared.The
idiomatic,performance, andstylecategories currently report a large backlog and are the main candidates for that rollout. A few rules are expected to stay suppressed because they conflict with deliberate contracts rather than indicating real issues:directory-package-mismatch(the engine requires every rule to live inpackage datadogregardless of directory), and the name-based rules such asprefer-snake-caseandavoid-get-and-list-prefixon shared library functions (these names are a public API consumed by the detection rules and cannot be renamed without a coordinated change across repositories).