eslint-plugin-functype 2.127.0 → 2.127.2
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 +11 -11
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/rules/prefer-flatmap.js +1 -1
- package/dist/rules/prefer-flatmap.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -83,7 +83,7 @@ A rule is **`error` in `recommended` once it is right on ~95–99% of real code*
|
|
|
83
83
|
| A router's control flow: `throw redirect(…)` or `throw notFound()` in a loader or route guard | nothing: recognized by its import (below) |
|
|
84
84
|
| Anything that can fail in normal operation | return an `Either` |
|
|
85
85
|
|
|
86
|
-
```ts
|
|
86
|
+
```ts ignore
|
|
87
87
|
import { invariant } from "functype"
|
|
88
88
|
|
|
89
89
|
function deriveRunId(workflowId: string, step: number): string {
|
|
@@ -119,7 +119,7 @@ TanStack Router redirects or shows Not found only when `beforeLoad` or `loader`
|
|
|
119
119
|
| `react-router` | `redirect`, `redirectDocument`, `replace`, `data` |
|
|
120
120
|
| `react-router-dom` (React Router 6), `@remix-run/node`, `@remix-run/cloudflare` | `redirect`, `redirectDocument`, `replace`, `data`, `json` |
|
|
121
121
|
|
|
122
|
-
```ts
|
|
122
|
+
```ts ignore
|
|
123
123
|
import { redirect } from "@tanstack/react-router"
|
|
124
124
|
|
|
125
125
|
beforeLoad: ({ params }) => {
|
|
@@ -194,7 +194,7 @@ Reports changing an array in place:
|
|
|
194
194
|
|
|
195
195
|
It catches the mutation wherever the array came from, including an inferred `const rows = load(); rows.push(x)`, which `prefer-list` can't see because there's no annotation or literal.
|
|
196
196
|
|
|
197
|
-
```ts
|
|
197
|
+
```ts ignore
|
|
198
198
|
rows.push(row) // reported → [...rows, row], or build rows with map / flatMap
|
|
199
199
|
xs.sort(byRank) // reported → xs.toSorted(byRank)
|
|
200
200
|
xs[i] = v // reported → xs.with(i, v)
|
|
@@ -226,7 +226,7 @@ Reports an `IO` that is built and never run, so it does nothing:
|
|
|
226
226
|
|
|
227
227
|
`no-floating-promises` and `await-thenable` miss both, because `IO` isn't thenable.
|
|
228
228
|
|
|
229
|
-
```ts
|
|
229
|
+
```ts ignore
|
|
230
230
|
log.info("saved") // reported, when info returns an IO → yield* it, or .run() it
|
|
231
231
|
save(user).tap(audit) // reported → return it, or run it
|
|
232
232
|
const user = await loadUser(id) // reported: user is the IO → await loadUser(id).runOrThrow()
|
|
@@ -242,7 +242,7 @@ Measured (2026-10-16) on functype's own source and tests, functype-log, functype
|
|
|
242
242
|
|
|
243
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
244
|
|
|
245
|
-
```ts
|
|
245
|
+
```ts ignore
|
|
246
246
|
await userService.updateSubscription(id, plan) // reported: a failed write goes unnoticed
|
|
247
247
|
parse(input) // reported, when parse returns an Either
|
|
248
248
|
await save(user).run() // reported: run() returns an Either → check it, or use runOrThrow()
|
|
@@ -265,7 +265,7 @@ Measured (2026-10-30) on agent-todo's agent-gate-api, which kept a hand-written
|
|
|
265
265
|
|
|
266
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
267
|
|
|
268
|
-
```ts
|
|
268
|
+
```ts ignore
|
|
269
269
|
return c.json(await svc.getDetails(id)) // reported: sends the Either's envelope
|
|
270
270
|
return c.json({ user, subscription: details }) // reported, at subscription
|
|
271
271
|
return JSON.stringify({ success: true, checkout }) // reported, at checkout: an MCP tool reporting success on failure
|
|
@@ -310,7 +310,7 @@ Only the component's or hook's own body counts as render. An event handler, an e
|
|
|
310
310
|
|
|
311
311
|
Reports a bare `.orThrow()` (or the older `.getOrThrow()`) in a component or hook body. When the value is missing it throws during render, and React unmounts the tree up to the nearest error boundary.
|
|
312
312
|
|
|
313
|
-
```tsx
|
|
313
|
+
```tsx ignore
|
|
314
314
|
function Profile({ user }: { user: Option<User> }) {
|
|
315
315
|
const u = user.orThrow() // reported → user.fold(() => <SignIn />, (u) => <Card user={u} />)
|
|
316
316
|
return <Card user={u} />
|
|
@@ -342,7 +342,7 @@ Reports a component that chooses what it renders by asking an `Option`, `Either`
|
|
|
342
342
|
- an **early return**: `if (user.isNone()) return <SignIn />` (or `return null`, `if (!user.isSome())`, `if (busy || user.isNone())`), with the other case rendered below it;
|
|
343
343
|
- a **short-circuit**: `{user.isSome() && <Card />}`, which renders one case and silently drops the other.
|
|
344
344
|
|
|
345
|
-
```tsx
|
|
345
|
+
```tsx ignore
|
|
346
346
|
function Profile({ user }: { user: Option<User> }) {
|
|
347
347
|
if (user.isNone()) return <SignIn /> // reported
|
|
348
348
|
return <Card user={user.orThrow()} />
|
|
@@ -395,7 +395,7 @@ Reports only; the rewrite is a **suggestion, never an autofix**. A fold rewrite
|
|
|
395
395
|
|
|
396
396
|
**`checkGuards`: guard, then unwrap.** Checking a container with an early exit and then pulling the value out is imperative branching. Getting a value out is fine: `orElse(default)` and `fold` are both proper exits and are never reported. What's reported is the shape below. The message picks its advice from what the guard does:
|
|
397
397
|
|
|
398
|
-
```ts
|
|
398
|
+
```ts ignore
|
|
399
399
|
if (e.isLeft()) return e // hands the failure back → e.flatMap(…) / e.map(…)
|
|
400
400
|
if (e.isLeft()) return Left({ kind: e.value.kind }) // a new failure → e.mapLeft(…).flatMap(…)
|
|
401
401
|
if (o.isNone()) return 0 // a fallback → o.map(…).orElse(0), or o.fold(() => 0, …)
|
|
@@ -432,7 +432,7 @@ A union nested in a union, such as `(string | null) | undefined`, is read as one
|
|
|
432
432
|
|
|
433
433
|
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.
|
|
434
434
|
|
|
435
|
-
```ts
|
|
435
|
+
```ts ignore
|
|
436
436
|
type Props = {
|
|
437
437
|
a?: string // fine
|
|
438
438
|
b: string | undefined // fine: the same "may be absent" as a?
|
|
@@ -454,7 +454,7 @@ Return types, variables, class fields and generic arguments (`Array<string | und
|
|
|
454
454
|
|
|
455
455
|
It reports three shapes, each once, at the outermost step:
|
|
456
456
|
|
|
457
|
-
```ts
|
|
457
|
+
```ts ignore
|
|
458
458
|
o.flatMap(f).flatMap(g).flatMap(h) // a flatMap chain 3 steps deep → Do notation
|
|
459
459
|
Option(x)
|
|
460
460
|
.flatMap((v) => Either.right(v))
|
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"./configs/agent.js";import r,{testFiles as i}from"./configs/tests.js";import a from"./rules/index.js";const o={rules:a,meta:{name:`eslint-plugin-functype`,version:`2.
|
|
1
|
+
import e from"./configs/recommended.js";import t from"./configs/strict.js";import n from"./configs/agent.js";import r,{testFiles as i}from"./configs/tests.js";import a from"./rules/index.js";const o={rules:a,meta:{name:`eslint-plugin-functype`,version:`2.127.2`},configs:{}};o.configs={recommended:{name:`functype-plugin/recommended`,plugins:{functype:o},rules:e},strict:{name:`functype-plugin/strict`,plugins:{functype:o},rules:t},agent:{name:`functype-plugin/agent`,plugins:{functype:o},rules:n},tests:{name:`functype-plugin/tests`,plugins:{functype:o},files:i,rules:r}};export{o as default};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["testRules","recommendedRules","strictRules","agentRules","tests_default","rules_default","plugin","testFiles"],"sources":["../src/index.ts"],"sourcesContent":["import agentRules from \"./configs/agent\"\nimport recommendedRules from \"./configs/recommended\"\nimport strictRules from \"./configs/strict\"\nimport testRules, { testFiles } from \"./configs/tests\"\nimport rules from \"./rules\"\n\nconst plugin = {\n rules,\n meta: {\n name: \"eslint-plugin-functype\",\n version: \"
|
|
1
|
+
{"version":3,"file":"index.js","names":["testRules","recommendedRules","strictRules","agentRules","tests_default","rules_default","plugin","testFiles"],"sources":["../src/index.ts"],"sourcesContent":["import agentRules from \"./configs/agent\"\nimport recommendedRules from \"./configs/recommended\"\nimport strictRules from \"./configs/strict\"\nimport testRules, { testFiles } from \"./configs/tests\"\nimport rules from \"./rules\"\n\n/** Set from package.json at build time by tsdown.config.ts, and in tests by vitest.config.ts. */\ndeclare const __VERSION__: string\n\nconst plugin = {\n rules,\n meta: {\n name: \"eslint-plugin-functype\",\n version: typeof __VERSION__ === \"undefined\" ? \"0.0.0-dev\" : __VERSION__,\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 tests: {\n name: \"functype-plugin/tests\",\n plugins: { functype: plugin },\n files: testFiles,\n rules: testRules,\n },\n}\n\nexport default plugin\n"],"mappings":"+LASA,MAAMM,EAAS,CACb,MAAAD,EACA,KAAM,CACJ,KAAM,yBACN,QAAA,SACF,EACA,QAAS,CAAC,CACZ,EAGA,EAAO,QAAU,CACf,YAAa,CACX,KAAM,8BACN,QAAS,CAAE,SAAUC,CAAO,EAC5B,MAAOL,CACT,EACA,OAAQ,CACN,KAAM,yBACN,QAAS,CAAE,SAAUK,CAAO,EAC5B,MAAOJ,CACT,EACA,MAAO,CACL,KAAM,wBACN,QAAS,CAAE,SAAUI,CAAO,EAC5B,MAAOH,CACT,EACA,MAAO,CACL,KAAM,wBACN,QAAS,CAAE,SAAUG,CAAO,EAC5B,MAAOC,EACP,MAAOP,CACT,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const
|
|
1
|
+
import{isExtractableByType as e,isIOByType as t}from"../utils/type-aware.js";const n=/* @__PURE__ */ new Set([`map`,`filter`,`slice`,`concat`,`split`]),r={meta:{type:`suggestion`,docs:{description:`Prefer .flatMap() over .map().flat() and nested transformations`,recommended:!0},fixable:`code`,schema:[{type:`object`,properties:{checkNestedMaps:{type:`boolean`,default:!0}},additionalProperties:!1}],messages:{preferFlatMapOverMapFlat:`Use .flatMap() instead of .map().flat()`,preferFlatMapNested:`Consider .flatMap() for nested transformations that return arrays`,preferFlatMapChain:`Use .flatMap() instead of chained .map() operations that flatten results`}},create(r){let i=(r.options[0]||{}).checkNestedMaps!==!1;function a(e){if(e.type!==`CallExpression`)return!1;let t=e.callee;if(t.type!==`MemberExpression`)return!1;if(t.property.name===`flat`){let e=t.object;if(e.type===`CallExpression`&&e.callee.type===`MemberExpression`&&e.callee.property.name===`map`)return!0}return!1}function o(e){let t=e.elements??[];return!t.some(e=>e&&e.type===`SpreadElement`)&&t.some(e=>e&&e.type===`ArrayExpression`)}function s(e){return e.type===`CallExpression`?s(e.callee):e.type===`MemberExpression`?s(e.object):e.type===`ChainExpression`||e.type===`TSNonNullExpression`||e.type===`TSAsExpression`||e.type===`TSSatisfiesExpression`?s(e.expression):e}function c(e){return e?e.type===`Identifier`?[e.name]:e.type===`AssignmentPattern`?c(e.left):e.type===`RestElement`?c(e.argument):e.type===`ArrayPattern`?e.elements.flatMap(e=>c(e)):e.type===`ObjectPattern`?e.properties.flatMap(e=>e.type===`RestElement`?c(e.argument):c(e.value)):[]:[]}function l(e,t){let n=s(t);return n.type===`Identifier`&&e.params.flatMap(c).includes(n.name)}function u(e){if(!e||!e.body)return!1;if(e.body.type===`ArrayExpression`)return o(e.body);if(e.body.type===`CallExpression`){let t=e.body;if(l(e,t))return!1;if(t.callee.type===`MemberExpression`){let e=t.callee.property.name;if(n.has(e))return!0}}return e.body.type===`BlockStatement`&&e.body.body.some(t=>d(t)&&!(t.argument.type===`CallExpression`&&l(e,t.argument)))}function d(e){return e.type!==`ReturnStatement`||!e.argument?!1:e.argument.type===`ArrayExpression`?o(e.argument):!!(e.argument.type===`CallExpression`&&e.argument.callee.type===`MemberExpression`&&n.has(e.argument.callee.property.name))}function f(e){if(e.type!==`CallExpression`)return!1;let t=e.callee;if(t.type!==`MemberExpression`)return!1;if(t.property.name===`map`){let t=e.arguments[0];if(t&&(t.type===`ArrowFunctionExpression`||t.type===`FunctionExpression`))return u(t)}return!1}function p(e){let t=/* @__PURE__ */ new Set([`Option`,`Some`,`None`,`Either`,`Right`,`Left`,`Try`,`Success`,`Failure`,`Task`,`Ok`,`Err`,`IO`]);return!!(e.type===`CallExpression`&&e.callee?.type===`Identifier`&&t.has(e.callee.name)||e.type===`CallExpression`&&e.callee?.type===`MemberExpression`&&e.callee.object?.type===`Identifier`&&t.has(e.callee.object.name))}function m(n){return p(n)||e(n,r)===!0||t(n,r)===!0}return{CallExpression(e){if(a(e)){let t=r.sourceCode;r.report({node:e,messageId:`preferFlatMapOverMapFlat`,fix(n){let r=e.callee.object,i=t.getText(r).replace(/\.map\s*\(/,`.flatMap(`);return n.replaceText(e,i)}});return}if(e.callee.type===`MemberExpression`&&e.callee.property.name===`map`){let t=e.callee.object;if(t.type===`CallExpression`&&t.callee.type===`MemberExpression`&&t.callee.property.name===`map`){let e=t.arguments[0];if(e&&u(e)&&!m(t.callee.object)){r.report({node:t,messageId:`preferFlatMapChain`});return}}}if(i&&f(e)){if(e.parent&&e.parent.type===`MemberExpression`&&e.parent.parent&&e.parent.parent.type===`CallExpression`&&e.parent.property.name===`flat`)return;let t=e.callee?.object;if(t?.type===`CallExpression`&&t.callee?.type===`MemberExpression`&&t.callee?.property?.name===`map`||e.parent?.type===`MemberExpression`&&e.parent.parent?.type===`CallExpression`&&e.parent.parent.callee?.property?.name===`map`||t&&m(t))return;r.report({node:e,messageId:`preferFlatMapNested`})}}}}};export{r as default};
|
|
2
2
|
//# sourceMappingURL=prefer-flatmap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefer-flatmap.js","names":["ARRAY_PRODUCING_METHODS","rule","checkNestedMaps","context","isMapFollowedByFlat","node","callee","object","isFlattenCandidateArrayLiteral","elements","arrayExpr","el","chainRoot","boundNames","param","prop","isShapePreserving","root","returned","functionNode","returnsArray","call","methodName","returnsArrayShape","stmt","isNestedMapReturningArrays","callback","isNonCollectionMonadReceiver","monadConstructors","sourceCode","mapCall","flatMapText","fixer","firstMapCallback"],"sources":["../../src/rules/prefer-flatmap.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\n\n/** Array-prototype methods whose call expression always returns an array. */\nconst ARRAY_PRODUCING_METHODS: ReadonlySet<string> = new Set([\"map\", \"filter\", \"slice\", \"concat\", \"split\"])\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"suggestion\",\n docs: {\n description: \"Prefer .flatMap() over .map().flat() and nested transformations\",\n recommended: true,\n },\n fixable: \"code\",\n schema: [\n {\n type: \"object\",\n properties: {\n checkNestedMaps: {\n type: \"boolean\",\n default: true,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n preferFlatMapOverMapFlat: \"Use .flatMap() instead of .map().flat()\",\n preferFlatMapNested: \"Consider .flatMap() for nested transformations that return arrays\",\n preferFlatMapChain: \"Use .flatMap() instead of chained .map() operations that flatten results\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n const checkNestedMaps = options.checkNestedMaps !== false\n\n function isMapFollowedByFlat(node: ASTNode): boolean {\n if (node.type !== \"CallExpression\") return false\n\n const callee = node.callee\n if (callee.type !== \"MemberExpression\") return false\n\n // Check if this is .flat()\n if (callee.property.name === \"flat\") {\n const object = callee.object\n\n // Check if the object is a .map() call\n if (\n object.type === \"CallExpression\" &&\n object.callee.type === \"MemberExpression\" &&\n object.callee.property.name === \"map\"\n ) {\n return true\n }\n }\n\n return false\n }\n\n /**\n * Heuristic for array literals that look like flatten candidates.\n * Skips append/identity patterns (`[...arr, x]`, `[...arr]`) and tuple\n * shapes (`[k, v]`) — those are not nested arrays, so .flatMap()\n * doesn't apply. Only flag when at least one element is itself an\n * ArrayExpression, signaling a true nested-array shape.\n */\n function isFlattenCandidateArrayLiteral(arrayExpr: ASTNode): boolean {\n const elements = arrayExpr.elements ?? []\n if (elements.some((el: ASTNode | null) => el && el.type === \"SpreadElement\")) {\n return false\n }\n return elements.some((el: ASTNode | null) => el && el.type === \"ArrayExpression\")\n }\n\n /**\n * The base identifier of a call/member chain: `members` in `members.filter(f).map(g)`, `r` in\n * `r.cells.map(f)`.\n */\n function chainRoot(node: ASTNode): ASTNode {\n if (node.type === \"CallExpression\") return chainRoot(node.callee)\n if (node.type === \"MemberExpression\") return chainRoot(node.object)\n if (\n node.type === \"ChainExpression\" ||\n node.type === \"TSNonNullExpression\" ||\n node.type === \"TSAsExpression\" ||\n node.type === \"TSSatisfiesExpression\"\n ) {\n return chainRoot(node.expression)\n }\n return node\n }\n\n /** Every name a parameter binds — plain, destructured, defaulted or rest. */\n function boundNames(param: ASTNode): ReadonlyArray<string> {\n if (!param) return []\n if (param.type === \"Identifier\") return [param.name]\n if (param.type === \"AssignmentPattern\") return boundNames(param.left)\n if (param.type === \"RestElement\") return boundNames(param.argument)\n if (param.type === \"ArrayPattern\") return param.elements.flatMap((el: ASTNode) => boundNames(el))\n if (param.type === \"ObjectPattern\") {\n return param.properties.flatMap((prop: ASTNode) =>\n prop.type === \"RestElement\" ? boundNames(prop.argument) : boundNames(prop.value),\n )\n }\n return []\n }\n\n /**\n * A callback that transforms its OWN element's array (`(r) => r.cells.map(f)`, `(s) => s.split(\" \")`,\n * `(xs) => xs.filter(p).map(g)`) keeps the shape: one array per element, a matrix, or an array inside\n * an Either/Option/Task being mapped. Nothing is being flattened, so .flatMap is not the fix (#324).\n */\n function isShapePreserving(functionNode: ASTNode, returned: ASTNode): boolean {\n const root = chainRoot(returned)\n return root.type === \"Identifier\" && functionNode.params.flatMap(boundNames).includes(root.name)\n }\n\n function returnsArray(functionNode: ASTNode): boolean {\n if (!functionNode || !functionNode.body) return false\n\n // Arrow function with expression body\n if (functionNode.body.type === \"ArrayExpression\") {\n return isFlattenCandidateArrayLiteral(functionNode.body)\n }\n\n // Arrow function with call expression body\n if (functionNode.body.type === \"CallExpression\") {\n const call = functionNode.body\n if (isShapePreserving(functionNode, call)) return false\n if (call.callee.type === \"MemberExpression\") {\n const methodName = call.callee.property.name\n // Common methods that return arrays\n if (ARRAY_PRODUCING_METHODS.has(methodName)) {\n return true\n }\n }\n }\n\n // Function with block body — any return statement returning an array shape?\n if (functionNode.body.type === \"BlockStatement\") {\n return functionNode.body.body.some(\n (stmt: ASTNode) =>\n returnsArrayShape(stmt) &&\n !(stmt.argument.type === \"CallExpression\" && isShapePreserving(functionNode, stmt.argument)),\n )\n }\n\n return false\n }\n\n /** A single statement that's `return <array-shaped-expression>`. */\n function returnsArrayShape(stmt: ASTNode): boolean {\n if (stmt.type !== \"ReturnStatement\" || !stmt.argument) return false\n if (stmt.argument.type === \"ArrayExpression\") return isFlattenCandidateArrayLiteral(stmt.argument)\n if (\n stmt.argument.type === \"CallExpression\" &&\n stmt.argument.callee.type === \"MemberExpression\" &&\n ARRAY_PRODUCING_METHODS.has(stmt.argument.callee.property.name)\n ) {\n return true\n }\n return false\n }\n\n function isNestedMapReturningArrays(node: ASTNode): boolean {\n if (node.type !== \"CallExpression\") return false\n\n const callee = node.callee\n if (callee.type !== \"MemberExpression\") return false\n\n // Check if this is .map()\n if (callee.property.name === \"map\") {\n const callback = node.arguments[0]\n if (callback && (callback.type === \"ArrowFunctionExpression\" || callback.type === \"FunctionExpression\")) {\n return returnsArray(callback)\n }\n }\n\n return false\n }\n\n /**\n * Skip the warning when the receiver (`.map`'s left side) is a known\n * non-collection monad constructor call. The rule has no type info, so\n * it can't tell `arr.map(cb => arr2)` (collection, .flatMap is the fix)\n * from `Try(...).map(cb => arr)` (non-collection — .flatMap on Try\n * expects Try<T>, not an array, so .flatMap is NOT the fix).\n *\n * We can't enumerate every non-collection receiver, but we *can* detect\n * the unambiguous case: the receiver is literally `Try(...)` /\n * `Option(...)` / `Either(...)` / `Right(...)` / `Left(...)` / etc.\n * When that holds, suppress the warning. For bare identifiers (`items`)\n * or array literals or array-method chains, we can't tell, so the rule\n * still fires as before.\n */\n function isNonCollectionMonadReceiver(node: ASTNode): boolean {\n const monadConstructors = new Set([\n \"Option\",\n \"Some\",\n \"None\",\n \"Either\",\n \"Right\",\n \"Left\",\n \"Try\",\n \"Success\",\n \"Failure\",\n \"Task\",\n \"Ok\",\n \"Err\",\n \"IO\",\n ])\n // Bare constructor: Try(...), Option(...), Right(x), etc.\n if (\n node.type === \"CallExpression\" &&\n node.callee?.type === \"Identifier\" &&\n monadConstructors.has(node.callee.name)\n ) {\n return true\n }\n // Companion call: Either.right(x), Option.none(), Try.success(v)\n if (\n node.type === \"CallExpression\" &&\n node.callee?.type === \"MemberExpression\" &&\n node.callee.object?.type === \"Identifier\" &&\n monadConstructors.has(node.callee.object.name)\n ) {\n return true\n }\n return false\n }\n\n return {\n CallExpression(node: ASTNode) {\n // Check for .map().flat() pattern first (highest priority)\n if (isMapFollowedByFlat(node)) {\n const sourceCode = context.sourceCode\n\n context.report({\n node,\n messageId: \"preferFlatMapOverMapFlat\",\n fix(fixer) {\n // Get the .map() call\n const mapCall = (node.callee as ASTNode).object\n const mapCallText = sourceCode.getText(mapCall)\n\n // Replace .map() with .flatMap() and remove .flat()\n const flatMapText = mapCallText.replace(/\\.map\\s*\\(/, \".flatMap(\")\n\n return fixer.replaceText(node, flatMapText)\n },\n })\n return // Don't check other patterns if we found .map().flat()\n }\n\n // Check for chained maps where intermediate results are arrays (highest priority after map().flat())\n if (node.callee.type === \"MemberExpression\" && node.callee.property.name === \"map\") {\n const object = node.callee.object\n if (\n object.type === \"CallExpression\" &&\n object.callee.type === \"MemberExpression\" &&\n object.callee.property.name === \"map\"\n ) {\n // Check if the first map returns arrays\n const firstMapCallback = object.arguments[0]\n if (firstMapCallback && returnsArray(firstMapCallback)) {\n context.report({\n node: object, // Report on the first map call\n messageId: \"preferFlatMapChain\",\n })\n return // Don't check other patterns for this chain\n }\n }\n }\n\n // Check for nested maps that return arrays (but not if they're part of map().flat() or chains)\n if (checkNestedMaps && isNestedMapReturningArrays(node)) {\n // Don't flag if this map is immediately followed by flat()\n if (\n node.parent &&\n node.parent.type === \"MemberExpression\" &&\n node.parent.parent &&\n node.parent.parent.type === \"CallExpression\" &&\n node.parent.property.name === \"flat\"\n ) {\n return // Skip - this will be handled by the map().flat() rule\n }\n\n // Don't flag if this map is part of a chain (either as first or second map)\n const object = node.callee?.object\n if (\n object?.type === \"CallExpression\" &&\n object.callee?.type === \"MemberExpression\" &&\n object.callee?.property?.name === \"map\"\n ) {\n return // Skip - this is part of a chain\n }\n\n // Check if this map feeds into another map\n if (\n node.parent?.type === \"MemberExpression\" &&\n node.parent.parent?.type === \"CallExpression\" &&\n node.parent.parent.callee?.property?.name === \"map\"\n ) {\n return // Skip - this feeds into a chain\n }\n\n // Don't flag when the receiver is a known non-collection monad\n // constructor — .flatMap on Try / Option / Either / etc. expects\n // a wrapped value, not an array, so suggesting it is wrong.\n if (object && isNonCollectionMonadReceiver(object)) {\n return\n }\n\n context.report({\n node,\n messageId: \"preferFlatMapNested\",\n })\n }\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"AAKA,MAAMA,kBAA+C,IAAI,IAAI,CAAC,MAAO,SAAU,QAAS,SAAU,OAAO,CAAC,EAEpGC,EAAwB,CAC5B,KAAM,CACJ,KAAM,aACN,KAAM,CACJ,YAAa,kEACb,YAAa,EACf,EACA,QAAS,OACT,OAAQ,CACN,CACE,KAAM,SACN,WAAY,CACV,gBAAiB,CACf,KAAM,UACN,QAAS,EACX,CACF,EACA,qBAAsB,EACxB,CACF,EACA,SAAU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,EAA2BpB,CAAI,EAAG,CAEvD,GACEA,EAAK,QACLA,EAAK,OAAO,OAAS,oBACrBA,EAAK,OAAO,QACZA,EAAK,OAAO,OAAO,OAAS,kBAC5BA,EAAK,OAAO,SAAS,OAAS,OAE9B,OAIF,IAAME,EAASF,EAAK,QAAQ,OAqB5B,GAnBEE,GAAQ,OAAS,kBACjBA,EAAO,QAAQ,OAAS,oBACxBA,EAAO,QAAQ,UAAU,OAAS,OAOlCF,EAAK,QAAQ,OAAS,oBACtBA,EAAK,OAAO,QAAQ,OAAS,kBAC7BA,EAAK,OAAO,OAAO,QAAQ,UAAU,OAAS,OAQ5CE,GAAUoB,EAA6BpB,CAAM,EAC/C,OAGFJ,EAAQ,OAAO,CACb,OACA,UAAW,qBACb,CAAC,CACH,CACF,CACF,CACF,CACF"}
|
|
1
|
+
{"version":3,"file":"prefer-flatmap.js","names":["ARRAY_PRODUCING_METHODS","rule","checkNestedMaps","context","isMapFollowedByFlat","node","callee","object","isFlattenCandidateArrayLiteral","elements","arrayExpr","el","chainRoot","boundNames","param","prop","isShapePreserving","root","returned","functionNode","returnsArray","call","methodName","returnsArrayShape","stmt","isNestedMapReturningArrays","callback","isNonCollectionMonadReceiver","monadConstructors","isNonCollectionReceiver","receiver","isExtractableByType","isIOByType","sourceCode","mapCall","flatMapText","fixer","firstMapCallback"],"sources":["../../src/rules/prefer-flatmap.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { isExtractableByType, isIOByType } from \"../utils/type-aware\"\n\n/** Array-prototype methods whose call expression always returns an array. */\nconst ARRAY_PRODUCING_METHODS: ReadonlySet<string> = new Set([\"map\", \"filter\", \"slice\", \"concat\", \"split\"])\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"suggestion\",\n docs: {\n description: \"Prefer .flatMap() over .map().flat() and nested transformations\",\n recommended: true,\n },\n fixable: \"code\",\n schema: [\n {\n type: \"object\",\n properties: {\n checkNestedMaps: {\n type: \"boolean\",\n default: true,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n preferFlatMapOverMapFlat: \"Use .flatMap() instead of .map().flat()\",\n preferFlatMapNested: \"Consider .flatMap() for nested transformations that return arrays\",\n preferFlatMapChain: \"Use .flatMap() instead of chained .map() operations that flatten results\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n const checkNestedMaps = options.checkNestedMaps !== false\n\n function isMapFollowedByFlat(node: ASTNode): boolean {\n if (node.type !== \"CallExpression\") return false\n\n const callee = node.callee\n if (callee.type !== \"MemberExpression\") return false\n\n // Check if this is .flat()\n if (callee.property.name === \"flat\") {\n const object = callee.object\n\n // Check if the object is a .map() call\n if (\n object.type === \"CallExpression\" &&\n object.callee.type === \"MemberExpression\" &&\n object.callee.property.name === \"map\"\n ) {\n return true\n }\n }\n\n return false\n }\n\n /**\n * Heuristic for array literals that look like flatten candidates.\n * Skips append/identity patterns (`[...arr, x]`, `[...arr]`) and tuple\n * shapes (`[k, v]`) — those are not nested arrays, so .flatMap()\n * doesn't apply. Only flag when at least one element is itself an\n * ArrayExpression, signaling a true nested-array shape.\n */\n function isFlattenCandidateArrayLiteral(arrayExpr: ASTNode): boolean {\n const elements = arrayExpr.elements ?? []\n if (elements.some((el: ASTNode | null) => el && el.type === \"SpreadElement\")) {\n return false\n }\n return elements.some((el: ASTNode | null) => el && el.type === \"ArrayExpression\")\n }\n\n /**\n * The base identifier of a call/member chain: `members` in `members.filter(f).map(g)`, `r` in\n * `r.cells.map(f)`.\n */\n function chainRoot(node: ASTNode): ASTNode {\n if (node.type === \"CallExpression\") return chainRoot(node.callee)\n if (node.type === \"MemberExpression\") return chainRoot(node.object)\n if (\n node.type === \"ChainExpression\" ||\n node.type === \"TSNonNullExpression\" ||\n node.type === \"TSAsExpression\" ||\n node.type === \"TSSatisfiesExpression\"\n ) {\n return chainRoot(node.expression)\n }\n return node\n }\n\n /** Every name a parameter binds — plain, destructured, defaulted or rest. */\n function boundNames(param: ASTNode): ReadonlyArray<string> {\n if (!param) return []\n if (param.type === \"Identifier\") return [param.name]\n if (param.type === \"AssignmentPattern\") return boundNames(param.left)\n if (param.type === \"RestElement\") return boundNames(param.argument)\n if (param.type === \"ArrayPattern\") return param.elements.flatMap((el: ASTNode) => boundNames(el))\n if (param.type === \"ObjectPattern\") {\n return param.properties.flatMap((prop: ASTNode) =>\n prop.type === \"RestElement\" ? boundNames(prop.argument) : boundNames(prop.value),\n )\n }\n return []\n }\n\n /**\n * A callback that transforms its OWN element's array (`(r) => r.cells.map(f)`, `(s) => s.split(\" \")`,\n * `(xs) => xs.filter(p).map(g)`) keeps the shape: one array per element, a matrix, or an array inside\n * an Either/Option/Task being mapped. Nothing is being flattened, so .flatMap is not the fix (#324).\n */\n function isShapePreserving(functionNode: ASTNode, returned: ASTNode): boolean {\n const root = chainRoot(returned)\n return root.type === \"Identifier\" && functionNode.params.flatMap(boundNames).includes(root.name)\n }\n\n function returnsArray(functionNode: ASTNode): boolean {\n if (!functionNode || !functionNode.body) return false\n\n // Arrow function with expression body\n if (functionNode.body.type === \"ArrayExpression\") {\n return isFlattenCandidateArrayLiteral(functionNode.body)\n }\n\n // Arrow function with call expression body\n if (functionNode.body.type === \"CallExpression\") {\n const call = functionNode.body\n if (isShapePreserving(functionNode, call)) return false\n if (call.callee.type === \"MemberExpression\") {\n const methodName = call.callee.property.name\n // Common methods that return arrays\n if (ARRAY_PRODUCING_METHODS.has(methodName)) {\n return true\n }\n }\n }\n\n // Function with block body — any return statement returning an array shape?\n if (functionNode.body.type === \"BlockStatement\") {\n return functionNode.body.body.some(\n (stmt: ASTNode) =>\n returnsArrayShape(stmt) &&\n !(stmt.argument.type === \"CallExpression\" && isShapePreserving(functionNode, stmt.argument)),\n )\n }\n\n return false\n }\n\n /** A single statement that's `return <array-shaped-expression>`. */\n function returnsArrayShape(stmt: ASTNode): boolean {\n if (stmt.type !== \"ReturnStatement\" || !stmt.argument) return false\n if (stmt.argument.type === \"ArrayExpression\") return isFlattenCandidateArrayLiteral(stmt.argument)\n if (\n stmt.argument.type === \"CallExpression\" &&\n stmt.argument.callee.type === \"MemberExpression\" &&\n ARRAY_PRODUCING_METHODS.has(stmt.argument.callee.property.name)\n ) {\n return true\n }\n return false\n }\n\n function isNestedMapReturningArrays(node: ASTNode): boolean {\n if (node.type !== \"CallExpression\") return false\n\n const callee = node.callee\n if (callee.type !== \"MemberExpression\") return false\n\n // Check if this is .map()\n if (callee.property.name === \"map\") {\n const callback = node.arguments[0]\n if (callback && (callback.type === \"ArrowFunctionExpression\" || callback.type === \"FunctionExpression\")) {\n return returnsArray(callback)\n }\n }\n\n return false\n }\n\n /**\n * The syntactic half of the receiver check, used with or without type information: the receiver\n * is literally a constructor or companion call, `Try(...)` / `Option(...)` / `Either.right(x)` /\n * etc. `.flatMap` on those expects the same container back, not an array. A bare identifier, an\n * array literal or an array-method chain can't be told apart without types, so it still reports;\n * `isNonCollectionReceiver` adds the type-aware check for those.\n */\n function isNonCollectionMonadReceiver(node: ASTNode): boolean {\n const monadConstructors = new Set([\n \"Option\",\n \"Some\",\n \"None\",\n \"Either\",\n \"Right\",\n \"Left\",\n \"Try\",\n \"Success\",\n \"Failure\",\n \"Task\",\n \"Ok\",\n \"Err\",\n \"IO\",\n ])\n // Bare constructor: Try(...), Option(...), Right(x), etc.\n if (\n node.type === \"CallExpression\" &&\n node.callee?.type === \"Identifier\" &&\n monadConstructors.has(node.callee.name)\n ) {\n return true\n }\n // Companion call: Either.right(x), Option.none(), Try.success(v)\n if (\n node.type === \"CallExpression\" &&\n node.callee?.type === \"MemberExpression\" &&\n node.callee.object?.type === \"Identifier\" &&\n monadConstructors.has(node.callee.object.name)\n ) {\n return true\n }\n return false\n }\n\n /**\n * Is `.map`'s receiver a container that isn't a collection, so `.flatMap` expects the same\n * container back and an array won't do (#520)? A literal constructor call counts. With type\n * information, so does any Option, Either, Try, Lazy, TaskOutcome or IO value, however it was\n * built: a variable, a parameter, a function's return. Collections (List, Set, arrays) have no\n * `orThrow` and aren't IO, so they still report. Without type information only the literal\n * call is recognized.\n */\n function isNonCollectionReceiver(receiver: ASTNode): boolean {\n return (\n isNonCollectionMonadReceiver(receiver) ||\n isExtractableByType(receiver, context) === true ||\n isIOByType(receiver, context) === true\n )\n }\n\n return {\n CallExpression(node: ASTNode) {\n // Check for .map().flat() pattern first (highest priority)\n if (isMapFollowedByFlat(node)) {\n const sourceCode = context.sourceCode\n\n context.report({\n node,\n messageId: \"preferFlatMapOverMapFlat\",\n fix(fixer) {\n // Get the .map() call\n const mapCall = (node.callee as ASTNode).object\n const mapCallText = sourceCode.getText(mapCall)\n\n // Replace .map() with .flatMap() and remove .flat()\n const flatMapText = mapCallText.replace(/\\.map\\s*\\(/, \".flatMap(\")\n\n return fixer.replaceText(node, flatMapText)\n },\n })\n return // Don't check other patterns if we found .map().flat()\n }\n\n // Check for chained maps where intermediate results are arrays (highest priority after map().flat())\n if (node.callee.type === \"MemberExpression\" && node.callee.property.name === \"map\") {\n const object = node.callee.object\n if (\n object.type === \"CallExpression\" &&\n object.callee.type === \"MemberExpression\" &&\n object.callee.property.name === \"map\"\n ) {\n // Check if the first map returns arrays\n const firstMapCallback = object.arguments[0]\n if (firstMapCallback && returnsArray(firstMapCallback) && !isNonCollectionReceiver(object.callee.object)) {\n context.report({\n node: object, // Report on the first map call\n messageId: \"preferFlatMapChain\",\n })\n return // Don't check other patterns for this chain\n }\n }\n }\n\n // Check for nested maps that return arrays (but not if they're part of map().flat() or chains)\n if (checkNestedMaps && isNestedMapReturningArrays(node)) {\n // Don't flag if this map is immediately followed by flat()\n if (\n node.parent &&\n node.parent.type === \"MemberExpression\" &&\n node.parent.parent &&\n node.parent.parent.type === \"CallExpression\" &&\n node.parent.property.name === \"flat\"\n ) {\n return // Skip - this will be handled by the map().flat() rule\n }\n\n // Don't flag if this map is part of a chain (either as first or second map)\n const object = node.callee?.object\n if (\n object?.type === \"CallExpression\" &&\n object.callee?.type === \"MemberExpression\" &&\n object.callee?.property?.name === \"map\"\n ) {\n return // Skip - this is part of a chain\n }\n\n // Check if this map feeds into another map\n if (\n node.parent?.type === \"MemberExpression\" &&\n node.parent.parent?.type === \"CallExpression\" &&\n node.parent.parent.callee?.property?.name === \"map\"\n ) {\n return // Skip - this feeds into a chain\n }\n\n // Don't flag when the receiver is a non-collection container: .flatMap on\n // Try / Option / Either / IO / etc. expects a wrapped value, not an array.\n if (object && isNonCollectionReceiver(object)) {\n return\n }\n\n context.report({\n node,\n messageId: \"preferFlatMapNested\",\n })\n }\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"6EAMA,MAAMA,kBAA+C,IAAI,IAAI,CAAC,MAAO,SAAU,QAAS,SAAU,OAAO,CAAC,EAEpGC,EAAwB,CAC5B,KAAM,CACJ,KAAM,aACN,KAAM,CACJ,YAAa,kEACb,YAAa,EACf,EACA,QAAS,OACT,OAAQ,CACN,CACE,KAAM,SACN,WAAY,CACV,gBAAiB,CACf,KAAM,UACN,QAAS,EACX,CACF,EACA,qBAAsB,EACxB,CACF,EACA,SAAU,CACR,yBAA0B,0CAC1B,oBAAqB,oEACrB,mBAAoB,0EACtB,CACF,EAEA,OAAO,EAAS,CAEd,IAAMC,GADUC,EAAQ,QAAQ,IAAM,CAAC,EAAA,CACP,kBAAoB,GAEpD,SAASC,EAAoB,EAAwB,CACnD,GAAIC,EAAK,OAAS,iBAAkB,MAAO,GAE3C,IAAMC,EAASD,EAAK,OACpB,GAAIC,EAAO,OAAS,mBAAoB,MAAO,GAG/C,GAAIA,EAAO,SAAS,OAAS,OAAQ,CACnC,IAAMC,EAASD,EAAO,OAGtB,GACEC,EAAO,OAAS,kBAChBA,EAAO,OAAO,OAAS,oBACvBA,EAAO,OAAO,SAAS,OAAS,MAEhC,MAAO,EAEX,CAEA,MAAO,EACT,CASA,SAASC,EAA+B,EAA6B,CACnE,IAAMC,EAAWC,EAAU,UAAY,CAAC,EAIxC,MAHA,CAAID,EAAS,KAAM,GAAuBE,GAAMA,EAAG,OAAS,eAAe,GAGpE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AM,EAC1C,OAGFJ,EAAQ,OAAO,CACb,OACA,UAAW,qBACb,CAAC,CACH,CACF,CACF,CACF,CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-functype",
|
|
3
|
-
"version": "2.127.
|
|
3
|
+
"version": "2.127.2",
|
|
4
4
|
"description": "Custom ESLint rules for functional TypeScript programming with functype library patterns including Do notation (ESLint 10+)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@types/node": "^24.19.1",
|
|
43
43
|
"@typescript-eslint/rule-tester": "^8.71.0",
|
|
44
44
|
"eslint-config-prettier": "^10.1.8",
|
|
45
|
-
"functype": "^1.27.
|
|
45
|
+
"functype": "^1.27.2",
|
|
46
46
|
"ts-builds": "^4.5.0",
|
|
47
47
|
"tsdown": "^0.23.0"
|
|
48
48
|
},
|