From 71951303ae875456d4118d602cdbcb25f87ecd55 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Sun, 13 Sep 2026 01:15:34 +0530 Subject: [PATCH] chore: discourage regular expressions in AGENTS.md and Greptile rules Regular expressions are hard to review and easy to get subtly wrong. AGENTS.md now asks for string functions or an existing validator instead, and a Greptile rule flags new ones in PHP files. --- .greptile/config.json | 10 ++++++++++ AGENTS.md | 1 + 2 files changed, 11 insertions(+) create mode 100644 .greptile/config.json diff --git a/.greptile/config.json b/.greptile/config.json new file mode 100644 index 0000000000..bc8a608f63 --- /dev/null +++ b/.greptile/config.json @@ -0,0 +1,10 @@ +{ + "rules": [ + { + "id": "no-regex", + "rule": "Flag every new regular expression (preg_match, preg_replace, preg_split, or a regex pattern passed to a validator). Ask for plain string functions instead, such as str_starts_with, str_ends_with, str_contains, strlen, substr, explode or ctype_*, or an existing validator. Regex is hard to review and easy to get subtly wrong. Accept one only when no string-function alternative exists and the PR explains why.", + "scope": ["**/*.php"], + "severity": "high" + } + ] +} diff --git a/AGENTS.md b/AGENTS.md index da9c7beadc..dd25856331 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -222,6 +222,7 @@ Actions should read like a story. The `action()` method is the plot: [`Teams/Htt ## Conventions - PSR-12 (Pint), PSR-4 autoloading. Avoid dependencies outside the `utopia-php` ecosystem. Never hardcode credentials — use env vars. Code changes may require a container restart; logs live on the relevant container. +- Do not add regular expressions (`preg_*`, regex patterns passed to validators). Use string functions (`str_starts_with`, `str_ends_with`, `str_contains`, `strlen`, `substr`, `explode`, `ctype_*`) or an existing validator instead; regex is hard to review and easy to get subtly wrong. If nothing else works, explain why in the PR. - When updating documents, pass only changed attributes as a sparse Document: ```php