coding-guidelines
Comprehensive coding standards for TypeScript/JavaScript projects with React. Use when writing new code, refactoring, or setting up project structure. Focuses on e2e type-safety, readability, and maintainability. Apply to any code creation, file structuring, or technical decision-making tasks.
What this skill does
# Coding Guidelines
Apply these standards to all TypeScript/JavaScript code. Focus on type-safety, readability, and maintainability.
## Core Principles
### Type Safety
- Never use `any`; almost never use `as`
- Let the compiler infer response types whenever possible
- Use e2e type-safety across the entire stack
- Use query-builders instead of pure SQL strings for type-safety and SQL-injection protection
### Code Organization
- Always use named exports; don't use default exports unless required
- Don't create index files only for exports
- Keep code close to where it's used unless reused 2-3 times
- A folder with a single file should be a single file
### Async/Await
- Prefer `await`/`async` over `Promise().then()`
- Handle errors with try-catch blocks
### Variable Management
- Unused vars should start with `_` (or not exist at all)
- Don't declare constants or functions inside React components; keep them pure
## Naming Conventions
### General Rules
- Don't abbreviate; use descriptive names
- Every character must earn its place
- Follow language conventions:
- `SNAKE_CAPS` for constants
- `camelCase` for functions
- `kebab-case` for file names
### Specificity
- Be concrete: `retryAfterMs` > `timeout`
- `emailValidator` > `validator`
- Avoid vague terms: `data`, `item`, `list`, `component`
- Examples:
- `userPayment` instead of `userPaymentData`
- `users` instead of `userList`
### Brevity
- Remove redundancy: `users` not `userList`
- Avoid suffixes like `Manager`, `Helper`, `Service` unless essential
- Prefer: `retryCount` over `maximumNumberOfTimesToRetryBeforeGivingUpOnTheRequest`
### Context Through Nesting
- Use nested objects to provide context
- Example: `config.public.ENV_NAME` instead of `ENV_NAME`
## String Handling
- Prefer string literals over string concatenation
- Don't use magic strings; extract to named constants or enums
## Control Flow
### Early Returns
- Always use early return over if-else
- Avoid indentation levels; strive for flat code
### Switch Alternatives
- Prefer hash-lists over switch-case
Example:
```typescript
// Good
const handlers = {
create: handleCreate,
update: handleUpdate,
delete: handleDelete,
} as const;
const handler = handlers[action];
```
## React Guidelines
### Component Purity
- Don't declare constants or functions inside components; keep them pure
- Extract logic outside component scope
### Data Fetching
- Don't fetch data in `useEffect`; use React Query
- You probably shouldn't use `useEffect`
- Use `use`, `useTransition`, and `startTransition` instead of `useEffect`
### React Query
- Don't use magic strings for cache tags; use an enum/factory
- Use enum for React Query cache strings
- Prefer `<Suspense>` and `useSuspenseQuery` over React Query `isLoading`
### Error Handling
- Use `errorBoundary` with retry button
## Software Engineering Principles
### Focus Areas
- e2e type-safety
- Error monitoring/observability
- Accessibility (a11y, WCAG 2.0 guidelines)
- Security (OWASP best practices)
- Automated tests
### Avoid Over-Engineering
- Don't pre-mature optimize
- KISS (Keep It Simple, Stupid) and YAGNI (You Aren't Gonna Need It)
- Avoid useless abstractions:
- Helper functions used only once
- Functions that mainly call one function
### Comments
- Comments are unnecessary 98% of the time
- Convert comments to functions or variables instead
- Code is reference, history, and functionality; it must be readable as a journal
### Monitoring and Error Handling
- Use Higher Order Functions for monitoring/error handling/profiling
## Testing
### Testing Philosophy
- Always test behavior, never test implementation
- Write a test for each bug you fix; you'll never have to fix it again
### Test Writing
- Don't use "should"; use 3rd person verbs
- Abuse the `describe` clauses for organization
## Git Workflow
- Do not include "Claude Code" in commit messages
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.