Skip to content

Commit bff493c

Browse files
Copilotkraenhansen
andcommitted
Add comprehensive ESLint rules based on codebase patterns and update Copilot instructions
Co-authored-by: kraenhansen <[email protected]>
1 parent 0b04824 commit bff493c

File tree

4 files changed

+1571
-44
lines changed

4 files changed

+1571
-44
lines changed

.github/copilot-instructions.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,32 @@ npm run bootstrap # Build native components (weak-node-api, examples)
4646

4747
## Key Patterns
4848

49+
### Code Style and Conventions
50+
51+
**Import Organization**:
52+
- Use Node.js built-in prefix: `import assert from "node:assert/strict"`
53+
- Group imports: builtin → external → internal → local
54+
- Prefer type-only imports: `import type { NodePath } from "@babel/core"`
55+
56+
**Type Definitions**:
57+
- Prefer `type` over `interface` for simple types and unions
58+
- Use `as const` for readonly arrays and objects: `const PLATFORMS = ["android", "apple"] as const`
59+
- Common pattern: `type PlatformName = (typeof PLATFORMS)[number]`
60+
61+
**Function Style**:
62+
- Prefer `export function` over `export const fn =`
63+
- Use async/await consistently for asynchronous operations
64+
- Prefer arrow functions for callbacks and inline functions
65+
66+
**Error Handling**:
67+
- Prefer `assert()` from `node:assert/strict` over throwing errors directly
68+
- Use structured error handling with custom error types when needed
69+
70+
**Immutable Data Patterns**:
71+
- Use `as const satisfies Record<string, z.ZodType>` for Zod schemas
72+
- Prefer readonly data structures where applicable
73+
- Use `const` assertions for compile-time immutability
74+
4975
### Babel Transformation
5076

5177
The core magic happens in `packages/host/src/node/babel-plugin/plugin.ts`:

eslint.config.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import globals from "globals";
55
import eslint from "@eslint/js";
66
import tseslint from "typescript-eslint";
77
import eslintConfigPrettier from "eslint-config-prettier/flat";
8+
import importPlugin from "eslint-plugin-import";
9+
import nodePlugin from "eslint-plugin-n";
10+
import unusedImports from "eslint-plugin-unused-imports";
811

912
export default tseslint.config(
1013
globalIgnores([
@@ -24,7 +27,13 @@ export default tseslint.config(
2427
eslint.configs.recommended,
2528
tseslint.configs.recommendedTypeChecked,
2629
{
30+
plugins: {
31+
import: importPlugin,
32+
n: nodePlugin,
33+
"unused-imports": unusedImports,
34+
},
2735
rules: {
36+
// Existing rule
2837
"@typescript-eslint/no-floating-promises": [
2938
"error",
3039
{
@@ -33,6 +42,56 @@ export default tseslint.config(
3342
],
3443
},
3544
],
45+
46+
// Import/Export Organization
47+
"@typescript-eslint/consistent-type-imports": [
48+
"error",
49+
{ prefer: "type-imports" },
50+
],
51+
"import/order": [
52+
"error",
53+
{
54+
groups: ["builtin", "external", "internal", "parent", "sibling"],
55+
"newlines-between": "always",
56+
alphabetize: { order: "asc", caseInsensitive: true },
57+
},
58+
],
59+
"n/prefer-node-protocol": "error",
60+
61+
// Type Consistency
62+
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
63+
"@typescript-eslint/prefer-as-const": "error",
64+
65+
// Immutable Patterns (excluding prefer-readonly-parameter-types per feedback)
66+
"@typescript-eslint/prefer-readonly": "error",
67+
68+
// Error Standards
69+
"@typescript-eslint/prefer-promise-reject-errors": "error",
70+
"@typescript-eslint/only-throw-error": "error",
71+
72+
// Function Style
73+
"@typescript-eslint/promise-function-async": "error",
74+
"@typescript-eslint/require-await": "error",
75+
"prefer-arrow-callback": "error",
76+
77+
// Console Control
78+
"no-console": ["warn", { allow: ["error", "warn"] }],
79+
80+
// Unused Code
81+
"@typescript-eslint/no-unused-vars": [
82+
"error",
83+
{
84+
argsIgnorePattern: "^_",
85+
varsIgnorePattern: "^_",
86+
},
87+
],
88+
"unused-imports/no-unused-imports": "error",
89+
90+
// Strict Typing Enhancements
91+
"@typescript-eslint/strict-boolean-expressions": "warn",
92+
"@typescript-eslint/no-unnecessary-condition": "warn",
93+
"@typescript-eslint/prefer-nullish-coalescing": "error",
94+
"@typescript-eslint/prefer-optional-chain": "error",
3695
},
3796
},
3897
{

0 commit comments

Comments
 (0)