Skip to content

Commit 8c15075

Browse files
Copilotastandrik
andcommitted
feat: add Zod validation and use-query-params preference rules to documentation
Co-authored-by: astandrik <[email protected]>
1 parent e22b929 commit 8c15075

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

.github/copilot-instructions.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,31 @@ const handleInputChange = useCallback((value: string) => {
130130
- Use React Router v5 hooks (`useHistory`, `useParams`)
131131
- Always validate route params exist before use
132132

133+
### URL Parameter Management (MANDATORY)
134+
135+
- **PREFER** `use-query-params` over `redux-location-state` for new development
136+
- **ALWAYS** use Zod schemas for URL parameter validation with fallbacks
137+
- **ALWAYS** use `z.enum([...]).catch(defaultValue)` pattern for safe parsing
138+
- Use custom `QueryParamConfig` objects for encoding/decoding complex parameters
139+
140+
```typescript
141+
// ✅ REQUIRED pattern for URL parameters
142+
const sortColumnSchema = z
143+
.enum(['column1', 'column2', 'column3'])
144+
.catch('column1');
145+
146+
const SortOrderParam: QueryParamConfig<SortOrder[]> = {
147+
encode: (value) => value ? encodeURIComponent(JSON.stringify(value)) : undefined,
148+
decode: (value) => {
149+
try {
150+
return value ? JSON.parse(decodeURIComponent(value)) : [];
151+
} catch {
152+
return [];
153+
}
154+
},
155+
};
156+
```
157+
133158
## Common Utilities
134159

135160
- Formatters: `formatBytes()`, `formatDateTime()` from `src/utils/dataFormatters/`

AGENTS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ Uses React Router v5 hooks (`useHistory`, `useParams`, etc.). Always validate ro
274274
- **ALWAYS** handle loading states in UI
275275
- **ALWAYS** validate route params exist before use
276276
- **ALWAYS** follow i18n naming rules from `i18n-naming-ruleset.md`
277+
- **ALWAYS** use Zod schemas for URL parameter validation with fallbacks
278+
- **PREFER** `use-query-params` over `redux-location-state` for new URL parameter handling
279+
- **PREFER** `use-query-params` over `redux-location-state` for new URL parameter handling
277280

278281
### Debugging Tips
279282

CLAUDE.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,33 @@ Complex modals use `@ebay/nice-modal-react` library. Simple dialogs use Gravity
264264

265265
Uses React Router v5 hooks (`useHistory`, `useParams`, etc.). Always validate route params exist before using them.
266266

267+
### URL Parameter Management
268+
269+
- **PREFER** `use-query-params` over `redux-location-state` for new development
270+
- **ALWAYS** use Zod schemas for URL parameter validation with fallbacks
271+
- Use custom `QueryParamConfig` objects for encoding/decoding complex parameters
272+
- Use `z.enum([...]).catch(defaultValue)` pattern for safe parsing with fallbacks
273+
274+
```typescript
275+
// ✅ PREFERRED pattern for URL parameters
276+
const sortColumnSchema = z
277+
.enum(['column1', 'column2', 'column3'])
278+
.catch('column1');
279+
280+
const SortOrderParam: QueryParamConfig<SortOrder[]> = {
281+
encode: (value) => value ? encodeURIComponent(JSON.stringify(value)) : undefined,
282+
decode: (value) => {
283+
try {
284+
return value ? JSON.parse(decodeURIComponent(value)) : [];
285+
} catch {
286+
return [];
287+
}
288+
},
289+
};
290+
291+
const [urlParam, setUrlParam] = useQueryParam('sort', SortOrderParam);
292+
```
293+
267294
### Critical Rules
268295

269296
- **NEVER** call APIs directly - use `window.api.module.method()`
@@ -274,6 +301,8 @@ Uses React Router v5 hooks (`useHistory`, `useParams`, etc.). Always validate ro
274301
- **ALWAYS** handle loading states in UI
275302
- **ALWAYS** validate route params exist before use
276303
- **ALWAYS** follow i18n naming rules from `i18n-naming-ruleset.md`
304+
- **ALWAYS** use Zod schemas for URL parameter validation with fallbacks
305+
- **PREFER** `use-query-params` over `redux-location-state` for new URL parameter handling
277306

278307
### Debugging Tips
279308

0 commit comments

Comments
 (0)