Skip to content

Ban classes and this with lint, starting from eslint-plugin-functional #83

Done

Description

@DetweilerRyan

Why

On #81 the owner asked for functions rather than stateful classes:

i'm not a big fan of using stateful OOP when largely pure functional approaches result in simpler and less dynamic and therefore less error prone runtime execution.

Review enforces that today. This issue is to make lint enforce it, starting from eslint-plugin-functional, as the owner asked. A trial found that the plugin doesn't load in this repository, so this issue also proposes writing the rules ourselves.

What would be banned

  • Classes, except Error subclasses (ParseError, ConfigError), the usual way to type errors.
  • this, which only means something inside a class or a function used as a method.

Local, contained mutation stays allowed. Examples are the accumulator lists in oxCrap's walks, the loop state in allow.ts and coverage.ts, and let. The owner accepted these on #81 as "largely pure".

What it would flag today (trial, 2026-11-23):

  • no-classes flags 4 classes, with 146 uses of this inside them;
  • src/store/useReceiptStore.ts ReceiptStore: app state, genuinely stateful;
  • e2e/screenplay/actor.ts and scripts/oxcrap/features/screenplay/actor.ts Actor: stateful test helpers;
  • scripts/oxcrap/run.ts Run: holds only an immutable Host.

Each one needs converting, or keeping with a disable comment and a reason. That's a design decision per class, so it belongs in the pull request for this issue.

Candidates

Answers from 2026-11-23.

eslint-plugin-functional 10.0.1, through oxlint's jsPlugins

  • Is it needed? We'd use 2 of its rules: no-classes, with ignoreIdentifierPattern: "Error$", and no-this-expressions.
  • Is it the real one? Yes, eslint-functional/eslint-plugin-functional.
  • Is it maintained? Yes. It has two maintainers, 10.0.0 was released 2026-06-03, and 10.0.1 on 2026-09-16.
  • Does the license allow it? It's MIT.
  • What comes with it? About 160 packages in a scratch install. Its peer dependencies are eslint ^9 or ^10, which we don't use, and typescript ≥ 4.7.4. It also pulls in @typescript-eslint/utils, ts-api-utils and is-immutable-type.
  • Is it safe? No. npm audit reports 2 high: GHSA-ggr8-5vv4-36mx, stack exhaustion in deepmerge-ts < 8.0.0. The plugin pins deepmerge-ts ^7.1.5, so there is no fixed release; npm's suggested fix is a downgrade to 3.7.2. For us the exposure is small, since it only merges our own rule options in dev tooling, but it is a known unfixed vulnerability.
  • Does it fit here? No, it doesn't load.
    • Under this repo's TypeScript 7: loading fails with TypeError: Cannot read properties of undefined (reading 'Intrinsic') at ts-api-utils. That package needs the TypeScript compiler's JS API, which TypeScript 7 doesn't have. This is the same gap that dropped Stryker's TypeScript checker (test: Add mutation testing with Stryker, starting with oxCrap #77).
    • Under TypeScript 6, in a scratch folder, it loads. It found 4 no-classes, 146 no-this-expressions and 43 no-let, and lint went from about 0.28 s to about 0.83 s.
    • immutable-data needs type information, which oxlint's JS plugins can't give it. It crashes on every file where it checks an array method, and each crash drops the other rules' results for that file. Another project reports the same gap.
    • oxlint's JS plugins are alpha and not subject to semver (announcement).

Writing it ourselves: a local oxlint JS plugin

  • What it is: about 30 lines in one file, such as scripts/lint/functional.ts, loaded with "jsPlugins": ["./scripts/lint/functional.ts"]. oxlint supports local plugin files, and Node runs TypeScript ones natively.
  • What it covers: two rules matching the plugin's:
    • a ClassDeclaration/ClassExpression visitor that skips classes extending Error;
    • a ThisExpression visitor.
  • What it avoids: it needs no type information and adds no dependency, so the TypeScript 7 gap and the vulnerability don't apply.
  • What it costs:
    • Maintenance: the plugin's tests are ours to write. It's tooling, so it gets unit tests, and it falls in scope for oxCrap and mutation testing once those cover more than scripts/oxcrap/.
    • Stability: it relies on the same alpha JS plugin API.

Already installed: oxlint's max-classes-per-file: 0

  • What it bans: every class, with no new code or dependency.
  • What it costs: it can't exempt Error subclasses, so ParseError and ConfigError would each need a disable comment. It also leaves this in a function used as a method unflagged.

Recommendation

Write the two rules ourselves. eslint-plugin-functional doesn't load under TypeScript 7, and its version has a known unfixed high vulnerability. max-classes-per-file works, but it bans typed errors and leaves this alone. The local plugin is small, has no dependency, and bans exactly what the owner asked for.

Open questions

  • The four classes: convert or keep each one?
    • ReceiptStore is the app's store, so converting it touches the React side.
    • The two Actors follow the screenplay pattern used in the e2e tests and feature contracts.
    • Run converts easily.
  • Scope: should the rule cover the whole repo, as func-style does, or start with scripts/?
  • Where the reasons live: a .meta.md sidecar for the plugin, or a section in an existing doc.

Activity

  1. DetweilerRyan commented on Nov 24, 2026

    @DetweilerRyan
    OwnerAuthor

    Decisions given in a Claude Code session, 2026-11-24, before the overnight run. The owner asked for the work to be done without their input where possible, with stacked pull requests. If an undecided choice comes up, the owner said "Pick the reversible default": choose the most reversible option and list it under "Decisions made" in the pull request.

    What happens to the four classes? The plan is a small local oxlint JS plugin, with no new dependency, that bans classes, except Error subclasses, and this.

    "Convert all but ReceiptStore": oxCrap's Run and both screenplay Actors become functions. ReceiptStore keeps its class, with a disable comment and a reason: it wraps Yjs's own stateful types for useSyncExternalStore.

  2. added 8 commits that reference this issue on Nov 24, 2026
    e8bf7a7
    d2e8891
    b611726
    020cc8a
    05781ed
    fb91fcd
    a086116
    4b05714
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions