eslint-plugin-functype 2.200.0 → 2.201.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 (61) hide show
  1. package/README.md +30 -2
  2. package/dist/cli/list-rules.js.map +1 -1
  3. package/dist/configs/recommended.d.ts +5 -1
  4. package/dist/configs/recommended.js +1 -1
  5. package/dist/configs/recommended.js.map +1 -1
  6. package/dist/index.d.ts +1 -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 +13 -11
  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-floating-io.js.map +1 -1
  16. package/dist/rules/no-floating-result.js.map +1 -1
  17. package/dist/rules/no-get-unsafe.js.map +1 -1
  18. package/dist/rules/no-getOrThrow-in-render.js.map +1 -1
  19. package/dist/rules/no-imperative-loops.js.map +1 -1
  20. package/dist/rules/no-let.js.map +1 -1
  21. package/dist/rules/no-serialize-container.js.map +1 -1
  22. package/dist/rules/no-uncalled-method.d.ts +16 -0
  23. package/dist/rules/no-uncalled-method.js +2 -0
  24. package/dist/rules/no-uncalled-method.js.map +1 -0
  25. package/dist/rules/prefer-do-notation.js +1 -1
  26. package/dist/rules/prefer-do-notation.js.map +1 -1
  27. package/dist/rules/prefer-either.js.map +1 -1
  28. package/dist/rules/prefer-flatmap.js.map +1 -1
  29. package/dist/rules/prefer-fold.js +1 -1
  30. package/dist/rules/prefer-fold.js.map +1 -1
  31. package/dist/rules/prefer-functype-map.js.map +1 -1
  32. package/dist/rules/prefer-functype-set.js.map +1 -1
  33. package/dist/rules/prefer-list.js.map +1 -1
  34. package/dist/rules/prefer-map.js.map +1 -1
  35. package/dist/rules/prefer-option.js.map +1 -1
  36. package/dist/rules/prefer-try.js.map +1 -1
  37. package/dist/utils/array-mutation.d.ts +1 -1
  38. package/dist/utils/array-mutation.js.map +1 -1
  39. package/dist/utils/ast-walk.js.map +1 -1
  40. package/dist/utils/async-detection.js.map +1 -1
  41. package/dist/utils/boundary-tags.d.ts +1 -1
  42. package/dist/utils/boundary-tags.js.map +1 -1
  43. package/dist/utils/collection-binding.d.ts +1 -1
  44. package/dist/utils/collection-binding.js.map +1 -1
  45. package/dist/utils/dependency-validator.js.map +1 -1
  46. package/dist/utils/functype-detection.d.ts +1 -1
  47. package/dist/utils/functype-detection.js.map +1 -1
  48. package/dist/utils/functype-predicates.d.ts +1 -1
  49. package/dist/utils/functype-predicates.js.map +1 -1
  50. package/dist/utils/host-throws.d.ts +1 -1
  51. package/dist/utils/host-throws.js.map +1 -1
  52. package/dist/utils/import-fixer.js.map +1 -1
  53. package/dist/utils/mutable-collection.d.ts +1 -1
  54. package/dist/utils/mutable-collection.js.map +1 -1
  55. package/dist/utils/react-render.js.map +1 -1
  56. package/dist/utils/readonly-contract.js.map +1 -1
  57. package/dist/utils/type-aware.d.ts +13 -1
  58. package/dist/utils/type-aware.js +1 -1
  59. package/dist/utils/type-aware.js.map +1 -1
  60. package/dist/utils/wire-types.js.map +1 -1
  61. 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` and `no-uncalled-method` 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 five type-aware rules, `no-array-mutation`, `no-floating-io`, `no-floating-result`, `no-serialize-container` and `no-uncalled-method`, 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,7 @@ 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 |
82
83
  | `functype/no-getOrThrow-in-render` | error | | React: no bare `.orThrow()` in a component or hook body; a throw in render unmounts the tree |
83
84
  | `functype/must-fold-on-component-return` | error | | React: render an `Option`/`Either`/`Try` with `fold` or `<MatchOption>`, not a guard or `&&` |
84
85
 
@@ -304,6 +305,33 @@ return c.json(result.toJSON()) // fine: the envelope on purpose
304
305
 
305
306
  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
307
 
308
+ ### `functype/no-uncalled-method`
309
+
310
+ 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.
311
+
312
+ ```ts ignore
313
+ const checkout = results.head // reported: a function, so `if (!checkout)` is never taken
314
+ return Option(results.head) // reported: Some(<function>), not Some(firstRow)
315
+ expect(results.head).toEqual(row) // reported
316
+ if (opt.isSome) {
317
+ } // reported: always true
318
+ const { head } = results // reported
319
+
320
+ results.head() // fine
321
+ results.headOption() // fine
322
+ results.head.bind(results) // fine: the function on purpose
323
+ results.size // fine: a property
324
+ ```
325
+
326
+ - **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.
327
+ - **Deliberate uses:** a call (`?.()`, `new` and a tagged template included, also through `as`, `!` or `satisfies`), `.bind` / `.call` / `.apply`, `typeof`, an assignment target, and `delete`.
328
+ - **Not covered yet:** destructuring in parameters, nested patterns and `for…of`, and computed reads with a variable key (`results[key]`).
329
+ - **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.
330
+
331
+ **It only runs with type-aware linting** (`parserOptions.projectService`). Without type information it reports nothing.
332
+
333
+ 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.
334
+
307
335
  ### React rules
308
336
 
309
337
  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,EAEA,SAASC,EAAS,EAAc,EAAoC,CAClE,OAAOD,EAAOE,GAASC,EAAOH,EAAO,KACvC,CAIA,SAASI,EAAsB,EAAgC,CAC7D,QAAQ,IAAIH,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,QAAS,GAAQ,CAChC,IAAMC,EAAOC,EAAI,SAAW,KAAO,KACnC,QAAQ,IAAI,KAAKD,EAAK,GAAGL,EAASM,EAAI,KAAM,OAAO,EAAE,KAAKA,EAAI,aAAa,CAC7E,CAAC,GAICF,EAAO,QAAQ,OAAS,IAC1B,QAAQ,IAAIJ,EAAS;YAAgB,KAAK,CAAC,EAC3CI,EAAO,QAAQ,QAAS,GA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I,2CAA2C,EACvD,QAAQ,IAAI,kEAAkE,EAE9E,QAAQ,IAAIA,EAAS;WAAe,QAAQ,CAAC,EAC7C,QAAQ,IAAI,wEAAwE,EACpF,QAAQ,IAAI,+EAA+E,EAC3F,QAAQ,IAAI,6DAA6D,CAC3E,CAEA,SAASqB,GAA6B,CACpC,QAAQ,IAAIrB,EAAS;oBAAwB,QAAQ,CAAC,EACtD,QAAQ,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,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,EA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QAAQ,MAAMrB,EAAS,sBAAuB,KAAK,EAAGqB,CAAK,EAC3D,QAAQ,KAAK,CAAC,CAChB,CAAC,E"}
@@ -28,11 +28,14 @@
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).
31
33
  * - no-getOrThrow-in-render and must-fold-on-component-return fire only inside a React component or
32
34
  * hook, and reported nothing on 1,403 files of React code.
33
35
  * - no-get-unsafe: an unwrap outside an `@interop` boundary; allowed in test files.
34
36
  *
35
- * no-array-mutation, no-floating-io, no-floating-result and no-serialize-container are type-aware:
37
+ * no-array-mutation, no-floating-io, no-floating-result, no-serialize-container and no-uncalled-method
38
+ * are type-aware:
36
39
  * without `parserOptions.projectService` they report nothing.
37
40
  */
38
41
  declare const recommendedRules: {
@@ -54,6 +57,7 @@ declare const recommendedRules: {
54
57
  "functype/no-floating-io": string;
55
58
  "functype/no-floating-result": string;
56
59
  "functype/no-serialize-container": string;
60
+ "functype/no-uncalled-method": string;
57
61
  "functype/no-getOrThrow-in-render": string;
58
62
  "functype/must-fold-on-component-return": string;
59
63
  "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-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-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 and no-uncalled-method\n * 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-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":"AAwCA,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,mCAAoC,QACpC,yCAA0C,QAC1C,0BAA2B,MAC3B,8BAA+B,KACjC,E"}
package/dist/index.d.ts CHANGED
@@ -18,6 +18,7 @@ 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-uncalled-method": import("eslint").Rule.RuleModule;
21
22
  "no-getOrThrow-in-render": import("eslint").Rule.RuleModule;
22
23
  "must-fold-on-component-return": import("eslint").Rule.RuleModule;
23
24
  };
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.201.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"}
@@ -8,16 +8,17 @@ import rule$5 from "./no-getOrThrow-in-render.js";
8
8
  import rule$7 from "./no-imperative-loops.js";
9
9
  import rule$8 from "./no-let.js";
10
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";
11
+ import rule$10 from "./no-uncalled-method.js";
12
+ import rule$11 from "./prefer-do-notation.js";
13
+ import rule$12 from "./prefer-either.js";
14
+ import rule$13 from "./prefer-flatmap.js";
15
+ import rule$14 from "./prefer-fold.js";
16
+ import rule$15 from "./prefer-functype-map.js";
17
+ import rule$16 from "./prefer-functype-set.js";
18
+ import rule$17 from "./prefer-list.js";
19
+ import rule$18 from "./prefer-map.js";
20
+ import rule$19 from "./prefer-option.js";
21
+ import rule$20 from "./prefer-try.js";
21
22
  declare const _default: {
22
23
  "prefer-option": import("eslint").Rule.RuleModule;
23
24
  "prefer-either": import("eslint").Rule.RuleModule;
@@ -37,7 +38,8 @@ declare const _default: {
37
38
  "no-floating-io": import("eslint").Rule.RuleModule;
38
39
  "no-floating-result": import("eslint").Rule.RuleModule;
39
40
  "no-serialize-container": import("eslint").Rule.RuleModule;
41
+ "no-uncalled-method": import("eslint").Rule.RuleModule;
40
42
  "no-getOrThrow-in-render": import("eslint").Rule.RuleModule;
41
43
  "must-fold-on-component-return": import("eslint").Rule.RuleModule;
42
44
  };
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 };
45
+ export { rule as collectionNaming, _default as default, rule$1 as mustFoldOnComponentReturn, rule$2 as noArrayMutation, rule$3 as noFloatingIo, rule$4 as noFloatingResult, rule$5 as noGetOrThrowInRender, rule$6 as noGetUnsafe, rule$7 as noImperativeLoops, rule$8 as noLet, rule$9 as noSerializeContainer, rule$10 as noUncalledMethod, rule$11 as preferDoNotation, rule$12 as preferEither, rule$13 as preferFlatmap, rule$14 as preferFold, rule$15 as preferFunctypeMap, rule$16 as preferFunctypeSet, rule$17 as preferList, rule$18 as preferMap, rule$19 as preferOption, rule$20 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-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"./no-uncalled-method.js";import d from"./prefer-do-notation.js";import f from"./prefer-either.js";import p from"./prefer-flatmap.js";import m from"./prefer-fold.js";import h from"./prefer-functype-map.js";import g from"./prefer-functype-set.js";import _ from"./prefer-list.js";import v from"./prefer-map.js";import y from"./prefer-option.js";import b from"./prefer-try.js";var x={"prefer-option":y,"prefer-either":f,"prefer-try":b,"prefer-list":_,"no-get-unsafe":a,"no-let":c,"prefer-fold":m,"prefer-map":v,"prefer-flatmap":p,"prefer-functype-map":h,"prefer-functype-set":g,"no-imperative-loops":s,"prefer-do-notation":d,"collection-naming":e,"no-array-mutation":n,"no-floating-io":r,"no-floating-result":i,"no-serialize-container":l,"no-uncalled-method":u,"no-getOrThrow-in-render":o,"must-fold-on-component-return":t};export{e as collectionNaming,x 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 noUncalledMethod,d as preferDoNotation,f as preferEither,p as preferFlatmap,m as preferFold,h as preferFunctypeMap,g as preferFunctypeSet,_ as preferList,v as preferMap,y as preferOption,b 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","noUncalledMethod","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","rule$20","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 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 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-uncalled-method\": noUncalledMethod,\n \"no-getOrThrow-in-render\": noGetOrThrowInRender,\n \"must-fold-on-component-return\": mustFoldOnComponentReturn,\n}\n"],"mappings":"A,uwBA8CA,IAAA0C,EAAe,CACb,gBAAiB1C,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,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,OAAS,WAAaA,EAAK,QAAU,KAEvFC,EAAwB,CAC5B,KAAM,CACJ,KAAM,aACN,KAAM,CACJ,YACE,oIACF,YAAa,EACf,EACA,OAAQ,CACN,CACE,KAAM,SACN,WAAY,CACV,mBAAoB,CAClB,KAAM,UACN,QAAS,EACX,CACF,EACA,qBAAsB,EACxB,CACF,EACA,SAAU,CACR,YACE,wNACF,aACE,8JACJ,CACF,EAEA,OAAO,EAAS,CAEd,IAAMC,GADUC,EAAQ,QAAQ,IAAM,CAAC,EAAA,CACJ,qBAAuB,GACpDC,EAAaD,EAAQ,WAGrBE,GAAsB,EAAe,IAAkB,CAC3D,IAAMC,EAAYC,EAAgBC,EAAMJ,CAAU,EAClD,GAAI,CAACE,EAAW,OAAO,KACvB,IAAMG,EAAKC,EAAkBV,CAAI,EAIjC,MAHI,CAACS,GAAME,EAAWF,CAAE,IAAM,aAC1BG,EAAoBN,EAAU,SAAUH,CAAO,IAAM,IACrDD,GAAsBW,EAA0Bb,EAAA,UAAmBI,CAAU,EAAU,KACpFE,CACT,EAEMQ,GAAU,EAAe,EAAmB,IAChDX,EAAQ,OAAO,CACb,OACA,YACA,KAAM,CACJ,SAAUC,EAAW,QAAQE,EAAU,QAAQ,EAC/C,OAAQA,EAAU,OAClB,QAASS,EAAgBT,EAAU,SAAW,OAChD,CACF,CAAC,EAEH,MAAO,CACL,YAAY,EAAe,CAEzB,GAAIN,EAAK,UAAW,OACpB,IAAMgB,EAAWpB,EAAcI,EAAK,UAAU,EAC9C,GAAIgB,IAAa,IAAA,IAAa,EAAEC,EAAYD,CAAQ,GAAKjB,EAAciB,CAAQ,GAAI,OACnF,IAAMV,EAAYD,EAAmBL,EAAMA,EAAK,IAAI,EAChDM,GAAWQ,EAAOd,EAAM,cAAeM,CAAS,CACtD,EAEA,kBAAkB,EAAe,CAC/B,GAAIN,EAAK,WAAa,MAAQ,CAACiB,EAAYjB,EAAK,KAAK,EAAG,OACxD,IAAMM,EAAYD,EAAmBL,EAAMA,EAAK,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, \"shortCircuit\", predicate)\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,wTAyBA,MAAMO,EAAiBC,GAAoD,CACzE,IAAMC,EACJD,EAAW,OAAS,kBAAoBA,EAAW,KAAK,SAAW,EAAIA,EAAW,KAAK,GAAKA,EAC9F,OAAOC,GAAW,OAAS,kBAAqBA,EAAU,UAAY,KAAQ,IAAA,EAChF,EAEMC,EAAiBC,GAA2BA,GAAM,OAAS,WAAaA,EAAK,QAAU,KAEvFC,EAAwB,CAC5B,KAAM,CACJ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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 === \"delete\") reportWrite(node, node.argument as ASTNode)\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,4IAOA,MAAMA,kBAAwC,IAAI,IAAI,CACpD,OACA,MACA,QACA,UACA,SACA,OACA,UACA,OACA,YACF,CAAC,EAQKC,EAAgB,GACpBC,EAAK,OAAS,mBACdA,EAAK,OAAS,kBACdA,EAAK,OAAS,iBACbA,EAAK,OAAS,mBAAqBD,EAAaC,EAAK,QAAmB,EAGrEC,GAAU,EAAe,IAAuD,CACpF,IAAMC,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EMG,GAAe,EAAe,IAA0B,CAC5D,GAAIN,EAASV,CAAI,EAAG,OACpB,IAAMiB,EAAUL,EAAcM,CAAM,EACpC,GAAID,EAAS,CACXX,EAAQ,OAAO,CAAE,OAAM,UAAW,oBAAqB,KAAM,CAAE,KAAML,EAAOgB,EAASd,CAAU,CAAE,CAAE,CAAC,EACpG,MACF,CACA,IAAMgB,EAASJ,EAAaG,CAAM,EAC9BC,GACFb,EAAQ,OAAO,CAAE,OAAM,UAAW,mBAAoB,KAAM,CAAE,KAAML,EAAOkB,EAAQhB,CAAU,CAAE,CAAE,CAAC,CAEtG,EAEA,MAAO,CACL,eAAe,EAAe,CAC5B,IAAMiB,EAASpB,EAAK,OACpB,GAAIoB,EAAO,OAAS,oBAAsBA,EAAO,SAAU,OAC3D,IAAMC,EAASD,EAAO,UAAU,OAAS,aAAeA,EAAO,SAAS,KAAO,KAC/E,GAAIC,IAAW,MAAQ,CAACvB,EAAiB,IAAIuB,CAAM,EAAG,OACtD,IAAMR,EAAQO,EAAO,OACjBrB,EAAac,CAAK,GAAKH,EAASV,CAAI,GACnCc,EAAyBD,EAAOP,CAAO,GAC5CA,EAAQ,OAAO,CACb,OACA,UAAW,iBACX,KAAM,CAAE,KAAML,EAAOY,EAAOV,CAAU,EAAG,QAAO,CAClD,CAAC,CACH,EAEA,qBAAqB,EAAe,CAClCa,EAAYhB,EAAMA,EAAK,IAAe,CACxC,EAEA,iBAAiB,EAAe,CAC9BgB,EAAYhB,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,iBACbA,EAAK,OAAS,mBAAqBD,EAAaC,EAAK,QAAmB,EAGrEC,GAAUD,EAAeE,IAAuD,CACpF,IAAMC,EAAOD,EAAW,QAAQF,CAAI,EACpC,OAAOG,EAAK,OAAS,GAAK,GAAGA,EAAK,MAAM,EAAG,EAAE,EAAE,GAAKA,CACtD,EAaMC,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,wDACb,YAAa,EACf,EACA,OAAQ,CACN,CACE,KAAM,SACN,WAAY,CAC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AC,EACpG,MACF,CACA,IAAMe,EAASJ,EAAaE,CAAM,EAC9BE,GACFZ,EAAQ,OAAO,CAAEL,OAAM,UAAW,mBAAoB,KAAM,CAAE,KAAMC,EAAOgB,EAAQf,CAAU,CAAE,CAAE,CAAC,CAEtG,EAEA,MAAO,CACL,eAAeF,EAAe,CAC5B,IAAMkB,EAASlB,EAAK,OACpB,GAAIkB,EAAO,OAAS,oBAAsBA,EAAO,SAAU,OAC3D,IAAMC,EAASD,EAAO,UAAU,OAAS,aAAeA,EAAO,SAAS,KAAO,KAC/E,GAAIC,IAAW,MAAQ,CAACrB,EAAiB,IAAIqB,CAAM,EAAG,OACtD,IAAMP,EAAQM,EAAO,OACjBnB,EAAaa,CAAK,GAAKF,EAASV,CAAI,GACnCJ,EAAyBgB,EAAOP,CAAO,GAC5CA,EAAQ,OAAO,CACbL,OACA,UAAW,iBACX,KAAM,CAAE,KAAMC,EAAOW,EAAOV,CAAU,EAAGiB,QAAO,CAClD,CAAC,CACH,EAEA,qBAAqBnB,EAAe,CAClCc,EAAYd,EAAMA,EAAK,IAAe,CACxC,EAEA,iBAAiBA,EAAe,CAC9Bc,EAAYd,EAAMA,EAAK,QAAmB,CAC5C,EAEA,gBAAgBA,EAAe,CACzBA,EAAK,WAAa,UAAUc,EAAYd,EAAMA,EAAK,QAAmB,CAC5E,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"}
@@ -1 +1 @@
1
- {"version":3,"file":"no-floating-result.js","names":["CHECKED","FAILURE_HANDLERS","FAILURE_SOURCES","handlesItsFailure","node","callee","property","name","rule","expression","canCarryFailureByType","context"],"sources":["../../src/rules/no-floating-result.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { canCarryFailureByType } from \"../utils/type-aware\"\n\n/** `f()`, `a?.f()`, `await …`, and `ok && f()` / `ok ? f() : g()`: statements whose only job is a value. */\nconst CHECKED: ReadonlySet<string> = new Set([\n \"CallExpression\",\n \"ChainExpression\",\n \"AwaitExpression\",\n \"LogicalExpression\",\n \"ConditionalExpression\",\n])\n\n/** Methods that run a callback on the failure, so a chain through one has handled it. */\nconst FAILURE_HANDLERS: ReadonlySet<string> = new Set([\"tapError\", \"tapLeft\"])\n\n/** Methods that can bring in a new failure, so a handler before one no longer covers the result. */\nconst FAILURE_SOURCES: ReadonlySet<string> = new Set([\"flatMap\", \"chain\", \"andThen\", \"flatMapError\", \"orElse\"])\n\n/**\n * Does the call chain in `node` handle its own failure? Walks the receiver chain from the outermost\n * call in: a `.tapError(…)` or `.tapLeft(…)` counts, unless a later `.flatMap(…)` can bring in a new,\n * unlogged failure. Arguments are never walked into.\n */\nconst handlesItsFailure = (node: ASTNode | undefined): boolean => {\n if (!node) return false\n if (node.type === \"AwaitExpression\") return handlesItsFailure(node.argument as ASTNode)\n if (node.type === \"ChainExpression\") return handlesItsFailure(node.expression as ASTNode)\n if (node.type !== \"CallExpression\") return false\n const callee = node.callee as ASTNode\n if (callee.type !== \"MemberExpression\") return false\n const property = callee.property as ASTNode\n const name = property.type === \"Identifier\" ? (property.name as string) : \"\"\n if (FAILURE_HANDLERS.has(name)) return true\n if (FAILURE_SOURCES.has(name)) return false\n return handlesItsFailure(callee.object as ASTNode)\n}\n\n/**\n * Reports a statement that computes an Either, Try or other failure-carrying result and drops it:\n * `await userService.updateSubscription(id, plan)` on its own line, or `parse(input)`. A Left or a\n * Failure in it is silently ignored. `no-floating-promises` doesn't help, because awaiting the promise\n * satisfies it while the result inside is thrown away.\n *\n * Only results that can carry a failure count: an ignored Option or List loses no error. A chain that\n * handles its own failure with `.tapError(…)` or `.tapLeft(…)` isn't reported: that is a best-effort\n * write that logs a failure on purpose, as in agent-todo's audit and cleanup writes. `void result`\n * marks any other deliberate drop. An `IO` that is never run is no-floating-io's.\n *\n * Type-aware only: without type information it reports nothing.\n */\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Disallow dropping an Either, Try or other result that can carry a failure\",\n recommended: false,\n },\n schema: [],\n messages: {\n floatingResult:\n \"This result is dropped, so a failure in it is silently ignored. Check isLeft() / isFailure(), fold it, or return it. Use void if dropping it is deliberate\",\n },\n },\n\n create(context) {\n return {\n ExpressionStatement(node: ASTNode) {\n const expression = node.expression as ASTNode\n // `void result` is a UnaryExpression, so a deliberate drop never gets this far.\n if (!CHECKED.has(expression.type) || handlesItsFailure(expression)) return\n if (canCarryFailureByType(expression, context))\n context.report({ node: expression, messageId: \"floatingResult\" })\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,+DAMA,MAAMA,kBAA+B,IAAI,IAAI,CAC3C,iBACA,kBACA,kBACA,oBACA,uBACF,CAAC,EAGKC,kBAAwC,IAAI,IAAI,CAAC,WAAY,SAAS,CAAC,EAGvEC,kBAAuC,IAAI,IAAI,CAAC,UAAW,QAAS,UAAW,eAAgB,QAAQ,CAAC,EAOxGC,EAAqB,GAAuC,CAChE,GAAI,CAACC,EAAM,MAAO,GAClB,GAAIA,EAAK,OAAS,kBAAmB,OAAOD,EAAkBC,EAAK,QAAmB,EACtF,GAAIA,EAAK,OAAS,kBAAmB,OAAOD,EAAkBC,EAAK,UAAqB,EACxF,GAAIA,EAAK,OAAS,iBAAkB,MAAO,GAC3C,IAAMC,EAASD,EAAK,OACpB,GAAIC,EAAO,OAAS,mBAAoB,MAAO,GAC/C,IAAMC,EAAWD,EAAO,SAClBE,EAAOD,EAAS,OAAS,aAAgBA,EAAS,KAAkB,GAG1E,OAFIL,EAAiB,IAAIM,CAAI,EAAU,GACvC,CAAIL,EAAgB,IAAIK,CAAI,GACrBJ,EAAkBE,EAAO,MAAiB,CACnD,EAeMG,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,4EACb,YAAa,EACf,EACA,OAAQ,CAAC,EACT,SAAU,CACR,eACE,4JACJ,CACF,EAEA,OAAO,EAAS,CACd,MAAO,CACL,oBAAoB,EAAe,CACjC,IAAMC,EAAaL,EAAK,WAEnBJ,EAAQ,IAAIS,EAAW,IAAI,GAAK,GAAkBA,CAAU,GAC7DC,EAAsBD,EAAYE,CAAO,GAC3CA,EAAQ,OAAO,CAAE,KAAMF,EAAY,UAAW,gBAAiB,CAAC,CACpE,CACF,CACF,CACF,E"}
1
+ {"version":3,"file":"no-floating-result.js","names":["canCarryFailureByType","CHECKED","FAILURE_HANDLERS","FAILURE_SOURCES","handlesItsFailure","node","callee","property","name","rule","context","expression"],"sources":["../../src/rules/no-floating-result.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { canCarryFailureByType } from \"../utils/type-aware\"\n\n/** `f()`, `a?.f()`, `await …`, and `ok && f()` / `ok ? f() : g()`: statements whose only job is a value. */\nconst CHECKED: ReadonlySet<string> = new Set([\n \"CallExpression\",\n \"ChainExpression\",\n \"AwaitExpression\",\n \"LogicalExpression\",\n \"ConditionalExpression\",\n])\n\n/** Methods that run a callback on the failure, so a chain through one has handled it. */\nconst FAILURE_HANDLERS: ReadonlySet<string> = new Set([\"tapError\", \"tapLeft\"])\n\n/** Methods that can bring in a new failure, so a handler before one no longer covers the result. */\nconst FAILURE_SOURCES: ReadonlySet<string> = new Set([\"flatMap\", \"chain\", \"andThen\", \"flatMapError\", \"orElse\"])\n\n/**\n * Does the call chain in `node` handle its own failure? Walks the receiver chain from the outermost\n * call in: a `.tapError(…)` or `.tapLeft(…)` counts, unless a later `.flatMap(…)` can bring in a new,\n * unlogged failure. Arguments are never walked into.\n */\nconst handlesItsFailure = (node: ASTNode | undefined): boolean => {\n if (!node) return false\n if (node.type === \"AwaitExpression\") return handlesItsFailure(node.argument as ASTNode)\n if (node.type === \"ChainExpression\") return handlesItsFailure(node.expression as ASTNode)\n if (node.type !== \"CallExpression\") return false\n const callee = node.callee as ASTNode\n if (callee.type !== \"MemberExpression\") return false\n const property = callee.property as ASTNode\n const name = property.type === \"Identifier\" ? (property.name as string) : \"\"\n if (FAILURE_HANDLERS.has(name)) return true\n if (FAILURE_SOURCES.has(name)) return false\n return handlesItsFailure(callee.object as ASTNode)\n}\n\n/**\n * Reports a statement that computes an Either, Try or other failure-carrying result and drops it:\n * `await userService.updateSubscription(id, plan)` on its own line, or `parse(input)`. A Left or a\n * Failure in it is silently ignored. `no-floating-promises` doesn't help, because awaiting the promise\n * satisfies it while the result inside is thrown away.\n *\n * Only results that can carry a failure count: an ignored Option or List loses no error. A chain that\n * handles its own failure with `.tapError(…)` or `.tapLeft(…)` isn't reported: that is a best-effort\n * write that logs a failure on purpose, as in agent-todo's audit and cleanup writes. `void result`\n * marks any other deliberate drop. An `IO` that is never run is no-floating-io's.\n *\n * Type-aware only: without type information it reports nothing.\n */\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Disallow dropping an Either, Try or other result that can carry a failure\",\n recommended: false,\n },\n schema: [],\n messages: {\n floatingResult:\n \"This result is dropped, so a failure in it is silently ignored. Check isLeft() / isFailure(), fold it, or return it. Use void if dropping it is deliberate\",\n },\n },\n\n create(context) {\n return {\n ExpressionStatement(node: ASTNode) {\n const expression = node.expression as ASTNode\n // `void result` is a UnaryExpression, so a deliberate drop never gets this far.\n if (!CHECKED.has(expression.type) || handlesItsFailure(expression)) return\n if (canCarryFailureByType(expression, context))\n context.report({ node: expression, messageId: \"floatingResult\" })\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,+DAMA,MAAMC,kBAA+B,IAAI,IAAI,CAC3C,iBACA,kBACA,kBACA,oBACA,uBACF,CAAC,EAGKC,kBAAwC,IAAI,IAAI,CAAC,WAAY,SAAS,CAAC,EAGvEC,kBAAuC,IAAI,IAAI,CAAC,UAAW,QAAS,UAAW,eAAgB,QAAQ,CAAC,EAOxGC,EAAqBC,GAAuC,CAChE,GAAI,CAACA,EAAM,MAAO,GAClB,GAAIA,EAAK,OAAS,kBAAmB,OAAOD,EAAkBC,EAAK,QAAmB,EACtF,GAAIA,EAAK,OAAS,kBAAmB,OAAOD,EAAkBC,EAAK,UAAqB,EACxF,GAAIA,EAAK,OAAS,iBAAkB,MAAO,GAC3C,IAAMC,EAASD,EAAK,OACpB,GAAIC,EAAO,OAAS,mBAAoB,MAAO,GAC/C,IAAMC,EAAWD,EAAO,SAClBE,EAAOD,EAAS,OAAS,aAAgBA,EAAS,KAAkB,GAG1E,OAFIL,EAAiB,IAAIM,CAAI,EAAU,GACvC,CAAIL,EAAgB,IAAIK,CAAI,GACrBJ,EAAkBE,EAAO,MAAiB,CACnD,EAeMG,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,4EACb,YAAa,EACf,EACA,OAAQ,CAAC,EACT,SAAU,CACR,eACE,4JACJ,CACF,EAEA,OAAOC,EAAS,CACd,MAAO,CACL,oBAAoBL,EAAe,CACjC,IAAMM,EAAaN,EAAK,WAEnBJ,EAAQ,IAAIU,EAAW,IAAI,GAAKP,GAAkBO,CAAU,GAC7DX,EAAsBW,EAAYD,CAAO,GAC3CA,EAAQ,OAAO,CAAE,KAAMC,EAAY,UAAW,gBAAiB,CAAC,CACpE,CACF,CACF,CACF,E"}
@@ -1 +1 @@
1
- {"version":3,"file":"no-get-unsafe.js","names":["DEFAULT_UNSAFE_METHODS","rule","options","context","allowInTests","unsafeMethods","allowInteropMarker","isChosenErrorThrow","methodName","node","isInTestFile","filename","isMonadicType","text","varName","property","isInsideTaggedDeclaration","isExtractableByType","sourceCode","objectText","argsText","a","wasSuffix","fixer"],"sources":["../../src/rules/no-get-unsafe.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { INTEROP_TAG, isInsideTaggedDeclaration } from \"../utils/boundary-tags\"\nimport { isExtractableByType } from \"../utils/type-aware\"\n\nconst DEFAULT_UNSAFE_METHODS: readonly string[] = [\"orThrow\", \"expect\", \"get\", \"getOrThrow\", \"unwrap\"]\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Avoid unsafe extractor calls on Option, Either, and other Extractable types\",\n recommended: true,\n },\n hasSuggestions: true,\n schema: [\n {\n type: \"object\",\n properties: {\n allowInTests: {\n type: \"boolean\",\n default: true,\n },\n allowInteropMarker: {\n type: \"boolean\",\n default: true,\n },\n unsafeMethods: {\n type: \"array\",\n items: { type: \"string\" },\n default: [...DEFAULT_UNSAFE_METHODS],\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n noUnsafeGet:\n \"Avoid unsafe .{{method}}() call: it throws a generic error. Use .fold(), .map(), or .getOrElse(() => default) instead. If a host needs the throw, name the error: .orThrow((e) => new MyError(e))\",\n suggestGetOrElse: \"Replace with .getOrElse(() => default) for a value fallback\",\n suggestFold: \"Replace with .fold(onNone, onSome) for branch handling\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n const allowInTests = options.allowInTests !== false\n const unsafeMethods: readonly string[] = options.unsafeMethods || DEFAULT_UNSAFE_METHODS\n // `@interop <reason>` on an enclosing declaration marks a host-contract boundary, as in prefer-either.\n const allowInteropMarker = options.allowInteropMarker !== false\n\n /**\n * `.orThrow(error)` / `.orThrow((e) => error)`: the caller chose the error. That is the documented way\n * to throw for a host that needs it, not an unsafe extraction; `prefer-either` and the README's\n * decision table both treat it that way. Only a bare `.orThrow()` throws a generic error.\n */\n const isChosenErrorThrow = (methodName: string, node: ASTNode): boolean =>\n methodName === \"orThrow\" && node.arguments.length > 0\n\n function isInTestFile() {\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\n function isMonadicType(node: ASTNode): boolean {\n // This is a simplified check - in a real implementation, you'd want\n // more sophisticated type checking using TypeScript's type checker\n if (!node) return false\n\n const sourceCode = context.sourceCode\n\n // Check for common patterns that indicate monadic types\n const text = sourceCode.getText(node)\n\n // Direct type checks - constructors or type names\n if (/\\b(Option|Either|Maybe|Result|Some|None|Left|Right)\\b/.test(text)) {\n return true\n }\n\n // Method chains that suggest monadic operations\n if (/\\.(map|flatMap|filter|fold)\\s*\\(/.test(text)) {\n return true\n }\n\n // Variable names that suggest monadic types (case insensitive)\n if (/\\b(option|either|maybe|result|some|none|left|right)\\w*\\b/i.test(text)) {\n return true\n }\n\n // Check the specific node type and name\n if (node.type === \"Identifier\") {\n const varName = node.name.toLowerCase()\n if (/(option|either|maybe|result|some|none|left|right|opt)/.test(varName)) {\n return true\n }\n }\n\n // Check for CallExpression pattern like Some(\"test\").map()\n if (node.type === \"CallExpression\" && node.callee.type === \"MemberExpression\" && node.callee.object) {\n return isMonadicType(node.callee.object)\n }\n\n return false\n }\n\n return {\n CallExpression(node: ASTNode) {\n if (allowInTests && isInTestFile()) return\n\n if (node.callee.type !== \"MemberExpression\") return\n\n const property = node.callee.property\n if (!property || property.type !== \"Identifier\") return\n\n const methodName = property.name\n if (!unsafeMethods.includes(methodName)) return\n if (isChosenErrorThrow(methodName, node)) return\n if (allowInteropMarker && isInsideTaggedDeclaration(node, INTEROP_TAG, context.sourceCode)) return\n\n // With type information, the receiver's type decides: no name guessing, so `missing.orThrow()`\n // on an Option is reported and `options.get(\"k\")` on a native Map is not. Without it, fall\n // back to the name/shape heuristic.\n const byType = isExtractableByType(node.callee.object, context)\n if (byType ?? isMonadicType(node.callee.object)) {\n const sourceCode = context.sourceCode\n const objectText = sourceCode.getText(node.callee.object)\n\n // Preserve the original call's argument text in the TODO comment so a suggestion\n // applied to `.expect(\"Should have a user here\")` or `.orThrow(new NotFound())`\n // doesn't silently drop information the developer intended to keep. Omit the\n // \"was\" suffix when the original call had no args (`.get()`, `.unwrap()`, etc.).\n const argsText = node.arguments.map((a: ASTNode) => sourceCode.getText(a)).join(\", \")\n const wasSuffix = argsText ? `; was ${methodName}(${argsText})` : \"\"\n\n context.report({\n node,\n messageId: \"noUnsafeGet\",\n data: { method: methodName },\n suggest: [\n {\n messageId: \"suggestGetOrElse\",\n fix(fixer) {\n return fixer.replaceText(\n node,\n `${objectText}.getOrElse(() => undefined /* TODO: default${wasSuffix} */)`,\n )\n },\n },\n {\n messageId: \"suggestFold\",\n fix(fixer) {\n return fixer.replaceText(\n node,\n `${objectText}.fold(() => undefined /* TODO: onNone${wasSuffix} */, (v) => v /* TODO: onSome */)`,\n )\n },\n },\n ],\n })\n }\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,mIAMA,MAAMA,EAA4C,CAAC,UAAW,SAAU,MAAO,aAAc,QAAQ,EAE/FC,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,8EACb,YAAa,EACf,EACA,eAAgB,GAChB,OAAQ,CACN,CACE,KAAM,SACN,WAAY,CACV,aAAc,CACZ,KAAM,UACN,QAAS,EACX,EACA,mBAAoB,CAClB,KAAM,UACN,QAAS,EACX,EACA,cAAe,CACb,KAAM,QACN,MAAO,CA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C,CAAI,GACnC,KAAsBO,EAA0BP,EAAA,UAAmBN,EAAQ,UAAU,KAK1Ec,EAAoBR,EAAK,OAAO,OAAQN,CAC9C,GAAKS,EAAcH,EAAK,OAAO,MAAM,GAAG,CAC/C,IAAMS,EAAaf,EAAQ,WACrBgB,EAAaD,EAAW,QAAQT,EAAK,OAAO,MAAM,EAMlDW,EAAWX,EAAK,UAAU,IAAK,GAAeS,EAAW,QAAQG,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAC9EC,EAAYF,EAAW,SAASZ,EAAW,GAAGY,EAAS,GAAK,GAElEjB,EAAQ,OAAO,CACb,OACA,UAAW,cACX,KAAM,CAAE,OAAQK,CAAW,EAC3B,QAAS,CACP,CACE,UAAW,mBACX,IAAI,EAAO,CACT,OAAOe,EAAM,YACXd,EACA,GAAGU,EAAW,6CAA6CG,EAAU,KACvE,CACF,CACF,EACA,CACE,UAAW,cACX,IAAI,EAAO,CACT,OAAOC,EAAM,YACXd,EACA,GAAGU,EAAW,uCAAuCG,EAAU,kCACjE,CACF,CACF,CACF,CACF,CAAC,CACH,CACF,CACF,CACF,CACF,E"}
1
+ {"version":3,"file":"no-get-unsafe.js","names":["isInsideTaggedDeclaration","isExtractableByType","DEFAULT_UNSAFE_METHODS","rule","context","options","allowInTests","unsafeMethods","allowInteropMarker","isChosenErrorThrow","methodName","node","isInTestFile","filename","isMonadicType","text","varName","property","sourceCode","objectText","argsText","a","wasSuffix","fixer"],"sources":["../../src/rules/no-get-unsafe.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { INTEROP_TAG, isInsideTaggedDeclaration } from \"../utils/boundary-tags\"\nimport { isExtractableByType } from \"../utils/type-aware\"\n\nconst DEFAULT_UNSAFE_METHODS: readonly string[] = [\"orThrow\", \"expect\", \"get\", \"getOrThrow\", \"unwrap\"]\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Avoid unsafe extractor calls on Option, Either, and other Extractable types\",\n recommended: true,\n },\n hasSuggestions: true,\n schema: [\n {\n type: \"object\",\n properties: {\n allowInTests: {\n type: \"boolean\",\n default: true,\n },\n allowInteropMarker: {\n type: \"boolean\",\n default: true,\n },\n unsafeMethods: {\n type: \"array\",\n items: { type: \"string\" },\n default: [...DEFAULT_UNSAFE_METHODS],\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n noUnsafeGet:\n \"Avoid unsafe .{{method}}() call: it throws a generic error. Use .fold(), .map(), or .getOrElse(() => default) instead. If a host needs the throw, name the error: .orThrow((e) => new MyError(e))\",\n suggestGetOrElse: \"Replace with .getOrElse(() => default) for a value fallback\",\n suggestFold: \"Replace with .fold(onNone, onSome) for branch handling\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n const allowInTests = options.allowInTests !== false\n const unsafeMethods: readonly string[] = options.unsafeMethods || DEFAULT_UNSAFE_METHODS\n // `@interop <reason>` on an enclosing declaration marks a host-contract boundary, as in prefer-either.\n const allowInteropMarker = options.allowInteropMarker !== false\n\n /**\n * `.orThrow(error)` / `.orThrow((e) => error)`: the caller chose the error. That is the documented way\n * to throw for a host that needs it, not an unsafe extraction; `prefer-either` and the README's\n * decision table both treat it that way. Only a bare `.orThrow()` throws a generic error.\n */\n const isChosenErrorThrow = (methodName: string, node: ASTNode): boolean =>\n methodName === \"orThrow\" && node.arguments.length > 0\n\n function isInTestFile() {\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\n function isMonadicType(node: ASTNode): boolean {\n // This is a simplified check - in a real implementation, you'd want\n // more sophisticated type checking using TypeScript's type checker\n if (!node) return false\n\n const sourceCode = context.sourceCode\n\n // Check for common patterns that indicate monadic types\n const text = sourceCode.getText(node)\n\n // Direct type checks - constructors or type names\n if (/\\b(Option|Either|Maybe|Result|Some|None|Left|Right)\\b/.test(text)) {\n return true\n }\n\n // Method chains that suggest monadic operations\n if (/\\.(map|flatMap|filter|fold)\\s*\\(/.test(text)) {\n return true\n }\n\n // Variable names that suggest monadic types (case insensitive)\n if (/\\b(option|either|maybe|result|some|none|left|right)\\w*\\b/i.test(text)) {\n return true\n }\n\n // Check the specific node type and name\n if (node.type === \"Identifier\") {\n const varName = node.name.toLowerCase()\n if (/(option|either|maybe|result|some|none|left|right|opt)/.test(varName)) {\n return true\n }\n }\n\n // Check for CallExpression pattern like Some(\"test\").map()\n if (node.type === \"CallExpression\" && node.callee.type === \"MemberExpression\" && node.callee.object) {\n return isMonadicType(node.callee.object)\n }\n\n return false\n }\n\n return {\n CallExpression(node: ASTNode) {\n if (allowInTests && isInTestFile()) return\n\n if (node.callee.type !== \"MemberExpression\") return\n\n const property = node.callee.property\n if (!property || property.type !== \"Identifier\") return\n\n const methodName = property.name\n if (!unsafeMethods.includes(methodName)) return\n if (isChosenErrorThrow(methodName, node)) return\n if (allowInteropMarker && isInsideTaggedDeclaration(node, INTEROP_TAG, context.sourceCode)) return\n\n // With type information, the receiver's type decides: no name guessing, so `missing.orThrow()`\n // on an Option is reported and `options.get(\"k\")` on a native Map is not. Without it, fall\n // back to the name/shape heuristic.\n const byType = isExtractableByType(node.callee.object, context)\n if (byType ?? isMonadicType(node.callee.object)) {\n const sourceCode = context.sourceCode\n const objectText = sourceCode.getText(node.callee.object)\n\n // Preserve the original call's argument text in the TODO comment so a suggestion\n // applied to `.expect(\"Should have a user here\")` or `.orThrow(new NotFound())`\n // doesn't silently drop information the developer intended to keep. Omit the\n // \"was\" suffix when the original call had no args (`.get()`, `.unwrap()`, etc.).\n const argsText = node.arguments.map((a: ASTNode) => sourceCode.getText(a)).join(\", \")\n const wasSuffix = argsText ? `; was ${methodName}(${argsText})` : \"\"\n\n context.report({\n node,\n messageId: \"noUnsafeGet\",\n data: { method: methodName },\n suggest: [\n {\n messageId: \"suggestGetOrElse\",\n fix(fixer) {\n return fixer.replaceText(\n node,\n `${objectText}.getOrElse(() => undefined /* TODO: default${wasSuffix} */)`,\n )\n },\n },\n {\n messageId: \"suggestFold\",\n fix(fixer) {\n return fixer.replaceText(\n node,\n `${objectText}.fold(() => undefined /* TODO: onNone${wasSuffix} */, (v) => v /* TODO: onSome */)`,\n )\n },\n },\n ],\n })\n }\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,mIAMA,MAAME,EAA4C,CAAC,UAAW,SAAU,MAAO,aAAc,QAAQ,EAE/FC,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,8EACb,YAAa,EACf,EACA,eAAgB,GAChB,OAAQ,CACN,CACE,KAAM,SACN,WAAY,CACV,aAAc,CACZ,KAAM,UACN,QAAS,EACX,EACA,mBAAoB,CAClB,KAAM,UACN,QAAS,EACX,EACA,cAAe,CACb,KAAM,QACN,MAAO,CAAE,KAAM,QAAS,EACxB,QAAS,CAAC,GAAGD,CAAsB,CACrC,CACF,EACA,qBAAsB,EACxB,CACF,EACA,SAAU,CACR,YACE,oMACF,iBAAkB,8DAClB,YAAa,wDACf,CACF,EAEA,OAAOE,EAAS,CACd,IAAMC,EAAUD,EAAQ,QAAQ,IAAM,CAAC,EACjCE,EAAeD,EAAQ,eAAiB,GACxCE,EAAmCF,EAAQ,eAAiBH,EAE5DM,EAAqBH,EAAQ,qBAAuB,GAOpDI,GAAsBC,EAAoBC,IAC9CD,IAAe,WAAaC,EAAK,UAAU,OAAS,EAEtD,SAASC,GAAe,CACtB,IAAMC,EAAWT,EAAQ,SACzB,MACE,kCAAkC,KAAKS,CAAQ,GAC/CA,EAAS,SAAS,WAAW,GAC7BA,EAAS,SAAS,QAAQ,GAC1BA,EAAS,SAAS,SAAS,CAE/B,CAEA,SAASC,EAAcH,EAAwB,CAG7C,GAAI,CAACA,EAAM,MAAO,GAKlB,IAAMI,EAHaX,EAAQ,WAGH,QAAQO,CAAI,EAapC,GAVI,wDAAwD,KAAKI,CAAI,GAKjE,m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AC,CACH,CACF,CACF,CACF,CACF,E"}
@@ -1 +1 @@
1
- {"version":3,"file":"no-getOrThrow-in-render.js","names":["THROWING_METHODS","exits","statement","continuesWithValue","provesWhen","receiverText","sourceCode","call","isGuarded","present","test","outcome","walk","node","stop","branch","child","rule","allowInteropMarker","context","callee","method","fn","enclosingFunction","renderKind","isExtractableByType","compact","isInsideTaggedDeclaration"],"sources":["../../src/rules/no-getOrThrow-in-render.ts"],"sourcesContent":["import type { Rule, SourceCode } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { INTEROP_TAG, isInsideTaggedDeclaration } from \"../utils/boundary-tags\"\nimport { compact, provesWhen } from \"../utils/functype-predicates\"\nimport { enclosingFunction, renderKind } from \"../utils/react-render\"\nimport { isExtractableByType } from \"../utils/type-aware\"\n\n/**\n * The extractors that throw a generic error when the value is missing. `orThrow` is the one functype's\n * containers carry; `getOrThrow` is its older name, which the rule is named after. Each is reported only\n * bare: `orThrow(error)` names the error, the way to send a failure to an error boundary on purpose.\n * `expect(handler)` is never reported, because its handler is the chosen throw.\n */\nconst THROWING_METHODS: ReadonlySet<string> = new Set([\"orThrow\", \"getOrThrow\"])\n\n/** A statement that leaves the function: `return …`, `throw …`, or a block that ends in one. */\nconst exits = (statement: ASTNode): boolean =>\n statement.type === \"ReturnStatement\" ||\n statement.type === \"ThrowStatement\" ||\n (statement.type === \"BlockStatement\" && statement.body.length > 0 && exits(statement.body.at(-1)))\n\n/**\n * Does `statement` only let control continue past it once the value is known to be there?\n *\n * - an early exit on the missing case: `if (!o.isSome()) return null`, `if (busy || o.isNone()) return <S />`,\n * `if (o.isEmpty) throw …`;\n * - an if / else-if chain whose every branch exits, except the way out that proves it:\n * `if (x) return <B />; else if (o.isNone()) return null`;\n * - `invariant(o.isSome(), \"…\")` from functype, which narrows the code after it.\n */\nconst continuesWithValue = (statement: ASTNode, receiverText: string, sourceCode: SourceCode): boolean => {\n if (statement.type === \"IfStatement\") {\n if (!exits(statement.consequent)) return false\n if (provesWhen(statement.test, false, receiverText, sourceCode) === \"present\") return true\n return statement.alternate ? continuesWithValue(statement.alternate, receiverText, sourceCode) : false\n }\n const call = statement.type === \"ExpressionStatement\" ? statement.expression : null\n return (\n call?.type === \"CallExpression\" &&\n call.callee.type === \"Identifier\" &&\n call.callee.name === \"invariant\" &&\n call.arguments.length > 0 &&\n provesWhen(call.arguments[0], true, receiverText, sourceCode) === \"present\"\n )\n}\n\n/**\n * Is the call inside a branch that already proved the value is there? `o.isSome() ? o.orThrow() : …`,\n * `!o.isSome() ? null : o.orThrow()`, `if (e.isRight()) return e.orThrow()`, `t.isSuccess() && t.orThrow()`,\n * or after a statement in an enclosing block that only continues once it is (`continuesWithValue`). Then\n * the call cannot throw.\n */\nconst isGuarded = (call: ASTNode, stop: ASTNode, receiverText: string, sourceCode: SourceCode): boolean => {\n const present = (test: ASTNode, outcome: boolean): boolean =>\n provesWhen(test, outcome, receiverText, sourceCode) === \"present\"\n\n const walk = (child: ASTNode, node: ASTNode | undefined): boolean => {\n if (!node || node === stop) return false\n const branch = node.type === \"IfStatement\" || node.type === \"ConditionalExpression\"\n if (branch && node.consequent === child && present(node.test, true)) return true\n if (branch && node.alternate === child && present(node.test, false)) return true\n if (node.type === \"LogicalExpression\" && node.right === child) {\n if (node.operator === \"&&\" && present(node.left, true)) return true\n if (node.operator === \"||\" && present(node.left, false)) return true\n }\n if (node.type === \"BlockStatement\") {\n const before = (node.body as ReadonlyArray<ASTNode>).slice(0, node.body.indexOf(child))\n if (before.some((statement) => continuesWithValue(statement, receiverText, sourceCode))) return true\n }\n return walk(node, node.parent)\n }\n return walk(call, call.parent)\n}\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Disallow a throwing extractor (.orThrow(), .getOrThrow()) in a React component or hook body\",\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 throwInRender:\n \"{{receiver}}.{{method}}() throws during render when the value is missing, and a throw in render unmounts the tree up to the nearest error boundary. Render both cases with .fold(…) or <MatchOption> / <MatchEither> / <MatchTry>, or read a fallback with .getOrElse(() => …). To reach an error boundary on purpose, name the error: .orThrow((e) => new MyError(e))\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n // `@interop <reason>` on an enclosing declaration marks a host contract, such as React's `use()`.\n const allowInteropMarker = options.allowInteropMarker !== false\n const sourceCode = context.sourceCode\n\n return {\n CallExpression(node: ASTNode) {\n const callee = node.callee as ASTNode\n if (callee.type !== \"MemberExpression\" || callee.computed || callee.property.type !== \"Identifier\") return\n const method = callee.property.name as string\n if (!THROWING_METHODS.has(method) || node.arguments.length > 0) return\n\n // Only the component's or hook's own body runs during render. An event handler, an effect or a\n // `.map` callback is a separate function, so a call there is not attributed to the render.\n const fn = enclosingFunction(node)\n if (!fn || renderKind(fn) === null) return\n\n // With type information the receiver must be a functype container (it has `orThrow` and `fold`);\n // without it, the method name decides — `orThrow()` is functype's own spelling.\n if (isExtractableByType(callee.object, context) === false) return\n const receiverText = compact(sourceCode.getText(callee.object))\n if (isGuarded(node, fn, receiverText, sourceCode)) return\n if (allowInteropMarker && isInsideTaggedDeclaration(node, INTEROP_TAG, sourceCode)) return\n\n context.report({\n node,\n messageId: \"throwInRender\",\n data: { receiver: sourceCode.getText(callee.object), method },\n })\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,0RAcA,MAAMA,kBAAwC,IAAI,IAAI,CAAC,UAAW,YAAY,CAAC,EAGzEC,EAAS,GACbC,EAAU,OAAS,mBACnBA,EAAU,OAAS,kBAClBA,EAAU,OAAS,kBAAoBA,EAAU,KAAK,OAAS,GAAKD,EAAMC,EAAU,KAAK,GAAG,EAAE,CAAC,EAW5FC,GAAsB,EAAoB,EAAsB,IAAoC,CACxG,GAAID,EAAU,OAAS,cAGrB,OAFKD,EAAMC,EAAU,UAAU,EAC3BE,EAAWF,EAAU,KAA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QAAS,EACX,CACF,EACA,qBAAsB,EACxB,CACF,EACA,SAAU,CACR,cACE,wWACJ,CACF,EAEA,OAAO,EAAS,CAGd,IAAMC,GAFUC,EAAQ,QAAQ,IAAM,CAAC,EAAA,CAEJ,qBAAuB,GACpDb,EAAaa,EAAQ,WAE3B,MAAO,CACL,eAAe,EAAe,CAC5B,IAAMC,EAASP,EAAK,OACpB,GAAIO,EAAO,OAAS,oBAAsBA,EAAO,UAAYA,EAAO,SAAS,OAAS,aAAc,OACpG,IAAMC,EAASD,EAAO,SAAS,KAC/B,GAAI,CAACpB,EAAiB,IAAIqB,CAAM,GAAKR,EAAK,UAAU,OAAS,EAAG,OAIhE,IAAMS,EAAKC,EAAkBV,CAAI,EAKjC,GAJI,CAACS,GAAME,EAAWF,CAAE,IAAM,MAI1BG,EAAoBL,EAAO,OAAQD,CAAO,IAAM,GAAO,OAC3D,IAAMd,EAAeqB,EAAQpB,EAAW,QAAQc,EAAO,MAAM,CAAC,EAC1DZ,EAAUK,EAAMS,EAAIjB,EAAcC,CAAU,GAC5CY,GAAsBS,EAA0Bd,EAAA,UAAmBP,CAAU,GAEjFa,EAAQ,OAAO,CACb,OACA,UAAW,gBACX,KAAM,CAAE,SAAUb,EAAW,QAAQc,EAAO,MAAM,EAAG,QAAO,CAC9D,CAAC,CACH,CACF,CACF,CACF,E"}
1
+ {"version":3,"file":"no-getOrThrow-in-render.js","names":["isInsideTaggedDeclaration","compact","provesWhen","enclosingFunction","renderKind","isExtractableByType","THROWING_METHODS","exits","statement","continuesWithValue","receiverText","sourceCode","call","isGuarded","stop","present","test","outcome","walk","child","node","branch","rule","context","allowInteropMarker","callee","method","fn"],"sources":["../../src/rules/no-getOrThrow-in-render.ts"],"sourcesContent":["import type { Rule, SourceCode } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { INTEROP_TAG, isInsideTaggedDeclaration } from \"../utils/boundary-tags\"\nimport { compact, provesWhen } from \"../utils/functype-predicates\"\nimport { enclosingFunction, renderKind } from \"../utils/react-render\"\nimport { isExtractableByType } from \"../utils/type-aware\"\n\n/**\n * The extractors that throw a generic error when the value is missing. `orThrow` is the one functype's\n * containers carry; `getOrThrow` is its older name, which the rule is named after. Each is reported only\n * bare: `orThrow(error)` names the error, the way to send a failure to an error boundary on purpose.\n * `expect(handler)` is never reported, because its handler is the chosen throw.\n */\nconst THROWING_METHODS: ReadonlySet<string> = new Set([\"orThrow\", \"getOrThrow\"])\n\n/** A statement that leaves the function: `return …`, `throw …`, or a block that ends in one. */\nconst exits = (statement: ASTNode): boolean =>\n statement.type === \"ReturnStatement\" ||\n statement.type === \"ThrowStatement\" ||\n (statement.type === \"BlockStatement\" && statement.body.length > 0 && exits(statement.body.at(-1)))\n\n/**\n * Does `statement` only let control continue past it once the value is known to be there?\n *\n * - an early exit on the missing case: `if (!o.isSome()) return null`, `if (busy || o.isNone()) return <S />`,\n * `if (o.isEmpty) throw …`;\n * - an if / else-if chain whose every branch exits, except the way out that proves it:\n * `if (x) return <B />; else if (o.isNone()) return null`;\n * - `invariant(o.isSome(), \"…\")` from functype, which narrows the code after it.\n */\nconst continuesWithValue = (statement: ASTNode, receiverText: string, sourceCode: SourceCode): boolean => {\n if (statement.type === \"IfStatement\") {\n if (!exits(statement.consequent)) return false\n if (provesWhen(statement.test, false, receiverText, sourceCode) === \"present\") return true\n return statement.alternate ? continuesWithValue(statement.alternate, receiverText, sourceCode) : false\n }\n const call = statement.type === \"ExpressionStatement\" ? statement.expression : null\n return (\n call?.type === \"CallExpression\" &&\n call.callee.type === \"Identifier\" &&\n call.callee.name === \"invariant\" &&\n call.arguments.length > 0 &&\n provesWhen(call.arguments[0], true, receiverText, sourceCode) === \"present\"\n )\n}\n\n/**\n * Is the call inside a branch that already proved the value is there? `o.isSome() ? o.orThrow() : …`,\n * `!o.isSome() ? null : o.orThrow()`, `if (e.isRight()) return e.orThrow()`, `t.isSuccess() && t.orThrow()`,\n * or after a statement in an enclosing block that only continues once it is (`continuesWithValue`). Then\n * the call cannot throw.\n */\nconst isGuarded = (call: ASTNode, stop: ASTNode, receiverText: string, sourceCode: SourceCode): boolean => {\n const present = (test: ASTNode, outcome: boolean): boolean =>\n provesWhen(test, outcome, receiverText, sourceCode) === \"present\"\n\n const walk = (child: ASTNode, node: ASTNode | undefined): boolean => {\n if (!node || node === stop) return false\n const branch = node.type === \"IfStatement\" || node.type === \"ConditionalExpression\"\n if (branch && node.consequent === child && present(node.test, true)) return true\n if (branch && node.alternate === child && present(node.test, false)) return true\n if (node.type === \"LogicalExpression\" && node.right === child) {\n if (node.operator === \"&&\" && present(node.left, true)) return true\n if (node.operator === \"||\" && present(node.left, false)) return true\n }\n if (node.type === \"BlockStatement\") {\n const before = (node.body as ReadonlyArray<ASTNode>).slice(0, node.body.indexOf(child))\n if (before.some((statement) => continuesWithValue(statement, receiverText, sourceCode))) return true\n }\n return walk(node, node.parent)\n }\n return walk(call, call.parent)\n}\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Disallow a throwing extractor (.orThrow(), .getOrThrow()) in a React component or hook body\",\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 throwInRender:\n \"{{receiver}}.{{method}}() throws during render when the value is missing, and a throw in render unmounts the tree up to the nearest error boundary. Render both cases with .fold(…) or <MatchOption> / <MatchEither> / <MatchTry>, or read a fallback with .getOrElse(() => …). To reach an error boundary on purpose, name the error: .orThrow((e) => new MyError(e))\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n // `@interop <reason>` on an enclosing declaration marks a host contract, such as React's `use()`.\n const allowInteropMarker = options.allowInteropMarker !== false\n const sourceCode = context.sourceCode\n\n return {\n CallExpression(node: ASTNode) {\n const callee = node.callee as ASTNode\n if (callee.type !== \"MemberExpression\" || callee.computed || callee.property.type !== \"Identifier\") return\n const method = callee.property.name as string\n if (!THROWING_METHODS.has(method) || node.arguments.length > 0) return\n\n // Only the component's or hook's own body runs during render. An event handler, an effect or a\n // `.map` callback is a separate function, so a call there is not attributed to the render.\n const fn = enclosingFunction(node)\n if (!fn || renderKind(fn) === null) return\n\n // With type information the receiver must be a functype container (it has `orThrow` and `fold`);\n // without it, the method name decides — `orThrow()` is functype's own spelling.\n if (isExtractableByType(callee.object, context) === false) return\n const receiverText = compact(sourceCode.getText(callee.object))\n if (isGuarded(node, fn, receiverText, sourceCode)) return\n if (allowInteropMarker && isInsideTaggedDeclaration(node, INTEROP_TAG, sourceCode)) return\n\n context.report({\n node,\n messageId: \"throwInRender\",\n data: { receiver: sourceCode.getText(callee.object), method },\n })\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,0RAcA,MAAMM,kBAAwC,IAAI,IAAI,CAAC,UAAW,YAAY,CAAC,EAGzEC,EAASC,GACbA,EAAU,OAAS,mBACnBA,EAAU,OAAS,kBAClBA,EAAU,OAAS,kBAAoBA,EAAU,KAAK,OAAS,GAAKD,EAAMC,EAAU,KAAK,GAAG,EAAE,CAAC,EAW5FC,GAAsBD,EAAoBE,EAAsBC,IAAoC,CACxG,GAAIH,EAAU,OAAS,cAGrB,OAFKD,EAAMC,EAAU,UAAU,EAC3BN,EAAWM,EAAU,KAAM,GAAOE,EAAcC,CAAU,IAAM,UAAkB,GAC/EH,EAAU,UAAYC,EAAmBD,EAAU,UAAWE,EAAcC,CAAU,EAAI,GAFxD,GAI3C,IAAMC,EAAOJ,EAAU,OAAS,sBAAwBA,EAAU,WAAa,KAC/E,OACEI,GAAM,OAAS,kBACfA,EAAK,OAAO,OAAS,cACrBA,EAAK,OAAO,OAAS,aACrBA,EAAK,UAAU,OAAS,GACxBV,EAAWU,EAAK,UAAU,GAAI,GAAMF,EAAcC,CAAU,IAAM,SAEtE,EAQME,GAAaD,EAAeE,EAAeJ,EAAsBC,IAAoC,CACzG,IAAMI,GAAWC,EAAeC,IAC9Bf,EAAWc,EAAMC,EAASP,EAAcC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