بنقرة واحدة
coding-standards
Coding standards, best practices, and patterns for TypeScript and Node.js/Bun CLI development.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Coding standards, best practices, and patterns for TypeScript and Node.js/Bun CLI development.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Scan skills to extract cross-cutting principles and distill them into rules — append, revise, or create new rule files
Use this skill when handling user input, working with file paths, spawning processes, working with secrets, or integrating external APIs. Provides CLI-focused security checklist and patterns.
Use this skill when writing new features, fixing bugs, or refactoring code. Enforces test-driven development with 80%+ coverage including unit and integration tests.
Use when building Elysia web applications or when the user asks about Elysia APIs, routing, MVC/folder structure, lifecycle hooks, validation/models, plugins, Eden, WebSockets, streaming, or best practices. TRIGGER when code imports from 'elysia' or '@elysiajs/*', or the user mentions Elysia. Prefer `elysia docs essential/best-practice` and `elysia search` (from @sc30gsw/elysiajs-cli) for authoritative patterns; use `elysia req` to hit routes without an HTTP server (via `app.handle()`).
| name | coding-standards |
| description | Coding standards, best practices, and patterns for TypeScript and Node.js/Bun CLI development. |
| origin | ECC |
Coding standards applicable to this TypeScript CLI project.
// ✅ GOOD: Descriptive names
const docsRepoPath = "essential/route";
const isBunRuntime = true;
const cacheExpiryMs = 24 * 60 * 60 * 1000;
// ❌ BAD: Unclear names
const p = "essential/route";
const flag = true;
const x = 86400000;
// ✅ GOOD: Verb-noun pattern
async function fetchDoc(path: DocsRepoRelativePath): Promise<Result<string, Error>> {}
function parseSearchOptions(raw: SearchCliOptionsRaw): SearchResolvedOptions {}
function isCacheValid(cachePath: string): boolean {}
// ❌ BAD: Unclear or noun-only
async function doc(p: string) {}
function options(raw: any) {}
// ✅ ALWAYS use spread operator
const updatedOptions = {
...options,
port: 8080,
};
const updatedArray = [...routes, newRoute];
// ❌ NEVER mutate directly
options.port = 8080; // BAD
routes.push(newRoute); // BAD
import { Result } from "better-result";
// ✅ GOOD: Result pattern for fallible operations
async function fetchDoc(path: string): Promise<Result<string, Error>> {
return Result.tryPromise({
try: async () => await fetcher(path),
catch: (e) => (e instanceof Error ? e : new Error(String(e))),
});
}
// Use exitOnError in CLI command actions
const content = exitOnError(await fetchDoc(path));
// ❌ BAD: Swallowing errors silently
async function fetchDoc(path: string) {
try {
return await fetcher(path);
} catch {
return null; // Silent failure
}
}
// ✅ GOOD: Parallel execution when possible
const [docsContent, searchIndex] = await Promise.all([fetchDoc(path), loadSearchIndex()]);
// ❌ BAD: Sequential when unnecessary
const docsContent = await fetchDoc(path);
const searchIndex = await loadSearchIndex();
// ✅ GOOD: Proper types with no any
interface DocsResolvedOptions {
cache: boolean;
}
function parseDocsOptions(raw: Partial<{ cache: boolean }>): DocsResolvedOptions {
return { cache: raw.cache !== false };
}
// ❌ BAD: Using 'any'
function parseDocsOptions(raw: any): any {
return raw;
}
src/
├── cli.ts # Entry point — registers all commands
├── commands/
│ ├── docs/index.ts # registerDocsCommand(program)
│ ├── search/index.ts # registerSearchCommand(program)
│ ├── request/index.ts # registerRequestCommand(program)
│ ├── serve/index.ts # registerServeCommand(program)
│ └── optimize/index.ts # registerOptimizeCommand(program)
├── constants/ # Shared constants
├── types/ # TypeScript types and brand types
└── utils/
├── display.ts # Terminal output helpers
├── fetcher.ts # HTTP fetch utilities
├── loader.ts # App entry resolution
├── routes.ts # Route extraction
└── runtime.ts # Bun/Node.js detection
src/commands/docs/index.ts # camelCase for modules
src/utils/display.ts # camelCase for utilities
src/types/http-method.ts # kebab-case for type files
// ✅ GOOD: Explain WHY, not WHAT
// Use exponential backoff to avoid overwhelming the GitHub API during outages
const delay = Math.min(1000 * Math.pow(2, retryCount), 30000);
// Commander passes inverted --no-cache as cache: false
const cache = raw.cache !== false;
// ❌ BAD: Stating the obvious
// Check if cache is valid
const isValid = isCacheValid(cachePath);
/**
* Fetch documentation from the ElysiaJS documentation repository.
*
* @param docPath - Repo-relative path to the documentation file
* @returns Ok with the markdown content, or Err with a descriptive error
*/
export async function fetchDoc(docPath: DocsRepoRelativePath): Promise<Result<string, Error>> {
// Implementation
}
import { describe, it, expect, vi } from "vitest";
describe("functionName", () => {
it("returns expected value for valid input", () => {
// Arrange
const input = "essential/route";
// Act
const result = normalizeDocsRepoRelativePath(input);
// Assert
expect(result).toBe("essential/route.md");
});
});
// ✅ GOOD: Descriptive test names
it("returns empty array when no routes match", () => {});
it("throws on invalid entry file path", () => {});
it("falls back to Node.js mode when Bun is unavailable", () => {});
// ❌ BAD: Vague test names
it("works", () => {});
it("test route", () => {});
Watch for these anti-patterns:
// ❌ BAD: Function > 50 lines
function processCommand() {
// 100 lines of code
}
// ✅ GOOD: Split into smaller functions
function processCommand() {
const opts = parseOptions(raw);
const result = await runCommand(opts);
return exitOnError(result);
}
// ❌ BAD: 5+ levels of nesting
if (entry) {
if (app) {
if (routes) {
if (routes.length > 0) {
for (const route of routes) {
// ...
}
}
}
}
}
// ✅ GOOD: Early returns
if (!entry) return
if (!app) return
if (!routes?.length) return
for (const route of routes) { ... }
// ❌ BAD: Unexplained numbers
if (retryCount > 3) {
}
const ttl = 86400000;
// ✅ GOOD: Named constants
const MAX_RETRIES = 3;
const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
if (retryCount > MAX_RETRIES) {
}
Remember: Code quality is not negotiable. Clear, maintainable code enables rapid development and confident refactoring.