eslint-plugin-functype 2.121.1 → 2.123.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,28 +25,46 @@ import functype from "eslint-plugin-functype"
25
25
  export default [functype.configs.strict]
26
26
  ```
27
27
 
28
+ ### Agent mode
29
+
30
+ For code a coding agent writes. An agent acts on what fails its build and passes over a warning, so `agent` has no warnings: every rule is `error` or `off`.
31
+
32
+ ```js
33
+ import functype from "eslint-plugin-functype"
34
+
35
+ export default [functype.configs.agent]
36
+ ```
37
+
38
+ - **`error`:** everything `strict` errors on, plus `no-floating-io` and the two React rules, which `strict` still warns on while they're measured. A forgotten `.run()` or a throw in render is the kind of mistake an agent makes and a reviewer misses.
39
+ - **`off`:** `prefer-flatmap` and `prefer-do-notation`, whose precision is unmeasured. At `error` they would teach an agent to write `eslint-disable`. Each moves to `error` once it's measured. `prefer-list` is off too: with type-aware linting, `no-array-mutation`, at `error`, covers its in-place-change case, and the rest asks for `ReadonlyArray<T>` types, a typing choice `strict` keeps at `warn`.
40
+ - `prefer-option`, `prefer-either` and `prefer-try` are `error`, as in `strict`. At a real boundary the agent marks it instead: `@interop <reason>` or `invariant()` for a throw (see below), `Wire<T>` for a data shape.
41
+ - `no-array-mutation` and `no-floating-io` need type-aware linting (typescript-eslint's parser with `parserOptions.projectService`). Without it they report nothing.
42
+ - Make sure the agent runs lint. An error it never sees doesn't steer it, so put `eslint` in the check it runs before it's done, such as `pnpm validate`.
43
+
28
44
  ## Rules
29
45
 
30
- | Rule | Recommended | Strict | Description |
31
- | ---------------------------------------- | :---------: | :----: | -------------------------------------------------------------------------------------------- |
32
- | `functype/no-let` | error | error | Use `const`; no reassignment |
33
- | `functype/no-imperative-loops` | error | error | Use `List`/array methods, async traversal or `IO.forEach` instead of loops |
34
- | `functype/prefer-functype-map` | error | error | Use functype `Map` instead of a native `Map` you only read |
35
- | `functype/prefer-functype-set` | error | error | Use functype `Set` instead of a native `Set` you only read |
36
- | `functype/collection-naming` | error | error | Import functype's `Map`/`Set` under their own names; spell the built-in `globalThis.Map` |
37
- | `functype/prefer-map` | error | error | Use `map` instead of pushing inside `forEach` |
38
- | `functype/prefer-fold` | error | error | Use `fold` instead of branching on `isSome()`/`isLeft()`/… |
39
- | `functype/prefer-option` | warn | error | Use `Option` instead of `null`/`undefined` |
40
- | `functype/prefer-either` | warn | error | Use `Either` for typed domain errors instead of `throw` |
41
- | `functype/prefer-try` | warn | error | Use `Try` / `Try.fromPromise` instead of try/catch |
42
- | `functype/prefer-flatmap` | warn | warn | Use `flatMap` instead of `map().flat()` |
43
- | `functype/prefer-do-notation` | warn | warn | Use `Do` notation for chained operations |
44
- | `functype/no-get-unsafe` | off | error | Disallow unsafe extraction (`.orThrow()`, `.expect()`) |
45
- | `functype/prefer-list` | off | warn | Use `List` instead of native arrays |
46
- | `functype/no-array-mutation` | off | error | Don't change an array in place (`push`, `sort`, `xs[i] = v`…); build a new one |
47
- | `functype/no-floating-io` | off | warn | Don't build an `IO` and drop it, or `await` it unrun; run, return or `yield*` it |
48
- | `functype/no-getOrThrow-in-render` | off | warn | React: no bare `.orThrow()` in a component or hook body; a throw in render unmounts the tree |
49
- | `functype/must-fold-on-component-return` | off | warn | React: render an `Option`/`Either`/`Try` with `fold` or `<MatchOption>`, not a guard or `&&` |
46
+ | Rule | Recommended | Strict | Agent | Description |
47
+ | ---------------------------------------- | :---------: | :----: | :---: | -------------------------------------------------------------------------------------------- |
48
+ | `functype/no-let` | error | error | error | Use `const`; no reassignment |
49
+ | `functype/no-imperative-loops` | error | error | error | Use `List`/array methods, async traversal or `IO.forEach` instead of loops |
50
+ | `functype/prefer-functype-map` | error | error | error | Use functype `Map` instead of a native `Map` you only read |
51
+ | `functype/prefer-functype-set` | error | error | error | Use functype `Set` instead of a native `Set` you only read |
52
+ | `functype/collection-naming` | error | error | error | Import functype's `Map`/`Set` under their own names; spell the built-in `globalThis.Map` |
53
+ | `functype/prefer-map` | error | error | error | Use `map` instead of pushing inside `forEach` |
54
+ | `functype/prefer-fold` | error | error | error | Use `fold` instead of branching on `isSome()`/`isLeft()`/… |
55
+ | `functype/prefer-option` | warn | error | error | Use `Option` instead of `null`/`undefined` |
56
+ | `functype/prefer-either` | warn | error | error | Use `Either` for typed domain errors instead of `throw` |
57
+ | `functype/prefer-try` | warn | error | error | Use `Try` / `Try.fromPromise` instead of try/catch |
58
+ | `functype/prefer-flatmap` | warn | warn | off | Use `flatMap` instead of `map().flat()` |
59
+ | `functype/prefer-do-notation` | warn | warn | off | Use `Do` notation for chained operations |
60
+ | `functype/no-get-unsafe` | off | error | error | Disallow unsafe extraction (`.orThrow()`, `.expect()`) |
61
+ | `functype/prefer-list` | off | warn | off | Use `List` instead of native arrays |
62
+ | `functype/no-array-mutation` | off | error | error | Don't change an array in place (`push`, `sort`, `xs[i] = v`…); build a new one |
63
+ | `functype/no-floating-io` | off | warn | error | Don't build an `IO` and drop it, or `await` it unrun; run, return or `yield*` it |
64
+ | `functype/no-floating-result` | off | error | error | Don't drop an `Either`/`Try` result; a failure in it is silently ignored |
65
+ | `functype/no-serialize-container` | off | error | error | Don't send an `Either`/`Option`/`List` to `c.json()` or `JSON.stringify()`; unwrap it first |
66
+ | `functype/no-getOrThrow-in-render` | off | warn | error | React: no bare `.orThrow()` in a component or hook body; a throw in render unmounts the tree |
67
+ | `functype/must-fold-on-component-return` | off | warn | error | React: render an `Option`/`Either`/`Try` with `fold` or `<MatchOption>`, not a guard or `&&` |
50
68
 
51
69
  ### Severity policy
52
70
 
@@ -62,6 +80,7 @@ A rule is **`error` in `recommended` once it is right on ~95–99% of real code*
62
80
  | --------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
63
81
  | A bug check: the condition can only fail because of a programmer error | `invariant(cond, msg)` from `functype` |
64
82
  | A host contract: the caller (React `use()`, React Query, a step runner, an MCP tool) needs a throw or rejection | `@interop <reason>` on the declaration, or `orThrow(builder)` |
83
+ | A router's control flow: `throw redirect(…)` or `throw notFound()` in a loader or route guard | nothing: recognized by its import (below) |
65
84
  | Anything that can fail in normal operation | return an `Either` |
66
85
 
67
86
  ```ts
@@ -90,6 +109,27 @@ const value = either.orThrow((left) => new StepError(left.message))
90
109
  - **Only JSDoc (`/** … */`) counts.** A `//` comment mentioning the tag does not.
91
110
  - **Opt out** per rule with `allowInteropMarker: false`.
92
111
 
112
+ ### Router control-flow throws
113
+
114
+ TanStack Router redirects or shows Not found only when `beforeLoad` or `loader` throws the value `redirect()` or `notFound()` returns, and React Router and Remix loaders work the same way. That throw is the router's API, so `prefer-either` leaves it alone when the helper is imported from one of these modules, under any local name or through a namespace import:
115
+
116
+ | Module | Helpers |
117
+ | ------------------------------------------------------------------------------- | --------------------------------------------------------- |
118
+ | `@tanstack/react-router`, `@tanstack/router-core` | `redirect`, `notFound` |
119
+ | `react-router` | `redirect`, `redirectDocument`, `replace`, `data` |
120
+ | `react-router-dom` (React Router 6), `@remix-run/node`, `@remix-run/cloudflare` | `redirect`, `redirectDocument`, `replace`, `data`, `json` |
121
+
122
+ ```ts
123
+ import { redirect } from "@tanstack/react-router"
124
+
125
+ beforeLoad: ({ params }) => {
126
+ if (params.id === "all") throw redirect({ to: "/queue" }) // fine: the router's redirect
127
+ if (!isValid(params.id)) throw new Error("bad id") // still reported
128
+ }
129
+ ```
130
+
131
+ Unlike `@interop`, this exempts only the router's own throws, so a real error thrown in the same function is still reported. A local `redirect` helper isn't the router's, and neither is `throw new Response(…)`. Add your own framework with the `hostThrows` option: `{ hostThrows: { "@acme/router": ["bounce"] } }`. It adds to the defaults: naming a default module adds helpers to its list rather than replacing it, and a module set to `[]` turns that module's defaults off.
132
+
93
133
  Prefer either tool to `eslint-disable`. A disable covers a whole file or line and says only "be quiet". `rg 'invariant\('` lists every bug check, and `rg '@interop'` lists every place the code touches a throw-based host.
94
134
 
95
135
  ## Rule options
@@ -198,6 +238,51 @@ void save(user) // fine: a deliberate drop
198
238
 
199
239
  Measured (2026-10-16) on functype's own source and tests, functype-log, functype-react, agent-todo's agent-gate-api and civala.ai's API: 0 false positives across about 1,340 IO-typed calls. The only hits were four deliberate drops in type-only tests. It's `off` in `recommended` and `warn` in `strict` while it is measured further.
200
240
 
