---
title: "Check every rule in code · Agent Wranglers"
url: https://agentwranglers.se/playbook/engineering/rules-as-code/check-every-rule-in-code
updated: 2026-10-20
licence: "All rights reserved"
---

# Check every rule in code

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Rules as code](https://agentwranglers.se/playbook/engineering/rules-as-code)
- Rule: Every rule a project follows must have a check in code that anyone can run again and that ends in a plain pass or fail.
- How: Write each rule as a build gate, a test or a script with an exit code. Zero means the rule holds, anything else means it is broken. The output names the rule, the file or page and the line, so nobody has to read, guess or interpret. A rule without a check is only a wish, so add the check in the same change as the rule.
- Check: Break one rule on purpose. The check fails, names the place, and exits with a code other than zero.
- Measured: On a reference site, the first full run of the checks found 678 sideways-scrolling failures. One CSS line in a new menu caused all of them, and the menu had looked fine in screenshots.

Example:

```js
// A rule as code: pass or fail, never "looks fine"
const problems = pages.filter(p => (p.html.match(/<h1[\s>]/g) || []).length !== 1);
for (const p of problems) console.log(`FAIL ${p.path}: needs exactly one h1`);
process.exit(problems.length ? 1 : 0);
```

```python
# The same rule as code in Python
import re, sys

problems = [page for page in pages if len(re.findall(r"<h1[\s>]", page.html)) != 1]
for page in problems:
    print(f"FAIL {page.path}: needs exactly one h1")
sys.exit(1 if problems else 0)
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers engineering playbook: https://agentwranglers.se/playbook/engineering/rules-as-code/check-every-rule-in-code`.

- Next: [Run one check of everything before every deploy](https://agentwranglers.se/playbook/engineering/rules-as-code/run-one-check-before-every-deploy)
- [Rules as code](https://agentwranglers.se/playbook/engineering/rules-as-code)
