Skip to content

Enforce Rego formatting and bug linting#183

Merged
whitemerch merged 2 commits into
mainfrom
chakib.hamie/enforce_regal_and_opa_fmt
Jun 15, 2026
Merged

Enforce Rego formatting and bug linting#183
whitemerch merged 2 commits into
mainfrom
chakib.hamie/enforce_regal_and_opa_fmt

Conversation

@whitemerch

@whitemerch whitemerch commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Motivation

With the Rego library files now free of linter-detected bugs, this PR adds tooling to keep them that way. It covers every .rego file 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 main that touches a .rego file or the Regal config. It checks formatting with opa fmt --fail across the whole repo, then runs regal lint restricted to the bugs category. 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 .rego files:

  1. opa fmt --fail — blocks the commit if any file is not properly formatted.
  2. regal lint --fail-level error with 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 fmt as 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-package since library tests intentionally live alongside their library files rather than in a separate test package.

QA Instruction

  1. cd assets/libraries && opa test . -v — all library tests pass.
  2. opa fmt --fail . — exits 0.
  3. regal lint --fail-level error --disable-category style --disable-category idiomatic --disable-category performance --disable-category imports --disable-category testing . — exits 0.
  4. Wait for the new lint-rego CI 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 bugs category only. Follow-up PRs will turn the rest of Regal back on for CI and pre-commit by dropping the matching --disable-category flags (and any other temporary suppressions) once the corresponding findings are cleared.

The idiomatic, performance, and style categories 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 in package datadog regardless of directory), and the name-based rules such as prefer-snake-case and avoid-get-and-list-prefix on shared library functions (these names are a public API consumed by the detection rules and cannot be renamed without a coordinated change across repositories).

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Jun 12, 2026

Copy link
Copy Markdown

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 47.98% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: e7dc9ee | Docs | Datadog PR Page | Give us feedback!

@whitemerch
whitemerch force-pushed the chakib.hamie/enforce_regal_and_opa_fmt branch 4 times, most recently from 49cb221 to 923d88e Compare June 12, 2026 15:35
@whitemerch
whitemerch force-pushed the chakib.hamie/enforce_regal_and_opa_fmt branch from 923d88e to 52c010e Compare June 12, 2026 15:38
@whitemerch
whitemerch marked this pull request as ready for review June 12, 2026 16:10
@whitemerch
whitemerch requested a review from a team as a code owner June 12, 2026 16:10
ChouraquiBen
ChouraquiBen previously approved these changes Jun 15, 2026

@ChouraquiBen ChouraquiBen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

- main
paths:
- "**/*.rego"
- ".regal/config.yaml"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sound of the concurrency limits rule

Comment thread .gitignore
*.out

/.idea/
/.vscode/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why though? I'm pretty sure that will lead to committing the folder 🤔

@whitemerch
whitemerch merged commit 08a26af into main Jun 15, 2026
19 checks passed
@whitemerch
whitemerch deleted the chakib.hamie/enforce_regal_and_opa_fmt branch June 15, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants