Skip to content

Latest commit

 

History

History
170 lines (127 loc) · 6.89 KB

AGENTS.md

File metadata and controls

170 lines (127 loc) · 6.89 KB

AGENTS.md — effect-oxlint

Effect-first library for writing oxlint custom lint rules. Wraps @oxlint/plugins in Effect v4 idioms.

Build / Lint / Test Commands

bun run check          # lint + format + typecheck (with auto-fix)
bun run test           # vitest run (all tests)
bun run typecheck      # tsgo type-check only

Running a single test

bunx vitest run test/Rule.test.ts              # single file
bunx vitest run -t "reports for matching"       # by test name pattern
bunx vitest run test/AST.test.ts -t "matchMember"  # file + name

Verification before submitting

All three must pass:

bun run check && bun run test && bun run typecheck

Project Structure

src/           12 modules — AST, Comment, Diagnostic, Plugin, Rule, RuleContext,
               Scope, SourceCode, Testing, Token, Visitor, index (barrel)
test/          11 test files — one per source module
vite.config.ts Lint rules, formatting, test config (vite-plus)

Single-package project. Bun is the package manager (bun@1.3.11). No monorepo tooling.

Code Style

Formatting (enforced by vite-plus)

  • Tabs for indentation (width 4), print width 80
  • Single quotes, semicolons, no trailing commas
  • Arrow parens always: (x) => ...
  • LF line endings
  • JSON files: 2-space indentation

Imports

  1. Type-only imports first: import type { ... } from '...'
  2. External namespace imports: import * as Arr from 'effect/Array'
  3. Internal imports last: import * as AST from './AST.ts'

Canonical Effect aliases (required):

import * as Arr from 'effect/Array';
import * as Option from 'effect/Option';
import * as P from 'effect/Predicate';
import * as R from 'effect/Record';
import * as Schema from 'effect/Schema';
import * as Str from 'effect/String';

Core combinators from root: import { Effect, pipe, flow, Match } from 'effect' — or from dedicated module: import * as Effect from 'effect/Effect'

All local imports include .ts extension: './AST.ts', not './AST'.

File & Naming Conventions

  • Source files: PascalCase (Rule.ts, SourceCode.ts, RuleContext.ts)
  • Test files: <ModuleName>.test.ts matching source name
  • Functions/variables: camelCase (matchMember, fromOxlintContext)
  • Types/interfaces/classes: PascalCase (RuleConfig, EffectVisitor)
  • Service keys: namespaced strings ('effect-oxlint/RuleContext')

Module Structure

Every source file follows this layout:

  1. Module-level JSDoc with @since tag
  2. Imports (ordered as above)
  3. Sections separated by // ---...--- // Section Name // ---...---
  4. Exported functions with JSDoc (@since, @example)
  5. Internal helpers marked /** @internal */

Types

  • readonly on all interface fields and function parameters
  • ReadonlyArray<T> instead of T[]
  • No any, no @ts-ignore, no non-null assertions (!)
  • exactOptionalPropertyTypes and noUncheckedIndexedAccess are enabled
  • Use | undefined explicitly for optional properties

Effect Patterns

  • Option for absence: Convert nullable values with Option.fromNullishOr at boundaries. Chain with Option.map, Option.flatMap, Option.match. Never use Option.getOrThrow.
  • Dual API: Public combinators support data-first and data-last via dual:
    export const matchMember: {
        (obj: string, props: string[]): (node: ESTree.Node) => Option<...>;
        (node: ESTree.Node, obj: string, props: string[]): Option<...>;
    } = dual(3, (node, obj, props) => { ... });
  • Effect.gen with function*: For effectful setup and complex combinators
  • Effect.runSync only at runtime boundaries: The FFI bridge in Rule.ts and test harnesses
  • Ref for mutable state: Ref.make / Ref.update in effectful contexts
  • Effect.void for no-ops: Not Effect.succeed(undefined)
  • pipe for composition: Especially Option chains and Effect pipelines
  • Context.Service for services: With unique namespaced string key

Effect Module Usage (not native JS)

  • Arr.* over Array.prototype.* — Arr.map, Arr.filter, Arr.reduce, Arr.contains, Arr.match, Arr.join
  • R.* over Object.* — R.union, R.filter, R.map
  • Str.* over String.prototype.* — Str.trim, Str.startsWith, Str.split
  • P.isString, P.isObject over raw typeof checks
  • Option over null | undefined in domain code
  • No imperative for / for...of loops in domain code

Error Handling

  • Return Option.none() or Effect.void for no-op / absent paths
  • No throw or try/catch in domain code (use Effect.try, Effect.tryPromise)
  • Tagged errors via Schema.TaggedErrorClass for cross-module failures
  • Test files may use throw and try/catch (lint overrides configured)

Testing

  • Framework: Vitest 4 + @effect/vitest
  • Import test utilities: import { describe, expect, test } from '@effect/vitest'
  • Effectful tests: it.effect('name', () => Effect.gen(function* () { ... }).pipe(Effect.provide(TestLayer)))
  • Pure tests: test('name', () => { expect(...).toBe(...) })
  • Use test for pure tests, it.effect for effectful tests (never it for pure tests)
  • Test module src/Testing.ts provides createMockContext, runRule, expectDiagnostics
  • Section separators between test groups (same // --- format as source)

JSDoc

  • Every exported API has JSDoc with @since 0.x.0
  • Module-level doc block at top of each file with description and @since
  • @internal marks non-public exports
  • @example with code blocks for key APIs
  • @deprecated where upstream deprecation exists

Oxlint-Specific Patterns

  • Re-export oxlint types with Oxlint prefix to avoid collision: OxlintPlugin, OxlintComment
  • RuleContext is a Context.Service wrapping oxlint's context
  • withSourceCode pattern: Effect.service(RuleContext).pipe(Effect.map(ctx => fn(ctx.sourceCode)))
  • Visitors are Record<string, (node: ESTree.Node) => Effect<void>>
  • toOxlintVisitor converts Effect visitors to plain oxlint visitors at the boundary
  • FFI boundary casts (as never) are used in Testing.ts node builders and are documented

Lint Rules (from vite.config.ts)

The project dogfoods its own oxlint-effect rules. Key enforced rules:

  • effect/throw-in-effect-gen: error — no throwing inside Effect.gen
  • effect/vm-in-wrong-file: error — view models in correct files
  • effect/no-opaque-instance-fields: error — no opaque instance fields
  • @typescript-eslint/no-explicit-any: error
  • @typescript-eslint/no-non-null-assertion: error
  • ~50 additional effect/* rules at warn level (prefer-option-over-null, avoid-native-fetch, prefer-match-over-switch, etc.)

Test file overrides: avoid-untagged-errors and avoid-try-catch disabled. FFI boundary overrides: prefer-option-over-null, casting-awareness, avoid-any, avoid-native-object-helpers, effect-run-in-body disabled for SourceCode.ts, Testing.ts, Rule.ts, Visitor.ts.