Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot an exception to this rule is in tests where the callback passed to describe and it are functions. Please update the instruction and eslint rule to reflect that (limiting the rule to hit only non *.test.ts files would be okay).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added exception for test files to the prefer-arrow-callback rule and updated Copilot instructions to document that describe and it functions use regular functions in tests. The rule now excludes **/*.test.ts and **/*.spec.ts files. Commit c13a5d1


**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
59 changes: 59 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// @ts-check

import { globalIgnores } from "eslint/config";

Check failure on line 3 in eslint.config.js

View workflow job for this annotation

GitHub Actions / Lint

`eslint/config` import should occur after import of `@eslint/js`
import globals from "globals";

Check failure on line 4 in eslint.config.js

View workflow job for this annotation

GitHub Actions / Lint

`globals` import should occur after import of `eslint-plugin-unused-imports`
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

Check failure on line 6 in eslint.config.js

View workflow job for this annotation

GitHub Actions / Lint

`typescript-eslint` import should occur after import of `eslint-plugin-unused-imports`
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([
Expand All @@ -24,7 +27,13 @@
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 +42,56 @@
],
},
],

// 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
Loading
Loading