Skip to content

Commit 63f2986

Browse files
committed
chore: add nullish check, early return, and function declaration patterns to AI configs
1 parent d7e1358 commit 63f2986

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

.cursorrules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Mobile depends on core. Core must NOT depend on mobile.
1919
- Strict boolean checks: `value !== undefined` not `if (value)`
2020
- Zero runtime dependencies
2121
- Always return cleanup in useEffect to remove listeners
22+
- Nullish checks: `== null` for both null and undefined, `!== undefined` only when distinction matters
23+
- Early returns (guard clauses) over nested if-else blocks
24+
- Function declarations use `function` keyword, not arrow: `function toggle(state: boolean) { return !state; }`
25+
- Short inline callbacks (map, filter args) are OK with arrow functions
2226

2327
## SSR-Safe Pattern
2428

.github/copilot-instructions.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
- Strict boolean checks: `value !== undefined` not `if (value)`
1717
- Zero runtime dependencies
1818
- Always return cleanup in useEffect to remove listeners
19+
- Nullish checks: use `== null` for both null and undefined:
20+
```ts
21+
if (ref == null) { continue; }
22+
items.filter(item => item != null);
23+
const controlled = valueProp !== undefined; // only when distinction matters
24+
```
25+
- Prefer early returns (guard clauses) over nested if-else blocks
26+
- Function declarations use `function` keyword, not arrow functions:
27+
```ts
28+
// ✅ function toggle(state: boolean) { return !state; }
29+
// ✅ items.filter(item => item != null) ← inline callback arrow OK
30+
// ❌ const toggle = (state: boolean) => !state;
31+
```
1932

2033
## SSR-Safe Pattern (CRITICAL)
2134

AGENTS.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,57 @@ src/hooks/useHookName/
4848
- **No `any` types** — Full TypeScript strict mode
4949
- **Zero runtime dependencies**
5050

51+
### Nullish Checks and Control Flow
52+
53+
**Use `== null` for nullish checks** — checks both null and undefined:
54+
55+
```ts
56+
// ✅ Good
57+
if (ref == null) {
58+
continue;
59+
}
60+
items.filter(item => item != null);
61+
62+
// ✅ Use !== undefined only when null/undefined distinction matters
63+
const controlled = valueProp !== undefined;
64+
```
65+
66+
**Prefer early returns (guard clauses)** over nested if-else:
67+
68+
```ts
69+
// ✅ Good — guard clause
70+
function process(value: string | null) {
71+
if (value == null) {
72+
return DEFAULT;
73+
}
74+
return transform(value);
75+
}
76+
77+
// ❌ Bad — nested if-else
78+
function process(value: string | null) {
79+
if (value != null) {
80+
return transform(value);
81+
} else {
82+
return DEFAULT;
83+
}
84+
}
85+
```
86+
87+
**Function declarations use `function` keyword**, arrow functions only for short inline callbacks:
88+
89+
```ts
90+
// ✅ Good — function keyword for declarations
91+
function toggle(state: boolean) {
92+
return !state;
93+
}
94+
95+
// ✅ Good — arrow for inline callbacks
96+
items.filter(item => item != null);
97+
98+
// ❌ Bad — arrow for function declarations
99+
const toggle = (state: boolean) => !state;
100+
```
101+
51102
### SSR-Safe Pattern
52103

53104
All hooks/utils accessing browser APIs must be SSR-safe:

0 commit comments

Comments
 (0)