Skip to content

Commit 21b7459

Browse files
authored
chore(engine): implement UT & copilot instructions (#23)
1 parent 071b4e0 commit 21b7459

33 files changed

+2895
-565
lines changed

.github/copilot-instructions.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
applyTo: "**/*.js, **/*.mjs, **/*.cjs"
3+
---
4+
5+
# Coding Standards for This Project
6+
7+
## 1  Language & Runtime
8+
9+
* Write all source files in **modern JavaScript (ECMAScript 2024)**.
10+
* Target **Node.js 22 or newer** and use native **ESM** syntax (`import`/`export`).
11+
12+
## 2  General Style
13+
14+
* Prefer **clarity over cleverness**; strive for readable, maintainable code.
15+
* Always use **async/await** for asynchronous operations.
16+
* When converting callback APIs, use `node:util` → `promisify`.
17+
* **Strings:** use **double quotes** (`"…"`) or **template literals** (\`\`); never single quotes.
18+
* **Semicolons:** terminate *every* statement with `;`.
19+
* **Equality:** use strict operators `===` / `!==`; never `==` / `!=`.
20+
* **Variables:**
21+
* `const` for bindings that never change,
22+
* `let` for re‑assignable bindings.
23+
* **Loops:** use `for…of` for arrays/iterables; use `for…in` only for object keys when truly needed.
24+
* **Arrow functions:** **always** wrap parameters in parentheses—even a single parameter.
25+
* **Conditionals & loops:** wrap condition expressions in parentheses.
26+
* No inline end‑of‑line comments; place comments on the **preceding line**.
27+
Keep comments concise; code should be self‑explanatory.
28+
* Respect **.editorconfig** rules (indentation, line endings, etc.).
29+
* Favor a **functional style** (pure functions, immutability) when practical.
30+
* Before adding any external dependency, **ask the user** for approval.
31+
32+
## 3  Imports
33+
34+
```js
35+
// Import Node.js Dependencies
36+
import fs from "node:fs/promises";
37+
import path from "node:path";
38+
39+
// Import Third‑party Dependencies
40+
import express from "express";
41+
42+
// Import Internal Dependencies
43+
import { doSomething } from "./lib/do‑something.js";
44+
```
45+
46+
* Order **exactly** as shown: Node.js core → Third‑party → Internal.
47+
* Precede each block with the indicated comment.
48+
* Use **`node:`** prefix for Node.js core modules (e.g., `import fs from "node:fs"`).
49+
* Use **`import`** syntax for all imports; never `require()`.
50+
51+
## 4  Naming
52+
53+
| Kind | Convention | Example |
54+
| --------------------------------- | ---------------- | ----------------------- |
55+
| Classes, Interfaces, Type Aliases | **PascalCase** | `class HttpServer {}` |
56+
| Variables, Functions, Methods | **camelCase** | `const fetchData = …` |
57+
| Private class fields & methods | `#` prefix | `#connectionPool` |
58+
| Exported constants | **ALL\_CAPS** | `export const API_URL` |
59+
| File‑local constants | `k` + PascalCase | `const kTimeoutMs = 30` |
60+
61+
Place all constants directly **beneath the imports** under a `// CONSTANTS` comment.
62+
63+
## 5  Testing
64+
65+
* Use Node.js **core test runner** `node:test`.
66+
* Use **`node:assert`** for assertions.
67+
* Cover edge cases and error handling.
68+
* **Never** modify production code solely to ease testing.
69+
* For browser‑like APIs, mock the DOM with **`happy-dom`**.
70+
71+
## 6  User Interaction (for Copilot / LLM)
72+
73+
* When the spec is ambiguous, **ask clarifying questions**.
74+
* Reply in the **same language** as the prompt; generate **English** for code, comments, and docs.

.github/markdown.instructions.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
description: 'Documentation and content creation standards'
3+
applyTo: '**/*.md'
4+
---
5+
6+
## Markdown Content Rules
7+
8+
The following markdown content rules are enforced in the validators:
9+
10+
1. **Headings**: Use appropriate heading levels (H2, H3, etc.) to structure your content. Do not use an H1 heading, as this will be generated based on the title.
11+
2. **Lists**: Use bullet points or numbered lists for lists. Ensure proper indentation and spacing.
12+
3. **Code Blocks**: Use fenced code blocks for code snippets. Specify the language for syntax highlighting.
13+
4. **Links**: Use proper markdown syntax for links. Ensure that links are valid and accessible.
14+
5. **Images**: Use proper markdown syntax for images. Include alt text for accessibility.
15+
6. **Tables**: Use markdown tables for tabular data. Ensure proper formatting and alignment.
16+
7. **Line Length**: Limit line length to 400 characters for readability.
17+
8. **Whitespace**: Use appropriate whitespace to separate sections and improve readability.
18+
19+
## Formatting and Structure
20+
21+
Follow these guidelines for formatting and structuring your markdown content:
22+
23+
- **Headings**: Use `##` for H2 and `###` for H3. Ensure that headings are used in a hierarchical manner. Recommend restructuring if content includes H4, and more strongly recommend for H5.
24+
- **Lists**: Use `-` for bullet points and `1.` for numbered lists. Indent nested lists with two spaces.
25+
- **Code Blocks**: Use triple backticks (`) to create fenced code blocks. Specify the language after the opening backticks for syntax highlighting (e.g., `csharp).
26+
- **Links**: Use `[link text](URL)` for links. Ensure that the link text is descriptive and the URL is valid.
27+
- **Images**: Use `![alt text](image URL)` for images. Include a brief description of the image in the alt text.
28+
- **Tables**: Use `|` to create tables. Ensure that columns are properly aligned and headers are included.
29+
- **Line Length**: Break lines at 80 characters to improve readability. Use soft line breaks for long paragraphs.
30+
- **Whitespace**: Use blank lines to separate sections and improve readability. Avoid excessive whitespace.
31+
32+
## Validation Requirements
33+
34+
Ensure compliance with the following validation requirements:
35+
36+
- **Content Rules**: Ensure that the content follows the markdown content rules specified above.
37+
- **Formatting**: Ensure that the content is properly formatted and structured according to the guidelines.
38+
- **Validation**: Run the validation tools to check for compliance with the rules and guidelines.

.github/typescript.instructions.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
applyTo: "**/*.ts, **/*.mts, **/*.cts"
3+
---
4+
5+
# TypeScript Coding Standards for This Project
6+
7+
These guidelines complement the existing **JavaScript** rules and are **binding** for all TypeScript source files.
8+
9+
---
10+
11+
## 1  Compiler Baseline (`tsconfig.json`)
12+
13+
The project’s `tsconfig.json` is **authoritative**. Do **not** change it.
14+
15+
```json
16+
{
17+
"compilerOptions": {
18+
"target": "es2022",
19+
"module": "NodeNext",
20+
"esModuleInterop": true,
21+
"allowJs": true,
22+
"resolveJsonModule": true,
23+
"isolatedModules": true,
24+
"verbatimModuleSyntax": true,
25+
26+
"strict": true,
27+
"strictNullChecks": true,
28+
"noImplicitOverride": true,
29+
"noImplicitThis": true,
30+
"noImplicitReturns": true,
31+
"noUnusedLocals": true,
32+
33+
"skipLibCheck": true,
34+
"forceConsistentCasingInFileNames": true,
35+
36+
"sourceMap": true,
37+
"declaration": true,
38+
"declarationMap": true,
39+
"experimentalDecorators": true,
40+
"lib": ["es2022"]
41+
}
42+
}
43+
```
44+
45+
Key implications:
46+
47+
* **ESM only** (`module: "NodeNext"`, `verbatimModuleSyntax: true`). Use `import`/`export`, never CommonJS `require`.
48+
* **Target ES2022** → you may use class fields, `at()` on arrays, `Error.cause`, `RegExp matchIndices`, etc.
49+
* **`strict` mode** with additional checks: treat all compile‑time warnings as **errors**.
50+
* **`allowJs`: true** means you *may* import legacy `.js` files; new code **must** be `.ts`/`.tsx`.
51+
* **Decorators** are enabled (`experimentalDecorators`). Use them sparingly and document intent.
52+
53+
---
54+
55+
## 2  General Style
56+
57+
(The JavaScript standards apply; this section covers TS‑specifics.)
58+
59+
| Topic | Rule |
60+
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
61+
| **Types vs Interfaces** | Prefer **`type` aliases** for unions, mapped & conditional types. <br>Use **`interface`** for plain object shapes intended for extension. |
62+
| **Explicit typing** | Always annotate **public APIs** (exported functions, class members, constants) with explicit types.<br>Local variables may rely on inference if trivial. |
63+
| **`any``unknown`** | `any` is allowed by config but **should be avoided**; use `unknown` with proper narrowing. |
64+
| **Nullish values** | Handle `null` / `undefined` explicitly (`strictNullChecks`). Use the *nullish coalescing* operator (`??`) or early returns. |
65+
| **Enums** | Avoid `enum`; prefer `as const` objects or union literal types for safer exhaustiveness. |
66+
| **Tuples & readonly** | Mark tuples as `readonly` when contents shouldn’t mutate (`readonly [T1, T2]`). |
67+
| **Generics** | Provide descriptive parameter names (`TData`, `TError`). Supply default type parameters when helpful. |
68+
| **Decorators** | Keep decorator logic *pure*; avoid hidden side‑effects. Document with JSDoc above the decorator. |
69+
| **Assertions & type casts** | Prefer `as` casting; avoid the angle‑bracket form. Keep casts to the narrowest scope possible. |
70+
| **Error handling** | Use custom `class`es extending `Error` with a descriptive **PascalCase** name and optional `cause`. |
71+
72+
---
73+
74+
## 3  Imports & Module Resolution
75+
76+
1. **Order** exactly as in the JavaScript guide: core → third‑party → internal.
77+
Always include file extensions (e.g. `"./util.js"`).
78+
2. **JSON modules** can be imported directly (`resolveJsonModule: true`).
79+
80+
```ts
81+
import packageJson from "../package.json" assert { type: "json" };
82+
```
83+
3. **Type‑only imports**: use the `import type { … } from "…";` form to avoid runtime overhead.
84+
4. Keep each import statement **on its own line**.
85+
86+
---
87+
88+
## 4  Naming Conventions
89+
90+
Follow the same table as the JavaScript guide, with additions:
91+
92+
* **Type parameters**: `T`, `TValue`, `TOptions` (PascalCase prefixed with `T`).
93+
* **Namespace imports** (rare): camelCase (e.g. `import * as fs from "node:fs/promises";`).
94+
95+
---
96+
97+
## 5  Testing
98+
99+
* Write tests in **TypeScript** (preferred extension `.spec.ts`).
100+
* Use **Node.js core test runner** (`node:test`). Configure the runner to load `tsx` or `ts-node/register` for runtime transpilation.

0 commit comments

Comments
 (0)