Skip to content

Commit e3d1f57

Browse files
ZviBaratzclaude
andcommitted
docs(ego-lint): add regex recipe reference for rule contributors
Add "Common Pattern Recipes" section to rules/README.md with 8 recipes covering the most common regex pattern types used in existing rules. Lowers the barrier for reviewers who know what to catch but need regex syntax help. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c52ff76 commit e3d1f57

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

rules/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,24 @@ m = re.search(pattern, test)
199199
print('Match!' if m else 'No match')
200200
"
201201
```
202+
203+
## Common Pattern Recipes
204+
205+
Quick-reference for the most common regex patterns used in existing rules. Copy, adapt, and test.
206+
207+
| What to match | Pattern | Matches | Doesn't match |
208+
|---------------|---------|---------|----------------|
209+
| Exact function call | `\\bfunctionName\\s*\\(` | `functionName(x)` | `myFunctionName(x)` |
210+
| Property access | `\\bobject\\.property\\b` | `object.property` | `myobject.property` |
211+
| String literal | `['"]string['"]` | `"string"`, `'string'` | `substring` |
212+
| Either-or | `\\b(oldApi\|newApi)\\b` | `oldApi`, `newApi` | `oldApis` |
213+
| Method chain | `\\.method\\s*\\(` | `obj.method()` | `method()` |
214+
| Constructor | `\\bnew\\s+ClassName\\b` | `new ClassName()` | `ClassName()` |
215+
| Import statement | `from\\s+['"]gi://Lib['"]` | `from 'gi://Lib'` | `from 'gi://LibExtra'` |
216+
| Start-of-line declaration | `^\\s*(let\|var)\\s+` | `let x = 1` | `const x = 1` |
217+
218+
**Tips:**
219+
- `\\b` = word boundary — prevents partial matches (e.g., `\\bLog\\b` matches `Log` but not `Login`)
220+
- `\\s*` = optional whitespace — handles `func()` and `func ()` both
221+
- Always double-escape in YAML: write `\\b` not `\b` (YAML interprets `\b` as backspace)
222+
- Test inline: `python3 -c "import re; print(re.search(r'\\byourPattern\\b', 'test string'))"`

0 commit comments

Comments
 (0)