Skip to content

Commit bdf8c0e

Browse files
authored
Add Recurse ML rules for naming and code patterns (stack-auth#780)
1 parent c7f5e9c commit bdf8c0e

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

.github/.recurseml.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
report_status_checks: false
2+
rules: .github/recurseml-rules/
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
description: Code Patterns and Best Practices
3+
globs: "**/*.{js,ts}"
4+
alwaysApply: true
5+
---
6+
7+
The following conventions MUST be followed in new code.
8+
DON'T report code patterns outside of the examples explicitly listed below:
9+
10+
- Never use `void asyncFunction()` or `asyncFunction().catch(console.error)` - use `runAsynchronously(asyncFunction)` instead
11+
- Use `parseJson`/`stringifyJson` from `stack-shared/utils/json` instead of `JSON.parse`/`JSON.stringify`
12+
- Instead of Vercel `waitUntil`, use `runAsynchronously(promise, { promiseCallback: waitUntil })`
13+
- Don't concatenate URLs as strings - avoid patterns like `/users/${userId}`
14+
- Replace non-null assertions with `?? throwErr("message", { extraData })` pattern
15+
- Properly handle async operations with try/catch blocks
16+
- Use helper functions for validation and environment variables
17+
18+
# Solution
19+
20+
Fix code pattern violations by:
21+
- Wrapping async calls with runAsynchronously
22+
- Importing parseJson/stringifyJson from stack-shared/utils/json
23+
- Using runAsynchronously with promiseCallback for waitUntil
24+
- Using proper URL construction utilities
25+
- Replacing ! assertions with ?? throwErr pattern

.github/recurseml-rules/naming.mdc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
description: Naming Conventions
3+
globs: "**/*.{js,ts}"
4+
alwaysApply: true
5+
---
6+
7+
Code changes MUST follow the naming guidelines below.
8+
DON'T report any other naming issues.
9+
10+
- Use `snake_case` for anything that goes over HTTP in REST APIs, `camelCase` for JavaScript elsewhere
11+
- `captureError`'s first argument should be a machine-readable ID without whitespaces (e.g., `'user-sign-up-email'` not `'Email failed to send'`)
12+
- When doing OAuth flows, specify the type (inner/outer/external) in variable names, comments, and error messages
13+
- Use descriptive names that clearly indicate purpose and context
14+
- Avoid abbreviations unless they are widely understood
15+
16+
# Solution
17+
18+
Fix naming inconsistencies by:
19+
- Converting API parameters to snake_case
20+
- Making captureError IDs machine-readable with hyphens
21+
- Adding OAuth type prefixes to variable names

0 commit comments

Comments
 (0)