Cline rules
.clinerules/typescript.mdCline rules
Quality
69/100
Scores the file, not the repository.Length
712 words
59 headings · 23 code blocksRepository
0
— · pushed 0 days agoLast changed
2 days ago
First indexed 2 days ago.1# TypeScript Backend Engineering Rules23## 1. Prefer Strong Typing at Assignment Time45Avoid late casts using `as` whenever possible.67### Bad89```ts10const data = fn()11const record = data as Record<string, unknown>12```1314### Good1516```ts17const data: Record<string, unknown> = fn()18```1920### Better2122```ts23type ProviderPayload = {24 model?: string25 stream?: boolean26 [key: string]: unknown27}2829const data: ProviderPayload = fn()30```3132### Rationale3334* Reduces unsafe casts35* Improves readability36* Better type inference37* Reduces temporary variables3839---4041## 2. Prefer Early Returns Over Nested Conditionals4243### Bad4445```ts46if (x) {47 if (y) {48 if (z) {49 doSomething()50 }51 }52}53```5455### Good5657```ts58if (!x) return error()59if (!y) return error()60if (!z) return error()6162doSomething()63```6465### Rationale6667* Reduces cyclomatic complexity68* Keeps the happy path visible69* Easier debugging and maintenance7071---7273## 3. Keep HTTP Handlers Thin7475HTTP handlers should orchestrate logic, not implement all logic inline.7677### Bad7879Large handlers containing:8081* validation82* transformation83* metrics84* streaming85* error handling86* business logic8788### Good8990```ts91handleStreamingResponse()92handleProviderError()93applyPayloadMiddlewares()94```9596### Rationale9798* Improves testability99* Improves maintainability100* Easier code reuse101102---103104## 4. Centralize Error Handling105106### Bad107108```ts109if (error instanceof ProviderError) ...110if (error instanceof ProviderError) ...111if (error instanceof ProviderError) ...112```113114### Good115116```ts117const providerError =118 error instanceof ProviderError119 ? error120 : null121```122123### Rationale124125* Reduces duplication126* Simplifies branching127* Easier future changes128129---130131## 5. Avoid Generic `Record<string, unknown>` When Structure Exists132133### Bad134135```ts136Record<string, unknown>137```138139for structured payloads.140141### Good142143```ts144type ProviderPayload = {145 model?: string146 stream?: boolean147 messages?: unknown[]148}149```150151### Rationale152153* Better autocomplete154* Better developer experience155* Self-documenting code156157---158159## 6. Keep the Happy Path Readable160161The main execution flow should be easy to scan top-to-bottom.162163### Preferred Structure164165```ts166parse167validate168resolve provider169transform payload170apply middlewares171execute request172return response173```174175### Rationale176177Handlers are read far more often than written.178179---180181## 7. Encapsulate Conditional Middleware Logic182183### Bad184185```ts186if (env.RTK_ENABLED === 'true') { ... }187if (env.CAVEMAN_ENABLED === 'true') { ... }188```189190spread across handlers.191192### Good193194```ts195applyPayloadMiddlewares()196```197198### Rationale199200* Better encapsulation201* Easier scaling202* Cleaner handlers203204---205206## 8. Separate Stream and Non-Stream Flows Early207208### Bad209210Interleaving stream and non-stream logic throughout the handler.211212### Good213214```ts215return isStream216 ? handleStreamingResponse(...)217 : handleJsonResponse(...)218```219220### Rationale221222* Reduces mental overhead223* Easier debugging224* Easier maintenance225226---227228## 9. Reduce Temporary Variables229230### Bad231232```ts233const a = fn()234const b = a as SomeType235```236237### Good238239```ts240const b: SomeType = fn()241```242243### Rationale244245* Less visual noise246* Less state tracking247* Cleaner code248249---250251## 10. Prefer Focused Helper Functions252253### Good254255```ts256badRequest()257handleProviderError()258handleStreamingResponse()259applyPayloadMiddlewares()260```261262### Rationale263264* Improves readability265* Easier testing266* Better reuse267* Smaller diffs in PRs268269---270271## 11. Avoid Repeated Runtime Type Checks272273### Bad274275```ts276if (typeof x === 'string') ...277if (typeof x === 'string') ...278```279280### Good281282Normalize once and reuse.283284```ts285const message =286 typeof x === 'string'287 ? x288 : 'unknown'289```290291### Rationale292293* Cleaner control flow294* Less duplication295296---297298## 12. Prefer Explicit Function Names299300### Bad301302```ts303handle()304process()305run()306```307308### Good309310```ts311handleStreamingResponse()312transformProviderPayload()313recordMetrics()314```315316### Rationale317318* Improves discoverability319* Easier onboarding320* Easier navigation in large codebases321322---323324## 13. Keep Side Effects Explicit325326Avoid hidden mutations when possible.327328### Bad329330```ts331modify(payload)332```333334### Good335336```ts337const updatedPayload = applyMiddleware(payload)338```339340Unless mutation is intentionally chosen for performance reasons and clearly documented.341342### Rationale343344* Easier debugging345* Predictable behavior346* Better composability347348---349350## 14. Prefer Small Composable Units351352### Bad353354Large 300+ line handlers or services.355356### Good357358Small focused helpers with single responsibility.359360### Rationale361362* Easier testing363* Easier refactoring364* Better long-term maintainability365366---367368## 15. Optimize for Readability First369370Readable code is usually more maintainable than clever abstractions.371372### Prefer373374* explicit naming375* flat control flow376* predictable structure377* isolated responsibilities378379### Avoid380381* over-engineering382* deeply nested abstractions383* unnecessary generics384* excessive indirection385
Also in sosan/proxy-llms
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| sosan/proxy-llms.clinerules/development-workflow.md · 0 | Cline rules | setuptestarchagent-behaviour | 78/100 | 2 days ago | |
| sosan/proxy-llms.clinerules/metrics.md · 0 | Cline rules | archsecurity | 54/100 | 2 days ago | |
| sosan/proxy-llms.clinerules/project-overview.md · 0 | Cline rules | testarch | 52/100 | 2 days ago | |
| sosan/proxy-llms.clinerules/routing-pattern.md · 0 | Cline rules | stylearchdo-not | 65/100 | 2 days ago | |
| sosan/proxy-llms.clinerules/security.md · 0 | Cline rules | setupstylearchsecurity+1 | 80/100 | 2 days ago | |
| sosan/proxy-llmsCLAUDE.md · 0 | CLAUDE.md | setupteststylesecurity+3 | 81/100 | 2 days ago |
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| bashdeban/fastmind.clinerules/.project-consistency-keeper2.md · 5 | Cline rules | setupbuildtestlint-format+11 | 100/100 | 3 days ago | |
| JCodesMore/ai-website-cloner-template.clinerules · 31k | Cline rules | buildlint-formatstylearch+3 | 97/100 | 2 days ago | |
| u9401066/zotero-keeper.clinerules/50-pubmed-project.md · 6 | Cline rules | testlint-formatstylearch+1 | 94/100 | 3 days ago | |
| u9401066/zotero-keepervscode-extension/resources/repo-assets/pubmed-search-mcp/.clinerules/50-pubmed-project.md · 6 | Cline rules | testlint-formatstylearch+1 | 94/100 | 3 days ago | |
| VaillerTeeter/HoshimiNest.clinerules/project-identity.md · 1 | Cline rules | setuparchtypesdo-not | 93/100 | yesterday | |
| blendsdk/codeops-mcp.clinerules/project.md · 0 | Cline rules | buildteststylearch+7 | 91/100 | 3 days ago | |
| cline/cline.clinerules/general.md · 66k | Cline rules | setupbuildstylearch+2 | 86/100 | 3 days ago | |
| u9401066/zotero-keeper.clinerules/60-pubmed-python.md · 6 | Cline rules | setuptestlint-formatstyle+2 | 86/100 | 3 days ago |