241
+ ### `functype/no-floating-result`
242
+
243
+ Reports a statement that computes a result that can carry a failure, such as an `Either` or `Try`, and drops it. A `Left` or `Failure` in it is silently ignored. `no-floating-promises` doesn't help: awaiting the promise satisfies it while the result inside is thrown away.
244
+
245
+ ```ts
246
+ await userService.updateSubscription(id, plan) // reported: a failed write goes unnoticed
247
+ parse(input) // reported, when parse returns an Either
248
+ await save(user).run() // reported: run() returns an Either → check it, or use runOrThrow()
249
+
250
+ const result = await userService.updateSubscription(id, plan) // fine: then check result.isLeft()
251
+ await audit.write(entry).tapLeft((e) => log.error(e)) // fine: a best-effort write that logs its failure
252
+ void (await cache.refresh()) // fine: a deliberate drop
253
+ ```
254
+
255
+ - **What counts:** a type, or a member of its union, with `fold` and `isLeft` or `isFailure`. That covers `Either`, `Try`, `Exit`, `Validation`, `Task`'s result (`TaskOutcome`) and Either-shaped wrappers such as a `ServiceResult`. An ignored `Option` or `List` loses no error, so it isn't reported. An `IO` that is never run is `no-floating-io`'s.
256
+ - **Handled chains:** a chain that passes through `.tapError(…)` or `.tapLeft(…)` isn't reported, because it handles its failure. A `.flatMap(…)` after the handler can bring in a new failure, so that chain is reported again. `Try` has no failure tap, so mark a deliberate `Try` drop with `void`.
257
+ - **Tests:** a test that calls something for its side effect and then checks mocks is reported too. Assert on the result, or turn the rule off for test files.
258
+ - **Not seen yet:** a drop inside a callback, such as `xs.forEach((x) => save(x))`, or in the first part of a comma expression, isn't its own statement, so it isn't reported. `ok && save(x)` and `ok ? a() : b()` are.
259
+
260
+ **It only runs with type-aware linting** (`parserOptions.projectService`). Without type information it reports nothing.
261
+
262
+ Measured (2026-10-30) on agent-todo's agent-gate-api, which kept a hand-written check for this: at the commit that added that check, the rule reports 20 drops in production code. agent-todo fixed every one of them as a real bug, among them 8 in the Stripe webhook handler, where a failed write still answered Stripe 200. On the current code, after those fixes, it reports none in production code and 12 in tests. functype-os, functype-log, functype-react, functype-eval and functype-mcp-server report none. It's `error` in `strict` and `agent`, and `off` in `recommended`, where it moves to `error` in 2.0.
263
+
264
+ ### `functype/no-serialize-container`
265
+
266
+ Reports a functype container handed to a JSON sink, anywhere inside the value. An `Either`, `Option` or `List` serializes as its `{"@functype", _tag, value}` envelope, so a client reading `subscription.plan` gets `undefined`, and a body built around a `Left` answers 200. The compiler can't catch it, because `c.json()` and `JSON.stringify()` accept any value.
267
+
268
+ ```ts
269
+ return c.json(await svc.getDetails(id)) // reported: sends the Either's envelope
270
+ return c.json({ user, subscription: details }) // reported, at subscription
271
+ return JSON.stringify({ success: true, checkout }) // reported, at checkout: an MCP tool reporting success on failure
272
+
273
+ return c.json(result.orThrow()) // fine, after checking result.isLeft()
274
+ return c.json({ items: list.toArray() }) // fine
275
+ return c.json(result.toJSON()) // fine: the envelope on purpose
276
+ ```
277
+
278
+ - **Sinks:** `JSON.stringify(x)`, and any `.json(x)` call with an argument: Hono's `c.json`, `Response.json`, Express's `res.json`. `new Response(JSON.stringify(x))` is covered by the first. A read such as `await res.json()` has no argument, so it never matches.
279
+ - **What counts:** a type with `_tag` and `fold`, which every functype container has and its `toJSON()` envelope doesn't. The rule looks through unions and intersections, array and tuple elements, object properties, `Record` values and utility types such as `Partial<T>` and `Omit<T, K>`, up to 4 levels deep, and names the path in the message.
280
+ - **The envelope on purpose:** call `.toJSON()` or `.serialize()` first. A test that checks a container's JSON output is reported too, so call `.toJSON()` there as well.
281
+
282
+ **It only runs with type-aware linting** (`parserOptions.projectService`). Without type information it reports nothing.
283
+
284
+ Measured (2026-10-31) on agent-todo's agent-gate-api, which kept a hand-written check for this. Before its fix commit (f002b90), the rule reports 4 calls, and each is a bug agent-todo fixed: `GET /billing`, which showed every paying user "billing account isn't properly linked" for about nine months; `PATCH /user/me` and `PATCH /user/preferences`, which answered 200 with a `Left` in the body; and an MCP tool that reported success on failure. On the current code it reports none, and none in agent-todo's UI or in functype's own packages. It's `error` in `strict` and `agent`, and `off` in `recommended`, where it moves to `error` in 2.0.
285
+
201
286
  ### React rules
202
287
 
203
288
  Two rules are for React code. They fire only inside a **component** (a function named in PascalCase whose body has JSX, including one wrapped in `memo` or `forwardRef`) or a **hook** (a function named `use` + a capital letter), so other code rarely trips them. The one exception is a non-React function whose name starts with `use` + a capital letter, which is read as a hook. Both are `off` in `recommended` and `warn` in `strict` while they're measured on real React code. To turn them on with `recommended`:
