eslint-plugin-functype 2.200.0 → 2.202.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.
Files changed (64) hide show
  1. package/README.md +64 -2
  2. package/dist/cli/list-rules.js.map +1 -1
  3. package/dist/configs/recommended.d.ts +9 -1
  4. package/dist/configs/recommended.js +1 -1
  5. package/dist/configs/recommended.js.map +1 -1
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.js +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/rules/collection-naming.js.map +1 -1
  10. package/dist/rules/index.d.ts +22 -18
  11. package/dist/rules/index.js +1 -1
  12. package/dist/rules/index.js.map +1 -1
  13. package/dist/rules/must-fold-on-component-return.js.map +1 -1
  14. package/dist/rules/no-array-mutation.js.map +1 -1
  15. package/dist/rules/no-container-mutation.d.ts +21 -0
  16. package/dist/rules/no-container-mutation.js +2 -0
  17. package/dist/rules/no-container-mutation.js.map +1 -0
  18. package/dist/rules/no-floating-io.js.map +1 -1
  19. package/dist/rules/no-floating-result.js.map +1 -1
  20. package/dist/rules/no-get-unsafe.js.map +1 -1
  21. package/dist/rules/no-getOrThrow-in-render.js.map +1 -1
  22. package/dist/rules/no-imperative-loops.js.map +1 -1
  23. package/dist/rules/no-let.js.map +1 -1
  24. package/dist/rules/no-serialize-container.js.map +1 -1
  25. package/dist/rules/no-uncalled-method.d.ts +16 -0
  26. package/dist/rules/no-uncalled-method.js +2 -0
  27. package/dist/rules/no-uncalled-method.js.map +1 -0
  28. package/dist/rules/prefer-do-notation.js +1 -1
  29. package/dist/rules/prefer-do-notation.js.map +1 -1
  30. package/dist/rules/prefer-either.js.map +1 -1
  31. package/dist/rules/prefer-flatmap.js.map +1 -1
  32. package/dist/rules/prefer-fold.js +1 -1
  33. package/dist/rules/prefer-fold.js.map +1 -1
  34. package/dist/rules/prefer-functype-map.js.map +1 -1
  35. package/dist/rules/prefer-functype-set.js.map +1 -1
  36. package/dist/rules/prefer-list.js.map +1 -1
  37. package/dist/rules/prefer-map.js.map +1 -1
  38. package/dist/rules/prefer-option.js.map +1 -1
  39. package/dist/rules/prefer-try.js.map +1 -1
  40. package/dist/utils/array-mutation.d.ts +1 -1
  41. package/dist/utils/array-mutation.js.map +1 -1
  42. package/dist/utils/ast-walk.js.map +1 -1
  43. package/dist/utils/async-detection.js.map +1 -1
  44. package/dist/utils/boundary-tags.d.ts +1 -1
  45. package/dist/utils/boundary-tags.js.map +1 -1
  46. package/dist/utils/collection-binding.d.ts +1 -1
  47. package/dist/utils/collection-binding.js.map +1 -1
  48. package/dist/utils/dependency-validator.js.map +1 -1
  49. package/dist/utils/functype-detection.d.ts +1 -1
  50. package/dist/utils/functype-detection.js.map +1 -1
  51. package/dist/utils/functype-predicates.d.ts +1 -1
  52. package/dist/utils/functype-predicates.js.map +1 -1
  53. package/dist/utils/host-throws.d.ts +1 -1
  54. package/dist/utils/host-throws.js.map +1 -1
  55. package/dist/utils/import-fixer.js.map +1 -1
  56. package/dist/utils/mutable-collection.d.ts +1 -1
  57. package/dist/utils/mutable-collection.js.map +1 -1
  58. package/dist/utils/react-render.js.map +1 -1
  59. package/dist/utils/readonly-contract.js.map +1 -1
  60. package/dist/utils/type-aware.d.ts +22 -1
  61. package/dist/utils/type-aware.js +1 -1
  62. package/dist/utils/type-aware.js.map +1 -1
  63. package/dist/utils/wire-types.js.map +1 -1
  64. package/package.json +3 -3
package/README.md CHANGED
@@ -22,7 +22,7 @@ There is one preset. The code it checks is written by coding agents, and an agen
22
22
  - **`error`:** every rule whose precision is measured on real code. A forgotten `.run()`, a dropped `Either` or a throw in render is the kind of mistake an agent makes and a reviewer misses.
23
23
  - **`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.
24
24
  - **At a real boundary, mark it** rather than disable the rule: `@interop <reason>` or `invariant()` for a throw (see below), `Wire<T>` for a data shape.
25
- - **Type-aware rules:** `no-array-mutation`, `no-floating-io`, `no-floating-result` and `no-serialize-container` need typescript-eslint's parser with `parserOptions.projectService`. Without it they report nothing.
25
+ - **Type-aware rules:** `no-array-mutation`, `no-floating-io`, `no-floating-result`, `no-serialize-container`, `no-uncalled-method` and `no-container-mutation` need typescript-eslint's parser with `parserOptions.projectService`. Without it they report nothing.
26
26
  - **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`.
27
27
 
28
28
  In 1.x the plugin had three presets: `recommended` and `strict`, which warned on rules still being measured, and `agent`, which didn't. 2.0's `recommended` is 1.x's `agent`, and `strict` and `agent` are gone: a config that names one fails to load (ESLint reports an `Unexpected undefined config`), so update it to `recommended`.
@@ -53,7 +53,7 @@ typescript-eslint, which this plugin runs on, doesn't support TypeScript 7 yet:
53
53
  }
