coding-standards

작성자: cloudflare

Use when writing or reviewing TypeScript in this repo. Covers the no-`any` rule and where to put new types, the uppercase-acronym style guide, and the rules…

npx skills add https://github.com/cloudflare/sandbox-sdk --skill coding-standards

Coding Standards

TypeScript: No any

Never use any unless absolutely necessary — and that should be a final resort.

Process when you reach for any:

  1. Look for an existing type that fits. Most domains already have one.
  2. If no suitable type exists, define a proper one in the right location:
    • Shared typespackages/shared/src/types.ts or relevant subdirectory
    • SDK-specific typespackages/sandbox/src/clients/types.ts or the appropriate client file
    • Container-specific types → under packages/sandbox-container/src/ with appropriate naming
  3. Use the new type everywhere it applies — don't leave one-off shapes scattered around.

This catches errors at compile time instead of runtime and keeps the codebase consistent.

Style: Uppercase Acronyms

When an acronym appears inside a camelCase or PascalCase identifier, keep it fully uppercase:

✅ Do❌ Don't
SandboxRPCAPISandboxRpcApi
containerURLcontainerUrl
parseHTTPHeaderparseHttpHeader
getAPIKeygetApiKey

Applies to all acronyms: API, URL, HTTP, RPC, SSE, SSH, DNS, ID, etc.

Exception: library-provided names keep their original casing (e.g. capnweb's RpcTarget stays RpcTarget).

Code Comments

Write comments for future readers, not for the current conversation.

Comments should describe the current state of the code. A developer reading the code months later won't have context about bugs that were fixed, conversations that happened, or earlier implementations.

Don't reference historical context

// ❌ Bad: references a bug the reader knows nothing about
// Uses character tracking to avoid the bug where indexOf('') returns wrong position

// ❌ Bad: implies something was wrong before
// Start the server with proper WebSocket typing

// ❌ Bad: "prevent" implies there was a problem to prevent
// Assign synchronously to prevent race conditions

Do describe current behavior and design intent

// ✅ Good: describes what the code does now
// Returns parsed events and any remaining unparsed content

// ✅ Good: explains design rationale without historical context
// Assigned synchronously so concurrent callers share the same connection attempt

// ✅ Good: explains a non-obvious implementation choice
// Uses IIFE to ensure promise exists before any await points

Smell test

If your comment contains "to avoid", "to fix", "to prevent", "instead of", or "properly" — reconsider whether you're describing current behavior or quietly referencing something that no longer exists. Rewrite to describe what the code does now and why this design was chosen.

API Design

When adding or modifying SDK methods:

  • Use clear, descriptive names that indicate what the method does
  • Validate inputs before passing to container APIs
  • Provide helpful error messages with context (use the custom error classes in packages/shared/src/errors/)

cloudflare의 다른 스킬

workerd-api-review
cloudflare
workerd 코드 리뷰를 위한 성능 최적화, API 설계 및 호환성, 보안 취약점, 표준 사양 준수. tcmalloc 인식…
official
workerd-safety-review
cloudflare
메모리 안전성, 스레드 안전성, 동시성, 그리고 workerd 코드 리뷰를 위한 중요 탐지 패턴. V8/KJ 경계 위험 요소, 수명 관리 등을 다룹니다.
official
module-registry
cloudflare
workerd에서 모듈 레지스트리를 작업할 때 로드 — 모듈 해석, 컴파일, 평가, 등록을 읽기, 수정, 디버깅, 검토하는 경우…
official
reproduce
cloudflare
cloudflare/agents GitHub 이슈를 재현하기 위해 최소한의 Agents/Worker 프로젝트를 스캐폴딩하고 임시 Cloudflare 계정에 배포한 후 보고합니다…
official
local-explorer
cloudflare
로컬 탐색기 또는 로컬 API에 제품/리소스를 추가하는 방법. 새로운 로컬 API나 UI 라우트를 구현할 때 사용합니다.
official
commit-categories
cloudflare
커밋을 체인지로그와 "새로운 기능" 요약으로 분류하는 규칙입니다. 체인지로그 또는 whats-new 명령에서 커밋을 분류하기 전에 반드시 로드되어야 합니다. 제공하는 기능:
official
architecture
cloudflare
코드베이스를 처음 탐색할 때, 새 클라이언트 메서드를 추가할 때, 새 컨테이너 핸들러/서비스를 추가할 때, 또는 요청 흐름을 이해할 때 사용합니다.
official
changesets
cloudflare
변경셋을 생성하거나, 릴리즈를 준비하거나, 버전을 올릴 때 사용합니다. 참조할 패키지, 사용자 대상 변경셋 설명 작성 방법 등을 다룹니다.
official