@@ -332,11 +417,49 @@ When the code after the guard awaits, the advice uses `flatMapAsync` / `foldAsyn
332
417
 
333
418
  ### `functype/prefer-option`
334
419
 
335
- | Option | Default | Description |
336
- | --------------- | ------- | -------------------------------------------------------------------------------------------------------- |
337
- | `allowUseState` | `true` | Don't report `T \| null` inside the type argument of `useState` / `useRef` (bare or `React.`-qualified). |
420
+ | Option | Default | Description |
421
+ | ---------------------- | ------- | -------------------------------------------------------------------------------------------------------- |
422
+ | `allowUseState` | `true` | Don't report `T \| null` inside the type argument of `useState` / `useRef` (bare or `React.`-qualified). |
423
+ | `checkOptionalMembers` | `false` | Report "may be absent" members and parameters too: `a?: T` and `a: T \| undefined` alike. |
424
+
425
+ `null` is idiomatic React state, and an `Option` there fights the hook's own API.
426
+
427
+ On a type-literal or interface member, and on a parameter, `a?: T` and `a: T | undefined` both mean "may be absent", so both are skipped by default. The caller writes `<X b="v" />` or `f()`, and an `Option` there would make every caller wrap the value. Skipping only one spelling would teach people to rewrite `b: string | undefined` as `b?: string`, which makes a required key optional.
428
+
429
+ ```ts
430
+ type Props = {
431
+ a?: string // fine
432
+ b: string | undefined // fine: the same "may be absent" as a?
433
+ c?: string | undefined // fine: the spelling exactOptionalPropertyTypes needs
434
+ d: string | null // reported: null is a deliberate value
435
+ }
436
+ const f = (x: string | undefined) => x ?? "" // fine
437
+ function g(): string | undefined {} // reported: a return type, where an Option pays
438
+ ```
439
+
440
+ Return types, variables, class fields and generic arguments (`Array<string | undefined>`) are still reported. With `checkOptionalMembers: true`, `a?: T` is reported too, so the two spellings still get the same verdict, and `c?: T | undefined` is reported once, as an optional member.
441
+
442
+ ### `functype/prefer-do-notation`
443
+
444
+ | Option | Default | Description |
445
+ | ------------------- | ------- | ----------------------------------------------------------------------------------------- |
446
+ | `minChainDepth` | `3` | Report a `.flatMap(…)` chain once it has this many `flatMap`/`map`/`filter`/`fold` steps. |
447
+ | `detectMixedMonads` | `true` | Report a composition chain that moves between Option, Either, Try and Task. |
448
+
449
+ It reports three shapes, each once, at the outermost step:
450
+
451
+ ```ts
452
+ o.flatMap(f).flatMap(g).flatMap(h) // a flatMap chain 3 steps deep → Do notation
453
+ Option(x)
454
+ .flatMap((v) => Either.right(v))
455
+ .map(f) // a chain that mixes monads → Do notation
456
+ user && user.profile && user.profile.name // a guard on each step of a path → user?.profile?.name
457
+ ```
338
458
 
339
- `null` is idiomatic React state, and an `Option` there fights the hook's own API. Nullable component parameters and props are still reported.
459
+ - **Only chains on a monad count.** With type information the type of the value each step is called on decides, so an array's `.flatMap(…)` chain is never reported, and neither is one after `.getOrElse([])` or `.fold(…)` has unwrapped the monad. Without it, the chain must start from a monad constructor, companion or conversion (`Option(x)`, `Either.right(x)`, `Try(f).toOption()`), an identifier annotated with a monad type, or one named like a monad (`option`, `result`, or a capitalized suffix such as `userOption`; `entry` and `registry` don't count).
460
+ - **Mixing is read along the chain**, from the monad each step's callback returns. A conversion such as `.toOption()` keeps the chain in one monad, and a monad built somewhere inside a callback isn't a step.
461
+ - **A guard chain is read from the AST.** Each operand must be a property of the one before it, so `isAdmin && settings.theme && user.profile.name` isn't one.
462
+ - **It has no autofix.** It reports only, so `eslint --fix` can't change code on its behalf.
340
463
 
341
464
  ### `functype/prefer-map`
342
465
 
@@ -0,0 +1,45 @@
1
+ //#region src/configs/agent.d.ts
2
+ /**
3
+ * The preset for code a coding agent writes. An agent acts on what fails its build and passes over a
4
+ * warning, so this preset has none: every rule is `error` or `off`.
5
+ *
6
+ * `error`: everything `strict` errors on, plus three rules `strict` still warns on while they are
7
+ * measured. no-floating-io has had 0 false positives across ~1,340 IO-typed calls, and the two React
8
+ * rules none across 1,403 files. A forgotten `.run()` or a throw in render is the kind of mistake an
9
+ * agent makes and a human reviewer misses. prefer-option, prefer-either and prefer-try are `error` here
10
+ * as in `strict`: at a real boundary an agent marks it (`@interop <reason>` or `invariant()` for a
11
+ * throw, `Wire<T>` for a data shape) instead of leaving the reader to guess.
12
+ *
13
+ * `off`: prefer-flatmap and prefer-do-notation, whose precision is unmeasured. At `error` they would
14
+ * teach an agent to write `eslint-disable`; each moves to `error` here once it is measured. Also
15
+ * prefer-list: with type-aware linting, its in-place-change case is no-array-mutation's, which is `error`
16
+ * here, and the rest asks for `ReadonlyArray<T>` types, a typing choice `strict` keeps at `warn`.
17
+ *
18
+ * no-array-mutation, no-floating-io, no-floating-result and no-serialize-container are type-aware:
19
+ * without `parserOptions.projectService` they report nothing.
20
+ */
21
+ declare const agentRules: {
22
+ "functype/no-floating-io": string;
23
+ "functype/no-getOrThrow-in-render": string;
24
+ "functype/must-fold-on-component-return": string;
25
+ "functype/no-serialize-container": string;
26
+ "functype/prefer-flatmap": string;
27
+ "functype/prefer-do-notation": string;
28
+ "functype/prefer-list": string;
29
+ "functype/prefer-option": string;
30
+ "functype/prefer-either": string;
31
+ "functype/prefer-try": string;
32
+ "functype/no-get-unsafe": string;
33
+ "functype/no-array-mutation": string;
34
+ "functype/no-floating-result": string;
35
+ "functype/prefer-functype-map": string;
36
+ "functype/prefer-functype-set": string;
37
+ "functype/no-imperative-loops": string;
38
+ "functype/no-let": string;
39
+ "functype/prefer-map": string;
40
+ "functype/prefer-fold": string;
41
+ "functype/collection-naming": string;
42
+ };
43
+ //#endregion
44
+ export { agentRules as default };
45
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1,2 @@
1
+ import e from"./strict.js";const t={...e,"functype/no-floating-io":`error`,"functype/no-getOrThrow-in-render":`error`,"functype/must-fold-on-component-return":`error`,"functype/no-serialize-container":`error`,"functype/prefer-flatmap":`off`,"functype/prefer-do-notation":`off`,"functype/prefer-list":`off`};export{t as default};
2
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","names":["strictRules","agentRules"],"sources":["../../src/configs/agent.ts"],"sourcesContent":["import strictRules from \"./strict\"\n\n/**\n * The preset for code a coding agent writes. An agent acts on what fails its build and passes over a\n * warning, so this preset has none: every rule is `error` or `off`.\n *\n * `error`: everything `strict` errors on, plus three rules `strict` still warns on while they are\n * measured. no-floating-io has had 0 false positives across ~1,340 IO-typed calls, and the two React\n * rules none across 1,403 files. A forgotten `.run()` or a throw in render is the kind of mistake an\n * agent makes and a human reviewer misses. prefer-option, prefer-either and prefer-try are `error` here\n * as in `strict`: at a real boundary an agent marks it (`@interop <reason>` or `invariant()` for a\n * throw, `Wire<T>` for a data shape) instead of leaving the reader to guess.\n *\n * `off`: prefer-flatmap and prefer-do-notation, whose precision is unmeasured. At `error` they would\n * teach an agent to write `eslint-disable`; each moves to `error` here once it is measured. Also\n * prefer-list: with type-aware linting, its in-place-change case is no-array-mutation's, which is `error`\n * here, and the rest asks for `ReadonlyArray<T>` types, a typing choice `strict` keeps at `warn`.\n *\n * no-array-mutation, no-floating-io, no-floating-result and no-serialize-container are type-aware:\n * without `parserOptions.projectService` they report nothing.\n */\nconst agentRules = {\n ...strictRules,\n \"functype/no-floating-io\": \"error\",\n \"functype/no-getOrThrow-in-render\": \"error\",\n \"functype/must-fold-on-component-return\": \"error\",\n \"functype/no-serialize-container\": \"error\",\n \"functype/prefer-flatmap\": \"off\",\n \"functype/prefer-do-notation\": \"off\",\n \"functype/prefer-list\": \"off\",\n}\n\nexport default agentRules\n"],"mappings":"2BAqBA,MAAMC,EAAa,CACjB,GAAGD,EACH,0BAA2B,QAC3B,mCAAoC,QACpC,yCAA0C,QAC1C,kCAAmC,QACnC,0BAA2B,MAC3B,8BAA+B,MAC/B,uBAAwB,KAC1B"}
@@ -27,6 +27,14 @@
27
27
  * ~1,340 IO-typed calls in five codebases, but no real hits yet either. 2.0 decides `recommended` after
28
28
  * measuring it against functype-os, whose async methods return IO there. Type-aware, like no-array-mutation.
29
29
  *
30
+ * no-floating-result (1.23) is off here and `error` in strict: a dropped Either or Try is a defect, not a
31
+ * style, and on agent-todo's API it found the 20 drops that project fixed by hand as real bugs. Turning a
32
+ * new error on here would fail consumers' builds on a 1.x minor, so it moves to `error` here in 2.0. Type-aware.
33
+ *
34
+ * no-serialize-container (1.23) is off here and `error` in strict, for the same reason: a container sent
35
+ * to `c.json()` or `JSON.stringify()` is a defect, and turning a new error on here would fail consumers'
36
+ * builds on a 1.x minor. It moves to `error` here in 2.0. Type-aware.
37
+ *
30
38
  * no-getOrThrow-in-render and must-fold-on-component-return are React rules: they fire only inside a
31
39
  * component (a PascalCase function with JSX) or a hook (`use*`), so non-React code rarely trips them (a
32
40
  * non-React function named `use*` is read as a hook). Both are new and unmeasured on real React code, so
@@ -50,6 +58,8 @@ declare const recommendedRules: {
50
58
  "functype/prefer-list": string;
51
59
  "functype/no-array-mutation": string;
52
60
  "functype/no-floating-io": string;
61
+ "functype/no-floating-result": string;
62
+ "functype/no-serialize-container": string;
53
63
  "functype/no-getOrThrow-in-render": string;
54
64
  "functype/must-fold-on-component-return": string;
55
65
  };
@@ -1,2 +1,2 @@
1
- const e={"functype/no-let":`error`,"functype/no-imperative-loops":`error`,"functype/prefer-functype-map":`error`,"functype/prefer-functype-set":`error`,"functype/prefer-map":`error`,"functype/prefer-fold":`error`,"functype/collection-naming":`error`,"functype/prefer-option":`warn`,"functype/prefer-either":`warn`,"functype/prefer-try":`warn`,"functype/prefer-flatmap":`warn`,"functype/prefer-do-notation":`warn`,"functype/no-get-unsafe":`off`,"functype/prefer-list":`off`,"functype/no-array-mutation":`off`,"functype/no-floating-io":`off`,"functype/no-getOrThrow-in-render":`off`,"functype/must-fold-on-component-return":`off`};export{e as default};
1
+ const e={"functype/no-let":`error`,"functype/no-imperative-loops":`error`,"functype/prefer-functype-map":`error`,"functype/prefer-functype-set":`error`,"functype/prefer-map":`error`,"functype/prefer-fold":`error`,"functype/collection-naming":`error`,"functype/prefer-option":`warn`,"functype/prefer-either":`warn`,"functype/prefer-try":`warn`,"functype/prefer-flatmap":`warn`,"functype/prefer-do-notation":`warn`,"functype/no-get-unsafe":`off`,"functype/prefer-list":`off`,"functype/no-array-mutation":`off`,"functype/no-floating-io":`off`,"functype/no-floating-result":`off`,"functype/no-serialize-container":`off`,"functype/no-getOrThrow-in-render":`off`,"functype/must-fold-on-component-return":`off`};export{e as default};
2
2
  //# sourceMappingURL=recommended.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"recommended.js","names":["recommendedRules"],"sources":["../../src/configs/recommended.ts"],"sourcesContent":["/**\n * Severity policy (#325): a rule is `error` once it is right on ~95–99% of real code and its known\n * false-positive classes are closed; it stays `warn` only while those classes are still open. FP here\n * is governance — a rule that is reliably right should fail the build, not print advice nobody reads\n * (CivalaOS shipped 85 new violations under \"lint OK\" because every rule but `no-let` warned).\n *\n * Still `warn`, and why:\n * - prefer-option / prefer-either / prefer-try: fire on correct code at serialization boundaries\n * (JSON rows, DTOs) and on throws that are correct (bug checks, host contracts). Wire<T> (#325 B),\n * invariant() and @interop (#342) close those; graduating them is a measured decision.\n * - prefer-flatmap / prefer-do-notation: heuristics without type information; precision unmeasured.\n *\n * Graduated with a precision condition: prefer-fold checks functype predicate calls (`isSome()`,\n * `isLeft()`) only; its null-check heuristic is opt-in (`checkNullable`) because it fired on plain\n * nullables — 31 of 31 hits in CivalaOS. prefer-map leaves loops to no-imperative-loops (`checkForLoops`\n * off), so one loop is one error.\n *\n * collection-naming is a convention, not a heuristic — functype's Map/Set imported under their own names,\n * the built-in spelled globalThis.Map — so it has no false-positive class and starts at error.\n *\n * no-array-mutation is off here only because turning a new error on in a 1.x minor would fail consumers'\n * builds on upgrade (91 hits across five consumers, every one a real in-place mutation). It's `error` in\n * strict, and planned for `error` here in 2.0. It is type-aware: without type information it reports nothing.\n *\n * no-floating-io (1.17) is off here and `warn` in strict while it is measured: 0 false positives across\n * ~1,340 IO-typed calls in five codebases, but no real hits yet either. 2.0 decides `recommended` after\n * measuring it against functype-os, whose async methods return IO there. Type-aware, like no-array-mutation.\n *\n * no-getOrThrow-in-render and must-fold-on-component-return are React rules: they fire only inside a\n * component (a PascalCase function with JSX) or a hook (`use*`), so non-React code rarely trips them (a\n * non-React function named `use*` is read as a hook). Both are new and unmeasured on real React code, so\n * they start where no-floating-io did: off here, `warn` in strict. They work without type information and\n * are more precise with it.\n */\nconst recommendedRules = {\n \"functype/no-let\": \"error\",\n \"functype/no-imperative-loops\": \"error\",\n \"functype/prefer-functype-map\": \"error\",\n \"functype/prefer-functype-set\": \"error\",\n \"functype/prefer-map\": \"error\",\n \"functype/prefer-fold\": \"error\",\n \"functype/collection-naming\": \"error\",\n \"functype/prefer-option\": \"warn\",\n \"functype/prefer-either\": \"warn\",\n \"functype/prefer-try\": \"warn\",\n \"functype/prefer-flatmap\": \"warn\",\n \"functype/prefer-do-notation\": \"warn\",\n \"functype/no-get-unsafe\": \"off\",\n \"functype/prefer-list\": \"off\",\n \"functype/no-array-mutation\": \"off\",\n \"functype/no-floating-io\": \"off\",\n \"functype/no-getOrThrow-in-render\": \"off\",\n \"functype/must-fold-on-component-return\": \"off\",\n}\n\nexport default recommendedRules\n"],"mappings":"AAkCA,MAAMA,EAAmB,CACvB,kBAAmB,QACnB,+BAAgC,QAChC,+BAAgC,QAChC,+BAAgC,QAChC,sBAAuB,QACvB,uBAAwB,QACxB,6BAA8B,QAC9B,yBAA0B,OAC1B,yBAA0B,OAC1B,sBAAuB,OACvB,0BAA2B,OAC3B,8BAA+B,OAC/B,yBAA0B,MAC1B,uBAAwB,MACxB,6BAA8B,MAC9B,0BAA2B,MAC3B,mCAAoC,MACpC,yCAA0C,KAC5C"}
1
+ {"version":3,"file":"recommended.js","names":["recommendedRules"],"sources":["../../src/configs/recommended.ts"],"sourcesContent":["/**\n * Severity policy (#325): a rule is `error` once it is right on ~95–99% of real code and its known\n * false-positive classes are closed; it stays `warn` only while those classes are still open. FP here\n * is governance — a rule that is reliably right should fail the build, not print advice nobody reads\n * (CivalaOS shipped 85 new violations under \"lint OK\" because every rule but `no-let` warned).\n *\n * Still `warn`, and why:\n * - prefer-option / prefer-either / prefer-try: fire on correct code at serialization boundaries\n * (JSON rows, DTOs) and on throws that are correct (bug checks, host contracts). Wire<T> (#325 B),\n * invariant() and @interop (#342) close those; graduating them is a measured decision.\n * - prefer-flatmap / prefer-do-notation: heuristics without type information; precision unmeasured.\n *\n * Graduated with a precision condition: prefer-fold checks functype predicate calls (`isSome()`,\n * `isLeft()`) only; its null-check heuristic is opt-in (`checkNullable`) because it fired on plain\n * nullables — 31 of 31 hits in CivalaOS. prefer-map leaves loops to no-imperative-loops (`checkForLoops`\n * off), so one loop is one error.\n *\n * collection-naming is a convention, not a heuristic — functype's Map/Set imported under their own names,\n * the built-in spelled globalThis.Map — so it has no false-positive class and starts at error.\n *\n * no-array-mutation is off here only because turning a new error on in a 1.x minor would fail consumers'\n * builds on upgrade (91 hits across five consumers, every one a real in-place mutation). It's `error` in\n * strict, and planned for `error` here in 2.0. It is type-aware: without type information it reports nothing.\n *\n * no-floating-io (1.17) is off here and `warn` in strict while it is measured: 0 false positives across\n * ~1,340 IO-typed calls in five codebases, but no real hits yet either. 2.0 decides `recommended` after\n * measuring it against functype-os, whose async methods return IO there. Type-aware, like no-array-mutation.\n *\n * no-floating-result (1.23) is off here and `error` in strict: a dropped Either or Try is a defect, not a\n * style, and on agent-todo's API it found the 20 drops that project fixed by hand as real bugs. Turning a\n * new error on here would fail consumers' builds on a 1.x minor, so it moves to `error` here in 2.0. Type-aware.\n *\n * no-serialize-container (1.23) is off here and `error` in strict, for the same reason: a container sent\n * to `c.json()` or `JSON.stringify()` is a defect, and turning a new error on here would fail consumers'\n * builds on a 1.x minor. It moves to `error` here in 2.0. Type-aware.\n *\n * no-getOrThrow-in-render and must-fold-on-component-return are React rules: they fire only inside a\n * component (a PascalCase function with JSX) or a hook (`use*`), so non-React code rarely trips them (a\n * non-React function named `use*` is read as a hook). Both are new and unmeasured on real React code, so\n * they start where no-floating-io did: off here, `warn` in strict. They work without type information and\n * are more precise with it.\n */\nconst recommendedRules = {\n \"functype/no-let\": \"error\",\n \"functype/no-imperative-loops\": \"error\",\n \"functype/prefer-functype-map\": \"error\",\n \"functype/prefer-functype-set\": \"error\",\n \"functype/prefer-map\": \"error\",\n \"functype/prefer-fold\": \"error\",\n \"functype/collection-naming\": \"error\",\n \"functype/prefer-option\": \"warn\",\n \"functype/prefer-either\": \"warn\",\n \"functype/prefer-try\": \"warn\",\n \"functype/prefer-flatmap\": \"warn\",\n \"functype/prefer-do-notation\": \"warn\",\n \"functype/no-get-unsafe\": \"off\",\n \"functype/prefer-list\": \"off\",\n \"functype/no-array-mutation\": \"off\",\n \"functype/no-floating-io\": \"off\",\n \"functype/no-floating-result\": \"off\",\n \"functype/no-serialize-container\": \"off\",\n \"functype/no-getOrThrow-in-render\": \"off\",\n \"functype/must-fold-on-component-return\": \"off\",\n}\n\nexport default recommendedRules\n"],"mappings":"AA0CA,MAAMA,EAAmB,CACvB,kBAAmB,QACnB,+BAAgC,QAChC,+BAAgC,QAChC,+BAAgC,QAChC,sBAAuB,QACvB,uBAAwB,QACxB,6BAA8B,QAC9B,yBAA0B,OAC1B,yBAA0B,OAC1B,sBAAuB,OACvB,0BAA2B,OAC3B,8BAA+B,OAC/B,yBAA0B,MAC1B,uBAAwB,MACxB,6BAA8B,MAC9B,0BAA2B,MAC3B,8BAA+B,MAC/B,kCAAmC,MACnC,mCAAoC,MACpC,yCAA0C,KAC5C"}
@@ -7,6 +7,8 @@ declare const strictRules: {
7
7
  "functype/prefer-list": string;
8
8
  "functype/no-array-mutation": string;
9
9
  "functype/no-floating-io": string;
10
+ "functype/no-floating-result": string;
11
+ "functype/no-serialize-container": string;
10
12
  "functype/no-getOrThrow-in-render": string;
11
13
  "functype/must-fold-on-component-return": string;
12
14
  "functype/prefer-functype-map": string;
@@ -1,2 +1,2 @@
1
- import e from"./recommended.js";const t={...e,"functype/prefer-option":`error`,"functype/prefer-either":`error`,"functype/prefer-try":`error`,"functype/no-get-unsafe":`error`,"functype/prefer-list":`warn`,"functype/no-array-mutation":`error`,"functype/no-floating-io":`warn`,"functype/no-getOrThrow-in-render":`warn`,"functype/must-fold-on-component-return":`warn`,"functype/prefer-functype-map":`error`,"functype/prefer-functype-set":`error`,"functype/no-imperative-loops":`error`};export{t as default};
1
+ import e from"./recommended.js";const t={...e,"functype/prefer-option":`error`,"functype/prefer-either":`error`,"functype/prefer-try":`error`,"functype/no-get-unsafe":`error`,"functype/prefer-list":`warn`,"functype/no-array-mutation":`error`,"functype/no-floating-io":`warn`,"functype/no-floating-result":`error`,"functype/no-serialize-container":`error`,"functype/no-getOrThrow-in-render":`warn`,"functype/must-fold-on-component-return":`warn`,"functype/prefer-functype-map":`error`,"functype/prefer-functype-set":`error`,"functype/no-imperative-loops":`error`};export{t as default};
2
2
  //# sourceMappingURL=strict.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"strict.js","names":["recommendedRules","strictRules"],"sources":["../../src/configs/strict.ts"],"sourcesContent":["import recommendedRules from \"./recommended\"\n\nconst strictRules = {\n ...recommendedRules,\n \"functype/prefer-option\": \"error\",\n \"functype/prefer-either\": \"error\",\n \"functype/prefer-try\": \"error\",\n \"functype/no-get-unsafe\": \"error\",\n \"functype/prefer-list\": \"warn\",\n \"functype/no-array-mutation\": \"error\",\n \"functype/no-floating-io\": \"warn\",\n \"functype/no-getOrThrow-in-render\": \"warn\",\n \"functype/must-fold-on-component-return\": \"warn\",\n \"functype/prefer-functype-map\": \"error\",\n \"functype/prefer-functype-set\": \"error\",\n \"functype/no-imperative-loops\": \"error\",\n}\n\nexport default strictRules\n"],"mappings":"gCAEA,MAAMC,EAAc,CAClB,GAAGD,EACH,yBAA0B,QAC1B,yBAA0B,QAC1B,sBAAuB,QACvB,yBAA0B,QAC1B,uBAAwB,OACxB,6BAA8B,QAC9B,0BAA2B,OAC3B,mCAAoC,OACpC,yCAA0C,OAC1C,+BAAgC,QAChC,+BAAgC,QAChC,+BAAgC,OAClC"}
1
+ {"version":3,"file":"strict.js","names":["recommendedRules","strictRules"],"sources":["../../src/configs/strict.ts"],"sourcesContent":["import recommendedRules from \"./recommended\"\n\nconst strictRules = {\n ...recommendedRules,\n \"functype/prefer-option\": \"error\",\n \"functype/prefer-either\": \"error\",\n \"functype/prefer-try\": \"error\",\n \"functype/no-get-unsafe\": \"error\",\n \"functype/prefer-list\": \"warn\",\n \"functype/no-array-mutation\": \"error\",\n \"functype/no-floating-io\": \"warn\",\n \"functype/no-floating-result\": \"error\",\n \"functype/no-serialize-container\": \"error\",\n \"functype/no-getOrThrow-in-render\": \"warn\",\n \"functype/must-fold-on-component-return\": \"warn\",\n \"functype/prefer-functype-map\": \"error\",\n \"functype/prefer-functype-set\": \"error\",\n \"functype/no-imperative-loops\": \"error\",\n}\n\nexport default strictRules\n"],"mappings":"gCAEA,MAAMC,EAAc,CAClB,GAAGD,EACH,yBAA0B,QAC1B,yBAA0B,QAC1B,sBAAuB,QACvB,yBAA0B,QAC1B,uBAAwB,OACxB,6BAA8B,QAC9B,0BAA2B,OAC3B,8BAA+B,QAC/B,kCAAmC,QACnC,mCAAoC,OACpC,yCAA0C,OAC1C,+BAAgC,QAChC,+BAAgC,QAChC,+BAAgC,OAClC"}
package/dist/index.d.ts CHANGED
@@ -17,6 +17,8 @@ declare const plugin: {
17
17
  "collection-naming": import("eslint").Rule.RuleModule;
18
18
  "no-array-mutation": import("eslint").Rule.RuleModule;
19
19
  "no-floating-io": import("eslint").Rule.RuleModule;
20
+ "no-floating-result": import("eslint").Rule.RuleModule;
21
+ "no-serialize-container": import("eslint").Rule.RuleModule;
20
22
  "no-getOrThrow-in-render": import("eslint").Rule.RuleModule;
21
23
  "must-fold-on-component-return": import("eslint").Rule.RuleModule;
22
24
  };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import e from"./configs/recommended.js";import t from"./configs/strict.js";import n from"./rules/index.js";const r={rules:n,meta:{name:`eslint-plugin-functype`,version:`2.0.0`},configs:{}};r.configs={recommended:{name:`functype-plugin/recommended`,plugins:{functype:r},rules:e},strict:{name:`functype-plugin/strict`,plugins:{functype:r},rules:t}};export{r as default};
1
+ import e from"./configs/recommended.js";import t from"./configs/strict.js";import n from"./configs/agent.js";import r from"./rules/index.js";const i={rules:r,meta:{name:`eslint-plugin-functype`,version:`2.0.0`},configs:{}};i.configs={recommended:{name:`functype-plugin/recommended`,plugins:{functype:i},rules:e},strict:{name:`functype-plugin/strict`,plugins:{functype:i},rules:t},agent:{name:`functype-plugin/agent`,plugins:{functype:i},rules:n}};export{i as default};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["recommendedRules","strictRules","rules_default","plugin"],"sources":["../src/index.ts"],"sourcesContent":["import recommendedRules from \"./configs/recommended\"\nimport strictRules from \"./configs/strict\"\nimport rules from \"./rules\"\n\nconst plugin = {\n rules,\n meta: {\n name: \"eslint-plugin-functype\",\n version: \"2.0.0\",\n },\n configs: {} as Record<string, unknown>,\n}\n\n// Self-referencing plugin in configs (ESLint flat config pattern)\nplugin.configs = {\n recommended: {\n name: \"functype-plugin/recommended\",\n plugins: { functype: plugin },\n rules: recommendedRules,\n },\n strict: {\n name: \"functype-plugin/strict\",\n plugins: { functype: plugin },\n rules: strictRules,\n },\n}\n\nexport default plugin\n"],"mappings":"2GAIA,MAAMG,EAAS,CACb,MAAAD,EACA,KAAM,CACJ,KAAM,yBACN,QAAS,OACX,EACA,QAAS,CAAC,CACZ,EAGA,EAAO,QAAU,CACf,YAAa,CACX,KAAM,8BACN,QAAS,CAAE,SAAUC,CAAO,EAC5B,MAAOH,CACT,EACA,OAAQ,CACN,KAAM,yBACN,QAAS,CAAE,SAAUG,CAAO,EAC5B,MAAOF,CACT,CACF"}
1
+ {"version":3,"file":"index.js","names":["recommendedRules","strictRules","agentRules","rules_default","plugin"],"sources":["../src/index.ts"],"sourcesContent":["import agentRules from \"./configs/agent\"\nimport recommendedRules from \"./configs/recommended\"\nimport strictRules from \"./configs/strict\"\nimport rules from \"./rules\"\n\nconst plugin = {\n rules,\n meta: {\n name: \"eslint-plugin-functype\",\n version: \"2.0.0\",\n },\n configs: {} as Record<string, unknown>,\n}\n\n// Self-referencing plugin in configs (ESLint flat config pattern)\nplugin.configs = {\n recommended: {\n name: \"functype-plugin/recommended\",\n plugins: { functype: plugin },\n rules: recommendedRules,\n },\n strict: {\n name: \"functype-plugin/strict\",\n plugins: { functype: plugin },\n rules: strictRules,\n },\n agent: {\n name: \"functype-plugin/agent\",\n plugins: { functype: plugin },\n rules: agentRules,\n },\n}\n\nexport default plugin\n"],"mappings":"6IAKA,MAAMI,EAAS,CACb,MAAAD,EACA,KAAM,CACJ,KAAM,yBACN,QAAS,OACX,EACA,QAAS,CAAC,CACZ,EAGA,EAAO,QAAU,CACf,YAAa,CACX,KAAM,8BACN,QAAS,CAAE,SAAUC,CAAO,EAC5B,MAAOJ,CACT,EACA,OAAQ,CACN,KAAM,yBACN,QAAS,CAAE,SAAUI,CAAO,EAC5B,MAAOH,CACT,EACA,MAAO,CACL,KAAM,wBACN,QAAS,CAAE,SAAUG,CAAO,EAC5B,MAAOF,CACT,CACF"}
@@ -2,20 +2,22 @@ import rule from "./collection-naming.js";
2
2
  import rule$1 from "./must-fold-on-component-return.js";
3
3
  import rule$2 from "./no-array-mutation.js";
4
4
  import rule$3 from "./no-floating-io.js";
5
- import rule$5 from "./no-get-unsafe.js";
6
- import rule$4 from "./no-getOrThrow-in-render.js";
7
- import rule$6 from "./no-imperative-loops.js";
8
- import rule$7 from "./no-let.js";
9
- import rule$8 from "./prefer-do-notation.js";
10
- import rule$9 from "./prefer-either.js";
11
- import rule$10 from "./prefer-flatmap.js";
12
- import rule$11 from "./prefer-fold.js";
13
- import rule$12 from "./prefer-functype-map.js";
14
- import rule$13 from "./prefer-functype-set.js";
15
- import rule$14 from "./prefer-list.js";
16
- import rule$15 from "./prefer-map.js";
17
- import rule$16 from "./prefer-option.js";
18
- import rule$17 from "./prefer-try.js";
5
+ import rule$4 from "./no-floating-result.js";
6
+ import rule$6 from "./no-get-unsafe.js";
7
+ import rule$5 from "./no-getOrThrow-in-render.js";
8
+ import rule$7 from "./no-imperative-loops.js";
9
+ import rule$8 from "./no-let.js";
10
+ import rule$9 from "./no-serialize-container.js";
11
+ import rule$10 from "./prefer-do-notation.js";
12
+ import rule$11 from "./prefer-either.js";
13
+ import rule$12 from "./prefer-flatmap.js";
14
+ import rule$13 from "./prefer-fold.js";
15
+ import rule$14 from "./prefer-functype-map.js";
16
+ import rule$15 from "./prefer-functype-set.js";
17
+ import rule$16 from "./prefer-list.js";
18
+ import rule$17 from "./prefer-map.js";
19
+ import rule$18 from "./prefer-option.js";
20
+ import rule$19 from "./prefer-try.js";
19
21
  //#region src/rules/index.d.ts
20
22
  declare const _default: {
21
23
  "prefer-option": import("eslint").Rule.RuleModule;
@@ -34,9 +36,11 @@ declare const _default: {
34
36
  "collection-naming": import("eslint").Rule.RuleModule;
35
37
  "no-array-mutation": import("eslint").Rule.RuleModule;
36
38
  "no-floating-io": import("eslint").Rule.RuleModule;
39
+ "no-floating-result": import("eslint").Rule.RuleModule;
40
+ "no-serialize-container": import("eslint").Rule.RuleModule;
37
41
  "no-getOrThrow-in-render": import("eslint").Rule.RuleModule;
38
42
  "must-fold-on-component-return": import("eslint").Rule.RuleModule;
39
43
  };
40
44
  //#endregion
41
- export { rule as collectionNaming, _default as default, rule$1 as mustFoldOnComponentReturn, rule$2 as noArrayMutation, rule$3 as noFloatingIo, rule$4 as noGetOrThrowInRender, rule$5 as noGetUnsafe, rule$6 as noImperativeLoops, rule$7 as noLet, rule$8 as preferDoNotation, rule$9 as preferEither, rule$10 as preferFlatmap, rule$11 as preferFold, rule$12 as preferFunctypeMap, rule$13 as preferFunctypeSet, rule$14 as preferList, rule$15 as preferMap, rule$16 as preferOption, rule$17 as preferTry };
45
+ export { rule as collectionNaming, _default as default, rule$1 as mustFoldOnComponentReturn, rule$2 as noArrayMutation, rule$3 as noFloatingIo, rule$4 as noFloatingResult, rule$5 as noGetOrThrowInRender, rule$6 as noGetUnsafe, rule$7 as noImperativeLoops, rule$8 as noLet, rule$9 as noSerializeContainer, rule$10 as preferDoNotation, rule$11 as preferEither, rule$12 as preferFlatmap, rule$13 as preferFold, rule$14 as preferFunctypeMap, rule$15 as preferFunctypeSet, rule$16 as preferList, rule$17 as preferMap, rule$18 as preferOption, rule$19 as preferTry };
42
46
  //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1,2 @@
1
- import e from"./collection-naming.js";import t from"./must-fold-on-component-return.js";import n from"./no-array-mutation.js";import r from"./no-floating-io.js";import i from"./no-get-unsafe.js";import a from"./no-getOrThrow-in-render.js";import o from"./no-imperative-loops.js";import s from"./no-let.js";import c from"./prefer-do-notation.js";import l from"./prefer-either.js";import u from"./prefer-flatmap.js";import d from"./prefer-fold.js";import f from"./prefer-functype-map.js";import p from"./prefer-functype-set.js";import m from"./prefer-list.js";import h from"./prefer-map.js";import g from"./prefer-option.js";import _ from"./prefer-try.js";var v={"prefer-option":g,"prefer-either":l,"prefer-try":_,"prefer-list":m,"no-get-unsafe":i,"no-let":s,"prefer-fold":d,"prefer-map":h,"prefer-flatmap":u,"prefer-functype-map":f,"prefer-functype-set":p,"no-imperative-loops":o,"prefer-do-notation":c,"collection-naming":e,"no-array-mutation":n,"no-floating-io":r,"no-getOrThrow-in-render":a,"must-fold-on-component-return":t};export{e as collectionNaming,v as default,t as mustFoldOnComponentReturn,n as noArrayMutation,r as noFloatingIo,a as noGetOrThrowInRender,i as noGetUnsafe,o as noImperativeLoops,s as noLet,c as preferDoNotation,l as preferEither,u as preferFlatmap,d as preferFold,f as preferFunctypeMap,p as preferFunctypeSet,m as preferList,h as preferMap,g as preferOption,_ as preferTry};
1
+ import e from"./collection-naming.js";import t from"./must-fold-on-component-return.js";import n from"./no-array-mutation.js";import r from"./no-floating-io.js";import i from"./no-floating-result.js";import a from"./no-get-unsafe.js";import o from"./no-getOrThrow-in-render.js";import s from"./no-imperative-loops.js";import c from"./no-let.js";import l from"./no-serialize-container.js";import u from"./prefer-do-notation.js";import d from"./prefer-either.js";import f from"./prefer-flatmap.js";import p from"./prefer-fold.js";import m from"./prefer-functype-map.js";import h from"./prefer-functype-set.js";import g from"./prefer-list.js";import _ from"./prefer-map.js";import v from"./prefer-option.js";import y from"./prefer-try.js";var b={"prefer-option":v,"prefer-either":d,"prefer-try":y,"prefer-list":g,"no-get-unsafe":a,"no-let":c,"prefer-fold":p,"prefer-map":_,"prefer-flatmap":f,"prefer-functype-map":m,"prefer-functype-set":h,"no-imperative-loops":s,"prefer-do-notation":u,"collection-naming":e,"no-array-mutation":n,"no-floating-io":r,"no-floating-result":i,"no-serialize-container":l,"no-getOrThrow-in-render":o,"must-fold-on-component-return":t};export{e as collectionNaming,b as default,t as mustFoldOnComponentReturn,n as noArrayMutation,r as noFloatingIo,i as noFloatingResult,o as noGetOrThrowInRender,a as noGetUnsafe,s as noImperativeLoops,c as noLet,l as noSerializeContainer,u as preferDoNotation,d as preferEither,f as preferFlatmap,p as preferFold,m as preferFunctypeMap,h as preferFunctypeSet,g as preferList,_ as preferMap,v as preferOption,y as preferTry};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["preferOption","preferEither","preferTry","preferList","noGetUnsafe","noLet","preferFold","preferMap","preferFlatmap","preferFunctypeMap","preferFunctypeSet","noImperativeLoops","preferDoNotation","collectionNaming","noArrayMutation","noFloatingIo","noGetOrThrowInRender","mustFoldOnComponentReturn","rule","rule$1","rule$2","rule$3","rule$5","rule$4","rule$6","rule$7","rule$8","rule$9","rule$10","rule$11","rule$12","rule$13","rule$14","rule$15","rule$16","rule$17","rules_default"],"sources":["../../src/rules/index.ts"],"sourcesContent":["import collectionNaming from \"./collection-naming\"\nimport mustFoldOnComponentReturn from \"./must-fold-on-component-return\"\nimport noArrayMutation from \"./no-array-mutation\"\nimport noFloatingIo from \"./no-floating-io\"\nimport noGetUnsafe from \"./no-get-unsafe\"\nimport noGetOrThrowInRender from \"./no-getOrThrow-in-render\"\nimport noImperativeLoops from \"./no-imperative-loops\"\nimport noLet from \"./no-let\"\nimport preferDoNotation from \"./prefer-do-notation\"\nimport preferEither from \"./prefer-either\"\nimport preferFlatmap from \"./prefer-flatmap\"\nimport preferFold from \"./prefer-fold\"\nimport preferFunctypeMap from \"./prefer-functype-map\"\nimport preferFunctypeSet from \"./prefer-functype-set\"\nimport preferList from \"./prefer-list\"\nimport preferMap from \"./prefer-map\"\nimport preferOption from \"./prefer-option\"\nimport preferTry from \"./prefer-try\"\n\nexport {\n collectionNaming,\n mustFoldOnComponentReturn,\n noArrayMutation,\n noFloatingIo,\n noGetOrThrowInRender,\n noGetUnsafe,\n noImperativeLoops,\n noLet,\n preferDoNotation,\n preferEither,\n preferFlatmap,\n preferFold,\n preferFunctypeMap,\n preferFunctypeSet,\n preferList,\n preferMap,\n preferOption,\n preferTry,\n}\n\nexport default {\n \"prefer-option\": preferOption,\n \"prefer-either\": preferEither,\n \"prefer-try\": preferTry,\n \"prefer-list\": preferList,\n \"no-get-unsafe\": noGetUnsafe,\n \"no-let\": noLet,\n \"prefer-fold\": preferFold,\n \"prefer-map\": preferMap,\n \"prefer-flatmap\": preferFlatmap,\n \"prefer-functype-map\": preferFunctypeMap,\n \"prefer-functype-set\": preferFunctypeSet,\n \"no-imperative-loops\": noImperativeLoops,\n \"prefer-do-notation\": preferDoNotation,\n \"collection-naming\": collectionNaming,\n \"no-array-mutation\": noArrayMutation,\n \"no-floating-io\": noFloatingIo,\n \"no-getOrThrow-in-render\": noGetOrThrowInRender,\n \"must-fold-on-component-return\": mustFoldOnComponentReturn,\n}\n"],"mappings":"8oBAwCA,IAAAoC,EAAe,CACb,gBAAiBpC,EACjB,gBAAiBC,EACjB,aAAcC,EACd,cAAeC,EACf,gBAAiBC,EACjB,SAAUC,EACV,cAAeC,EACf,aAAcC,EACd,iBAAkBC,EAClB,sBAAuBC,EACvB,sBAAuBC,EACvB,sBAAuBC,EACvB,qBAAsBC,EACtB,oBAAqBC,EACrB,oBAAqBC,EACrB,iBAAkBC,EAClB,0BAA2BC,EAC3B,gCAAiCC,CACnC"}
1
+ {"version":3,"file":"index.js","names":["preferOption","preferEither","preferTry","preferList","noGetUnsafe","noLet","preferFold","preferMap","preferFlatmap","preferFunctypeMap","preferFunctypeSet","noImperativeLoops","preferDoNotation","collectionNaming","noArrayMutation","noFloatingIo","noFloatingResult","noSerializeContainer","noGetOrThrowInRender","mustFoldOnComponentReturn","rule","rule$1","rule$2","rule$3","rule$4","rule$6","rule$5","rule$7","rule$8","rule$9","rule$10","rule$11","rule$12","rule$13","rule$14","rule$15","rule$16","rule$17","rule$18","rule$19","rules_default"],"sources":["../../src/rules/index.ts"],"sourcesContent":["import collectionNaming from \"./collection-naming\"\nimport mustFoldOnComponentReturn from \"./must-fold-on-component-return\"\nimport noArrayMutation from \"./no-array-mutation\"\nimport noFloatingIo from \"./no-floating-io\"\nimport noFloatingResult from \"./no-floating-result\"\nimport noGetUnsafe from \"./no-get-unsafe\"\nimport noGetOrThrowInRender from \"./no-getOrThrow-in-render\"\nimport noImperativeLoops from \"./no-imperative-loops\"\nimport noLet from \"./no-let\"\nimport noSerializeContainer from \"./no-serialize-container\"\nimport preferDoNotation from \"./prefer-do-notation\"\nimport preferEither from \"./prefer-either\"\nimport preferFlatmap from \"./prefer-flatmap\"\nimport preferFold from \"./prefer-fold\"\nimport preferFunctypeMap from \"./prefer-functype-map\"\nimport preferFunctypeSet from \"./prefer-functype-set\"\nimport preferList from \"./prefer-list\"\nimport preferMap from \"./prefer-map\"\nimport preferOption from \"./prefer-option\"\nimport preferTry from \"./prefer-try\"\n\nexport {\n collectionNaming,\n mustFoldOnComponentReturn,\n noArrayMutation,\n noFloatingIo,\n noFloatingResult,\n noGetOrThrowInRender,\n noGetUnsafe,\n noImperativeLoops,\n noLet,\n noSerializeContainer,\n preferDoNotation,\n preferEither,\n preferFlatmap,\n preferFold,\n preferFunctypeMap,\n preferFunctypeSet,\n preferList,\n preferMap,\n preferOption,\n preferTry,\n}\n\nexport default {\n \"prefer-option\": preferOption,\n \"prefer-either\": preferEither,\n \"prefer-try\": preferTry,\n \"prefer-list\": preferList,\n \"no-get-unsafe\": noGetUnsafe,\n \"no-let\": noLet,\n \"prefer-fold\": preferFold,\n \"prefer-map\": preferMap,\n \"prefer-flatmap\": preferFlatmap,\n \"prefer-functype-map\": preferFunctypeMap,\n \"prefer-functype-set\": preferFunctypeSet,\n \"no-imperative-loops\": noImperativeLoops,\n \"prefer-do-notation\": preferDoNotation,\n \"collection-naming\": collectionNaming,\n \"no-array-mutation\": noArrayMutation,\n \"no-floating-io\": noFloatingIo,\n \"no-floating-result\": noFloatingResult,\n \"no-serialize-container\": noSerializeContainer,\n \"no-getOrThrow-in-render\": noGetOrThrowInRender,\n \"must-fold-on-component-return\": mustFoldOnComponentReturn,\n}\n"],"mappings":"guBA4CA,IAAAwC,EAAe,CACb,gBAAiBxC,EACjB,gBAAiBC,EACjB,aAAcC,EACd,cAAeC,EACf,gBAAiBC,EACjB,SAAUC,EACV,cAAeC,EACf,aAAcC,EACd,iBAAkBC,EAClB,sBAAuBC,EACvB,sBAAuBC,EACvB,sBAAuBC,EACvB,qBAAsBC,EACtB,oBAAqBC,EACrB,oBAAqBC,EACrB,iBAAkBC,EAClB,qBAAsBC,EACtB,yBAA0BC,EAC1B,0BAA2BC,EAC3B,gCAAiCC,CACnC"}
@@ -0,0 +1,19 @@
1
+ import { Rule } from "eslint";
2
+ //#region src/rules/no-floating-result.d.ts
3
+ /**
4
+ * Reports a statement that computes an Either, Try or other failure-carrying result and drops it:
5
+ * `await userService.updateSubscription(id, plan)` on its own line, or `parse(input)`. A Left or a
6
+ * Failure in it is silently ignored. `no-floating-promises` doesn't help, because awaiting the promise
7
+ * satisfies it while the result inside is thrown away.
8
+ *
9
+ * Only results that can carry a failure count: an ignored Option or List loses no error. A chain that
10
+ * handles its own failure with `.tapError(…)` or `.tapLeft(…)` isn't reported: that is a best-effort
11
+ * write that logs a failure on purpose, as in agent-todo's audit and cleanup writes. `void result`
12
+ * marks any other deliberate drop. An `IO` that is never run is no-floating-io's.
13
+ *
14
+ * Type-aware only: without type information it reports nothing.
15
+ */
16
+ declare const rule: Rule.RuleModule;
17
+ //#endregion
18
+ export { rule as default };
19
+ //# sourceMappingURL=no-floating-result.d.ts.map
@@ -0,0 +1,2 @@
1
+ import{canCarryFailureByType as e}from"../utils/type-aware.js";const t=/* @__PURE__ */ new Set([`CallExpression`,`ChainExpression`,`AwaitExpression`,`LogicalExpression`,`ConditionalExpression`]),n=/* @__PURE__ */ new Set([`tapError`,`tapLeft`]),r=/* @__PURE__ */ new Set([`flatMap`,`chain`,`andThen`,`flatMapError`,`orElse`]),i=e=>{if(!e)return!1;if(e.type===`AwaitExpression`)return i(e.argument);if(e.type===`ChainExpression`)return i(e.expression);if(e.type!==`CallExpression`)return!1;let t=e.callee;if(t.type!==`MemberExpression`)return!1;let a=t.property,o=a.type===`Identifier`?a.name:``;return n.has(o)?!0:!r.has(o)&&i(t.object)},a={meta:{type:`problem`,docs:{description:`Disallow dropping an Either, Try or other result that can carry a failure`,recommended:!1},schema:[],messages:{floatingResult:`This result is dropped, so a failure in it is silently ignored. Check isLeft() / isFailure(), fold it, or return it. Use void if dropping it is deliberate`}},create(n){return{ExpressionStatement(r){let a=r.expression;t.has(a.type)&&!i(a)&&e(a,n)&&n.report({node:a,messageId:`floatingResult`})}}}};export{a as default};
2
+ //# sourceMappingURL=no-floating-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-floating-result.js","names":["CHECKED","FAILURE_HANDLERS","FAILURE_SOURCES","handlesItsFailure","node","callee","property","name","rule","expression","canCarryFailureByType","context"],"sources":["../../src/rules/no-floating-result.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { canCarryFailureByType } from \"../utils/type-aware\"\n\n/** `f()`, `a?.f()`, `await …`, and `ok && f()` / `ok ? f() : g()`: statements whose only job is a value. */\nconst CHECKED: ReadonlySet<string> = new Set([\n \"CallExpression\",\n \"ChainExpression\",\n \"AwaitExpression\",\n \"LogicalExpression\",\n \"ConditionalExpression\",\n])\n\n/** Methods that run a callback on the failure, so a chain through one has handled it. */\nconst FAILURE_HANDLERS: ReadonlySet<string> = new Set([\"tapError\", \"tapLeft\"])\n\n/** Methods that can bring in a new failure, so a handler before one no longer covers the result. */\nconst FAILURE_SOURCES: ReadonlySet<string> = new Set([\"flatMap\", \"chain\", \"andThen\", \"flatMapError\", \"orElse\"])\n\n/**\n * Does the call chain in `node` handle its own failure? Walks the receiver chain from the outermost\n * call in: a `.tapError(…)` or `.tapLeft(…)` counts, unless a later `.flatMap(…)` can bring in a new,\n * unlogged failure. Arguments are never walked into.\n */\nconst handlesItsFailure = (node: ASTNode | undefined): boolean => {\n if (!node) return false\n if (node.type === \"AwaitExpression\") return handlesItsFailure(node.argument as ASTNode)\n if (node.type === \"ChainExpression\") return handlesItsFailure(node.expression as ASTNode)\n if (node.type !== \"CallExpression\") return false\n const callee = node.callee as ASTNode\n if (callee.type !== \"MemberExpression\") return false\n const property = callee.property as ASTNode\n const name = property.type === \"Identifier\" ? (property.name as string) : \"\"\n if (FAILURE_HANDLERS.has(name)) return true\n if (FAILURE_SOURCES.has(name)) return false\n return handlesItsFailure(callee.object as ASTNode)\n}\n\n/**\n * Reports a statement that computes an Either, Try or other failure-carrying result and drops it:\n * `await userService.updateSubscription(id, plan)` on its own line, or `parse(input)`. A Left or a\n * Failure in it is silently ignored. `no-floating-promises` doesn't help, because awaiting the promise\n * satisfies it while the result inside is thrown away.\n *\n * Only results that can carry a failure count: an ignored Option or List loses no error. A chain that\n * handles its own failure with `.tapError(…)` or `.tapLeft(…)` isn't reported: that is a best-effort\n * write that logs a failure on purpose, as in agent-todo's audit and cleanup writes. `void result`\n * marks any other deliberate drop. An `IO` that is never run is no-floating-io's.\n *\n * Type-aware only: without type information it reports nothing.\n */\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Disallow dropping an Either, Try or other result that can carry a failure\",\n recommended: false,\n },\n schema: [],\n messages: {\n floatingResult:\n \"This result is dropped, so a failure in it is silently ignored. Check isLeft() / isFailure(), fold it, or return it. Use void if dropping it is deliberate\",\n },\n },\n\n create(context) {\n return {\n ExpressionStatement(node: ASTNode) {\n const expression = node.expression as ASTNode\n // `void result` is a UnaryExpression, so a deliberate drop never gets this far.\n if (!CHECKED.has(expression.type) || handlesItsFailure(expression)) return\n if (canCarryFailureByType(expression, context))\n context.report({ node: expression, messageId: \"floatingResult\" })\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"+DAMA,MAAMA,kBAA+B,IAAI,IAAI,CAC3C,iBACA,kBACA,kBACA,oBACA,uBACF,CAAC,EAGKC,kBAAwC,IAAI,IAAI,CAAC,WAAY,SAAS,CAAC,EAGvEC,kBAAuC,IAAI,IAAI,CAAC,UAAW,QAAS,UAAW,eAAgB,QAAQ,CAAC,EAOxGC,EAAqB,GAAuC,CAChE,GAAI,CAACC,EAAM,MAAO,GAClB,GAAIA,EAAK,OAAS,kBAAmB,OAAOD,EAAkBC,EAAK,QAAmB,EACtF,GAAIA,EAAK,OAAS,kBAAmB,OAAOD,EAAkBC,EAAK,UAAqB,EACxF,GAAIA,EAAK,OAAS,iBAAkB,MAAO,GAC3C,IAAMC,EAASD,EAAK,OACpB,GAAIC,EAAO,OAAS,mBAAoB,MAAO,GAC/C,IAAMC,EAAWD,EAAO,SAClBE,EAAOD,EAAS,OAAS,aAAgBA,EAAS,KAAkB,GAG1E,OAFIL,EAAiB,IAAIM,CAAI,EAAU,GACvC,CAAIL,EAAgB,IAAIK,CAAI,GACrBJ,EAAkBE,EAAO,MAAiB,CACnD,EAeMG,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,4EACb,YAAa,EACf,EACA,OAAQ,CAAC,EACT,SAAU,CACR,eACE,4JACJ,CACF,EAEA,OAAO,EAAS,CACd,MAAO,CACL,oBAAoB,EAAe,CACjC,IAAMC,EAAaL,EAAK,WAEnBJ,EAAQ,IAAIS,EAAW,IAAI,GAAK,GAAkBA,CAAU,GAC7DC,EAAsBD,EAAYE,CAAO,GAC3CA,EAAQ,OAAO,CAAE,KAAMF,EAAY,UAAW,gBAAiB,CAAC,CACpE,CACF,CACF,CACF"}
@@ -0,0 +1,16 @@
1
+ import { Rule } from "eslint";
2
+ //#region src/rules/no-serialize-container.d.ts
3
+ /**
4
+ * Reports a functype container handed to a JSON sink, anywhere inside the value. An Either, Option or
5
+ * List serializes as its `{"@functype", _tag, value}` envelope, so a client reading `subscription.plan`
6
+ * gets `undefined`, and a body built around a Left answers 200. The compiler can't catch it, because
7
+ * `c.json()` and `JSON.stringify()` accept any value (#364).
8
+ *
9
+ * Calling `.toJSON()` or `.serialize()` first says the envelope is what you mean, and isn't reported.
10
+ *
11
+ * Type-aware only: without type information it reports nothing.
12
+ */
13
+ declare const rule: Rule.RuleModule;
14
+ //#endregion
15
+ export { rule as default };
16
+ //# sourceMappingURL=no-serialize-container.d.ts.map
@@ -0,0 +1,2 @@
1
+ import{containerInsideByType as e}from"../utils/type-aware.js";function t(e){let t=e.callee,[n]=e.arguments;if(n===void 0||n.type===`SpreadElement`||t.type!==`MemberExpression`||t.computed||t.property.type!==`Identifier`)return;if(t.property.name===`json`)return n;let r=t.object;return t.property.name===`stringify`&&r.type===`Identifier`&&r.name===`JSON`?n:void 0}const n={meta:{type:`problem`,docs:{description:`Disallow passing an Either, Option, List or other functype container to a JSON sink`,recommended:!1},schema:[],messages:{serializedContainer:`This sends the {{name}}'s {_tag, value} envelope{{where}}, not its value. Unwrap it first: check isLeft() / isNone() and return the error, fold() it, or call .toArray() on a List. Use .toJSON() if the envelope is what you mean`}},create(n){return{CallExpression(r){let i=t(r);if(i===void 0)return;let a=e(i,n);a!==void 0&&n.report({node:i,messageId:`serializedContainer`,data:{name:a.name,where:a.path===``?``:` at ${a.path}`}})}}}};export{n as default};
2
+ //# sourceMappingURL=no-serialize-container.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-serialize-container.js","names":["serializedArgument","callee","call","first","object","rule","argument","node","found","containerInsideByType","context"],"sources":["../../src/rules/no-serialize-container.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { containerInsideByType } from \"../utils/type-aware\"\n\n/**\n * `JSON.stringify(x)` or `*.json(x)`: Hono's `c.json`, `Response.json`, Express's `res.json`. A read\n * such as `await res.json()` has no argument, so it never matches.\n */\nfunction serializedArgument(call: ASTNode): ASTNode | undefined {\n const callee = call.callee as ASTNode\n const [first] = call.arguments as ReadonlyArray<ASTNode>\n if (first === undefined || first.type === \"SpreadElement\") return undefined\n if (callee.type !== \"MemberExpression\" || callee.computed || callee.property.type !== \"Identifier\") return undefined\n if (callee.property.name === \"json\") return first\n const object = callee.object as ASTNode\n return callee.property.name === \"stringify\" && object.type === \"Identifier\" && object.name === \"JSON\"\n ? first\n : undefined\n}\n\n/**\n * Reports a functype container handed to a JSON sink, anywhere inside the value. An Either, Option or\n * List serializes as its `{\"@functype\", _tag, value}` envelope, so a client reading `subscription.plan`\n * gets `undefined`, and a body built around a Left answers 200. The compiler can't catch it, because\n * `c.json()` and `JSON.stringify()` accept any value (#364).\n *\n * Calling `.toJSON()` or `.serialize()` first says the envelope is what you mean, and isn't reported.\n *\n * Type-aware only: without type information it reports nothing.\n */\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Disallow passing an Either, Option, List or other functype container to a JSON sink\",\n recommended: false,\n },\n schema: [],\n messages: {\n serializedContainer:\n \"This sends the {{name}}'s {_tag, value} envelope{{where}}, not its value. Unwrap it first: check isLeft() / isNone() and return the error, fold() it, or call .toArray() on a List. Use .toJSON() if the envelope is what you mean\",\n },\n },\n\n create(context) {\n return {\n CallExpression(node: ASTNode) {\n const argument = serializedArgument(node)\n if (argument === undefined) return\n const found = containerInsideByType(argument, context)\n if (found === undefined) return\n context.report({\n node: argument,\n messageId: \"serializedContainer\",\n data: { name: found.name, where: found.path === \"\" ? \"\" : ` at ${found.path}` },\n })\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"+DASA,SAASA,EAAmB,EAAoC,CAC9D,IAAMC,EAASC,EAAK,OACd,CAACC,GAASD,EAAK,UAErB,GADIC,IAAU,IAAA,IAAaA,EAAM,OAAS,iBACtCF,EAAO,OAAS,oBAAsBA,EAAO,UAAYA,EAAO,SAAS,OAAS,aAAc,OACpG,GAAIA,EAAO,SAAS,OAAS,OAAQ,OAAOE,EAC5C,IAAMC,EAASH,EAAO,OACtB,OAAOA,EAAO,SAAS,OAAS,aAAeG,EAAO,OAAS,cAAgBA,EAAO,OAAS,OAC3FD,EACA,IAAA,EACN,CAYA,MAAME,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,sFACb,YAAa,EACf,EACA,OAAQ,CAAC,EACT,SAAU,CACR,oBACE,oOACJ,CACF,EAEA,OAAO,EAAS,CACd,MAAO,CACL,eAAe,EAAe,CAC5B,IAAMC,EAAWN,EAAmBO,CAAI,EACxC,GAAID,IAAa,IAAA,GAAW,OAC5B,IAAME,EAAQC,EAAsBH,EAAUI,CAAO,EACjDF,IAAU,IAAA,IACdE,EAAQ,OAAO,CACb,KAAMJ,EACN,UAAW,sBACX,KAAM,CAAE,KAAME,EAAM,KAAM,MAAOA,EAAM,OAAS,GAAK,GAAK,OAAOA,EAAM,MAAO,CAChF,CAAC,CACH,CACF,CACF,CACF"}
@@ -1,5 +1,2 @@
1
- import{getFunctypeImports as e,isChainedMethodCall as t}from"../utils/functype-detection.js";const n=/* @__PURE__ */ new Set([`Option`,`Either`,`Try`,`Task`]),r=/* @__PURE__ */ new Set([`parent`,`loc`,`range`]),i=(e,t)=>/* @__PURE__ */ new Set([...e,...t]);function a(e){if(e.type!==`CallExpression`)return/* @__PURE__ */ new Set;let t=e.callee;return t?.type===`Identifier`&&n.has(t.name)?/* @__PURE__ */ new Set([t.name]):t?.type===`MemberExpression`&&t.object?.type===`Identifier`&&n.has(t.object.name)?/* @__PURE__ */ new Set([t.object.name]):/* @__PURE__ */ new Set}function o(e){return Object.entries(e).filter(([e])=>!r.has(e)).flatMap(([,e])=>Array.isArray(e)?e:[e]).filter(e=>typeof e==`object`&&!!e)}function s(e){if(!e||typeof e!=`object`)return/* @__PURE__ */ new Set;let t=e;return o(t).reduce((e,t)=>i(e,s(t)),a(t))}const c=/* @__PURE__ */ new Set([`flatMap`,`map`,`filter`,`fold`]),l=/* @__PURE__ */ new Set([`flatMap`,`map`,`filter`]);function u(e){if(e.callee.type!==`MemberExpression`||e.callee.object.type!==`CallExpression`)return 1;let t=e.callee.property,n=e.callee.object;return(t.type===`Identifier`&&c.has(t.name)?1:0)+u(n)}function d(e){if(e.callee?.type!==`MemberExpression`||e.callee.object?.type!==`CallExpression`)return 0;let t=e.callee.property,n=e.callee.object;return(t.type===`Identifier`&&l.has(t.name)?1:0)+d(n)}function f(e){if(e.callee?.type!==`MemberExpression`)return!1;let t=e.callee.property;return t.type!==`Identifier`||!l.has(t.name)?!1:d(e)>=1}function p(e){if(e.type!==`LogicalExpression`||e.operator!==`&&`)return 0;let t=e.right;return+(t.type===`MemberExpression`||t.type===`LogicalExpression`&&t.operator===`&&`)+p(e.left)}const m={meta:{type:`suggestion`,docs:{description:`Prefer Do notation for complex monadic compositions and nested operations`,recommended:!0},fixable:`code`,messages:{preferDoForNestedChecks:`Prefer Do notation for nested null/undefined checks instead of logical AND chains`,preferDoForChainedMethods:`Prefer Do notation for complex flatMap chains ({{count}} levels deep)`,preferDoForMixedMonads:`Consider Do notation when mixing Option, Either, and Try operations`,preferDoAsyncForChainedTasks:`Prefer DoAsync notation for chained async operations`},schema:[{type:`object`,properties:{minChainDepth:{type:`integer`,minimum:2,default:3},detectMixedMonads:{type:`boolean`,default:!0}},additionalProperties:!1}]},create(n){let r=n.options[0]||{},i=r.minChainDepth||3,a=r.detectMixedMonads!==!1,o=e(n),c=o.functions.has(`Do`)||o.functions.has(`DoAsync`);function l(e){e.operator===`&&`&&p(e)>=2&&d(e)&&n.report({node:e,messageId:`preferDoForNestedChecks`,fix:c?t=>h(t,e):void 0})}function d(e){let t=n.sourceCode.getText(e).match(/\w+(\.\w+){2,}/g);return t!==null&&t.length>0}function m(e){if(!t(e,`flatMap`))return;let r=u(e);r>=i&&n.report({node:e,messageId:`preferDoForChainedMethods`,data:{count:r.toString()},fix:c?t=>g(t,e):void 0})}function h(e,t){let r=n.sourceCode.getText(t),i=r.match(/(\w+)(\.\w+)+/);if(i){let n=i[1],r=`Do(function* () {
2
- const obj = yield* $(Option(${n}))
3
- return yield* $(Option(obj${i[0].substring(n.length)}))
4
- })`;return e.replaceText(t,r)}return e.replaceText(t,`/* TODO: Convert to Do notation */ ${r}`)}function g(e,t){let r=n.sourceCode.getText(t);return e.replaceText(t,`/* TODO: Consider Do notation for complex chains */ ${r}`)}function _(e){a&&f(e)&&s(e).size>=2&&n.report({node:e,messageId:`preferDoForMixedMonads`})}return{LogicalExpression(e){l(e)},CallExpression(e){m(e),_(e)}}}};export{m as default};
1
+ import{isExtractableByType as e}from"../utils/type-aware.js";import{isChainedMethodCall as t}from"../utils/functype-detection.js";const n=/* @__PURE__ */ new Set([`Option`,`Either`,`Try`,`Task`]),r=/* @__PURE__ */ new Set([`parent`,`loc`,`range`]),i=(e,t)=>/* @__PURE__ */ new Set([...e,...t]);function a(e){if(e.type!==`CallExpression`)return/* @__PURE__ */ new Set;let t=e.callee;return t?.type===`Identifier`&&n.has(t.name)?/* @__PURE__ */ new Set([t.name]):t?.type===`MemberExpression`&&t.object?.type===`Identifier`&&n.has(t.object.name)?/* @__PURE__ */ new Set([t.object.name]):/* @__PURE__ */ new Set}function o(e){return Object.entries(e).filter(([e])=>!r.has(e)).flatMap(([,e])=>Array.isArray(e)?e:[e]).filter(e=>typeof e==`object`&&!!e)}const s=/* @__PURE__ */ new Set([`flatMap`,`map`,`filter`,`fold`]),c=/* @__PURE__ */ new Set([`flatMap`]),l=/* @__PURE__ */ new Set([`flatMap`,`map`,`filter`]);function u(e){if(e.type!==`CallExpression`||e.callee?.type!==`MemberExpression`)return 0;let t=e.callee.property;return(t.type===`Identifier`&&s.has(t.name)?1:0)+u(e.callee.object)}function d(e){if(e.callee?.type!==`MemberExpression`||e.callee.object?.type!==`CallExpression`)return 0;let t=e.callee.property,n=e.callee.object;return(t.type===`Identifier`&&l.has(t.name)?1:0)+d(n)}function f(e){if(e.callee?.type!==`MemberExpression`)return!1;let t=e.callee.property;return t.type!==`Identifier`||!l.has(t.name)?!1:d(e)>=1}function p(e){return e.type!==`LogicalExpression`||e.operator!==`&&`?[e]:[...p(e.left),...p(e.right)]}const m=e=>e.type===`Identifier`||e.type===`ThisExpression`||e.type===`MemberExpression`,h=/* @__PURE__ */ new Set,g=/* @__PURE__ */ new Set([`ArrowFunctionExpression`,`FunctionExpression`,`FunctionDeclaration`]);function _(e){let t=e?.typeAnnotation;return t?.type!==`TSTypeReference`||t.typeName?.type!==`Identifier`?h:n.has(t.typeName.name)?/* @__PURE__ */ new Set([t.typeName.name]):h}const v=/^(option|opt|either|result|maybe|task)\d*$/i,y=/[a-z0-9](Option|Either|Result|Maybe|Try|Task)\d*$/,b=/* @__PURE__ */ new Map([[`toOption`,`Option`],[`toEither`,`Either`],[`toTry`,`Try`]]);function x(e){if(e.type===`ConditionalExpression`)return i(x(e.consequent),x(e.alternate));if(e.type!==`CallExpression`)return h;if(a(e).size>0)return a(e);if(e.callee?.type!==`MemberExpression`||e.callee.property.type!==`Identifier`)return h;let t=b.get(e.callee.property.name);return t===void 0?l.has(e.callee.property.name)?x(e.callee.object):h:/* @__PURE__ */ new Set([t])}function S(e){return e.type!==`CallExpression`||a(e).size>0||e.callee?.type!==`MemberExpression`||e.callee.property.type!==`Identifier`||!l.has(e.callee.property.name)?e:S(e.callee.object)}const C={meta:{type:`suggestion`,docs:{description:`Prefer Do notation for complex monadic compositions and nested operations`,recommended:!0},messages:{preferDoForNestedChecks:`This && chain guards each step of a property path. Use optional chaining (a?.b?.c), or Option(a).flatMap(…) when you want an Option`,preferDoForChainedMethods:`Prefer Do notation for complex flatMap chains ({{count}} levels deep)`,preferDoForMixedMonads:`Consider Do notation when mixing Option, Either, and Try operations`,preferDoAsyncForChainedTasks:`Prefer DoAsync notation for chained async operations`},schema:[{type:`object`,properties:{minChainDepth:{type:`integer`,minimum:2,default:3},detectMixedMonads:{type:`boolean`,default:!0}},additionalProperties:!1}]},create(n){let r=n.options[0]||{},d=r.minChainDepth||3,C=r.detectMixedMonads!==!1,w=e=>n.sourceCode.getText(e).replace(/\s+/g,``);function T(e){let t=(n.sourceCode.getScope(e).references.find(t=>t.identifier===e)?.resolved)?.defs[0]?.name;return _(t?.typeAnnotation)}function E(t){let r=e(t.callee.object,n);if(r!==void 0)return r;let i=S(t);return x(i).size>0?!0:i.type===`Identifier`?T(i).size>0||v.test(i.name)||y.test(i.name):!1}function D(e){let t=e.parent,n=t?.parent;if(t?.type===`MemberExpression`&&t.object===e&&n?.type===`CallExpression`&&n.callee===t)return t.property.type===`Identifier`&&s.has(t.property.name)?n:void 0}function O(e,t){let n=D(e);if(n===void 0)return!1;let r=n.callee.property;return r.type===`Identifier`&&t.has(r.name)||O(n,t)}function k(e){if(e.operator!==`&&`)return;let t=e.parent;if(t?.type===`LogicalExpression`&&t.operator===`&&`)return;let r=p(e);r.reduce((e,t,n)=>{let i=r[n-1],a=i!==void 0&&m(i)&&t.type===`MemberExpression`&&w(t.object)===w(i)?e.run+1:1;return{run:a,best:Math.max(e.best,a)}},{run:0,best:0}).best>=3&&n.report({node:e,messageId:`preferDoForNestedChecks`})}function A(e){if(!t(e,`flatMap`)||O(e,c))return;let r=u(e);r<d||!E(e)||n.report({node:e,messageId:`preferDoForChainedMethods`,data:{count:r.toString()}})}function j(e){if(e?.type!==`ArrowFunctionExpression`&&e?.type!==`FunctionExpression`)return[];let t=e.body;if(t.type!==`BlockStatement`)return[t];let n=e=>e.type===`ReturnStatement`?e.argument?[e.argument]:[]:g.has(e.type)?[]:o(e).flatMap(n);return n(t)}function M(e){if(e.type===`Identifier`)return T(e);if(e.type!==`CallExpression`||e.callee?.type!==`MemberExpression`)return a(e);let t=e.callee.property,n=t.type===`Identifier`&&l.has(t.name)?j(e.arguments[0]).reduce((e,t)=>i(e,x(t)),h):h;if(a(e).size>0)return i(n,a(e));let r=t.type===`Identifier`?b.get(t.name):void 0;return r===void 0?i(n,M(e.callee.object)):i(n,/* @__PURE__ */ new Set([r]))}function N(e){C&&f(e)&&!O(e,l)&&E(e)&&M(e).size>=2&&n.report({node:e,messageId:`preferDoForMixedMonads`})}return{LogicalExpression(e){k(e)},CallExpression(e){A(e),N(e)}}}};export{C as default};
5
2
  //# sourceMappingURL=prefer-do-notation.js.map