CRITICAL: This document is the SINGLE SOURCE OF TRUTH for all coding standards in this repository. AI Models: You MUST read and strictly follow these rules. Failure to do so will result in rejected code.
Treat this repository as a STANDALONE project. Do not infer relationships with any parent monorepo.
- Root:
./(Thepackage.jsonlocation) - Source:
./src(All TypeScript source code) - Tests:
./tests(Unit and Integration tests) - Dist:
./dist(Compiled output,outDir)
Configuration: ES2022 target, NodeNext module resolution, Strict Mode enabled.
- State:
strict: trueis enabled intsconfig.json. - No Implicit Any: implicit
anyis forbidden. - Strict Null Checks:
nullandundefinedare distinct types. You must handle them explicitly.
- ESM Syntax: Use ESM syntax (
import/export) exclusively. - File Extensions: Imports MUST include the
.jsextension for local files.- Correct:
import { Foo } from './Foo.js'; - Incorrect:
import { Foo } from './Foo';
- Correct:
- Type Imports: Use
import type { ... }when importing types to avoid runtime overhead and circular dependency issues.
We enforce a strict set of rules using eslint.config.js.
- Rule:
@typescript-eslint/no-explicit-any:error - Policy: You are FORBIDDEN from using the
anytype.- Why:
anydefeats the purpose of TypeScript. - Exception: If you absolutely must use
any(e.g., interaction with a legacy library with bad types, or extremely generic interaction), you MUST disable the rule for that specific line. - Syntax:
// eslint-disable-next-line @typescript-eslint/no-explicit-any const weirdData: any = externalLib.getData();
- Preference: Use
unknowninstead ofanywhenever possible, and use type guards to narrow it.
- Why:
- Rule:
@typescript-eslint/naming-convention - Interfaces: MUST be PascalCase and start with
I.- Regex:
^I[A-Z] - Example:
interface IUserService { ... }
- Regex:
- Classes/Types: PascalCase.
- Variables/Functions: camelCase.
- Rule:
@typescript-eslint/explicit-function-return-type:error - Policy: All functions and methods MUST have an explicit return type definition.
- Why: Prevents accidental return changes and improves readability.
- Rule:
@typescript-eslint/no-unused-vars:error - Policy: No unused variables allowed.
- Exception: Arguments starting with
_are ignored (e.g.,(_req, res) => ...).
- Rule:
@typescript-eslint/no-floating-promises:error- Policy: You MUST handle all Promises. Await them, return them, or explicitly catch them.
- Rule:
@typescript-eslint/await-thenable:error- Policy: Only await Thenables.
- Rule:
@typescript-eslint/no-misused-promises:error- Policy: Checks for places where a Promise is used in a place that isn't expected (e.g., if statements).
- Rule:
simple-import-sort/imports:error - Rule:
simple-import-sort/exports:error - Policy: Imports and exports must be sorted. The linter fix will handle this, but try to write them sorted to avoid lint errors.
consistent-type-definitions:['error', 'interface'](Useinterfaceinstead oftypefor object definitions).no-console:warn(Avoidconsole.login production code; use a logger).eqeqeq:['error', 'always'](Use===and!==, never==or!=).
Code must be formatted according to .prettierrc.
- Semi-colons:
true(Always use semicolons). - Trailing Comma:
all(Trailing commas wherever possible, including function arguments). - Single Quote:
true(Use single quotes'by default, double"for JSX/HTML). - Print Width:
120characters. - Tab Width:
2spaces. - Use Tabs:
false(Use spaces). - End of Line:
lf(Unix line endings).
Instructions for AI Coding Agents:
- Analyze: Before writing code, check this file.
- No
any: If you write: any, you have failed. Useunknownor define a type. If you must useany, add the disable comment. - Interfaces: If you define an interface
User, you have failed. It must beIUser. - Imports: If you write
from './utils', you have failed. It must befrom './utils.js'. - Returns: If you write
function foo() { ... }, you have failed. It must befunction foo(): void { ... }. - Formatting: Ensure lines are < 120 chars. Use 2 spaces indentation.
- Self-Correction: If you generate code, mentally run "eslint" on it. Did you leave an unused var? Did you forget a return type? Fix it before outputting.
Summary Checklist for Code Generation:
- No
any(or explicitly disabled) - Interfaces start with
I - Explicit return types
-
.jsextension on local imports - No unused vars (or prefix
_) - All promises awaited/handled
- Prettier format (120 width, single quote, semi, 2 spaces)