54
54
  ```
55
55
 
56
- Every rule that works without type information works there. The four type-aware rules, `no-array-mutation`, `no-floating-io`, `no-floating-result` and `no-serialize-container`, report nothing, because Oxlint doesn't pass type information to JS plugins yet. Checked on 2026-11-22 with Oxlint 1.94.0.
56
+ Every rule that works without type information works there. The six type-aware rules, `no-array-mutation`, `no-floating-io`, `no-floating-result`, `no-serialize-container`, `no-uncalled-method` and `no-container-mutation`, report nothing, because Oxlint doesn't pass type information to JS plugins yet. Checked on 2026-11-22 with Oxlint 1.94.0.
57
57
 
58
58
  When typescript-eslint supports TypeScript 7.1's new compiler API, the 6.0 alias can go and nothing in this plugin changes; its `@typescript/native` peer suggests that name stays. Until then, prefer the side-by-side setup, which keeps the type-aware rules.
59
59
 
@@ -79,6 +79,8 @@ When typescript-eslint supports TypeScript 7.1's new compiler API, the 6.0 alias
79
79
  | `functype/no-floating-io` | error | | Don't build an `IO` and drop it, or `await` it unrun; run, return or `yield*` it |
80
80
  | `functype/no-floating-result` | error | off | Don't drop an `Either`/`Try` result; a failure in it is silently ignored |
81
81
  | `functype/no-serialize-container` | error | off | Don't send an `Either`/`Option`/`List` to `c.json()` or `JSON.stringify()`; unwrap it first |
82
+ | `functype/no-uncalled-method` | error | | Call a functype method: `list.head()`, not `list.head`; read without `()` it is the function |
83
+ | `functype/no-container-mutation` | error | | Don't change a functype value in place, even through a cast; build a new one |
82
84
  | `functype/no-getOrThrow-in-render` | error | | React: no bare `.orThrow()` in a component or hook body; a throw in render unmounts the tree |
83
85
  | `functype/must-fold-on-component-return` | error | | React: render an `Option`/`Either`/`Try` with `fold` or `<MatchOption>`, not a guard or `&&` |
84
86
 
@@ -304,6 +306,66 @@ return c.json(result.toJSON()) // fine: the envelope on purpose
304
306
 
305
307
  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 `recommended`, and `off` in `tests`, which assert on a container's `JSON.stringify` envelope.
306
308
 
309
+ ### `functype/no-uncalled-method`
310
+
311
+ Reports a functype method read as a value instead of called. On functype 2, `head`, `last`, `tail`, `init`, `headOption` and `lastOption` are methods, and a read without `()` compiles wherever any value is accepted. It yields the function itself: always truthy, never the element. A detached functype method also throws when it's called later.
312
+
313
+ ```ts ignore
314
+ const checkout = results.head // reported: a function, so `if (!checkout)` is never taken
315
+ return Option(results.head) // reported: Some(<function>), not Some(firstRow)
316
+ expect(results.head).toEqual(row) // reported
317
+ if (opt.isSome) {
318
+ } // reported: always true
319
+ const { head } = results // reported
320
+
321
+ results.head() // fine
322
+ results.headOption() // fine
323
+ results.head.bind(results) // fine: the function on purpose
324
+ results.size // fine: a property
325
+ ```
326
+
327
+ - **What counts:** a member declared as a method in functype's own files, read on a value with `_tag` and `fold`. A type of your own with that shape, or an interface extending `List` with methods of its own, isn't reported for those methods. Getters such as `size` and `isEmpty`, and function-valued data such as `Some(fn).value` or a `Ref` holding a callback, are never reported.
328
+ - **Deliberate uses:** a call (`?.()`, `new` and a tagged template included, also through `as`, `!` or `satisfies`), `.bind` / `.call` / `.apply`, `typeof`, an assignment target, and `delete`.
329
+ - **Not covered yet:** destructuring in parameters, nested patterns and `for…of`, and computed reads with a variable key (`results[key]`).
330
+ - **Why a lint rule:** the upgrade tool rewrites these reads once, in your own code. The rule keeps them from coming back, and runs in libraries that never run the upgrade tool.
331
+
332
+ **It only runs with type-aware linting** (`parserOptions.projectService`). Without type information it reports nothing.
333
+
334
+ Measured (2026-11-22) on seven codebases on functype 1.x and 2.x, 1,126 files: no hits. Run on a library's code from before its 2.0 port, it reports the `Option(list.head)` that library shipped. It's `error` in `recommended`, and stays on in `tests`: `expect(list.head)` is one of the bugs it's for.
335
+
336
+ ### `functype/no-container-mutation`
337
+
338
+ Reports a write to a functype value that TypeScript can't see. The types mark every field read-only, so such a write needs the value's type hidden: an `as` cast, or a variable that holds one. Since functype 2.2, collections no longer freeze each value, so at run time nothing else stops these writes.
339
+
340
+ ```ts ignore
341
+ ;(list as unknown as { value: number[] }).value = [9] // reported
342
+ ;(list as any).value[0] = 9 // reported: the List's own array
343
+ ;(list as any).value.push(9) // reported: a mutating method through a cast
344
+ const record = list as unknown as Record<string, unknown>
345
+ record.extra = 1 // reported: a variable holding a cast
346
+ delete (opt as any).value // reported
347
+ Object.assign(list, { extra: 1 }) // reported: compiles without a cast
348
+ for ((list as any).extra of xs) {
349
+ } // reported
350
+
351
+ list.map((x) => x + 1) // fine: a new List
352
+ if (box.isSome()) box.value.n = 1 // fine: the Option's payload, not the Option
353
+ mine.dirty = true // fine: a field of your own subtype of List
354
+ ```
355
+
356
+ - **What it reports:** an assignment, compound assignment, `++`/`--`, `delete`, or a destructuring or `for…of`/`for…in` target whose path starts from a functype value held under an `as` cast or `<T>` assertion. That includes a variable written only where it's declared and initialised from one, or declared `: any`. It also reports a mutating method, such as `push`, `splice`, `sort`, `add`, `set`, `delete` or `clear`, called on data reached through such a value. Called on the functype value itself, cast or not, the method is functype's own and returns a new value, so `(fmap as Map<string, number>).set("a", 1)` isn't reported. And it reports `Object.assign`, `Object.defineProperty`, `Object.defineProperties` and `Object.setPrototypeOf`, and the matching `Reflect` calls, aimed at a functype value, cast or not, since those compile without one. `globalThis.Object.assign` and `Object["assign"]` count too.
357
+ - **What it leaves alone:** a write that compiles without a cast. That's either a field of your own type, or data a container holds but doesn't own, such as an Option's payload or a List element's own field. Freezing never stopped those writes either. A cast anywhere on the path still counts, so `(opt.value as T).n = 1` is reported.
358
+ - **A functype value** has `_tag` and a `fold` that functype itself declares, so a type of your own with that shape isn't reported. A union counts when any of its members is a functype value.
359
+ - **What it can't see:** a value passed to a parameter typed `any` and written there, plain JavaScript, `Reflect.apply` and `.call` on these functions, and a destructured `assign`. Linting can't follow a value once its type is gone, so functype covers those in development instead: under `NODE_ENV=development`, or with `FUNCTYPE_FREEZE=1`, collections freeze each value, and such a write throws. It also doesn't follow a cast through:
360
+ - a variable assigned again after its declaration;
361
+ - an object field;
362
+ - a conditional or `??` (`const o = ok ? (list as any) : null`);
363
+ - a comma expression.
364
+
365
+ **It only runs with type-aware linting** (`parserOptions.projectService`). Without type information it reports nothing.
366
+
367
+ Measured (2026-11-23) on seven codebases, 1,128 files including 343 test files, all with type information: no hits. Writes planted in one of those test files, through a cast-holding variable and through `: any`, are reported. It's `error` in `recommended`, and stays on in `tests`.
368
+
307
369
  ### React rules
308
370
 
309
371
  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 `error` in `recommended`.
@@ -1 +1 @@
1
- {"version":3,"file":"list-rules.js","names":["plugin","colors","colorize","color","text","printDependencyStatus","result","icon","dep","warning","status","statusColor","main","args","showHelp","showUsage","checkDeps","validatePeerDependencies","rules","rule","ruleName","fullName","typeColor","printCustomUsageInfo","error"],"sources":["../../src/cli/list-rules.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport plugin from \"../index.js\"\nimport { validatePeerDependencies, type ValidationResult } from \"../utils/dependency-validator.js\"\n\n// Colors for console output\nconst colors = {\n reset: \"\\x1b[0m\",\n bright: \"\\x1b[1m\",\n red: \"\\x1b[31m\",\n green: \"\\x1b[32m\",\n yellow: \"\\x1b[33m\",\n blue: \"\\x1b[34m\",\n magenta: \"\\x1b[35m\",\n cyan: \"\\x1b[36m\",\n} as const\n\nfunction colorize(text: string, color: keyof typeof colors): string {\n return colors[color] + text + colors.reset\n}\n\n// Removed unused utility functions - they were for the old config-based approach\n\nfunction printDependencyStatus(result: ValidationResult): void {\n console.log(colorize(\"\\n🔍 Dependency Status Check:\", \"bright\"))\n console.log(colorize(\"=\".repeat(40), \"blue\"))\n\n // Show available dependencies\n if (result.available.length > 0) {\n console.log(colorize(\"\\n✅ Available:\", \"green\"))\n result.available.forEach((dep) => {\n const icon = dep.required ? \"🔧\" : \"🔌\"\n console.log(` ${icon} ${colorize(dep.name, \"green\")} - ${dep.description}`)\n })\n }\n\n // Show missing dependencies\n if (result.missing.length > 0) {\n console.log(colorize(\"\\n❌ Missing:\", \"red\"))\n result.missing.forEach((dep) => {\n const icon = dep.required ? \"⚠️ \" : \"💡\"\n const color = dep.required ? \"red\" : \"yellow\"\n console.log(` ${icon} ${colorize(dep.name, color)} - ${dep.description}`)\n })\n\n if (result.installCommand) {\n console.log(colorize(\"\\n📦 Install missing dependencies:\", \"bright\"))\n console.log(` ${colorize(result.installCommand, \"cyan\")}`)\n }\n }\n\n // Show warnings\n if (result.warnings.length > 0) {\n console.log(colorize(\"\\n⚠️ Warnings:\", \"yellow\"))\n result.warnings.forEach((warning) => console.log(` ${warning}`))\n }\n\n // Overall status\n const status = result.isValid ? \"✅ Ready to use\" : \"❌ Configuration will fail\"\n const statusColor = result.isValid ? \"green\" : \"red\"\n console.log(colorize(`\\n${status}`, statusColor))\n}\n\nasync function main(): Promise<void> {\n const args = process.argv.slice(2)\n const showHelp = args.includes(\"--help\") || args.includes(\"-h\")\n const showUsage = args.includes(\"--usage\") || args.includes(\"-u\")\n const checkDeps = args.includes(\"--check-deps\") || args.includes(\"--check\")\n\n if (showHelp) {\n console.log(colorize(\"📋 ESLint Plugin Functype - Custom Rules\", \"bright\"))\n console.log(\"\\nUsage: pnpm run list-rules [options]\")\n console.log(\"\\nOptions:\")\n console.log(\" --verbose, -v Show rule descriptions and schemas\")\n console.log(\" --usage, -u Show usage examples\")\n console.log(\" --check-deps Check peer dependency status\")\n console.log(\" --help, -h Show this help message\")\n console.log(\"\\nThis command lists all custom rules provided by the functype plugin.\")\n return\n }\n\n // Handle dependency check\n if (checkDeps) {\n console.log(colorize(\"🔧 ESLint Plugin Functype - Dependency Check\", \"bright\"))\n const result = validatePeerDependencies()\n printDependencyStatus(result)\n\n if (!result.isValid) {\n process.exit(1)\n }\n return\n }\n\n console.log(colorize(\"🔧 ESLint Plugin Functype - Custom Rules\", \"bright\"))\n\n if (!plugin.rules) {\n console.error(colorize(\"❌ No rules found in plugin.\", \"red\"))\n process.exit(1)\n }\n\n console.log(colorize(\"\\n📦 Available Custom Rules:\", \"bright\"))\n console.log(colorize(\"=\".repeat(40), \"blue\"))\n\n const rules = Object.keys(plugin.rules)\n\n rules.forEach((ruleName) => {\n const rule = plugin.rules[ruleName]\n const fullName = `functype/${ruleName}`\n\n console.log(`\\n${colorize(\"●\", \"green\")} ${colorize(fullName, \"bright\")}`)\n\n if (rule.meta?.docs?.description) {\n console.log(` ${colorize(\"Description:\", \"cyan\")} ${rule.meta.docs.description}`)\n }\n\n if (rule.meta?.type) {\n const typeColor = rule.meta.type === \"problem\" ? \"red\" : rule.meta.type === \"suggestion\" ? \"yellow\" : \"blue\"\n console.log(` ${colorize(\"Type:\", \"cyan\")} ${colorize(rule.meta.type, typeColor)}`)\n }\n\n if (rule.meta?.fixable) {\n console.log(` ${colorize(\"Fixable:\", \"cyan\")} ${colorize(\"Yes\", \"green\")}`)\n }\n\n if (showUsage) {\n console.log(` ${colorize(\"Usage:\", \"cyan\")} \"${fullName}\": \"error\"`)\n }\n })\n\n console.log(colorize(`\\n📊 Summary: ${rules.length} custom rules available`, \"bright\"))\n\n if (showUsage) {\n printCustomUsageInfo()\n }\n\n console.log(colorize(\"\\n💡 Tips:\", \"bright\"))\n console.log(\"• Use --verbose to see detailed rule information\")\n console.log(\"• Use --usage to see configuration examples\")\n console.log('• All rules are prefixed with \"functype/\"')\n console.log(\"• Consider using eslint-config-functype for pre-configured setup\")\n\n console.log(colorize(\"\\n🔗 Links:\", \"bright\"))\n console.log(\"• Documentation: https://github.com/jordanburke/eslint-plugin-functype\")\n console.log(\"• Configuration Bundle: https://github.com/jordanburke/eslint-config-functype\")\n console.log(\"• Functype Library: https://github.com/jordanburke/functype\")\n}\n\nfunction printCustomUsageInfo(): void {\n console.log(colorize(\"\\n💡 Usage Examples:\", \"bright\"))\n console.log(colorize(\"=\".repeat(30), \"blue\"))\n console.log(\"\\n\" + colorize(\"ESLint 9+ (flat config):\", \"green\"))\n console.log(' import functypePlugin from \"eslint-plugin-functype\"')\n console.log(\" export default [\")\n console.log(\" {\")\n console.log(\" plugins: { functype: functypePlugin },\")\n console.log(\" rules: {\")\n console.log(' \"functype/prefer-option\": \"error\",')\n console.log(' \"functype/prefer-either\": \"error\",')\n console.log(' \"functype/no-get-unsafe\": \"error\",')\n console.log(\" }\")\n console.log(\" }\")\n console.log(\" ]\")\n console.log(\"\\n\" + colorize(\"With eslint-config-functype (recommended):\", \"green\"))\n console.log(' import functypeConfig from \"eslint-config-functype\"')\n console.log(\" export default [functypeConfig.recommended]\")\n}\n\n// Run the CLI\nmain().catch((error) => {\n console.error(colorize(\"❌ Unexpected error:\", \"red\"), error)\n process.exit(1)\n})\n"],"mappings":";A,uGAMA,MAAMC,EAAS,CACb,MAAO,UACP,OAAQ,UACR,IAAK,WACL,MAAO,WACP,OAAQ,WACR,KAAM,WACN,QAAS,WACT,KAAM,UACR,EA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B,QAAQ,IAAI;EAAOA,EAAS,6CAA8C,OAAO,CAAC,EAClF,QAAQ,IAAI,uDAAuD,EACnE,QAAQ,IAAI,+CAA+C,CAC7D,CAGAU,EAAK,CAAC,CAAC,MAAO,GAAU,CACtB,QAAQ,MAAMV,EAAS,sBAAuB,KAAK,EAAGsB,CAAK,EAC3D,QAAQ,KAAK,CAAC,CAChB,CAAC,E"}
1
+ {"version":3,"file":"list-rules.js","names":["plugin","validatePeerDependencies","colors","colorize","text","color","printDependencyStatus","result","dep","icon","warning","status","statusColor","main","args","showHelp","showUsage","checkDeps","rules","ruleName","rule","fullName","typeColor","printCustomUsageInfo","error"],"sources":["../../src/cli/list-rules.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport plugin from \"../index.js\"\nimport { validatePeerDependencies, type ValidationResult } from \"../utils/dependency-validator.js\"\n\n// Colors for console output\nconst colors = {\n reset: \"\\x1b[0m\",\n bright: \"\\x1b[1m\",\n red: \"\\x1b[31m\",\n green: \"\\x1b[32m\",\n yellow: \"\\x1b[33m\",\n blue: \"\\x1b[34m\",\n magenta: \"\\x1b[35m\",\n cyan: \"\\x1b[36m\",\n} as const\n\nfunction colorize(text: string, color: keyof typeof colors): string {\n return colors[color] + text + colors.reset\n}\n\n// Removed unused utility functions - they were for the old config-based approach\n\nfunction printDependencyStatus(result: ValidationResult): void {\n console.log(colorize(\"\\n🔍 Dependency Status Check:\", \"bright\"))\n console.log(colorize(\"=\".repeat(40), \"blue\"))\n\n // Show available dependencies\n if (result.available.length > 0) {\n console.log(colorize(\"\\n✅ Available:\", \"green\"))\n result.available.forEach((dep) => {\n const icon = dep.required ? \"🔧\" : \"🔌\"\n console.log(` ${icon} ${colorize(dep.name, \"green\")} - ${dep.description}`)\n })\n }\n\n // Show missing dependencies\n if (result.missing.length > 0) {\n console.log(colorize(\"\\n❌ Missing:\", \"red\"))\n result.missing.forEach((dep) => {\n const icon = dep.required ? \"⚠️ \" : \"💡\"\n const color = dep.required ? \"red\" : \"yellow\"\n console.log(` ${icon} ${colorize(dep.name, color)} - ${dep.description}`)\n })\n\n if (result.installCommand) {\n console.log(colorize(\"\\n📦 Install missing dependencies:\", \"bright\"))\n console.log(` ${colorize(result.installCommand, \"cyan\")}`)\n }\n }\n\n // Show warnings\n if (result.warnings.length > 0) {\n console.log(colorize(\"\\n⚠️ Warnings:\", \"yellow\"))\n result.warnings.forEach((warning) => console.log(` ${warning}`))\n }\n\n // Overall status\n const status = result.isValid ? \"✅ Ready to use\" : \"❌ Configuration will fail\"\n const statusColor = result.isValid ? \"green\" : \"red\"\n console.log(colorize(`\\n${status}`, statusColor))\n}\n\nasync function main(): Promise<void> {\n const args = process.argv.slice(2)\n const showHelp = args.includes(\"--help\") || args.includes(\"-h\")\n const showUsage = args.includes(\"--usage\") || args.includes(\"-u\")\n const checkDeps = args.includes(\"--check-deps\") || args.includes(\"--check\")\n\n if (showHelp) {\n console.log(colorize(\"📋 ESLint Plugin Functype - Custom Rules\", \"bright\"))\n console.log(\"\\nUsage: pnpm run list-rules [options]\")\n console.log(\"\\nOptions:\")\n console.log(\" --verbose, -v Show rule descriptions and schemas\")\n console.log(\" --usage, -u Show usage examples\")\n console.log(\" --check-deps Check peer dependency status\")\n console.log(\" --help, -h Show this help message\")\n console.log(\"\\nThis command lists all custom rules provided by the functype plugin.\")\n return\n }\n\n // Handle dependency check\n if (checkDeps) {\n console.log(colorize(\"🔧 ESLint Plugin Functype - Dependency Check\", \"bright\"))\n const result = validatePeerDependencies()\n printDependencyStatus(result)\n\n if (!result.isValid) {\n process.exit(1)\n }\n return\n }\n\n console.log(colorize(\"🔧 ESLint Plugin Functype - Custom Rules\", \"bright\"))\n\n if (!plugin.rules) {\n console.error(colorize(\"❌ No rules found in plugin.\", \"red\"))\n process.exit(1)\n }\n\n console.log(colorize(\"\\n📦 Available Custom Rules:\", \"bright\"))\n console.log(colorize(\"=\".repeat(40), \"blue\"))\n\n const rules = Object.keys(plugin.rules)\n\n rules.forEach((ruleName) => {\n const rule = plugin.rules[ruleName]\n const fullName = `functype/${ruleName}`\n\n console.log(`\\n${colorize(\"●\", \"green\")} ${colorize(fullName, \"bright\")}`)\n\n if (rule.meta?.docs?.description) {\n console.log(` ${colorize(\"Description:\", \"cyan\")} ${rule.meta.docs.description}`)\n }\n\n if (rule.meta?.type) {\n const typeColor = rule.meta.type === \"problem\" ? \"red\" : rule.meta.type === \"suggestion\" ? \"yellow\" : \"blue\"\n console.log(` ${colorize(\"Type:\", \"cyan\")} ${colorize(rule.meta.type, typeColor)}`)\n }\n\n if (rule.meta?.fixable) {\n console.log(` ${colorize(\"Fixable:\", \"cyan\")} ${colorize(\"Yes\", \"green\")}`)\n }\n\n if (showUsage) {\n console.log(` ${colorize(\"Usage:\", \"cyan\")} \"${fullName}\": \"error\"`)\n }\n })\n\n console.log(colorize(`\\n📊 Summary: ${rules.length} custom rules available`, \"bright\"))\n\n if (showUsage) {\n printCustomUsageInfo()\n }\n\n console.log(colorize(\"\\n💡 Tips:\", \"bright\"))\n console.log(\"• Use --verbose to see detailed rule information\")\n console.log(\"• Use --usage to see configuration examples\")\n console.log('• All rules are prefixed with \"functype/\"')\n console.log(\"• Consider using eslint-config-functype for pre-configured setup\")\n\n console.log(colorize(\"\\n🔗 Links:\", \"bright\"))\n console.log(\"• Documentation: https://github.com/jordanburke/eslint-plugin-functype\")\n console.log(\"• Configuration Bundle: https://github.com/jordanburke/eslint-config-functype\")\n console.log(\"• Functype Library: https://github.com/jordanburke/functype\")\n}\n\nfunction printCustomUsageInfo(): void {\n console.log(colorize(\"\\n💡 Usage Examples:\", \"bright\"))\n console.log(colorize(\"=\".repeat(30), \"blue\"))\n console.log(\"\\n\" + colorize(\"ESLint 9+ (flat config):\", \"green\"))\n console.log(' import functypePlugin from \"eslint-plugin-functype\"')\n console.log(\" export default [\")\n console.log(\" {\")\n console.log(\" plugins: { functype: functypePlugin },\")\n console.log(\" rules: {\")\n console.log(' \"functype/prefer-option\": \"error\",')\n console.log(' \"functype/prefer-either\": \"error\",')\n console.log(' \"functype/no-get-unsafe\": \"error\",')\n console.log(\" }\")\n console.log(\" }\")\n console.log(\" ]\")\n console.log(\"\\n\" + colorize(\"With eslint-config-functype (recommended):\", \"green\"))\n console.log(' import functypeConfig from \"eslint-config-functype\"')\n console.log(\" export default [functypeConfig.recommended]\")\n}\n\n// Run the CLI\nmain().catch((error) => {\n console.error(colorize(\"❌ Unexpected error:\", \"red\"), error)\n process.exit(1)\n})\n"],"mappings":";A,uGAMA,MAAME,EAAS,CACb,MAAO,UACP,OAAQ,UACR,IAAK,WACL,MAAO,WACP,OAAQ,WACR,KAAM,WACN,QAAS,WACT,KAAM,UACR,EAEA,SAASC,EAASC,EAAcC,EAAoC,CAClE,OAAOH,EAAOG,GAASD,EAAOF,EAAO,KACvC,CAIA,SAASI,EAAsBC,EAAgC,CAC7D,QAAQ,IAAIJ,EAAS;6BAAiC,QAAQ,CAAC,EAC/D,QAAQ,IAAIA,EAAS,IAAI,OAAO,EAAE,EAAG,MAAM,CAAC,EAGxCI,EAAO,UAAU,OAAS,IAC5B,QAAQ,IAAIJ,EAAS;cAAkB,OAAO,CAAC,EAC/CI,EAAO,UAAU,QAASC,GAAQ,CAChC,IAAMC,EAAOD,EAAI,SAAW,KAAO,KACnC,QAAQ,IAAI,KAAKC,EAAK,GAAGN,EAASK,EAAI,KAAM,OAAO,EAAE,KAAKA,EAAI,aAAa,CAC7E,CAAC,GAICD,EAAO,QAAQ,OAAS,IAC1B,QAAQ,IAAIJ,EAAS;YAAgB,KAAK,CAAC,EAC3CI,EAAO,QAAQ,QAASC,GAAQ,CAC9B,IAAMC,EAAOD,EAAI,SAAW,MAAQ,KAC9BH,EAAQG,EAAI,SAAW,MAAQ,SACrC,QAAQ,IAAI,KAAKC,EAAK,GAAGN,EAASK,EAAI,KAAMH,CAAK,EAAE,KAAKG,EAAI,aAAa,CAC3E,CAAC,EAEGD,EAAO,iBACT,QAAQ,IAAIJ,EAAS;kCAAsC,QAAQ,CAAC,EACpE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AAQ,IAAIA,EAAS,IAAI,OAAO,EAAE,EAAG,MAAM,CAAC,EAC5C,QAAQ,IAAI;EAAOA,EAAS,2BAA4B,OAAO,CAAC,EAChE,QAAQ,IAAI,uDAAuD,EACnE,QAAQ,IAAI,oBAAoB,EAChC,QAAQ,IAAI,OAAO,EACnB,QAAQ,IAAI,8CAA8C,EAC1D,QAAQ,IAAI,gBAAgB,EAC5B,QAAQ,IAAI,4CAA4C,EACxD,QAAQ,IAAI,4CAA4C,EACxD,QAAQ,IAAI,4CAA4C,EACxD,QAAQ,IAAI,SAAS,EACrB,QAAQ,IAAI,OAAO,EACnB,QAAQ,IAAI,KAAK,EACjB,QAAQ,IAAI;EAAOA,EAAS,6CAA8C,OAAO,CAAC,EAClF,QAAQ,IAAI,uDAAuD,EACnE,QAAQ,IAAI,+CAA+C,CAC7D,CAGAU,EAAK,CAAC,CAAC,MAAOW,GAAU,CACtB,QAAQ,MAAMrB,EAAS,sBAAuB,KAAK,EAAGqB,CAAK,EAC3D,QAAQ,KAAK,CAAC,CAChB,CAAC,E"}
@@ -28,11 +28,17 @@
28
28
  * - no-floating-result: on agent-todo's API it found the 20 drops that project fixed by hand as real
