Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ npm run bootstrap # Build native components (weak-node-api, examples)

## Key Patterns

### Code Style and Conventions

**Import Organization**:
- Use Node.js built-in prefix: `import assert from "node:assert/strict"`
- Group imports: builtin → external → internal → local
- Prefer type-only imports: `import type { NodePath } from "@babel/core"`

**Type Definitions**:
- Prefer `type` over `interface` for simple types and unions
- Use `as const` for readonly arrays and objects: `const PLATFORMS = ["android", "apple"] as const`
- Common pattern: `type PlatformName = (typeof PLATFORMS)[number]`

**Function Style**:
- Prefer `export function` over `export const fn =`
- Use async/await consistently for asynchronous operations
- Prefer arrow functions for callbacks and inline functions (except in tests where `describe` and `it` use regular functions)

**Error Handling**:
- Prefer `assert()` from `node:assert/strict` over throwing errors directly
- Use structured error handling with custom error types when needed

**Immutable Data Patterns**:
- Use `const` assertions for compile-time immutability

### Babel Transformation

The core magic happens in `packages/host/src/node/babel-plugin/plugin.ts`:
Expand Down
74 changes: 71 additions & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// @ts-check

import { globalIgnores } from "eslint/config";
// import { globalIgnores } from "eslint/config";
import globals from "globals";
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import eslintConfigPrettier from "eslint-config-prettier/flat";
import importPlugin from "eslint-plugin-import";
import nodePlugin from "eslint-plugin-n";
import unusedImports from "eslint-plugin-unused-imports";

export default tseslint.config(
globalIgnores([
{
ignores: [
"**/dist/**",
"**/build/**",
"apps/test-app/ios/**",
Expand All @@ -20,11 +24,18 @@ export default tseslint.config(
"packages/node-tests/tests/**",
"packages/node-tests/*.generated.js",
"packages/node-tests/*.generated.d.ts",
]),
],
},
eslint.configs.recommended,
tseslint.configs.recommendedTypeChecked,
{
plugins: {
import: importPlugin,
n: nodePlugin,
"unused-imports": unusedImports,
},
rules: {
// Existing rule
"@typescript-eslint/no-floating-promises": [
"error",
{
Expand All @@ -33,6 +44,56 @@ export default tseslint.config(
],
},
],

// Import/Export Organization
"@typescript-eslint/consistent-type-imports": [
"error",
{ prefer: "type-imports" },
],
"import/order": [
"error",
{
groups: ["builtin", "external", "internal", "parent", "sibling"],
"newlines-between": "always",
alphabetize: { order: "asc", caseInsensitive: true },
},
],
"n/prefer-node-protocol": "error",

// Type Consistency
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
"@typescript-eslint/prefer-as-const": "error",

// Immutable Patterns (excluding prefer-readonly-parameter-types per feedback)
"@typescript-eslint/prefer-readonly": "error",

// Error Standards
"@typescript-eslint/prefer-promise-reject-errors": "error",
"@typescript-eslint/only-throw-error": "error",

// Function Style
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-await": "error",
"prefer-arrow-callback": "error",

// Console Control
"no-console": ["warn", { allow: ["error", "warn"] }],

// Unused Code
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
"unused-imports/no-unused-imports": "error",

// Strict Typing Enhancements
"@typescript-eslint/strict-boolean-expressions": "warn",
"@typescript-eslint/no-unnecessary-condition": "warn",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/prefer-optional-chain": "error",
},
},
{
Expand Down Expand Up @@ -81,4 +142,11 @@ export default tseslint.config(
},
},
},
{
// Exception for test files: allow regular functions in describe() and it() callbacks
files: ["**/*.test.ts", "**/*.spec.ts"],
rules: {
"prefer-arrow-callback": "off",
},
},
);
Loading