29
29
  * bugs, and in functype it found an async `bracket` that dropped a failed release.
30
30
  * - no-serialize-container: 4 calls on agent-todo's API, each a bug that project fixed.
31
+ * - no-uncalled-method: 0 hits on 1,126 files of seven consumers on 1.x and 2.x; it finds the
32
+ * `Option(list.head)` a published library shipped against 2.0 (#603).
33
+ * - no-container-mutation: 0 hits on 1,128 files of seven consumers, 343 of them tests, all type-checked;
34
+ * planted writes through a cast-holding variable are reported. Since functype 2.2 collections no
35
+ * longer freeze each value, so this rule is what reports a write through a cast.
31
36
  * - no-getOrThrow-in-render and must-fold-on-component-return fire only inside a React component or
32
37
  * hook, and reported nothing on 1,403 files of React code.
33
38
  * - no-get-unsafe: an unwrap outside an `@interop` boundary; allowed in test files.
34
39
  *
35
- * no-array-mutation, no-floating-io, no-floating-result and no-serialize-container are type-aware:
40
+ * no-array-mutation, no-floating-io, no-floating-result, no-serialize-container, no-uncalled-method
41
+ * and no-container-mutation are type-aware:
36
42
  * without `parserOptions.projectService` they report nothing.
37
43
  */
38
44
  declare const recommendedRules: {
@@ -54,6 +60,8 @@ declare const recommendedRules: {
54
60
  "functype/no-floating-io": string;
55
61
  "functype/no-floating-result": string;
56
62
  "functype/no-serialize-container": string;
63
+ "functype/no-uncalled-method": string;
64
+ "functype/no-container-mutation": string;
57
65
  "functype/no-getOrThrow-in-render": string;
58
66
  "functype/must-fold-on-component-return": string;
59
67
  "functype/prefer-flatmap": string;
@@ -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`,{checkGuards:!0}],"functype/collection-naming":`error`,"functype/prefer-list":`error`,"functype/no-array-mutation":`error`,"functype/prefer-option":`error`,"functype/prefer-either":`error`,"functype/prefer-try":`error`,"functype/no-get-unsafe":`error`,"functype/no-floating-io":`error`,"functype/no-floating-result":`error`,"functype/no-serialize-container":`error`,"functype/no-getOrThrow-in-render":`error`,"functype/must-fold-on-component-return":`error`,"functype/prefer-flatmap":`off`,"functype/prefer-do-notation":`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`,{checkGuards:!0}],"functype/collection-naming":`error`,"functype/prefer-list":`error`,"functype/no-array-mutation":`error`,"functype/prefer-option":`error`,"functype/prefer-either":`error`,"functype/prefer-try":`error`,"functype/no-get-unsafe":`error`,"functype/no-floating-io":`error`,"functype/no-floating-result":`error`,"functype/no-serialize-container":`error`,"functype/no-uncalled-method":`error`,"functype/no-container-mutation":`error`,"functype/no-getOrThrow-in-render":`error`,"functype/must-fold-on-component-return":`error`,"functype/prefer-flatmap":`off`,"functype/prefer-do-notation":`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 * The one preset. Code here is written by coding agents, and an agent acts on what fails its build\n * and passes over a warning, so every rule is `error` or `off`, never `warn`. A rule is `error` once it\n * is right on ~95–99% of real code with its known false-positive classes closed (#325); until it is\n * measured, it is `off`, because at `error` it would teach an agent to write `eslint-disable`.\n *\n * In 1.x this was `agent`; `recommended` and `strict` warned on rules still being measured. 2.0 has\n * one preset, and tests.ts relaxes it for test files.\n *\n * `off`, and why:\n * - prefer-flatmap / prefer-do-notation: heuristics without type information; precision unmeasured.\n *\n * `error`, with what it was measured on:\n * - prefer-fold checks functype predicate calls (`isSome()`, `isLeft()`), and guards followed by an\n * unwrap (`checkGuards`): a pass-through guard is a hand-written flatMap. Its null-check heuristic\n * is opt-in (`checkNullable`) because it fired on plain nullables: 31 of 31 hits in a private app\n * monorepo. Inside a React component, a guard followed by an unwrap is also reported by\n * must-fold-on-component-return.\n * - prefer-map leaves loops to no-imperative-loops (`checkForLoops` off), so one loop is one error.\n * - collection-naming is a convention, not a heuristic, so it has no false-positive class.\n * - no-array-mutation: 91 hits across five consumers, every one a real in-place mutation.\n * - prefer-list: about 96% precise on five consumers (#362). Supabase's generated types are skipped\n * by shape. A local array changed by a method or an index write is reported once, by\n * no-array-mutation; a mutated field is still reported by both.\n * - prefer-option / prefer-either / prefer-try: at a real boundary the code marks it instead\n * (`@interop <reason>` or `invariant()` for a throw, `Wire<T>` for a data shape).\n * - no-floating-io: 0 false positives across ~1,340 IO-typed calls in five codebases.\n * - no-floating-result: on agent-todo's API it found the 20 drops that project fixed by hand as real\n * bugs, and in functype it found an async `bracket` that dropped a failed release.\n * - no-serialize-container: 4 calls on agent-todo's API, each a bug that project fixed.\n * - no-getOrThrow-in-render and must-fold-on-component-return fire only inside a React component or\n * hook, and reported nothing on 1,403 files of React code.\n * - no-get-unsafe: an unwrap outside an `@interop` boundary; allowed in test files.\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 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\", { checkGuards: true }],\n \"functype/collection-naming\": \"error\",\n \"functype/prefer-list\": \"error\",\n \"functype/no-array-mutation\": \"error\",\n \"functype/prefer-option\": \"error\",\n \"functype/prefer-either\": \"error\",\n \"functype/prefer-try\": \"error\",\n \"functype/no-get-unsafe\": \"error\",\n \"functype/no-floating-io\": \"error\",\n \"functype/no-floating-result\": \"error\",\n \"functype/no-serialize-container\": \"error\",\n \"functype/no-getOrThrow-in-render\": \"error\",\n \"functype/must-fold-on-component-return\": \"error\",\n \"functype/prefer-flatmap\": \"off\",\n \"functype/prefer-do-notation\": \"off\",\n}\n\nexport default recommendedRules\n"],"mappings":"AAqCA,MAAMA,EAAmB,CACvB,kBAAmB,QACnB,+BAAgC,QAChC,+BAAgC,QAChC,+BAAgC,QAChC,sBAAuB,QACvB,uBAAwB,CAAC,QAAS,CAAE,YAAa,EAAK,CAAC,EACvD,6BAA8B,QAC9B,uBAAwB,QACxB,6BAA8B,QAC9B,yBAA0B,QAC1B,yBAA0B,QAC1B,sBAAuB,QACvB,yBAA0B,QAC1B,0BAA2B,QAC3B,8BAA+B,QAC/B,kCAAmC,QACnC,mCAAoC,QACpC,yCAA0C,QAC1C,0BAA2B,MAC3B,8BAA+B,KACjC,E"}
1
+ {"version":3,"file":"recommended.js","names":["recommendedRules"],"sources":["../../src/configs/recommended.ts"],"sourcesContent":["/**\n * The one preset. Code here is written by coding agents, and an agent acts on what fails its build\n * and passes over a warning, so every rule is `error` or `off`, never `warn`. A rule is `error` once it\n * is right on ~95–99% of real code with its known false-positive classes closed (#325); until it is\n * measured, it is `off`, because at `error` it would teach an agent to write `eslint-disable`.\n *\n * In 1.x this was `agent`; `recommended` and `strict` warned on rules still being measured. 2.0 has\n * one preset, and tests.ts relaxes it for test files.\n *\n * `off`, and why:\n * - prefer-flatmap / prefer-do-notation: heuristics without type information; precision unmeasured.\n *\n * `error`, with what it was measured on:\n * - prefer-fold checks functype predicate calls (`isSome()`, `isLeft()`), and guards followed by an\n * unwrap (`checkGuards`): a pass-through guard is a hand-written flatMap. Its null-check heuristic\n * is opt-in (`checkNullable`) because it fired on plain nullables: 31 of 31 hits in a private app\n * monorepo. Inside a React component, a guard followed by an unwrap is also reported by\n * must-fold-on-component-return.\n * - prefer-map leaves loops to no-imperative-loops (`checkForLoops` off), so one loop is one error.\n * - collection-naming is a convention, not a heuristic, so it has no false-positive class.\n * - no-array-mutation: 91 hits across five consumers, every one a real in-place mutation.\n * - prefer-list: about 96% precise on five consumers (#362). Supabase's generated types are skipped\n * by shape. A local array changed by a method or an index write is reported once, by\n * no-array-mutation; a mutated field is still reported by both.\n * - prefer-option / prefer-either / prefer-try: at a real boundary the code marks it instead\n * (`@interop <reason>` or `invariant()` for a throw, `Wire<T>` for a data shape).\n * - no-floating-io: 0 false positives across ~1,340 IO-typed calls in five codebases.\n * - no-floating-result: on agent-todo's API it found the 20 drops that project fixed by hand as real\n * bugs, and in functype it found an async `bracket` that dropped a failed release.\n * - no-serialize-container: 4 calls on agent-todo's API, each a bug that project fixed.\n * - no-uncalled-method: 0 hits on 1,126 files of seven consumers on 1.x and 2.x; it finds the\n * `Option(list.head)` a published library shipped against 2.0 (#603).\n * - no-container-mutation: 0 hits on 1,128 files of seven consumers, 343 of them tests, all type-checked;\n * planted writes through a cast-holding variable are reported. Since functype 2.2 collections no\n * longer freeze each value, so this rule is what reports a write through a cast.\n * - no-getOrThrow-in-render and must-fold-on-component-return fire only inside a React component or\n * hook, and reported nothing on 1,403 files of React code.\n * - no-get-unsafe: an unwrap outside an `@interop` boundary; allowed in test files.\n *\n * no-array-mutation, no-floating-io, no-floating-result, no-serialize-container, no-uncalled-method\n * and no-container-mutation are type-aware:\n * without `parserOptions.projectService` they report nothing.\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\", { checkGuards: true }],\n \"functype/collection-naming\": \"error\",\n \"functype/prefer-list\": \"error\",\n \"functype/no-array-mutation\": \"error\",\n \"functype/prefer-option\": \"error\",\n \"functype/prefer-either\": \"error\",\n \"functype/prefer-try\": \"error\",\n \"functype/no-get-unsafe\": \"error\",\n \"functype/no-floating-io\": \"error\",\n \"functype/no-floating-result\": \"error\",\n \"functype/no-serialize-container\": \"error\",\n \"functype/no-uncalled-method\": \"error\",\n \"functype/no-container-mutation\": \"error\",\n \"functype/no-getOrThrow-in-render\": \"error\",\n \"functype/must-fold-on-component-return\": \"error\",\n \"functype/prefer-flatmap\": \"off\",\n \"functype/prefer-do-notation\": \"off\",\n}\n\nexport default recommendedRules\n"],"mappings":"AA2CA,MAAMA,EAAmB,CACvB,kBAAmB,QACnB,+BAAgC,QAChC,+BAAgC,QAChC,+BAAgC,QAChC,sBAAuB,QACvB,uBAAwB,CAAC,QAAS,CAAE,YAAa,EAAK,CAAC,EACvD,6BAA8B,QAC9B,uBAAwB,QACxB,6BAA8B,QAC9B,yBAA0B,QAC1B,yBAA0B,QAC1B,sBAAuB,QACvB,yBAA0B,QAC1B,0BAA2B,QAC3B,8BAA+B,QAC/B,kCAAmC,QACnC,8BAA+B,QAC/B,iCAAkC,QAClC,mCAAoC,QACpC,yCAA0C,QAC1C,0BAA2B,MAC3B,8BAA+B,KACjC,E"}
package/dist/index.d.ts CHANGED
@@ -18,6 +18,8 @@ declare const plugin: {
18
18
  "no-floating-io": import("eslint").Rule.RuleModule;
19
19
  "no-floating-result": import("eslint").Rule.RuleModule;
20
20
  "no-serialize-container": import("eslint").Rule.RuleModule;
21
+ "no-container-mutation": import("eslint").Rule.RuleModule;
22
+ "no-uncalled-method": import("eslint").Rule.RuleModule;
21
23
  "no-getOrThrow-in-render": import("eslint").Rule.RuleModule;
22
24
  "must-fold-on-component-return": import("eslint").Rule.RuleModule;
23
25
  };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import e from"./configs/recommended.js";import t,{testFiles as n}from"./configs/tests.js";import r from"./rules/index.js";const i={rules:r,meta:{name:`eslint-plugin-functype`,version:`2.200.0`},configs:{}};i.configs={recommended:{name:`functype-plugin/recommended`,plugins:{functype:i},rules:e},tests:{name:`functype-plugin/tests`,plugins:{functype:i},files:n,rules:t}};export{i as default};
1
+ import e from"./configs/recommended.js";import t,{testFiles as n}from"./configs/tests.js";import r from"./rules/index.js";const i={rules:r,meta:{name:`eslint-plugin-functype`,version:`2.202.0`},configs:{}};i.configs={recommended:{name:`functype-plugin/recommended`,plugins:{functype:i},rules:e},tests:{name:`functype-plugin/tests`,plugins:{functype:i},files:n,rules:t}};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":["testRules","recommendedRules","tests_default","rules_default","plugin","testFiles"],"sources":["../src/index.ts"],"sourcesContent":["import recommendedRules from \"./configs/recommended\"\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 tests: {\n name: \"functype-plugin/tests\",\n plugins: { functype: plugin },\n files: testFiles,\n rules: testRules,\n },\n}\n\nexport default plugin\n"],"mappings":"A,0HAOA,MAAMI,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,MAAOH,CACT,EACA,MAAO,CACL,KAAM,wBACN,QAAS,CAAE,SAAUG,CAAO,EAC5B,MAAOC,EACP,MAAOL,CACT,CACF,E"}
1
+ {"version":3,"file":"index.js","names":["rules","testRules","recommendedRules","tests_default","testFiles","rules_default","plugin"],"sources":["../src/index.ts"],"sourcesContent":["import recommendedRules from \"./configs/recommended\"\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 tests: {\n name: \"functype-plugin/tests\",\n plugins: { functype: plugin },\n files: testFiles,\n rules: testRules,\n },\n}\n\nexport default plugin\n"],"mappings":"A,0HAOA,MAAMM,EAAS,CACbN,MAAAA,EACA,KAAM,CACJ,KAAM,yBACN,QAAA,SACF,EACA,QAAS,CAAC,CACZ,EAGAM,EAAO,QAAU,CACf,YAAa,CACX,KAAM,8BACN,QAAS,CAAE,SAAUA,CAAO,EAC5B,MAAOJ,CACT,EACA,MAAO,CACL,KAAM,wBACN,QAAS,CAAE,SAAUI,CAAO,EAC5B,MAAOF,EACP,MAAOH,CACT,CACF,E"}
@@ -1 +1 @@
1
- {"version":3,"file":"collection-naming.js","names":["rule","allowAlias","context","hit","functypeCollectionAt","node","source","spec","COLLECTION_NAMES"],"sources":["../../src/rules/collection-naming.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { COLLECTION_NAMES, functypeCollectionAt } from \"../utils/collection-binding\"\n\n/**\n * functype's `Map` / `Set` are the default collections (Scala-style): import them under their own names,\n * and spell the built-in `globalThis.Map` / `globalThis.Set` where it is genuinely needed.\n *\n * Two defects:\n * - `new Map()` on functype's Map. It's a factory, so TypeScript only says TS7009 (\"target lacks a construct\n * signature, implicitly has an 'any' type\"), or TS2350 (\"Only a void function can be called with the 'new'\n * keyword\") when `noImplicitAny` is off. Neither says what to write instead. This message does.\n * - `import { Map as FMap } from \"functype\"`. Aliases let a file keep the built-in under the plain name,\n * which inverts the convention and drifts (`FMap`, `FMapOf`, `IMap`…). `allowAlias: true` opts out.\n *\n * Applies in test files too: tests are read as examples, by people and agents.\n */\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Use functype's Map/Set under their own names; spell the built-in globalThis.Map/globalThis.Set\",\n recommended: true,\n },\n schema: [\n {\n type: \"object\",\n properties: {\n allowAlias: {\n type: \"boolean\",\n default: false,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n newFunctypeCollection:\n \"functype's {{name}} is a factory, not a class: use {{local}}(…) or {{local}}.empty(). For the built-in, write new globalThis.{{name}}(…)\",\n aliasedImport:\n \"Import functype's {{name}} as {{name}}, not {{local}}: functype's {{name}} is the default collection. Spell the built-in globalThis.{{name}}\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n const allowAlias = options.allowAlias === true\n\n return {\n NewExpression(node: ASTNode) {\n const hit = functypeCollectionAt(node.callee, context.sourceCode)\n if (hit === null) return\n context.report({ node, messageId: \"newFunctypeCollection\", data: hit })\n },\n\n ImportDeclaration(node: ASTNode) {\n if (allowAlias) return\n const source = node.source?.value\n if (typeof source !== \"string\" || !(source === \"functype\" || source.startsWith(\"functype/\"))) return\n ;(node.specifiers as ReadonlyArray<ASTNode>)\n .filter(\n (spec) =>\n spec.type === \"ImportSpecifier\" &&\n spec.imported?.type === \"Identifier\" &&\n COLLECTION_NAMES.includes(spec.imported.name) &&\n spec.local.name !== spec.imported.name,\n )\n .forEach((spec) =>\n context.report({\n node: spec,\n messageId: \"aliasedImport\",\n data: { name: spec.imported.name, local: spec.local.name },\n }),\n )\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,4FAkBA,MAAMA,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,iGACb,YAAa,EACf,EACA,OAAQ,CACN,CACE,KAAM,SACN,WAAY,CACV,WAAY,CACV,KAAM,UACN,QAAS,EACX,CACF,EACA,qBAAsB,EACxB,CACF,EACA,SAAU,CACR,sBACE,2IACF,cACE,8IACJ,CACF,EAEA,OAAO,EAAS,CAEd,IAAMC,GADUC,EAAQ,QAAQ,IAAM,CAAC,EAAA,CACZ,aAAe,GAE1C,MAAO,CACL,cAAc,EAAe,CAC3B,IAAMC,EAAMC,EAAqBC,EAAK,OAAQH,EAAQ,UAAU,EAC5DC,IAAQ,MACZD,EAAQ,OAAO,CAAE,OAAM,UAAW,wBAAyB,KAAMC,CAAI,CAAC,CACxE,EAEA,kBAAkB,EAAe,CAC/B,GAAIF,EAAY,OAChB,IAAMK,EAASD,EAAK,QAAQ,MACxB,OAAOC,GAAW,WAAcA,IAAW,YAAcA,EAAO,WAAW,WAAW,IACzFD,EAAM,WACJ,OACE,GACCE,EAAK,OAAS,mBACdA,EAAK,UAAU,OAAS,cACxBC,EAAiB,SAASD,EAAK,SAAS,IAAI,GAC5CA,EAAK,MAAM,OAASA,EAAK,SAAS,IACtC,CAAC,CACA,QAAS,GACRL,EAAQ,OAAO,CACb,KAAMK,EACN,UAAW,gBACX,KAAM,CAAE,KAAMA,EAAK,SAAS,KAAM,MAAOA,EAAK,MAAM,IAAK,CAC3D,CAAC,CACH,CACJ,CACF,CACF,CACF,E"}
1
+ {"version":3,"file":"collection-naming.js","names":["COLLECTION_NAMES","functypeCollectionAt","rule","context","allowAlias","node","hit","source","spec"],"sources":["../../src/rules/collection-naming.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { COLLECTION_NAMES, functypeCollectionAt } from \"../utils/collection-binding\"\n\n/**\n * functype's `Map` / `Set` are the default collections (Scala-style): import them under their own names,\n * and spell the built-in `globalThis.Map` / `globalThis.Set` where it is genuinely needed.\n *\n * Two defects:\n * - `new Map()` on functype's Map. It's a factory, so TypeScript only says TS7009 (\"target lacks a construct\n * signature, implicitly has an 'any' type\"), or TS2350 (\"Only a void function can be called with the 'new'\n * keyword\") when `noImplicitAny` is off. Neither says what to write instead. This message does.\n * - `import { Map as FMap } from \"functype\"`. Aliases let a file keep the built-in under the plain name,\n * which inverts the convention and drifts (`FMap`, `FMapOf`, `IMap`…). `allowAlias: true` opts out.\n *\n * Applies in test files too: tests are read as examples, by people and agents.\n */\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Use functype's Map/Set under their own names; spell the built-in globalThis.Map/globalThis.Set\",\n recommended: true,\n },\n schema: [\n {\n type: \"object\",\n properties: {\n allowAlias: {\n type: \"boolean\",\n default: false,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n newFunctypeCollection:\n \"functype's {{name}} is a factory, not a class: use {{local}}(…) or {{local}}.empty(). For the built-in, write new globalThis.{{name}}(…)\",\n aliasedImport:\n \"Import functype's {{name}} as {{name}}, not {{local}}: functype's {{name}} is the default collection. Spell the built-in globalThis.{{name}}\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n const allowAlias = options.allowAlias === true\n\n return {\n NewExpression(node: ASTNode) {\n const hit = functypeCollectionAt(node.callee, context.sourceCode)\n if (hit === null) return\n context.report({ node, messageId: \"newFunctypeCollection\", data: hit })\n },\n\n ImportDeclaration(node: ASTNode) {\n if (allowAlias) return\n const source = node.source?.value\n if (typeof source !== \"string\" || !(source === \"functype\" || source.startsWith(\"functype/\"))) return\n ;(node.specifiers as ReadonlyArray<ASTNode>)\n .filter(\n (spec) =>\n spec.type === \"ImportSpecifier\" &&\n spec.imported?.type === \"Identifier\" &&\n COLLECTION_NAMES.includes(spec.imported.name) &&\n spec.local.name !== spec.imported.name,\n )\n .forEach((spec) =>\n context.report({\n node: spec,\n messageId: \"aliasedImport\",\n data: { name: spec.imported.name, local: spec.local.name },\n }),\n )\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,4FAkBA,MAAME,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,iGACb,YAAa,EACf,EACA,OAAQ,CACN,CACE,KAAM,SACN,WAAY,CACV,WAAY,CACV,KAAM,UACN,QAAS,EACX,CACF,EACA,qBAAsB,EACxB,CACF,EACA,SAAU,CACR,sBACE,2IACF,cACE,8IACJ,CACF,EAEA,OAAOC,EAAS,CAEd,IAAMC,GADUD,EAAQ,QAAQ,IAAM,CAAC,EAAA,CACZ,aAAe,GAE1C,MAAO,CACL,cAAcE,EAAe,CAC3B,IAAMC,EAAML,EAAqBI,EAAK,OAAQF,EAAQ,UAAU,EAC5DG,IAAQ,MACZH,EAAQ,OAAO,CAAEE,OAAM,UAAW,wBAAyB,KAAMC,CAAI,CAAC,CACxE,EAEA,kBAAkBD,EAAe,CAC/B,GAAID,EAAY,OAChB,IAAMG,EAASF,EAAK,QAAQ,MACxB,OAAOE,GAAW,WAAcA,IAAW,YAAcA,EAAO,WAAW,WAAW,IACxFF,EAAK,WACJ,OACEG,GACCA,EAAK,OAAS,mBACdA,EAAK,UAAU,OAAS,cACxBR,EAAiB,SAASQ,EAAK,SAAS,IAAI,GAC5CA,EAAK,MAAM,OAASA,EAAK,SAAS,IACtC,CAAC,CACA,QAASA,GACRL,EAAQ,OAAO,CACb,KAAMK,EACN,UAAW,gBACX,KAAM,CAAE,KAAMA,EAAK,SAAS,KAAM,MAAOA,EAAK,MAAM,IAAK,CAC3D,CAAC,CACH,CACJ,CACF,CACF,CACF,E"}
@@ -1,23 +1,25 @@
1
1
  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
- import rule$3 from "./no-floating-io.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";
4
+ import rule$3 from "./no-container-mutation.js";
5
+ import rule$4 from "./no-floating-io.js";
6
+ import rule$5 from "./no-floating-result.js";
7
+ import rule$7 from "./no-get-unsafe.js";
8
+ import rule$6 from "./no-getOrThrow-in-render.js";
9
+ import rule$8 from "./no-imperative-loops.js";
10
+ import rule$9 from "./no-let.js";
11
+ import rule$10 from "./no-serialize-container.js";
12
+ import rule$11 from "./no-uncalled-method.js";
13
+ import rule$12 from "./prefer-do-notation.js";
14
+ import rule$13 from "./prefer-either.js";
15
+ import rule$14 from "./prefer-flatmap.js";
16
+ import rule$15 from "./prefer-fold.js";
17
+ import rule$16 from "./prefer-functype-map.js";
18
+ import rule$17 from "./prefer-functype-set.js";
19
+ import rule$18 from "./prefer-list.js";
20
+ import rule$19 from "./prefer-map.js";
21
+ import rule$20 from "./prefer-option.js";
22
+ import rule$21 from "./prefer-try.js";
21
23
  declare const _default: {
22
24
  "prefer-option": import("eslint").Rule.RuleModule;
23
25
  "prefer-either": import("eslint").Rule.RuleModule;
@@ -37,7 +39,9 @@ declare const _default: {
37
39
  "no-floating-io": import("eslint").Rule.RuleModule;
38
40
  "no-floating-result": import("eslint").Rule.RuleModule;
39
41
  "no-serialize-container": import("eslint").Rule.RuleModule;
42
+ "no-container-mutation": import("eslint").Rule.RuleModule;
43
+ "no-uncalled-method": import("eslint").Rule.RuleModule;
40
44
  "no-getOrThrow-in-render": import("eslint").Rule.RuleModule;
41
45
  "must-fold-on-component-return": import("eslint").Rule.RuleModule;
42
46
  };
43
- 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 };
47
+ export { rule as collectionNaming, _default as default, rule$1 as mustFoldOnComponentReturn, rule$2 as noArrayMutation, rule$3 as noContainerMutation, rule$4 as noFloatingIo, rule$5 as noFloatingResult, rule$6 as noGetOrThrowInRender, rule$7 as noGetUnsafe, rule$8 as noImperativeLoops, rule$9 as noLet, rule$10 as noSerializeContainer, rule$11 as noUncalledMethod, rule$12 as preferDoNotation, rule$13 as preferEither, rule$14 as preferFlatmap, rule$15 as preferFold, rule$16 as preferFunctypeMap, rule$17 as preferFunctypeSet, rule$18 as preferList, rule$19 as preferMap, rule$20 as preferOption, rule$21 as preferTry };
@@ -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-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};
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-container-mutation.js";import i from"./no-floating-io.js";import a from"./no-floating-result.js";import o from"./no-get-unsafe.js";import s from"./no-getOrThrow-in-render.js";import c from"./no-imperative-loops.js";import l from"./no-let.js";import u from"./no-serialize-container.js";import d from"./no-uncalled-method.js";import f from"./prefer-do-notation.js";import p from"./prefer-either.js";import m from"./prefer-flatmap.js";import h from"./prefer-fold.js";import g from"./prefer-functype-map.js";import _ from"./prefer-functype-set.js";import v from"./prefer-list.js";import y from"./prefer-map.js";import b from"./prefer-option.js";import x from"./prefer-try.js";var S={"prefer-option":b,"prefer-either":p,"prefer-try":x,"prefer-list":v,"no-get-unsafe":o,"no-let":l,"prefer-fold":h,"prefer-map":y,"prefer-flatmap":m,"prefer-functype-map":g,"prefer-functype-set":_,"no-imperative-loops":c,"prefer-do-notation":f,"collection-naming":e,"no-array-mutation":n,"no-floating-io":i,"no-floating-result":a,"no-serialize-container":u,"no-container-mutation":r,"no-uncalled-method":d,"no-getOrThrow-in-render":s,"must-fold-on-component-return":t};export{e as collectionNaming,S as default,t as mustFoldOnComponentReturn,n as noArrayMutation,r as noContainerMutation,i as noFloatingIo,a as noFloatingResult,s as noGetOrThrowInRender,o as noGetUnsafe,c as noImperativeLoops,l as noLet,u as noSerializeContainer,d as noUncalledMethod,f as preferDoNotation,p as preferEither,m as preferFlatmap,h as preferFold,g as preferFunctypeMap,_ as preferFunctypeSet,v as preferList,y as preferMap,b as preferOption,x 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","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":"A,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,E"}
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","noContainerMutation","noUncalledMethod","noGetOrThrowInRender","mustFoldOnComponentReturn","rule","rule$1","rule$2","rule$3","rule$4","rule$5","rule$7","rule$6","rule$8","rule$9","rule$10","rule$11","rule$12","rule$13","rule$14","rule$15","rule$16","rule$17","rule$18","rule$19","rule$20","rule$21","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 noContainerMutation from \"./no-container-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 noUncalledMethod from \"./no-uncalled-method\"\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 noContainerMutation,\n noFloatingIo,\n noFloatingResult,\n noGetOrThrowInRender,\n noGetUnsafe,\n noImperativeLoops,\n noLet,\n noSerializeContainer,\n noUncalledMethod,\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-container-mutation\": noContainerMutation,\n \"no-uncalled-method\": noUncalledMethod,\n \"no-getOrThrow-in-render\": noGetOrThrowInRender,\n \"must-fold-on-component-return\": mustFoldOnComponentReturn,\n}\n"],"mappings":"A,izBAgDA,IAAA4C,EAAe,CACb,gBAAiB5C,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,wBAAyBC,EACzB,qBAAsBC,EACtB,0BAA2BC,EAC3B,gCAAiCC,CACnC,E"}
@@ -1 +1 @@
1
- {"version":3,"file":"must-fold-on-component-return.js","names":["returnedValue","statement","consequent","isNullLiteral","node","rule","allowInteropMarker","context","sourceCode","componentPredicate","predicate","testedPredicate","test","fn","enclosingFunction","renderKind","isExtractableByType","isInsideTaggedDeclaration","report","MATCH_COMPONENT","returned","producesJSX"],"sources":["../../src/rules/must-fold-on-component-return.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { INTEROP_TAG, isInsideTaggedDeclaration } from \"../utils/boundary-tags\"\nimport { MATCH_COMPONENT, testedPredicate } from \"../utils/functype-predicates\"\nimport { enclosingFunction, producesJSX, renderKind } from \"../utils/react-render\"\nimport { isExtractableByType } from \"../utils/type-aware\"\n\n/**\n * Reports a component that chooses what it renders by asking an Option / Either / Try which case it\n * holds, in the two shapes `prefer-fold` leaves alone:\n *\n * - an early return: `if (user.isNone()) return <SignIn />`, then the other case below it;\n * - a short-circuit: `{user.isSome() && <Profile />}`, which renders one case and drops the other.\n *\n * A ternary or an if/else on `isSome()` / `isLeft()` / … is `prefer-fold`'s, everywhere, so this rule\n * doesn't report it a second time.\n *\n * The test may wrap the call: `if (!o.isSome()) return null`, `if (busy || o.isNone()) return <S />`.\n * Only a functype predicate *call* counts. `state.isPending` (a `useIO` result) and `items.isEmpty` are\n * properties, never calls, so they're not reported. With type information the receiver must also be a\n * functype container.\n */\n\n/** `return x` alone, or as the only statement of a block: what an early-return guard hands back. */\nconst returnedValue = (consequent: ASTNode): ASTNode | null | undefined => {\n const statement =\n consequent.type === \"BlockStatement\" && consequent.body.length === 1 ? consequent.body[0] : consequent\n return statement?.type === \"ReturnStatement\" ? (statement.argument ?? null) : undefined\n}\n\nconst isNullLiteral = (node: ASTNode): boolean => node?.type === \"Literal\" && node.value === null\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"suggestion\",\n docs: {\n description:\n \"Require a React component to render an Option, Either or Try with fold or a Match component, not an isSome()/isLeft() guard or &&\",\n recommended: false,\n },\n schema: [\n {\n type: \"object\",\n properties: {\n allowInteropMarker: {\n type: \"boolean\",\n default: true,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n guardReturn:\n \"This component picks what it renders with an early return on {{receiver}}.{{method}}(). Render both cases in one expression: {{receiver}}.fold(…) or <{{matcher}}>, so neither branch reads a value that isn't there.\",\n shortCircuit:\n \"{{receiver}}.{{method}}() && … renders one case and drops the other. Use {{receiver}}.fold(…) with null for the case that renders nothing, or <{{matcher}}>.\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n const allowInteropMarker = options.allowInteropMarker !== false\n const sourceCode = context.sourceCode\n\n /** The predicate `test` calls, when `node` sits directly in a component's body (not a nested callback). */\n const componentPredicate = (node: ASTNode, test: ASTNode) => {\n const predicate = testedPredicate(test, sourceCode)\n if (!predicate) return null\n const fn = enclosingFunction(node)\n if (!fn || renderKind(fn) !== \"component\") return null\n if (isExtractableByType(predicate.receiver, context) === false) return null\n if (allowInteropMarker && isInsideTaggedDeclaration(node, INTEROP_TAG, sourceCode)) return null\n return predicate\n }\n\n const report = (node: ASTNode, messageId: string, predicate: NonNullable<ReturnType<typeof componentPredicate>>) =>\n context.report({\n node,\n messageId,\n data: {\n receiver: sourceCode.getText(predicate.receiver),\n method: predicate.method,\n matcher: MATCH_COMPONENT[predicate.method] ?? \"Match\",\n },\n })\n\n return {\n IfStatement(node: ASTNode) {\n // An if/else is prefer-fold's. A guard is an `if` with no `else` that returns JSX or `null`.\n if (node.alternate) return\n const returned = returnedValue(node.consequent)\n if (returned === undefined || !(producesJSX(returned) || isNullLiteral(returned))) return\n const predicate = componentPredicate(node, node.test)\n if (predicate) report(node, \"guardReturn\", predicate)\n },\n\n LogicalExpression(node: ASTNode) {\n if (node.operator !== \"&&\" || !producesJSX(node.right)) return\n const predicate = componentPredicate(node, node.left)\n if (predicate) report(node, \"shortCircuit\", predicate)\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,wTAyBA,MAAMA,EAAiB,GAAoD,CACzE,IAAMC,EACJC,EAAW,OAAS,kBAAoBA,EAAW,KAAK,SAAW,EAAIA,EAAW,KAAK,GAAKA,EAC9F,OAAOD,GAAW,OAAS,kBAAqBA,EAAU,UAAY,KAAQ,IAAA,EAChF,EAEME,EAAiB,GAA2BC,GAAM,OAA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,IAAI,EAChDM,GAAWQ,EAAOd,EAAM,eAAgBM,CAAS,CACvD,CACF,CACF,CACF,E"}
1
+ {"version":3,"file":"must-fold-on-component-return.js","names":["isInsideTaggedDeclaration","MATCH_COMPONENT","testedPredicate","enclosingFunction","producesJSX","renderKind","isExtractableByType","returnedValue","consequent","statement","isNullLiteral","node","rule","context","allowInteropMarker","sourceCode","componentPredicate","test","predicate","fn","report","messageId","returned"],"sources":["../../src/rules/must-fold-on-component-return.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { INTEROP_TAG, isInsideTaggedDeclaration } from \"../utils/boundary-tags\"\nimport { MATCH_COMPONENT, testedPredicate } from \"../utils/functype-predicates\"\nimport { enclosingFunction, producesJSX, renderKind } from \"../utils/react-render\"\nimport { isExtractableByType } from \"../utils/type-aware\"\n\n/**\n * Reports a component that chooses what it renders by asking an Option / Either / Try which case it\n * holds, in the two shapes `prefer-fold` leaves alone:\n *\n * - an early return: `if (user.isNone()) return <SignIn />`, then the other case below it;\n * - a short-circuit: `{user.isSome() && <Profile />}`, which renders one case and drops the other.\n *\n * A ternary or an if/else on `isSome()` / `isLeft()` / … is `prefer-fold`'s, everywhere, so this rule\n * doesn't report it a second time.\n *\n * The test may wrap the call: `if (!o.isSome()) return null`, `if (busy || o.isNone()) return <S />`.\n * Only a functype predicate *call* counts. `state.isPending` (a `useIO` result) and `items.isEmpty` are\n * properties, never calls, so they're not reported. With type information the receiver must also be a\n * functype container.\n */\n\n/** `return x` alone, or as the only statement of a block: what an early-return guard hands back. */\nconst returnedValue = (consequent: ASTNode): ASTNode | null | undefined => {\n const statement =\n consequent.type === \"BlockStatement\" && consequent.body.length === 1 ? consequent.body[0] : consequent\n return statement?.type === \"ReturnStatement\" ? (statement.argument ?? null) : undefined\n}\n\nconst isNullLiteral = (node: ASTNode): boolean => node?.type === \"Literal\" && node.value === null\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"suggestion\",\n docs: {\n description:\n \"Require a React component to render an Option, Either or Try with fold or a Match component, not an isSome()/isLeft() guard or &&\",\n recommended: false,\n },\n schema: [\n {\n type: \"object\",\n properties: {\n allowInteropMarker: {\n type: \"boolean\",\n default: true,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n guardReturn:\n \"This component picks what it renders with an early return on {{receiver}}.{{method}}(). Render both cases in one expression: {{receiver}}.fold(…) or <{{matcher}}>, so neither branch reads a value that isn't there.\",\n shortCircuit:\n \"{{receiver}}.{{method}}() && … renders one case and drops the other. Use {{receiver}}.fold(…) with null for the case that renders nothing, or <{{matcher}}>.\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n const allowInteropMarker = options.allowInteropMarker !== false\n const sourceCode = context.sourceCode\n\n /** The predicate `test` calls, when `node` sits directly in a component's body (not a nested callback). */\n const componentPredicate = (node: ASTNode, test: ASTNode) => {\n const predicate = testedPredicate(test, sourceCode)\n if (!predicate) return null\n const fn = enclosingFunction(node)\n if (!fn || renderKind(fn) !== \"component\") return null\n if (isExtractableByType(predicate.receiver, context) === false) return null\n if (allowInteropMarker && isInsideTaggedDeclaration(node, INTEROP_TAG, sourceCode)) return null\n return predicate\n }\n\n const report = (node: ASTNode, messageId: string, predicate: NonNullable<ReturnType<typeof componentPredicate>>) =>\n context.report({\n node,\n messageId,\n data: {\n receiver: sourceCode.getText(predicate.receiver),\n method: predicate.method,\n matcher: MATCH_COMPONENT[predicate.method] ?? \"Match\",\n },\n })\n\n return {\n IfStatement(node: ASTNode) {\n // An if/else is prefer-fold's. A guard is an `if` with no `else` that returns JSX or `null`.\n if (node.alternate) return\n const returned = returnedValue(node.consequent)\n if (returned === undefined || !(producesJSX(returned) || isNullLiteral(returned))) return\n const predicate = componentPredicate(node, node.test)\n if (predicate) report(node, \"guardReturn\", predicate)\n },\n\n LogicalExpression(node: ASTNode) {\n if (node.operator !== \"&&\" || !producesJSX(node.right)) return\n const predicate = componentPredicate(node, node.left)\n if (predicate) report(node, \"shortCircu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a,EAAElB,EAAYkB,CAAQ,GAAKZ,EAAcY,CAAQ,GAAI,OACnF,IAAMJ,EAAYF,EAAmBL,EAAMA,EAAK,IAAI,EAChDO,GAAWE,EAAOT,EAAM,cAAeO,CAAS,CACtD,EAEA,kBAAkBP,EAAe,CAC/B,GAAIA,EAAK,WAAa,MAAQ,CAACP,EAAYO,EAAK,KAAK,EAAG,OACxD,IAAMO,EAAYF,EAAmBL,EAAMA,EAAK,IAAI,EAChDO,GAAWE,EAAOT,EAAM,eAAgBO,CAAS,CACvD,CACF,CACF,CACF,E"}
@@ -1 +1 @@
1
- {"version":3,"file":"no-array-mutation.js","names":["MUTATING_METHODS","isFreshValue","node","nameOf","text","sourceCode","rule","options","context","allowInTests","allowInteropMarker","filename","isExempt","isInsideTaggedDeclaration","elementTarget","array","isMutableArrayExpression","lengthTarget","reportWrite","element","target","length","callee","method"],"sources":["../../src/rules/no-array-mutation.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { isMutableArrayExpression } from \"../utils/array-mutation\"\nimport { INTEROP_TAG, isInsideTaggedDeclaration } from \"../utils/boundary-tags\"\n\n/** Array methods that change the array they're called on. */\nconst MUTATING_METHODS: ReadonlySet<string> = new Set([\n \"push\",\n \"pop\",\n \"shift\",\n \"unshift\",\n \"splice\",\n \"sort\",\n \"reverse\",\n \"fill\",\n \"copyWithin\",\n])\n\n/**\n * Is `node` assumed to be a value nothing else can see yet — `[...xs]`, `xs.slice()`, `Array.from(it)`,\n * `items.map(f)`? Mutating it on the spot (`[...xs].sort(byRank)`) is the common copy-then-sort idiom.\n * Every call result is assumed fresh, so `getSharedCache().push(x)` is missed too: a recall gap the rule\n * accepts to keep false positives at zero. Only a named array (a binding or a property) is reported.\n */\nconst isFreshValue = (node: ASTNode): boolean =>\n node.type === \"ArrayExpression\" ||\n node.type === \"CallExpression\" ||\n node.type === \"NewExpression\" ||\n (node.type === \"AwaitExpression\" && isFreshValue(node.argument as ASTNode))\n\n/** The variable or property name of a mutated array, for the message: `rows`, `this.events`, `acc.errors`. */\nconst nameOf = (node: ASTNode, sourceCode: Rule.RuleContext[\"sourceCode\"]): string => {\n const text = sourceCode.getText(node)\n return text.length > 40 ? `${text.slice(0, 37)}…` : text\n}\n\n/**\n * Reports in-place mutation of a mutable array: `push` / `pop` / `shift` / `unshift` / `splice` / `sort` /\n * `reverse` / `fill` / `copyWithin`, assignment to an element (`xs[i] = v`, `xs[i] += 1`, `xs[i]++`),\n * `delete xs[i]`, and setting `length`.\n *\n * This is the mutation itself, wherever the array came from — an inferred `const rows = load()` included,\n * which `prefer-list` can't see because it has no annotation or literal to hook onto. Type-aware only:\n * without type information it reports nothing, so `push` on a custom class or a `Set` is never mistaken\n * for an array. Mutating a literal or a call result on the spot (`[...xs].sort(byRank)`) isn't reported:\n * it's assumed to be a fresh copy (see isFreshValue for the recall gap that leaves).\n */\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Disallow changing an array in place — build a new one\",\n recommended: true,\n },\n schema: [\n {\n type: \"object\",\n properties: {\n allowInTests: { type: \"boolean\", default: true },\n allowInteropMarker: { type: \"boolean\", default: true },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n mutatingMethod:\n \"{{name}}.{{method}}() changes the array in place. Build a new one instead: [...{{name}}, x], map / filter / flatMap / toSorted, a List, or a fold\",\n elementAssignment:\n \"Assigning to an element of {{name}} changes the array in place. Build a new one instead: {{name}}.with(i, v), map, a List, or a fold\",\n lengthAssignment:\n \"Setting {{name}}.length changes the array in place. Build a new one instead: {{name}}.slice(0, n), or start from []\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n const allowInTests = options.allowInTests !== false\n const allowInteropMarker = options.allowInteropMarker !== false\n const sourceCode = context.sourceCode\n\n const isInTestFile = (): boolean => {\n const filename = context.filename\n return (\n /\\.(test|spec)\\.(ts|js|tsx|jsx)$/.test(filename) ||\n filename.includes(\"__tests__\") ||\n filename.includes(\"/test/\") ||\n filename.includes(\"/tests/\")\n )\n }\n if (allowInTests && isInTestFile()) return {}\n\n /** `@interop <reason>` on an enclosing declaration marks a host boundary that has to mutate. */\n const isExempt = (node: ASTNode): boolean =>\n allowInteropMarker && isInsideTaggedDeclaration(node, INTEROP_TAG, sourceCode)\n\n /** `xs[i]` (a computed member) on a named mutable array, or null. */\n const elementTarget = (node: ASTNode | null | undefined): ASTNode | null => {\n if (node?.type !== \"MemberExpression\") return null\n const array = node.object as ASTNode\n if (isFreshValue(array)) return null\n if (node.computed) return isMutableArrayExpression(array, context) ? array : null\n return null\n }\n\n /** `xs.length` on a named mutable array, or null. */\n const lengthTarget = (node: ASTNode | null | undefined): ASTNode | null => {\n if (node?.type !== \"MemberExpression\" || node.computed) return null\n const array = node.object as ASTNode\n if (node.property?.type !== \"Identifier\" || node.property.name !== \"length\" || isFreshValue(array)) return null\n return isMutableArrayExpression(array, context) ? array : null\n }\n\n const reportWrite = (node: ASTNode, target: ASTNode): void => {\n if (isExempt(node)) return\n const element = elementTarget(target)\n if (element) {\n context.report({ node, messageId: \"elementAssignment\", data: { name: nameOf(element, sourceCode) } })\n return\n }\n const length = lengthTarget(target)\n if (length) {\n context.report({ node, messageId: \"lengthAssignment\", data: { name: nameOf(length, sourceCode) } })\n }\n }\n\n return {\n CallExpression(node: ASTNode) {\n const callee = node.callee as ASTNode\n if (callee.type !== \"MemberExpression\" || callee.computed) return\n const method = callee.property?.type === \"Identifier\" ? callee.property.name : null\n if (method === null || !MUTATING_METHODS.has(method)) return\n const array = callee.object as ASTNode\n if (isFreshValue(array) || isExempt(node)) return\n if (!isMutableArrayExpression(array, context)) return\n context.report({\n node,\n messageId: \"mutatingMethod\",\n data: { name: nameOf(array, sourceCode), method },\n })\n },\n\n AssignmentExpression(node: ASTNode) {\n reportWrite(node, node.left as ASTNode)\n },\n\n UpdateExpression(node: ASTNode) {\n reportWrite(node, node.argument as ASTNode)\n },\n\n UnaryExpression(node: ASTNode) {\n if (node.operator === \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hB,EAAMA,EAAK,QAAmB,CAC5C,EAEA,gBAAgB,EAAe,CACzBA,EAAK,WAAa,UAAUgB,EAAYhB,EAAMA,EAAK,QAAmB,CAC5E,CACF,CACF,CACF,E"}
1
+ {"version":3,"file":"no-array-mutation.js","names":["isMutableArrayExpression","isInsideTaggedDeclaration","MUTATING_METHODS","isFreshValue","node","nameOf","sourceCode","text","rule","context","options","allowInTests","allowInteropMarker","filename","isExempt","elementTarget","array","lengthTarget","reportWrite","target","element","length","callee","method"],"sources":["../../src/rules/no-array-mutation.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { isMutableArrayExpression } from \"../utils/array-mutation\"\nimport { INTEROP_TAG, isInsideTaggedDeclaration } from \"../utils/boundary-tags\"\n\n/** Array methods that change the array they're called on. */\nconst MUTATING_METHODS: ReadonlySet<string> = new Set([\n \"push\",\n \"pop\",\n \"shift\",\n \"unshift\",\n \"splice\",\n \"sort\",\n \"reverse\",\n \"fill\",\n \"copyWithin\",\n])\n\n/**\n * Is `node` assumed to be a value nothing else can see yet — `[...xs]`, `xs.slice()`, `Array.from(it)`,\n * `items.map(f)`? Mutating it on the spot (`[...xs].sort(byRank)`) is the common copy-then-sort idiom.\n * Every call result is assumed fresh, so `getSharedCache().push(x)` is missed too: a recall gap the rule\n * accepts to keep false positives at zero. Only a named array (a binding or a property) is reported.\n */\nconst isFreshValue = (node: ASTNode): boolean =>\n node.type === \"ArrayExpression\" ||\n node.type === \"CallExpression\" ||\n node.type === \"NewExpression\" ||\n (node.type === \"AwaitExpression\" && isFreshValue(node.argument as ASTNode))\n\n/** The variable or property name of a mutated array, for the message: `rows`, `this.events`, `acc.errors`. */\nconst nameOf = (node: ASTNode, sourceCode: Rule.RuleContext[\"sourceCode\"]): string => {\n const text = sourceCode.getText(node)\n return text.length > 40 ? `${text.slice(0, 37)}…` : text\n}\n\n/**\n * Reports in-place mutation of a mutable array: `push` / `pop` / `shift` / `unshift` / `splice` / `sort` /\n * `reverse` / `fill` / `copyWithin`, assignment to an element (`xs[i] = v`, `xs[i] += 1`, `xs[i]++`),\n * `delete xs[i]`, and setting `length`.\n *\n * This is the mutation itself, wherever the array came from — an inferred `const rows = load()` included,\n * which `prefer-list` can't see because it has no annotation or literal to hook onto. Type-aware only:\n * without type information it reports nothing, so `push` on a custom class or a `Set` is never mistaken\n * for an array. Mutating a literal or a call result on the spot (`[...xs].sort(byRank)`) isn't reported:\n * it's assumed to be a fresh copy (see isFreshValue for the recall gap that leaves).\n */\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Disallow changing an array in place — build a new one\",\n recommended: true,\n },\n schema: [\n {\n type: \"object\",\n properties: {\n allowInTests: { type: \"boolean\", default: true },\n allowInteropMarker: { type: \"boolean\", default: true },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n mutatingMethod:\n \"{{name}}.{{method}}() changes the array in place. Build a new one instead: [...{{name}}, x], map / filter / flatMap / toSorted, a List, or a fold\",\n elementAssignment:\n \"Assigning to an element of {{name}} changes the array in place. Build a new one instead: {{name}}.with(i, v), map, a List, or a fold\",\n lengthAssignment:\n \"Setting {{name}}.length changes the array in place. Build a new one instead: {{name}}.slice(0, n), or start from []\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n const allowInTests = options.allowInTests !== false\n const allowInteropMarker = options.allowInteropMarker !== false\n const sourceCode = context.sourceCode\n\n const isInTestFile = (): boolean => {\n const filename = context.filename\n return (\n /\\.(test|spec)\\.(ts|js|tsx|jsx)$/.test(filename) ||\n filename.includes(\"__tests__\") ||\n filename.includes(\"/test/\") ||\n filename.includes(\"/tests/\")\n )\n }\n if (allowInTests && isInTestFile()) return {}\n\n /** `@interop <reason>` on an enclosing declaration marks a host boundary that has to mutate. */\n const isExempt = (node: ASTNode): boolean =>\n allowInteropMarker && isInsideTaggedDeclaration(node, INTEROP_TAG, sourceCode)\n\n /** `xs[i]` (a computed member) on a named mutable array, or null. */\n const elementTarget = (node: ASTNode | null | undefined): ASTNode | null => {\n if (node?.type !== \"MemberExpression\") return null\n const array = node.object as ASTNode\n if (isFreshValue(array)) return null\n if (node.computed) return isMutableArrayExpression(array, context) ? array : null\n return null\n }\n\n /** `xs.length` on a named mutable array, or null. */\n const lengthTarget = (node: ASTNode | null | undefined): ASTNode | null => {\n if (node?.type !== \"MemberExpression\" || node.computed) return null\n const array = node.object as ASTNode\n if (node.property?.type !== \"Identifier\" || node.property.name !== \"length\" || isFreshValue(array)) return null\n return isMutableArrayExpression(array, context) ? array : null\n }\n\n const reportWrite = (node: ASTNode, target: ASTNode): void => {\n if (isExempt(node)) return\n const element = elementTarget(target)\n if (element) {\n context.report({ node, messageId: \"elementAssignment\", data: { name: nameOf(element, sourceCode) } })\n return\n }\n const length = lengthTarget(target)\n if (length) {\n context.report({ node, messageId: \"lengthAssignment\", data: { name: nameOf(length, sourceCode) } })\n }\n }\n\n return {\n CallExpression(node: ASTNode) {\n const callee = node.callee as ASTNode\n if (callee.type !== \"MemberExpression\" || callee.computed) return\n const method = callee.property?.type === \"Identifier\" ? callee.property.name : null\n if (method === null || !MUTATING_METHODS.has(method)) return\n const array = callee.object as ASTNode\n if (isFreshValue(array) || isExempt(node)) return\n if (!isMutableArrayExpression(array, context)) return\n context.report({\n node,\n messageId: \"mutatingMethod\",\n data: { name: nameOf(array, sourceCode), method },\n })\n },\n\n AssignmentExpression(node: ASTNode) {\n reportWrite(node, node.left as ASTNode)\n },\n\n UpdateExpression(node: ASTNode) {\n reportWrite(node, node.argument as ASTNode)\n },\n\n UnaryExpression(node: ASTNode) {\n if (node.operator === \"delete\") reportWrite(node, node.argument as ASTNode)\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,4IAOA,MAAME,kBAAwC,IAAI,IAAI,CACpD,OACA,MACA,QACA,UACA,SACA,OACA,UACA,OACA,YACF,CAAC,EAQKC,EAAgBC,GACpBA,EAAK,OAAS,mBACdA,EAAK,OAAS,kBACdA,EAAK,OAAS,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functype value that TypeScript can't see. The types mark every field read-only,
4
+ * so such a write needs the value's type hidden: an `as` cast, or a variable that holds one
5
+ * (`const o = list as any; o.x = 1`). The rule reports:
6
+ *
7
+ * - an assignment, compound assignment, `++`/`--`, `delete`, destructuring or `for…of`/`for…in` target
8
+ * whose path starts from a functype value held under a hiding cast; and
9
+ * - a mutating method (`push`, `splice`, `sort`, `add`, `set`, `delete`, `clear` and the like) called on
10
+ * data reached through such a value: `(list as any).value.push(9)`. Called on the functype value
11
+ * itself, cast or not, the method is functype's own and builds a new value, so it isn't reported; and
12
+ * - `Object.assign`, `Object.defineProperty(ies)`, `Object.setPrototypeOf` and the matching `Reflect`
13
+ * calls aimed at a functype value, cast or not, since those compile without one.
14
+ *
15
+ * A write that compiles without a cast is left alone: it is to a field of your own type, or to the data a
16
+ * container holds (an Option's payload, a List element's own field), which the container doesn't own.
17
+ * Only values whose `fold` functype declares count. Type-aware only: without type information it reports
18
+ * nothing. It can't see a value passed to an `any` parameter and written there, or plain JavaScript.
19
+ */
20
+ declare const rule: Rule.RuleModule;
21
+ export { rule as default };
@@ -0,0 +1,2 @@
1
+ import{functypeValueByType as e}from"../utils/type-aware.js";const t=/* @__PURE__ */ new Set([`TSAsExpression`,`TSTypeAssertion`]),n=/* @__PURE__ */ new Set([`TSNonNullExpression`,`TSSatisfiesExpression`,`ChainExpression`]),r={Object:/* @__PURE__ */ new Set([`assign`,`defineProperty`,`defineProperties`,`setPrototypeOf`]),Reflect:/* @__PURE__ */ new Set([`set`,`defineProperty`,`deleteProperty`,`setPrototypeOf`])},i=/* @__PURE__ */ new Set([`push`,`pop`,`shift`,`unshift`,`splice`,`sort`,`reverse`,`fill`,`copyWithin`,`add`,`set`,`delete`,`clear`]),a=/* @__PURE__ */ new Set([`globalThis`,`window`,`self`,`global`]),o=e=>{let t=e.property;return!e.computed&&t.type===`Identifier`?t.name:e.computed&&t.type===`Literal`&&typeof t.value==`string`?t.value:void 0},s=e=>{if(e.type===`Identifier`)return e.name;if(e.type!==`MemberExpression`)return;let t=e.object;return t.type===`Identifier`&&a.has(t.name)?o(e):void 0},c=e=>{let t=e.callee;if(t.type!==`MemberExpression`)return!1;let n=s(t.object),i=o(t);return n!==void 0&&i!==void 0&&(r[n]?.has(i)??!1)},l=e=>{if(e==null)return[];switch(e.type){case`MemberExpression`:return[e];case`ObjectPattern`:return e.properties.flatMap(e=>l(e.type===`RestElement`?e.argument:e.value));case`ArrayPattern`:return e.elements.flatMap(e=>l(e));case`RestElement`:return l(e.argument);case`AssignmentPattern`:return l(e.left);default:return t.has(e.type)||n.has(e.type)?l(e.expression):[]}},u={meta:{type:`problem`,docs:{description:`Disallow changing a functype value in place`,recommended:!1},schema:[],messages:{mutation:`This changes a {{name}} in place. functype values don't change after they're built, and other values share their data. Build a new one instead: map, filter, add, set or concat`}},create(r){let a=(e,t)=>e===null?void 0:e.set.get(t)??a(e.upper,t),s=e=>{let t=a(r.sourceCode.getScope(e),e.name),n=t?.defs[0];if(t===void 0||t.defs.length!==1||n?.type!==`Variable`)return;let i=n.node;if(i.id?.type!==`Identifier`||i.init==null||t.references.filter(e=>e.isWrite()).length>1)return;let o=i.id.typeAnnotation?.typeAnnotation,s=o?.type===`TSAnyKeyword`||o?.type===`TSUnknownKeyword`;return{init:i.init,erased:s}},u=(i,a,o=0)=>{if(o>10)return;if(t.has(i.type))return u(i.expression,!0,o+1);if(n.has(i.type))return u(i.expression,a,o+1);let c=e(i,r);if(c!==void 0)return a?c:void 0;if(i.type===`MemberExpression`)return u(i.object,a,o+1);if(i.type!==`Identifier`)return;let l=s(i);return l===void 0?void 0:u(l.init,a||l.erased,o+1)},d=(i,a=0)=>{if(a>10)return;if(t.has(i.type)||n.has(i.type))return d(i.expression,a+1);let o=e(i,r);if(o!==void 0)return o;if(i.type===`MemberExpression`)return u(i,!1,a+1);if(i.type!==`Identifier`)return;let c=s(i);return c===void 0?void 0:d(c.init,a+1)},f=(i,a=0)=>{if(a>10)return!1;if(t.has(i.type)||n.has(i.type))return f(i.expression,a+1);if(e(i,r)!==void 0)return!0;if(i.type!==`Identifier`)return!1;let o=s(i);return o!==void 0&&f(o.init,a+1)},p=(e,t)=>{t!==void 0&&r.report({node:e,messageId:`mutation`,data:{name:t}})},m=(e,r)=>{let i=n.has(r.type)||t.has(r.type)?r.expression:r;i.type===`MemberExpression`&&p(e,u(i.object,!1))},h=(e,t)=>{l(t).forEach(t=>m(e,t))};return{AssignmentExpression(e){h(e,e.left)},UpdateExpression(e){m(e,e.argument)},UnaryExpression(e){e.operator===`delete`&&m(e,e.argument)},"ForOfStatement, ForInStatement"(e){let t=e.left;t.type!==`VariableDeclaration`&&h(e,t)},CallExpression(e){let t=e.callee;if(t.type===`MemberExpression`&&!c(e)){let n=o(t),r=t.object;if(n!==void 0&&i.has(n)&&!f(r)){p(e,u(r,!1));return}}let[n]=e.arguments;n!==void 0&&n.type!==`SpreadElement`&&c(e)&&p(e,d(n))}}}};export{u as default};
2
+ //# sourceMappingURL=no-container-mutation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-container-mutation.js","names":["functypeValueByType","ERASING","TRANSPARENT","TARGET_FIRST","MUTATING_METHODS","GLOBALS","keyName","member","property","namespaceName","node","object","isTargetFirstCall","call","callee","namespace","method","memberTargets","pattern","p","rule","context","findVariable","scope","name","soleValue","identifier","variable","definition","declarator","r","annotation","erased","hiddenRoot","depth","held","targetRoot","isContainerItself","report","checkMember","write","target","checkPattern","left","receiver","first"],"sources":["../../src/rules/no-container-mutation.ts"],"sourcesContent":["import type { Rule, Scope } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { functypeValueByType } from \"../utils/type-aware\"\n\n/** Casts that hide a value's type from TypeScript: `x as T`, `<T>x`. */\nconst ERASING: ReadonlySet<string> = new Set([\"TSAsExpression\", \"TSTypeAssertion\"])\n\n/** Wrappers that keep a value's type: `x!`, `x satisfies T`, `a?.b`. */\nconst TRANSPARENT: ReadonlySet<string> = new Set([\"TSNonNullExpression\", \"TSSatisfiesExpression\", \"ChainExpression\"])\n\n/** Calls that change their first argument: `Object.assign(target, …)`, `Reflect.set(target, …)`. */\nconst TARGET_FIRST: Readonly<Record<string, ReadonlySet<string>>> = {\n Object: new Set([\"assign\", \"defineProperty\", \"defineProperties\", \"setPrototypeOf\"]),\n Reflect: new Set([\"set\", \"defineProperty\", \"deleteProperty\", \"setPrototypeOf\"]),\n}\n\n/**\n * Methods that change the array, Set or Map they're called on. Through a cast, they change the data a\n * container holds: `(list as any).value.push(9)`.\n */\nconst MUTATING_METHODS: ReadonlySet<string> = new Set([\n \"push\",\n \"pop\",\n \"shift\",\n \"unshift\",\n \"splice\",\n \"sort\",\n \"reverse\",\n \"fill\",\n \"copyWithin\",\n \"add\",\n \"set\",\n \"delete\",\n \"clear\",\n])\n\n/** Names the global object goes by: `globalThis.Object.assign(…)`. */\nconst GLOBALS: ReadonlySet<string> = new Set([\"globalThis\", \"window\", \"self\", \"global\"])\n\nconst keyName = (member: ASTNode): string | undefined => {\n const property = member.property as ASTNode\n if (!member.computed && property.type === \"Identifier\") return property.name\n return member.computed && property.type === \"Literal\" && typeof property.value === \"string\"\n ? property.value\n : undefined\n}\n\n/** `Object` or `Reflect`, also reached as `globalThis.Object`. */\nconst namespaceName = (node: ASTNode): string | undefined => {\n if (node.type === \"Identifier\") return node.name\n if (node.type !== \"MemberExpression\") return undefined\n const object = node.object as ASTNode\n return object.type === \"Identifier\" && GLOBALS.has(object.name) ? keyName(node) : undefined\n}\n\nconst isTargetFirstCall = (call: ASTNode): boolean => {\n const callee = call.callee as ASTNode\n if (callee.type !== \"MemberExpression\") return false\n const namespace = namespaceName(callee.object as ASTNode)\n const method = keyName(callee)\n return namespace !== undefined && method !== undefined && (TARGET_FIRST[namespace]?.has(method) ?? false)\n}\n\n/** The member expressions a destructuring or loop target writes to: `(list as any).x` in `({ a: (list as any).x } = o)`. */\nconst memberTargets = (pattern: ASTNode | null | undefined): ReadonlyArray<ASTNode> => {\n if (pattern === null || pattern === undefined) return []\n switch (pattern.type) {\n case \"MemberExpression\":\n return [pattern]\n case \"ObjectPattern\":\n return (pattern.properties as ReadonlyArray<ASTNode>).flatMap((p) =>\n memberTargets(p.type === \"RestElement\" ? (p.argument as ASTNode) : (p.value as ASTNode)),\n )\n case \"ArrayPattern\":\n return (pattern.elements as ReadonlyArray<ASTNode | null>).flatMap((e) => memberTargets(e))\n case \"RestElement\":\n return memberTargets(pattern.argument as ASTNode)\n case \"AssignmentPattern\":\n return memberTargets(pattern.left as ASTNode)\n default:\n return ERASING.has(pattern.type) || TRANSPARENT.has(pattern.type)\n ? memberTargets(pattern.expression as ASTNode)\n : []\n }\n}\n\n/**\n * Reports a write to a functype value that TypeScript can't see. The types mark every field read-only,\n * so such a write needs the value's type hidden: an `as` cast, or a variable that holds one\n * (`const o = list as any; o.x = 1`). The rule reports:\n *\n * - an assignment, compound assignment, `++`/`--`, `delete`, destructuring or `for…of`/`for…in` target\n * whose path starts from a functype value held under a hiding cast; and\n * - a mutating method (`push`, `splice`, `sort`, `add`, `set`, `delete`, `clear` and the like) called on\n * data reached through such a value: `(list as any).value.push(9)`. Called on the functype value\n * itself, cast or not, the method is functype's own and builds a new value, so it isn't reported; and\n * - `Object.assign`, `Object.defineProperty(ies)`, `Object.setPrototypeOf` and the matching `Reflect`\n * calls aimed at a functype value, cast or not, since those compile without one.\n *\n * A write that compiles without a cast is left alone: it is to a field of your own type, or to the data a\n * container holds (an Option's payload, a List element's own field), which the container doesn't own.\n * Only values whose `fold` functype declares count. Type-aware only: without type information it reports\n * nothing. It can't see a value passed to an `any` parameter and written there, or plain JavaScript.\n */\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Disallow changing a functype value in place\",\n recommended: false,\n },\n schema: [],\n messages: {\n mutation:\n \"This changes a {{name}} in place. functype values don't change after they're built, and other values share their data. Build a new one instead: map, filter, add, set or concat\",\n },\n },\n\n create(context) {\n const findVariable = (scope: Scope.Scope | null, name: string): Scope.Variable | undefined =>\n scope === null ? undefined : (scope.set.get(name) ?? findVariable(scope.upper, name))\n\n /** The one value a variable ever holds: the initialiser of a variable written only where it's declared. */\n const soleValue = (identifier: ASTNode): { readonly init: ASTNode; readonly erased: boolean } | undefined => {\n const variable = findVariable(context.sourceCode.getScope(identifier as never), identifier.name)\n const definition = variable?.defs[0]\n if (variable === undefined || variable.defs.length !== 1 || definition?.type !== \"Variable\") return undefined\n const declarator = definition.node as unknown as ASTNode\n if (declarator.id?.type !== \"Identifier\" || declarator.init == null) return undefined\n if (variable.references.filter((r) => r.isWrite()).length > 1) return undefined\n // `const o: any = list` hides the type as a cast does.\n const annotation = (declarator.id.typeAnnotation as ASTNode | undefined)?.typeAnnotation as ASTNode | undefined\n const erased = annotation?.type === \"TSAnyKeyword\" || annotation?.type === \"TSUnknownKeyword\"\n return { init: declarator.init as ASTNode, erased }\n }\n\n /**\n * The functype value a written path starts from, if it was hidden from TypeScript on the way: `list`\n * in `(list as any).value[0]`, or in `o.x` after `const o = list as any`.\n */\n const hiddenRoot = (node: ASTNode, erased: boolean, depth = 0): string | undefined => {\n if (depth > 10) return undefined\n if (ERASING.has(node.type)) return hiddenRoot(node.expression as ASTNode, true, depth + 1)\n if (TRANSPARENT.has(node.type)) return hiddenRoot(node.expression as ASTNode, erased, depth + 1)\n const name = functypeValueByType(node, context)\n if (name !== undefined) return erased ? name : undefined\n if (node.type === \"MemberExpression\") return hiddenRoot(node.object as ASTNode, erased, depth + 1)\n if (node.type !== \"Identifier\") return undefined\n const held = soleValue(node)\n return held === undefined ? undefined : hiddenRoot(held.init, erased || held.erased, depth + 1)\n }\n\n /**\n * The functype value a call's target is, cast or not: `list` in `Object.assign(list, …)` or\n * `Object.assign(o, …)` after `const o = list`. A member of one counts only when a cast hides it, so\n * `Object.assign(opt.value, …)` on an Option's payload is left alone, as `opt.value.n = 1` is.\n */\n const targetRoot = (node: ASTNode, depth = 0): string | undefined => {\n if (depth > 10) return undefined\n if (ERASING.has(node.type) || TRANSPARENT.has(node.type)) return targetRoot(node.expression as ASTNode, depth + 1)\n const name = functypeValueByType(node, context)\n if (name !== undefined) return name\n if (node.type === \"MemberExpression\") return hiddenRoot(node, false, depth + 1)\n if (node.type !== \"Identifier\") return undefined\n const held = soleValue(node)\n return held === undefined ? undefined : targetRoot(held.init, depth + 1)\n }\n\n /**\n * Is `node` the functype value itself, however it's cast or aliased? Then a method called on it is\n * functype's own and builds a new value: `(fmap as FMap<K, V>).set(k, v)`, `(list as any).add(1)`.\n */\n const isContainerItself = (node: ASTNode, depth = 0): boolean => {\n if (depth > 10) return false\n if (ERASING.has(node.type) || TRANSPARENT.has(node.type))\n return isContainerItself(node.expression as ASTNode, depth + 1)\n if (functypeValueByType(node, context) !== undefined) return true\n if (node.type !== \"Identifier\") return false\n const held = soleValue(node)\n return held !== undefined && isContainerItself(held.init, depth + 1)\n }\n\n const report = (node: ASTNode, name: string | undefined): void => {\n if (name !== undefined) context.report({ node, messageId: \"mutation\", data: { name } })\n }\n\n /** A written member: `(list as any).x` writes into whatever `(list as any)` is. */\n const checkMember = (write: ASTNode, target: ASTNode): void => {\n const member = TRANSPARENT.has(target.type) || ERASING.has(target.type) ? (target.expression as ASTNode) : target\n if (member.type === \"MemberExpression\") report(write, hiddenRoot(member.object as ASTNode, false))\n }\n\n const checkPattern = (write: ASTNode, pattern: ASTNode): void => {\n memberTargets(pattern).forEach((target) => checkMember(write, target))\n }\n\n return {\n AssignmentExpression(node: ASTNode) {\n checkPattern(node, node.left as ASTNode)\n },\n UpdateExpression(node: ASTNode) {\n checkMember(node, node.argument as ASTNode)\n },\n UnaryExpression(node: ASTNode) {\n if (node.operator === \"delete\") checkMember(node, node.argument as ASTNode)\n },\n \"ForOfStatement, ForInStatement\"(node: ASTNode) {\n const left = node.left as ASTNode\n if (left.type !== \"VariableDeclaration\") checkPattern(node, left)\n },\n CallExpression(node: ASTNode) {\n const callee = node.callee as ASTNode\n // Object.* and Reflect.* first: `Reflect.set` is a target-first call, not a Map's `set`.\n if (callee.type === \"MemberExpression\" && !isTargetFirstCall(node)) {\n const method = keyName(callee)\n const receiver = callee.object as ASTNode\n if (method !== undefined && MUTATING_METHODS.has(method) && !isContainerItself(receiver)) {\n report(node, hiddenRoot(receiver, false))\n return\n }\n }\n const [first] = node.arguments as ReadonlyArray<ASTNode>\n if (first !== undefined && first.type !== \"SpreadElement\" && isTargetFirstCall(node)) {\n report(node, targetRoot(first))\n }\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,6DAMA,MAAMC,kBAA+B,IAAI,IAAI,CAAC,iBAAkB,iBAAiB,CAAC,EAG5EC,kBAAmC,IAAI,IAAI,CAAC,sBAAuB,wBAAyB,iBAAiB,CAAC,EAG9GC,EAA8D,CAClE,uBAAQ,IAAI,IAAI,CAAC,SAAU,iBAAkB,mBAAoB,gBAAgB,CAAC,EAClF,wBAAS,IAAI,IAAI,CAAC,MAAO,iBAAkB,iBAAkB,gBAAgB,CAAC,CAChF,EAMMC,kBAAwC,IAAI,IAAI,CACpD,OACA,MACA,QACA,UACA,SACA,OACA,UACA,OACA,aACA,MACA,MACA,SACA,OACF,CAAC,EAGKC,kBAA+B,IAAI,IAAI,CAAC,aAAc,SAAU,OAAQ,QAAQ,CAAC,EAEjFC,EAAWC,GAAwC,CACvD,IAAMC,EAAWD,EAAO,SAExB,MADI,CAACA,EAAO,UAAYC,EAAS,OAAS,aAAqBA,EAAS,KACjED,EAAO,UAAYC,EAAS,OAAS,WAAa,OAAOA,EAAS,OAAU,SAC/EA,EAAS,MACT,IAAA,EACN,EAGMC,EAAiBC,GAAsC,CAC3D,GAAIA,EAAK,OAAS,aAAc,OAAOA,EAAK,KAC5C,GAAIA,EAAK,OAAS,mBAAoB,OACtC,IAAMC,EAASD,EAAK,OACpB,OAAOC,EAAO,OAAS,cAAgBN,EAAQ,IAAIM,EAAO,IAAI,EAAIL,EAAQI,CAAI,EAAI,IAAA,EACpF,EAEME,EAAqBC,GAA2B,CACpD,IAAMC,EAASD,EAAK,OACpB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A,EAAK,WAAa,UAAU6B,EAAY7B,EAAMA,EAAK,QAAmB,CAC5E,EACA,iCAAiCA,EAAe,CAC9C,IAAMiC,EAAOjC,EAAK,KACdiC,EAAK,OAAS,uBAAuBD,EAAahC,EAAMiC,CAAI,CAClE,EACA,eAAejC,EAAe,CAC5B,IAAMI,EAASJ,EAAK,OAEpB,GAAII,EAAO,OAAS,oBAAsB,CAACF,EAAkBF,CAAI,EAAG,CAClE,IAAMM,EAASV,EAAQQ,CAAM,EACvB8B,EAAW9B,EAAO,OACxB,GAAIE,IAAW,IAAA,IAAaZ,EAAiB,IAAIY,CAAM,GAAK,CAACqB,EAAkBO,CAAQ,EAAG,CACxFN,EAAO5B,EAAMuB,EAAWW,EAAU,EAAK,CAAC,EACxC,MACF,CACF,CACA,GAAM,CAACC,GAASnC,EAAK,UACjBmC,IAAU,IAAA,IAAaA,EAAM,OAAS,iBAAmBjC,EAAkBF,CAAI,GACjF4B,EAAO5B,EAAM0B,EAAWS,CAAK,CAAC,CAElC,CACF,CACF,CACF,E"}
@@ -1 +1 @@
1
- {"version":3,"file":"no-floating-io.js","names":["rule","expression","node","isIOByType","context"],"sources":["../../src/rules/no-floating-io.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { isIOByType } from \"../utils/type-aware\"\n\n/**\n * Reports an `IO` that is built and then dropped, so it never runs:\n *\n * - an expression statement whose value is an `IO` — `log.info(\"saved\")`, `save(user).tap(audit)`;\n * - `await` on an `IO`. `IO` is not a Promise, so `await io` hands back the `IO` itself, unrun.\n *\n * `no-floating-promises` and `await-thenable` don't see either case, because `IO` is not thenable.\n * Returning, yielding, assigning or passing an `IO` along is fine: someone else runs it. `void io`\n * marks a deliberate drop 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 building an IO and never running it\",\n recommended: false,\n },\n schema: [],\n messages: {\n floatingIO:\n \"This IO is built and never run, so it does nothing. Run it (.run(), .runOrThrow(), .runExit()), return it, or yield* it inside IO.gen\",\n awaitedIO:\n \"await on an IO does nothing: IO is not a Promise, so this returns the IO unrun. Await .run() or .runOrThrow() instead\",\n },\n },\n\n create(context) {\n return {\n ExpressionStatement(node: ASTNode) {\n const expression = node.expression as ASTNode\n // `void io` is a deliberate drop; `await io` is reported by the AwaitExpression visitor.\n if (expression.type === \"AwaitExpression\") return\n if (expression.type === \"UnaryExpression\" && expression.operator === \"void\") return\n if (isIOByType(expression, context)) context.report({ node: expression, messageId: \"floatingIO\" })\n },\n AwaitExpression(node: ASTNode) {\n if (isIOByType(node.argument as ASTNode, context)) context.report({ node, messageId: \"awaitedIO\" })\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,oDAiBA,MAAMA,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,+CACb,YAAa,EACf,EACA,OAAQ,CAAC,EACT,SAAU,CACR,WACE,wIACF,UACE,uHACJ,CACF,EAEA,OAAO,EAAS,CACd,MAAO,CACL,oBAAoB,EAAe,CACjC,IAAMC,EAAaC,EAAK,WAEpBD,EAAW,OAAS,oBACpBA,EAAW,OAAS,mBAAqBA,EAAW,WAAa,SACjEE,EAAWF,EAAYG,CAAO,GAAGA,EAAQ,OAAO,CAAE,KAAMH,EAAY,UAAW,YAAa,CAAC,CACnG,EACA,gBAAgB,EAAe,CACzBE,EAAWD,EAAK,SAAqBE,CAAO,GAAGA,EAAQ,OAAO,CAAE,OAAM,UAAW,WAAY,CAAC,CACpG,CACF,CACF,CACF,E"}
1
+ {"version":3,"file":"no-floating-io.js","names":["isIOByType","rule","context","node","expression"],"sources":["../../src/rules/no-floating-io.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { isIOByType } from \"../utils/type-aware\"\n\n/**\n * Reports an `IO` that is built and then dropped, so it never runs:\n *\n * - an expression statement whose value is an `IO` — `log.info(\"saved\")`, `save(user).tap(audit)`;\n * - `await` on an `IO`. `IO` is not a Promise, so `await io` hands back the `IO` itself, unrun.\n *\n * `no-floating-promises` and `await-thenable` don't see either case, because `IO` is not thenable.\n * Returning, yielding, assigning or passing an `IO` along is fine: someone else runs it. `void io`\n * marks a deliberate drop 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 building an IO and never running it\",\n recommended: false,\n },\n schema: [],\n messages: {\n floatingIO:\n \"This IO is built and never run, so it does nothing. Run it (.run(), .runOrThrow(), .runExit()), return it, or yield* it inside IO.gen\",\n awaitedIO:\n \"await on an IO does nothing: IO is not a Promise, so this returns the IO unrun. Await .run() or .runOrThrow() instead\",\n },\n },\n\n create(context) {\n return {\n ExpressionStatement(node: ASTNode) {\n const expression = node.expression as ASTNode\n // `void io` is a deliberate drop; `await io` is reported by the AwaitExpression visitor.\n if (expression.type === \"AwaitExpression\") return\n if (expression.type === \"UnaryExpression\" && expression.operator === \"void\") return\n if (isIOByType(expression, context)) context.report({ node: expression, messageId: \"floatingIO\" })\n },\n AwaitExpression(node: ASTNode) {\n if (isIOByType(node.argument as ASTNode, context)) context.report({ node, messageId: \"awaitedIO\" })\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,oDAiBA,MAAMC,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,+CACb,YAAa,EACf,EACA,OAAQ,CAAC,EACT,SAAU,CACR,WACE,wIACF,UACE,uHACJ,CACF,EAEA,OAAOC,EAAS,CACd,MAAO,CACL,oBAAoBC,EAAe,CACjC,IAAMC,EAAaD,EAAK,WAEpBC,EAAW,OAAS,oBACpBA,EAAW,OAAS,mBAAqBA,EAAW,WAAa,SACjEJ,EAAWI,EAAYF,CAAO,GAAGA,EAAQ,OAAO,CAAE,KAAME,EAAY,UAAW,YAAa,CAAC,CACnG,EACA,gBAAgBD,EAAe,CACzBH,EAAWG,EAAK,SAAqBD,CAAO,GAAGA,EAAQ,OAAO,CAAEC,OAAM,UAAW,WAAY,CAAC,CACpG,CACF,CACF,CACF,E"}