eslint-plugin-functype 2.120.0 → 2.121.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 (88) hide show
  1. package/README.md +107 -19
  2. package/dist/cli/list-rules.js.map +1 -1
  3. package/dist/configs/recommended.d.ts +8 -2
  4. package/dist/configs/recommended.js +1 -1
  5. package/dist/configs/recommended.js.map +1 -1
  6. package/dist/configs/strict.d.ts +2 -2
  7. package/dist/configs/strict.js +1 -1
  8. package/dist/configs/strict.js.map +1 -1
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.js.map +1 -1
  11. package/dist/rules/collection-naming.d.ts +0 -2
  12. package/dist/rules/collection-naming.js.map +1 -1
  13. package/dist/rules/index.d.ts +20 -18
  14. package/dist/rules/index.js +1 -1
  15. package/dist/rules/index.js.map +1 -1
  16. package/dist/rules/must-fold-on-component-return.d.ts +4 -0
  17. package/dist/rules/must-fold-on-component-return.js +2 -0
  18. package/dist/rules/must-fold-on-component-return.js.map +1 -0
  19. package/dist/rules/no-array-mutation.d.ts +0 -2
  20. package/dist/rules/no-array-mutation.js +1 -1
  21. package/dist/rules/no-array-mutation.js.map +1 -1
  22. package/dist/rules/no-floating-io.d.ts +0 -2
  23. package/dist/rules/no-floating-io.js.map +1 -1
  24. package/dist/rules/no-get-unsafe.d.ts +0 -2
  25. package/dist/rules/no-get-unsafe.js.map +1 -1
  26. package/dist/rules/no-getOrThrow-in-render.d.ts +4 -0
  27. package/dist/rules/no-getOrThrow-in-render.js +2 -0
  28. package/dist/rules/no-getOrThrow-in-render.js.map +1 -0
  29. package/dist/rules/no-imperative-loops.d.ts +0 -2
  30. package/dist/rules/no-imperative-loops.js +1 -1
  31. package/dist/rules/no-imperative-loops.js.map +1 -1
  32. package/dist/rules/no-let.d.ts +0 -2
  33. package/dist/rules/no-let.js.map +1 -1
  34. package/dist/rules/prefer-do-notation.d.ts +0 -2
  35. package/dist/rules/prefer-do-notation.js.map +1 -1
  36. package/dist/rules/prefer-either.d.ts +0 -2
  37. package/dist/rules/prefer-either.js.map +1 -1
  38. package/dist/rules/prefer-flatmap.d.ts +0 -2
  39. package/dist/rules/prefer-flatmap.js +1 -1
  40. package/dist/rules/prefer-flatmap.js.map +1 -1
  41. package/dist/rules/prefer-fold.d.ts +0 -2
  42. package/dist/rules/prefer-fold.js +1 -1
  43. package/dist/rules/prefer-fold.js.map +1 -1
  44. package/dist/rules/prefer-functype-map.d.ts +0 -2
  45. package/dist/rules/prefer-functype-map.js.map +1 -1
  46. package/dist/rules/prefer-functype-set.d.ts +0 -2
  47. package/dist/rules/prefer-functype-set.js.map +1 -1
  48. package/dist/rules/prefer-list.d.ts +0 -2
  49. package/dist/rules/prefer-list.js +2 -2
  50. package/dist/rules/prefer-list.js.map +1 -1
  51. package/dist/rules/prefer-map.d.ts +0 -2
  52. package/dist/rules/prefer-map.js.map +1 -1
  53. package/dist/rules/prefer-option.d.ts +0 -2
  54. package/dist/rules/prefer-option.js.map +1 -1
  55. package/dist/rules/prefer-try.d.ts +0 -2
  56. package/dist/rules/prefer-try.js.map +1 -1
  57. package/dist/types/ast.d.ts +0 -2
  58. package/dist/utils/array-mutation.d.ts +0 -2
  59. package/dist/utils/array-mutation.js.map +1 -1
  60. package/dist/utils/ast-walk.d.ts +0 -2
  61. package/dist/utils/ast-walk.js.map +1 -1
  62. package/dist/utils/async-detection.d.ts +0 -2
  63. package/dist/utils/async-detection.js.map +1 -1
  64. package/dist/utils/boundary-tags.d.ts +0 -2
  65. package/dist/utils/boundary-tags.js.map +1 -1
  66. package/dist/utils/collection-binding.d.ts +0 -2
  67. package/dist/utils/collection-binding.js.map +1 -1
  68. package/dist/utils/dependency-validator.d.ts +1 -2
  69. package/dist/utils/dependency-validator.js.map +1 -1
  70. package/dist/utils/functype-detection.d.ts +0 -2
  71. package/dist/utils/functype-detection.js.map +1 -1
  72. package/dist/utils/functype-predicates.d.ts +38 -0
  73. package/dist/utils/functype-predicates.js +2 -0
  74. package/dist/utils/functype-predicates.js.map +1 -0
  75. package/dist/utils/import-fixer.d.ts +0 -2
  76. package/dist/utils/import-fixer.js.map +1 -1
  77. package/dist/utils/mutable-collection.d.ts +0 -2
  78. package/dist/utils/mutable-collection.js.map +1 -1
  79. package/dist/utils/react-render.d.ts +13 -0
  80. package/dist/utils/react-render.js +2 -0
  81. package/dist/utils/react-render.js.map +1 -0
  82. package/dist/utils/readonly-contract.d.ts +0 -2
  83. package/dist/utils/readonly-contract.js.map +1 -1
  84. package/dist/utils/type-aware.d.ts +0 -2
  85. package/dist/utils/type-aware.js.map +1 -1
  86. package/dist/utils/wire-types.d.ts +0 -2
  87. package/dist/utils/wire-types.js.map +1 -1
  88. package/package.json +6 -6
package/README.md CHANGED
@@ -27,24 +27,26 @@ export default [functype.configs.strict]
27
27
 
28
28
  ## Rules
29
29
 
30
- | Rule | Recommended | Strict | Description |
31
- | ------------------------------ | :---------: | :----: | ---------------------------------------------------------------------------------------- |
32
- | `functype/no-let` | error | error | Use `const`; no reassignment |
33
- | `functype/no-imperative-loops` | error | error | Use `List`/array methods, async traversal or `IO.forEach` instead of loops |
34
- | `functype/prefer-functype-map` | error | error | Use functype `Map` instead of a native `Map` you only read |
35
- | `functype/prefer-functype-set` | error | error | Use functype `Set` instead of a native `Set` you only read |
36
- | `functype/collection-naming` | error | error | Import functype's `Map`/`Set` under their own names; spell the built-in `globalThis.Map` |
37
- | `functype/prefer-map` | error | error | Use `map` instead of pushing inside `forEach` |
38
- | `functype/prefer-fold` | error | error | Use `fold` instead of branching on `isSome()`/`isLeft()`/… |
39
- | `functype/prefer-option` | warn | error | Use `Option` instead of `null`/`undefined` |
40
- | `functype/prefer-either` | warn | error | Use `Either` for typed domain errors instead of `throw` |
41
- | `functype/prefer-try` | warn | error | Use `Try` / `Try.fromPromise` instead of try/catch |
42
- | `functype/prefer-flatmap` | warn | warn | Use `flatMap` instead of `map().flat()` |
43
- | `functype/prefer-do-notation` | warn | warn | Use `Do` notation for chained operations |
44
- | `functype/no-get-unsafe` | off | error | Disallow unsafe extraction (`.orThrow()`, `.expect()`) |
45
- | `functype/prefer-list` | off | warn | Use `List` instead of native arrays |
46
- | `functype/no-array-mutation` | off | error | Don't change an array in place (`push`, `sort`, `xs[i] = v`…); build a new one |
47
- | `functype/no-floating-io` | off | warn | Don't build an `IO` and drop it, or `await` it unrun; run, return or `yield*` it |
30
+ | Rule | Recommended | Strict | Description |
31
+ | ---------------------------------------- | :---------: | :----: | -------------------------------------------------------------------------------------------- |
32
+ | `functype/no-let` | error | error | Use `const`; no reassignment |
33
+ | `functype/no-imperative-loops` | error | error | Use `List`/array methods, async traversal or `IO.forEach` instead of loops |
34
+ | `functype/prefer-functype-map` | error | error | Use functype `Map` instead of a native `Map` you only read |
35
+ | `functype/prefer-functype-set` | error | error | Use functype `Set` instead of a native `Set` you only read |
36
+ | `functype/collection-naming` | error | error | Import functype's `Map`/`Set` under their own names; spell the built-in `globalThis.Map` |
37
+ | `functype/prefer-map` | error | error | Use `map` instead of pushing inside `forEach` |
38
+ | `functype/prefer-fold` | error | error | Use `fold` instead of branching on `isSome()`/`isLeft()`/… |
39
+ | `functype/prefer-option` | warn | error | Use `Option` instead of `null`/`undefined` |
40
+ | `functype/prefer-either` | warn | error | Use `Either` for typed domain errors instead of `throw` |
41
+ | `functype/prefer-try` | warn | error | Use `Try` / `Try.fromPromise` instead of try/catch |
42
+ | `functype/prefer-flatmap` | warn | warn | Use `flatMap` instead of `map().flat()` |
43
+ | `functype/prefer-do-notation` | warn | warn | Use `Do` notation for chained operations |
44
+ | `functype/no-get-unsafe` | off | error | Disallow unsafe extraction (`.orThrow()`, `.expect()`) |
45
+ | `functype/prefer-list` | off | warn | Use `List` instead of native arrays |
46
+ | `functype/no-array-mutation` | off | error | Don't change an array in place (`push`, `sort`, `xs[i] = v`…); build a new one |
47
+ | `functype/no-floating-io` | off | warn | Don't build an `IO` and drop it, or `await` it unrun; run, return or `yield*` it |
48
+ | `functype/no-getOrThrow-in-render` | off | warn | React: no bare `.orThrow()` in a component or hook body; a throw in render unmounts the tree |
49
+ | `functype/must-fold-on-component-return` | off | warn | React: render an `Option`/`Either`/`Try` with `fold` or `<MatchOption>`, not a guard or `&&` |
48
50
 
49
51
  ### Severity policy
50
52
 
@@ -83,7 +85,7 @@ const value = either.orThrow((left) => new StepError(left.message))
83
85
 
84
86
  `invariant()` covers one statement and narrows the condition for the code after it, so a function can mix bug checks with `Either`-returning failures. `@interop` rules:
85
87
 
86
- - **Scope:** the tagged declaration and everything nested in it. That can be a function, `const`, method, class field, object property, type alias or interface. A sibling declaration is not covered. Honored by `prefer-either`, `prefer-option`, `prefer-fold` and `prefer-try`.
88
+ - **Scope:** the tagged declaration and everything nested in it. That can be a function, `const`, method, class field, object property, type alias or interface. A sibling declaration is not covered. Honored by `prefer-either`, `prefer-option`, `prefer-fold`, `prefer-try`, `no-get-unsafe`, `no-getOrThrow-in-render` and `must-fold-on-component-return`.
87
89
  - **The reason is required**, on the same line as the tag. A bare `@interop` exempts nothing.
88
90
  - **Only JSDoc (`/** … */`) counts.** A `//` comment mentioning the tag does not.
89
91
  - **Opt out** per rule with `allowInteropMarker: false`.
@@ -196,6 +198,92 @@ void save(user) // fine: a deliberate drop
196
198
 
197
199
  Measured (2026-10-16) on functype's own source and tests, functype-log, functype-react, agent-todo's agent-gate-api and civala.ai's API: 0 false positives across about 1,340 IO-typed calls. The only hits were four deliberate drops in type-only tests. It's `off` in `recommended` and `warn` in `strict` while it is measured further.
198
200
 
201
+ ### React rules
202
+
203
+ Two rules are for React code. They fire only inside a **component** (a function named in PascalCase whose body has JSX, including one wrapped in `memo` or `forwardRef`) or a **hook** (a function named `use` + a capital letter), so other code rarely trips them. The one exception is a non-React function whose name starts with `use` + a capital letter, which is read as a hook. Both are `off` in `recommended` and `warn` in `strict` while they're measured on real React code. To turn them on with `recommended`:
204
+
205
+ ```js
206
+ import functype from "eslint-plugin-functype"
207
+
208
+ export default [
209
+ functype.configs.recommended,
210
+ {
211
+ files: ["**/*.tsx", "**/*.jsx"],
212
+ rules: {
213
+ "functype/no-getOrThrow-in-render": "error",
214
+ "functype/must-fold-on-component-return": "warn",
215
+ },
216
+ },
217
+ ]
218
+ ```
219
+
220
+ Both work without type information. With it (`parserOptions.projectService`), the receiver must also be a functype container, so an unrelated object that happens to have an `orThrow` or `isSome` method is not reported.
221
+
222
+ Only the component's or hook's own body counts as render. An event handler, an effect, or a callback passed to `.map` is a separate function, so a call there is not reported. That also means a call inside a callback that does run during render (`useMemo(() => …)`, `items.map((o) => o.orThrow())` in JSX) is missed: the rules prefer missing a case to reporting valid code.
223
+
224
+ ### `functype/no-getOrThrow-in-render`
225
+
226
+ Reports a bare `.orThrow()` (or the older `.getOrThrow()`) in a component or hook body. When the value is missing it throws during render, and React unmounts the tree up to the nearest error boundary.
227
+
228
+ ```tsx
229
+ function Profile({ user }: { user: Option<User> }) {
230
+ const u = user.orThrow() // reported → user.fold(() => <SignIn />, (u) => <Card user={u} />)
231
+ return <Card user={u} />
232
+ }
233
+
234
+ user.isSome() ? <Card user={user.orThrow()} /> : null // fine: guarded, it can't throw
235
+ if (user.isNone()) return null // …and every later user.orThrow() in this body is guarded too
236
+ const u = user.orThrow((e) => new NotFound(e)) // fine: a named error, sent to the error boundary on purpose
237
+ <button onClick={() => save(user.orThrow())} /> // fine: an event handler runs after render
238
+ ```
239
+
240
+ A call is guarded when its test proves the value is there on the same receiver:
241
+
242
+ - it sits in the branch of an `if`, a ternary, an `&&` or an `||` that only runs once the value is there: `user.isSome() ? … : …`, `!user.isSome() ? null : …`, `busy && user.isSome() ? … : …`, `user.isNone() || …`;
243
+ - it comes after a statement that only lets control past once the value is there: an early `return` / `throw` on the missing case (`if (!user.isSome()) return null`, `if (busy || user.isNone()) return <Spinner />`, `if (user.isEmpty) return null`), an if / else-if chain whose branches all exit, or `invariant(user.isSome(), "…")`.
244
+
245
+ The test can be `isSome()` / `isRight()` / `isSuccess()`, their opposites, `isEmpty`, and `!`, `&&` and `||` over them. `.expect(handler)` is not reported, because its handler is the chosen throw. The rule is named after `getOrThrow`, the method's older name; functype's containers spell it `orThrow`.
246
+
247
+ | Option | Default | Description |
248
+ | -------------------- | :-----: | ----------------------------------------------------------- |
249
+ | `allowInteropMarker` | `true` | Skip calls inside a declaration tagged `@interop <reason>`. |
250
+
251
+ `no-get-unsafe` reports the same calls anywhere. This rule is narrower and more confident: it reports only where the throw lands in render.
252
+
253
+ ### `functype/must-fold-on-component-return`
254
+
255
+ Reports a component that chooses what it renders by asking an `Option`, `Either` or `Try` which case it holds, in the two shapes `prefer-fold` doesn't report at its default options:
256
+
257
+ - an **early return**: `if (user.isNone()) return <SignIn />` (or `return null`, `if (!user.isSome())`, `if (busy || user.isNone())`), with the other case rendered below it;
258
+ - a **short-circuit**: `{user.isSome() && <Card />}`, which renders one case and silently drops the other.
259
+
260
+ ```tsx
261
+ function Profile({ user }: { user: Option<User> }) {
262
+ if (user.isNone()) return <SignIn /> // reported
263
+ return <Card user={user.orThrow()} />
264
+ }
265
+
266
+ // → one expression for both cases:
267
+ return user.fold(
268
+ () => <SignIn />,
269
+ (u) => <Card user={u} />,
270
+ )
271
+ // → or, from functype-react:
272
+ return <MatchOption value={user} Some={(u) => <Card user={u} />} None={() => <SignIn />} />
273
+
274
+ const header = <h1>{user.isSome() && <Badge />}</h1> // reported → {user.fold(() => null, () => <Badge />)}
275
+ ```
276
+
277
+ The message names the `Match` component that fits: `<MatchOption>` for `isSome`/`isNone`, `<MatchEither>` for `isLeft`/`isRight`, `<MatchTry>` for `isSuccess`/`isFailure`.
278
+
279
+ A ternary or an if/else on a predicate is `prefer-fold`'s, everywhere, so this rule leaves it alone rather than report it twice. If you turn on `prefer-fold`'s `checkGuards`, an early return followed by an unwrap is reported by both rules. Only a predicate _call_ counts: `state.isPending` on a `useIO` result and `items.isEmpty` are properties, and are never reported. A guard that does other work before it returns, or returns something other than JSX or `null`, is not reported either. The rule reports only; there are no suggestions, because the rewrite moves code between branches.
280
+
281
+ | Option | Default | Description |
282
+ | -------------------- | :-----: | ---------------------------------------------------------- |
283
+ | `allowInteropMarker` | `true` | Skip code inside a declaration tagged `@interop <reason>`. |
284
+
285
+ Measured (2026-10-25) with both rules on functype-react's source and tests (type-aware), and on agent-todo, mnemons and civala.ai (1,403 files, without type information): no reports. None of that code uses these shapes in a component, and `useIOValue`'s `exit.orThrow()` is guarded by `exit.isSuccess()`, so the measurement shows the false-positive rate, not the hit rate.
286
+
199
287
  ### `functype/no-get-unsafe`
200
288
 
201
289
  | Option | Default | Description |
@@ -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":";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,GAAQ,CAC9B,IAAMC,EAAOC,EAAI,SAAW,MAAQ,KAC9BL,EAAQK,EAAI,SAAW,MAAQ,SACrC,QAAQ,IAAI,KAAKD,EAAK,GAAGL,EAASM,EAAI,KAAML,CAAK,EAAE,KAAKK,EAAI,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DAA6D,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"}
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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ule is `error` once it is right on ~95–99% of real code and its known
4
3
  * false-positive classes are closed; it stays `warn` only while those classes are still open. FP here
@@ -26,6 +25,12 @@
26
25
  * no-floating-io (1.17) is off here and `warn` in strict while it is measured: 0 false positives across
27
26
  * ~1,340 IO-typed calls in five codebases, but no real hits yet either. 2.0 decides `recommended` after
28
27
  * measuring it against functype-os, whose async methods return IO there. Type-aware, like no-array-mutation.
28
+ *
29
+ * no-getOrThrow-in-render and must-fold-on-component-return are React rules: they fire only inside a
30
+ * component (a PascalCase function with JSX) or a hook (`use*`), so non-React code rarely trips them (a
31
+ * non-React function named `use*` is read as a hook). Both are new and unmeasured on real React code, so
32
+ * they start where no-floating-io did: off here, `warn` in strict. They work without type information and
33
+ * are more precise with it.
29
34
  */
30
35
  declare const recommendedRules: {
31
36
  "functype/no-let": string;
@@ -44,7 +49,8 @@ declare const recommendedRules: {
44
49
  "functype/prefer-list": string;
45
50
  "functype/no-array-mutation": string;
46
51
  "functype/no-floating-io": string;
52
+ "functype/no-getOrThrow-in-render": string;
53
+ "functype/must-fold-on-component-return": string;
47
54
  };
48
- //#endregion
49
55
  export { recommendedRules as default };
50
56
  //# sourceMappingURL=recommended.d.ts.map
@@ -1,2 +1,2 @@
1
- const e={"functype/no-let":`error`,"functype/no-imperative-loops":`error`,"functype/prefer-functype-map":`error`,"functype/prefer-functype-set":`error`,"functype/prefer-map":`error`,"functype/prefer-fold":`error`,"functype/collection-naming":`error`,"functype/prefer-option":`warn`,"functype/prefer-either":`warn`,"functype/prefer-try":`warn`,"functype/prefer-flatmap":`warn`,"functype/prefer-do-notation":`warn`,"functype/no-get-unsafe":`off`,"functype/prefer-list":`off`,"functype/no-array-mutation":`off`,"functype/no-floating-io":`off`};export{e as default};
1
+ const e={"functype/no-let":`error`,"functype/no-imperative-loops":`error`,"functype/prefer-functype-map":`error`,"functype/prefer-functype-set":`error`,"functype/prefer-map":`error`,"functype/prefer-fold":`error`,"functype/collection-naming":`error`,"functype/prefer-option":`warn`,"functype/prefer-either":`warn`,"functype/prefer-try":`warn`,"functype/prefer-flatmap":`warn`,"functype/prefer-do-notation":`warn`,"functype/no-get-unsafe":`off`,"functype/prefer-list":`off`,"functype/no-array-mutation":`off`,"functype/no-floating-io":`off`,"functype/no-getOrThrow-in-render":`off`,"functype/must-fold-on-component-return":`off`};export{e as default};
2
2
  //# sourceMappingURL=recommended.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"recommended.js","names":["recommendedRules"],"sources":["../../src/configs/recommended.ts"],"sourcesContent":["/**\n * Severity policy (#325): a rule is `error` once it is right on ~95–99% of real code and its known\n * false-positive classes are closed; it stays `warn` only while those classes are still open. FP here\n * is governance — a rule that is reliably right should fail the build, not print advice nobody reads\n * (CivalaOS shipped 85 new violations under \"lint OK\" because every rule but `no-let` warned).\n *\n * Still `warn`, and why:\n * - prefer-option / prefer-either / prefer-try: fire on correct code at serialization boundaries\n * (JSON rows, DTOs) and on throws that are correct (bug checks, host contracts). Wire<T> (#325 B),\n * invariant() and @interop (#342) close those; graduating them is a measured decision.\n * - prefer-flatmap / prefer-do-notation: heuristics without type information; precision unmeasured.\n *\n * Graduated with a precision condition: prefer-fold checks functype predicate calls (`isSome()`,\n * `isLeft()`) only; its null-check heuristic is opt-in (`checkNullable`) because it fired on plain\n * nullables — 31 of 31 hits in CivalaOS. prefer-map leaves loops to no-imperative-loops (`checkForLoops`\n * off), so one loop is one error.\n *\n * collection-naming is a convention, not a heuristic — functype's Map/Set imported under their own names,\n * the built-in spelled globalThis.Map — so it has no false-positive class and starts at error.\n *\n * no-array-mutation is off here only because turning a new error on in a 1.x minor would fail consumers'\n * builds on upgrade (91 hits across five consumers, every one a real in-place mutation). It's `error` in\n * strict, and planned for `error` here in 2.0. It is type-aware: without type information it reports nothing.\n *\n * no-floating-io (1.17) is off here and `warn` in strict while it is measured: 0 false positives across\n * ~1,340 IO-typed calls in five codebases, but no real hits yet either. 2.0 decides `recommended` after\n * measuring it against functype-os, whose async methods return IO there. Type-aware, like no-array-mutation.\n */\nconst recommendedRules = {\n \"functype/no-let\": \"error\",\n \"functype/no-imperative-loops\": \"error\",\n \"functype/prefer-functype-map\": \"error\",\n \"functype/prefer-functype-set\": \"error\",\n \"functype/prefer-map\": \"error\",\n \"functype/prefer-fold\": \"error\",\n \"functype/collection-naming\": \"error\",\n \"functype/prefer-option\": \"warn\",\n \"functype/prefer-either\": \"warn\",\n \"functype/prefer-try\": \"warn\",\n \"functype/prefer-flatmap\": \"warn\",\n \"functype/prefer-do-notation\": \"warn\",\n \"functype/no-get-unsafe\": \"off\",\n \"functype/prefer-list\": \"off\",\n \"functype/no-array-mutation\": \"off\",\n \"functype/no-floating-io\": \"off\",\n}\n\nexport default recommendedRules\n"],"mappings":"AA4BA,MAAMA,EAAmB,CACvB,kBAAmB,QACnB,+BAAgC,QAChC,+BAAgC,QAChC,+BAAgC,QAChC,sBAAuB,QACvB,uBAAwB,QACxB,6BAA8B,QAC9B,yBAA0B,OAC1B,yBAA0B,OAC1B,sBAAuB,OACvB,0BAA2B,OAC3B,8BAA+B,OAC/B,yBAA0B,MAC1B,uBAAwB,MACxB,6BAA8B,MAC9B,0BAA2B,KAC7B"}
1
+ {"version":3,"file":"recommended.js","names":["recommendedRules"],"sources":["../../src/configs/recommended.ts"],"sourcesContent":["/**\n * Severity policy (#325): a rule is `error` once it is right on ~95–99% of real code and its known\n * false-positive classes are closed; it stays `warn` only while those classes are still open. FP here\n * is governance — a rule that is reliably right should fail the build, not print advice nobody reads\n * (CivalaOS shipped 85 new violations under \"lint OK\" because every rule but `no-let` warned).\n *\n * Still `warn`, and why:\n * - prefer-option / prefer-either / prefer-try: fire on correct code at serialization boundaries\n * (JSON rows, DTOs) and on throws that are correct (bug checks, host contracts). Wire<T> (#325 B),\n * invariant() and @interop (#342) close those; graduating them is a measured decision.\n * - prefer-flatmap / prefer-do-notation: heuristics without type information; precision unmeasured.\n *\n * Graduated with a precision condition: prefer-fold checks functype predicate calls (`isSome()`,\n * `isLeft()`) only; its null-check heuristic is opt-in (`checkNullable`) because it fired on plain\n * nullables — 31 of 31 hits in CivalaOS. prefer-map leaves loops to no-imperative-loops (`checkForLoops`\n * off), so one loop is one error.\n *\n * collection-naming is a convention, not a heuristic — functype's Map/Set imported under their own names,\n * the built-in spelled globalThis.Map — so it has no false-positive class and starts at error.\n *\n * no-array-mutation is off here only because turning a new error on in a 1.x minor would fail consumers'\n * builds on upgrade (91 hits across five consumers, every one a real in-place mutation). It's `error` in\n * strict, and planned for `error` here in 2.0. It is type-aware: without type information it reports nothing.\n *\n * no-floating-io (1.17) is off here and `warn` in strict while it is measured: 0 false positives across\n * ~1,340 IO-typed calls in five codebases, but no real hits yet either. 2.0 decides `recommended` after\n * measuring it against functype-os, whose async methods return IO there. Type-aware, like no-array-mutation.\n *\n * no-getOrThrow-in-render and must-fold-on-component-return are React rules: they fire only inside a\n * component (a PascalCase function with JSX) or a hook (`use*`), so non-React code rarely trips them (a\n * non-React function named `use*` is read as a hook). Both are new and unmeasured on real React code, so\n * they start where no-floating-io did: off here, `warn` in strict. They work without type information and\n * are more precise with it.\n */\nconst recommendedRules = {\n \"functype/no-let\": \"error\",\n \"functype/no-imperative-loops\": \"error\",\n \"functype/prefer-functype-map\": \"error\",\n \"functype/prefer-functype-set\": \"error\",\n \"functype/prefer-map\": \"error\",\n \"functype/prefer-fold\": \"error\",\n \"functype/collection-naming\": \"error\",\n \"functype/prefer-option\": \"warn\",\n \"functype/prefer-either\": \"warn\",\n \"functype/prefer-try\": \"warn\",\n \"functype/prefer-flatmap\": \"warn\",\n \"functype/prefer-do-notation\": \"warn\",\n \"functype/no-get-unsafe\": \"off\",\n \"functype/prefer-list\": \"off\",\n \"functype/no-array-mutation\": \"off\",\n \"functype/no-floating-io\": \"off\",\n \"functype/no-getOrThrow-in-render\": \"off\",\n \"functype/must-fold-on-component-return\": \"off\",\n}\n\nexport default recommendedRules\n"],"mappings":"AAkCA,MAAMA,EAAmB,CACvB,kBAAmB,QACnB,+BAAgC,QAChC,+BAAgC,QAChC,+BAAgC,QAChC,sBAAuB,QACvB,uBAAwB,QACxB,6BAA8B,QAC9B,yBAA0B,OAC1B,yBAA0B,OAC1B,sBAAuB,OACvB,0BAA2B,OAC3B,8BAA+B,OAC/B,yBAA0B,MAC1B,uBAAwB,MACxB,6BAA8B,MAC9B,0BAA2B,MAC3B,mCAAoC,MACpC,yCAA0C,KAC5C,E"}
@@ -1,4 +1,3 @@
1
- //#region src/configs/strict.d.ts
2
1
  declare const strictRules: {
3
2
  "functype/prefer-option": string;
4
3
  "functype/prefer-either": string;
@@ -7,6 +6,8 @@ declare const strictRules: {
7
6
  "functype/prefer-list": string;
8
7
  "functype/no-array-mutation": string;
9
8
  "functype/no-floating-io": string;
9
+ "functype/no-getOrThrow-in-render": string;
10
+ "functype/must-fold-on-component-return": string;
10
11
  "functype/prefer-functype-map": string;
11
12
  "functype/prefer-functype-set": string;
12
13
  "functype/no-imperative-loops": string;
@@ -17,6 +18,5 @@ declare const strictRules: {
17
18
  "functype/prefer-flatmap": string;
18
19
  "functype/prefer-do-notation": string;
19
20
  };
20
- //#endregion
21
21
  export { strictRules as default };
22
22
  //# sourceMappingURL=strict.d.ts.map
@@ -1,2 +1,2 @@
1
- import e from"./recommended.js";const t={...e,"functype/prefer-option":`error`,"functype/prefer-either":`error`,"functype/prefer-try":`error`,"functype/no-get-unsafe":`error`,"functype/prefer-list":`warn`,"functype/no-array-mutation":`error`,"functype/no-floating-io":`warn`,"functype/prefer-functype-map":`error`,"functype/prefer-functype-set":`error`,"functype/no-imperative-loops":`error`};export{t as default};
1
+ import e from"./recommended.js";const t={...e,"functype/prefer-option":`error`,"functype/prefer-either":`error`,"functype/prefer-try":`error`,"functype/no-get-unsafe":`error`,"functype/prefer-list":`warn`,"functype/no-array-mutation":`error`,"functype/no-floating-io":`warn`,"functype/no-getOrThrow-in-render":`warn`,"functype/must-fold-on-component-return":`warn`,"functype/prefer-functype-map":`error`,"functype/prefer-functype-set":`error`,"functype/no-imperative-loops":`error`};export{t as default};
2
2
  //# sourceMappingURL=strict.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"strict.js","names":["recommendedRules","strictRules"],"sources":["../../src/configs/strict.ts"],"sourcesContent":["import recommendedRules from \"./recommended\"\n\nconst strictRules = {\n ...recommendedRules,\n \"functype/prefer-option\": \"error\",\n \"functype/prefer-either\": \"error\",\n \"functype/prefer-try\": \"error\",\n \"functype/no-get-unsafe\": \"error\",\n \"functype/prefer-list\": \"warn\",\n \"functype/no-array-mutation\": \"error\",\n \"functype/no-floating-io\": \"warn\",\n \"functype/prefer-functype-map\": \"error\",\n \"functype/prefer-functype-set\": \"error\",\n \"functype/no-imperative-loops\": \"error\",\n}\n\nexport default strictRules\n"],"mappings":"gCAEA,MAAMC,EAAc,CAClB,GAAGD,EACH,yBAA0B,QAC1B,yBAA0B,QAC1B,sBAAuB,QACvB,yBAA0B,QAC1B,uBAAwB,OACxB,6BAA8B,QAC9B,0BAA2B,OAC3B,+BAAgC,QAChC,+BAAgC,QAChC,+BAAgC,OAClC"}
1
+ {"version":3,"file":"strict.js","names":["recommendedRules","strictRules"],"sources":["../../src/configs/strict.ts"],"sourcesContent":["import recommendedRules from \"./recommended\"\n\nconst strictRules = {\n ...recommendedRules,\n \"functype/prefer-option\": \"error\",\n \"functype/prefer-either\": \"error\",\n \"functype/prefer-try\": \"error\",\n \"functype/no-get-unsafe\": \"error\",\n \"functype/prefer-list\": \"warn\",\n \"functype/no-array-mutation\": \"error\",\n \"functype/no-floating-io\": \"warn\",\n \"functype/no-getOrThrow-in-render\": \"warn\",\n \"functype/must-fold-on-component-return\": \"warn\",\n \"functype/prefer-functype-map\": \"error\",\n \"functype/prefer-functype-set\": \"error\",\n \"functype/no-imperative-loops\": \"error\",\n}\n\nexport default strictRules\n"],"mappings":"A,gCAEA,MAAMC,EAAc,CAClB,GAAGD,EACH,yBAA0B,QAC1B,yBAA0B,QAC1B,sBAAuB,QACvB,yBAA0B,QAC1B,uBAAwB,OACxB,6BAA8B,QAC9B,0BAA2B,OAC3B,mCAAoC,OACpC,yCAA0C,OAC1C,+BAAgC,QAChC,+BAAgC,QAChC,+BAAgC,OAClC,E"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/index.d.ts
2
1
  declare const plugin: {
3
2
  rules: {
4
3
  "prefer-option": import("eslint").Rule.RuleModule;
@@ -17,6 +16,8 @@ declare const plugin: {
17
16
  "collection-naming": import("eslint").Rule.RuleModule;
18
17
  "no-array-mutation": import("eslint").Rule.RuleModule;
19
18
  "no-floating-io": import("eslint").Rule.RuleModule;
19
+ "no-getOrThrow-in-render": import("eslint").Rule.RuleModule;
20
+ "must-fold-on-component-return": import("eslint").Rule.RuleModule;
20
21
  };
21
22
  meta: {
22
23
  name: string;
@@ -24,6 +25,5 @@ declare const plugin: {
24
25
  };
25
26
  configs: Record<string, unknown>;
26
27
  };
27
- //#endregion
28
28
  export { plugin as default };
29
29
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["recommendedRules","strictRules","rules_default","plugin"],"sources":["../src/index.ts"],"sourcesContent":["import recommendedRules from \"./configs/recommended\"\nimport strictRules from \"./configs/strict\"\nimport rules from \"./rules\"\n\nconst plugin = {\n rules,\n meta: {\n name: \"eslint-plugin-functype\",\n version: \"2.0.0\",\n },\n configs: {} as Record<string, unknown>,\n}\n\n// Self-referencing plugin in configs (ESLint flat config pattern)\nplugin.configs = {\n recommended: {\n name: \"functype-plugin/recommended\",\n plugins: { functype: plugin },\n rules: recommendedRules,\n },\n strict: {\n name: \"functype-plugin/strict\",\n plugins: { functype: plugin },\n rules: strictRules,\n },\n}\n\nexport default plugin\n"],"mappings":"2GAIA,MAAMG,EAAS,CACb,MAAAD,EACA,KAAM,CACJ,KAAM,yBACN,QAAS,OACX,EACA,QAAS,CAAC,CACZ,EAGA,EAAO,QAAU,CACf,YAAa,CACX,KAAM,8BACN,QAAS,CAAE,SAAUC,CAAO,EAC5B,MAAOH,CACT,EACA,OAAQ,CACN,KAAM,yBACN,QAAS,CAAE,SAAUG,CAAO,EAC5B,MAAOF,CACT,CACF"}
1
+ {"version":3,"file":"index.js","names":["recommendedRules","strictRules","rules_default","plugin"],"sources":["../src/index.ts"],"sourcesContent":["import recommendedRules from \"./configs/recommended\"\nimport strictRules from \"./configs/strict\"\nimport rules from \"./rules\"\n\nconst plugin = {\n rules,\n meta: {\n name: \"eslint-plugin-functype\",\n version: \"2.0.0\",\n },\n configs: {} as Record<string, unknown>,\n}\n\n// Self-referencing plugin in configs (ESLint flat config pattern)\nplugin.configs = {\n recommended: {\n name: \"functype-plugin/recommended\",\n plugins: { functype: plugin },\n rules: recommendedRules,\n },\n strict: {\n name: \"functype-plugin/strict\",\n plugins: { functype: plugin },\n rules: strictRules,\n },\n}\n\nexport default plugin\n"],"mappings":"A,2GAIA,MAAMG,EAAS,CACb,MAAAD,EACA,KAAM,CACJ,KAAM,yBACN,QAAS,OACX,EACA,QAAS,CAAC,CACZ,EAGA,EAAO,QAAU,CACf,YAAa,CACX,KAAM,8BACN,QAAS,CAAE,SAAUC,CAAO,EAC5B,MAAOH,CACT,EACA,OAAQ,CACN,KAAM,yBACN,QAAS,CAAE,SAAUG,CAAO,EAC5B,MAAOF,CACT,CACF,E"}
@@ -1,5 +1,4 @@
1
1
  import { Rule } from "eslint";
2
- //#region src/rules/collection-naming.d.ts
3
2
  /**
4
3
  * functype's `Map` / `Set` are the default collections (Scala-style): import them under their own names,
5
4
  * and spell the built-in `globalThis.Map` / `globalThis.Set` where it is genuinely needed.
@@ -14,6 +13,5 @@ import { Rule } from "eslint";
14
13
  * Applies in test files too: tests are read as examples, by people and agents.
15
14
  */
16
15
  declare const rule: Rule.RuleModule;
17
- //#endregion
18
16
  export { rule as default };
19
17
  //# sourceMappingURL=collection-naming.d.ts.map
@@ -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":"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"}
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,20 +1,21 @@
1
1
  import rule from "./collection-naming.js";
2
- import rule$1 from "./no-array-mutation.js";
3
- import rule$2 from "./no-floating-io.js";
4
- import rule$3 from "./no-get-unsafe.js";
5
- import rule$4 from "./no-imperative-loops.js";
6
- import rule$5 from "./no-let.js";
7
- import rule$6 from "./prefer-do-notation.js";
8
- import rule$7 from "./prefer-either.js";
9
- import rule$8 from "./prefer-flatmap.js";
10
- import rule$9 from "./prefer-fold.js";
11
- import rule$10 from "./prefer-functype-map.js";
12
- import rule$11 from "./prefer-functype-set.js";
13
- import rule$12 from "./prefer-list.js";
14
- import rule$13 from "./prefer-map.js";
15
- import rule$14 from "./prefer-option.js";
16
- import rule$15 from "./prefer-try.js";
17
- //#region src/rules/index.d.ts
2
+ import rule$1 from "./must-fold-on-component-return.js";
3
+ import rule$2 from "./no-array-mutation.js";
4
+ import rule$3 from "./no-floating-io.js";
5
+ import rule$5 from "./no-get-unsafe.js";
6
+ import rule$4 from "./no-getOrThrow-in-render.js";
7
+ import rule$6 from "./no-imperative-loops.js";
8
+ import rule$7 from "./no-let.js";
9
+ import rule$8 from "./prefer-do-notation.js";
10
+ import rule$9 from "./prefer-either.js";
11
+ import rule$10 from "./prefer-flatmap.js";
12
+ import rule$11 from "./prefer-fold.js";
13
+ import rule$12 from "./prefer-functype-map.js";
14
+ import rule$13 from "./prefer-functype-set.js";
15
+ import rule$14 from "./prefer-list.js";
16
+ import rule$15 from "./prefer-map.js";
17
+ import rule$16 from "./prefer-option.js";
18
+ import rule$17 from "./prefer-try.js";
18
19
  declare const _default: {
19
20
  "prefer-option": import("eslint").Rule.RuleModule;
20
21
  "prefer-either": import("eslint").Rule.RuleModule;
@@ -32,7 +33,8 @@ declare const _default: {
32
33
  "collection-naming": import("eslint").Rule.RuleModule;
33
34
  "no-array-mutation": import("eslint").Rule.RuleModule;
34
35
  "no-floating-io": import("eslint").Rule.RuleModule;
36
+ "no-getOrThrow-in-render": import("eslint").Rule.RuleModule;
37
+ "must-fold-on-component-return": import("eslint").Rule.RuleModule;
35
38
  };
36
- //#endregion
37
- export { rule as collectionNaming, _default as default, rule$1 as noArrayMutation, rule$2 as noFloatingIo, rule$3 as noGetUnsafe, rule$4 as noImperativeLoops, rule$5 as noLet, rule$6 as preferDoNotation, rule$7 as preferEither, rule$8 as preferFlatmap, rule$9 as preferFold, rule$10 as preferFunctypeMap, rule$11 as preferFunctypeSet, rule$12 as preferList, rule$13 as preferMap, rule$14 as preferOption, rule$15 as preferTry };
39
+ export { rule as collectionNaming, _default as default, rule$1 as mustFoldOnComponentReturn, rule$2 as noArrayMutation, rule$3 as noFloatingIo, rule$4 as noGetOrThrowInRender, rule$5 as noGetUnsafe, rule$6 as noImperativeLoops, rule$7 as noLet, rule$8 as preferDoNotation, rule$9 as preferEither, rule$10 as preferFlatmap, rule$11 as preferFold, rule$12 as preferFunctypeMap, rule$13 as preferFunctypeSet, rule$14 as preferList, rule$15 as preferMap, rule$16 as preferOption, rule$17 as preferTry };
38
40
  //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1,2 @@
1
- import e from"./collection-naming.js";import t from"./no-array-mutation.js";import n from"./no-floating-io.js";import r from"./no-get-unsafe.js";import i from"./no-imperative-loops.js";import a from"./no-let.js";import o from"./prefer-do-notation.js";import s from"./prefer-either.js";import c from"./prefer-flatmap.js";import l from"./prefer-fold.js";import u from"./prefer-functype-map.js";import d from"./prefer-functype-set.js";import f from"./prefer-list.js";import p from"./prefer-map.js";import m from"./prefer-option.js";import h from"./prefer-try.js";var g={"prefer-option":m,"prefer-either":s,"prefer-try":h,"prefer-list":f,"no-get-unsafe":r,"no-let":a,"prefer-fold":l,"prefer-map":p,"prefer-flatmap":c,"prefer-functype-map":u,"prefer-functype-set":d,"no-imperative-loops":i,"prefer-do-notation":o,"collection-naming":e,"no-array-mutation":t,"no-floating-io":n};export{e as collectionNaming,g as default,t as noArrayMutation,n as noFloatingIo,r as noGetUnsafe,i as noImperativeLoops,a as noLet,o as preferDoNotation,s as preferEither,c as preferFlatmap,l as preferFold,u as preferFunctypeMap,d as preferFunctypeSet,f as preferList,p as preferMap,m as preferOption,h 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-get-unsafe.js";import a from"./no-getOrThrow-in-render.js";import o from"./no-imperative-loops.js";import s from"./no-let.js";import c from"./prefer-do-notation.js";import l from"./prefer-either.js";import u from"./prefer-flatmap.js";import d from"./prefer-fold.js";import f from"./prefer-functype-map.js";import p from"./prefer-functype-set.js";import m from"./prefer-list.js";import h from"./prefer-map.js";import g from"./prefer-option.js";import _ from"./prefer-try.js";var v={"prefer-option":g,"prefer-either":l,"prefer-try":_,"prefer-list":m,"no-get-unsafe":i,"no-let":s,"prefer-fold":d,"prefer-map":h,"prefer-flatmap":u,"prefer-functype-map":f,"prefer-functype-set":p,"no-imperative-loops":o,"prefer-do-notation":c,"collection-naming":e,"no-array-mutation":n,"no-floating-io":r,"no-getOrThrow-in-render":a,"must-fold-on-component-return":t};export{e as collectionNaming,v as default,t as mustFoldOnComponentReturn,n as noArrayMutation,r as noFloatingIo,a as noGetOrThrowInRender,i as noGetUnsafe,o as noImperativeLoops,s as noLet,c as preferDoNotation,l as preferEither,u as preferFlatmap,d as preferFold,f as preferFunctypeMap,p as preferFunctypeSet,m as preferList,h as preferMap,g as preferOption,_ as preferTry};
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","rule","rule$1","rule$2","rule$3","rule$4","rule$5","rule$6","rule$7","rule$8","rule$9","rule$10","rule$11","rule$12","rule$13","rule$14","rule$15","rules_default"],"sources":["../../src/rules/index.ts"],"sourcesContent":["import collectionNaming from \"./collection-naming\"\nimport noArrayMutation from \"./no-array-mutation\"\nimport noFloatingIo from \"./no-floating-io\"\nimport noGetUnsafe from \"./no-get-unsafe\"\nimport noImperativeLoops from \"./no-imperative-loops\"\nimport noLet from \"./no-let\"\nimport preferDoNotation from \"./prefer-do-notation\"\nimport preferEither from \"./prefer-either\"\nimport preferFlatmap from \"./prefer-flatmap\"\nimport preferFold from \"./prefer-fold\"\nimport preferFunctypeMap from \"./prefer-functype-map\"\nimport preferFunctypeSet from \"./prefer-functype-set\"\nimport preferList from \"./prefer-list\"\nimport preferMap from \"./prefer-map\"\nimport preferOption from \"./prefer-option\"\nimport preferTry from \"./prefer-try\"\n\nexport {\n collectionNaming,\n noArrayMutation,\n noFloatingIo,\n noGetUnsafe,\n noImperativeLoops,\n noLet,\n preferDoNotation,\n preferEither,\n preferFlatmap,\n preferFold,\n preferFunctypeMap,\n preferFunctypeSet,\n preferList,\n preferMap,\n preferOption,\n preferTry,\n}\n\nexport default {\n \"prefer-option\": preferOption,\n \"prefer-either\": preferEither,\n \"prefer-try\": preferTry,\n \"prefer-list\": preferList,\n \"no-get-unsafe\": noGetUnsafe,\n \"no-let\": noLet,\n \"prefer-fold\": preferFold,\n \"prefer-map\": preferMap,\n \"prefer-flatmap\": preferFlatmap,\n \"prefer-functype-map\": preferFunctypeMap,\n \"prefer-functype-set\": preferFunctypeSet,\n \"no-imperative-loops\": noImperativeLoops,\n \"prefer-do-notation\": preferDoNotation,\n \"collection-naming\": collectionNaming,\n \"no-array-mutation\": noArrayMutation,\n \"no-floating-io\": noFloatingIo,\n}\n"],"mappings":"gjBAoCA,IAAAgC,EAAe,CACb,gBAAiBhC,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,CACpB"}
1
+ {"version":3,"file":"index.js","names":["preferOption","preferEither","preferTry","preferList","noGetUnsafe","noLet","preferFold","preferMap","preferFlatmap","preferFunctypeMap","preferFunctypeSet","noImperativeLoops","preferDoNotation","collectionNaming","noArrayMutation","noFloatingIo","noGetOrThrowInRender","mustFoldOnComponentReturn","rule","rule$1","rule$2","rule$3","rule$5","rule$4","rule$6","rule$7","rule$8","rule$9","rule$10","rule$11","rule$12","rule$13","rule$14","rule$15","rule$16","rule$17","rules_default"],"sources":["../../src/rules/index.ts"],"sourcesContent":["import collectionNaming from \"./collection-naming\"\nimport mustFoldOnComponentReturn from \"./must-fold-on-component-return\"\nimport noArrayMutation from \"./no-array-mutation\"\nimport noFloatingIo from \"./no-floating-io\"\nimport noGetUnsafe from \"./no-get-unsafe\"\nimport noGetOrThrowInRender from \"./no-getOrThrow-in-render\"\nimport noImperativeLoops from \"./no-imperative-loops\"\nimport noLet from \"./no-let\"\nimport preferDoNotation from \"./prefer-do-notation\"\nimport preferEither from \"./prefer-either\"\nimport preferFlatmap from \"./prefer-flatmap\"\nimport preferFold from \"./prefer-fold\"\nimport preferFunctypeMap from \"./prefer-functype-map\"\nimport preferFunctypeSet from \"./prefer-functype-set\"\nimport preferList from \"./prefer-list\"\nimport preferMap from \"./prefer-map\"\nimport preferOption from \"./prefer-option\"\nimport preferTry from \"./prefer-try\"\n\nexport {\n collectionNaming,\n mustFoldOnComponentReturn,\n noArrayMutation,\n noFloatingIo,\n noGetOrThrowInRender,\n noGetUnsafe,\n noImperativeLoops,\n noLet,\n preferDoNotation,\n preferEither,\n preferFlatmap,\n preferFold,\n preferFunctypeMap,\n preferFunctypeSet,\n preferList,\n preferMap,\n preferOption,\n preferTry,\n}\n\nexport default {\n \"prefer-option\": preferOption,\n \"prefer-either\": preferEither,\n \"prefer-try\": preferTry,\n \"prefer-list\": preferList,\n \"no-get-unsafe\": noGetUnsafe,\n \"no-let\": noLet,\n \"prefer-fold\": preferFold,\n \"prefer-map\": preferMap,\n \"prefer-flatmap\": preferFlatmap,\n \"prefer-functype-map\": preferFunctypeMap,\n \"prefer-functype-set\": preferFunctypeSet,\n \"no-imperative-loops\": noImperativeLoops,\n \"prefer-do-notation\": preferDoNotation,\n \"collection-naming\": collectionNaming,\n \"no-array-mutation\": noArrayMutation,\n \"no-floating-io\": noFloatingIo,\n \"no-getOrThrow-in-render\": noGetOrThrowInRender,\n \"must-fold-on-component-return\": mustFoldOnComponentReturn,\n}\n"],"mappings":"A,8oBAwCA,IAAAoC,EAAe,CACb,gBAAiBpC,EACjB,gBAAiBC,EACjB,aAAcC,EACd,cAAeC,EACf,gBAAiBC,EACjB,SAAUC,EACV,cAAeC,EACf,aAAcC,EACd,iBAAkBC,EAClB,sBAAuBC,EACvB,sBAAuBC,EACvB,sBAAuBC,EACvB,qBAAsBC,EACtB,oBAAqBC,EACrB,oBAAqBC,EACrB,iBAAkBC,EAClB,0BAA2BC,EAC3B,gCAAiCC,CACnC,E"}
@@ -0,0 +1,4 @@
1
+ import { Rule } from "eslint";
2
+ declare const rule: Rule.RuleModule;
3
+ export { rule as default };
4
+ //# sourceMappingURL=must-fold-on-component-return.d.ts.map
@@ -0,0 +1,2 @@
1
+ import{isInsideTaggedDeclaration as e}from"../utils/boundary-tags.js";import{MATCH_COMPONENT as t,testedPredicate as n}from"../utils/functype-predicates.js";import{enclosingFunction as r,producesJSX as i,renderKind as a}from"../utils/react-render.js";import{isExtractableByType as o}from"../utils/type-aware.js";const s=e=>{let t=e.type===`BlockStatement`&&e.body.length===1?e.body[0]:e;return t?.type===`ReturnStatement`?t.argument??null:void 0},c=e=>e?.type===`Literal`&&e.value===null,l={meta:{type:`suggestion`,docs:{description:`Require a React component to render an Option, Either or Try with fold or a Match component, not an isSome()/isLeft() guard or &&`,recommended:!1},schema:[{type:`object`,properties:{allowInteropMarker:{type:`boolean`,default:!0}},additionalProperties:!1}],messages:{guardReturn:`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.`,shortCircuit:`{{receiver}}.{{method}}() && … renders one case and drops the other. Use {{receiver}}.fold(…) with null for the case that renders nothing, or <{{matcher}}>.`}},create(l){let u=(l.options[0]||{}).allowInteropMarker!==!1,d=l.sourceCode,f=(t,i)=>{let s=n(i,d);if(!s)return null;let c=r(t);return!c||a(c)!==`component`||o(s.receiver,l)===!1||u&&e(t,`interop`,d)?null:s},p=(e,n,r)=>l.report({node:e,messageId:n,data:{receiver:d.getText(r.receiver),method:r.method,matcher:t[r.method]??`Match`}});return{IfStatement(e){if(e.alternate)return;let t=s(e.consequent);if(t===void 0||!(i(t)||c(t)))return;let n=f(e,e.test);n&&p(e,`guardReturn`,n)},LogicalExpression(e){if(e.operator!==`&&`||!i(e.right))return;let t=f(e,e.left);t&&p(e,`shortCircuit`,t)}}}};export{l as default};
2
+ //# sourceMappingURL=must-fold-on-component-return.js.map
@@ -0,0 +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,5 +1,4 @@
1
1
  import { Rule } from "eslint";
2
- //#region src/rules/no-array-mutation.d.ts
3
2
  /**
4
3
  * Reports in-place mutation of a mutable array: `push` / `pop` / `shift` / `unshift` / `splice` / `sort` /
5
4
  * `reverse` / `fill` / `copyWithin`, assignment to an element (`xs[i] = v`, `xs[i] += 1`, `xs[i]++`),
@@ -12,6 +11,5 @@ import { Rule } from "eslint";
12
11
  * it's assumed to be a fresh copy (see isFreshValue for the recall gap that leaves).
13
12
  */
14
13
  declare const rule: Rule.RuleModule;
15
- //#endregion
16
14
  export { rule as default };
17
15
  //# sourceMappingURL=no-array-mutation.d.ts.map
@@ -1,2 +1,2 @@
1
- import{isMutableArrayExpression as e}from"../utils/array-mutation.js";import{isInsideTaggedDeclaration as t}from"../utils/boundary-tags.js";const n=/* @__PURE__ */ new Set([`push`,`pop`,`shift`,`unshift`,`splice`,`sort`,`reverse`,`fill`,`copyWithin`]),r=e=>e.type===`ArrayExpression`||e.type===`CallExpression`||e.type===`NewExpression`||e.type===`AwaitExpression`&&r(e.argument),i=(e,t)=>{let n=t.getText(e);return n.length>40?`${n.slice(0,37)}…`:n},a={meta:{type:`problem`,docs:{description:`Disallow changing an array in place — build a new one`,recommended:!0},schema:[{type:`object`,properties:{allowInTests:{type:`boolean`,default:!0},allowInteropMarker:{type:`boolean`,default:!0}},additionalProperties:!1}],messages:{mutatingMethod:`{{name}}.{{method}}() changes the array in place. Build a new one instead: [...{{name}}, x], map / filter / flatMap / toSorted, a List, or a fold`,elementAssignment:`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`,lengthAssignment:`Setting {{name}}.length changes the array in place. Build a new one instead: {{name}}.slice(0, n), or start from []`}},create(a){let o=a.options[0]||{},s=o.allowInTests!==!1,c=o.allowInteropMarker!==!1,l=a.sourceCode;if(s&&(()=>{let e=a.filename;return/\.(test|spec)\.(ts|js|tsx|jsx)$/.test(e)||e.includes(`__tests__`)||e.includes(`/test/`)||e.includes(`/tests/`)})())return{};let u=e=>c&&t(e,`interop`,l),d=t=>{if(t?.type!==`MemberExpression`)return null;let n=t.object;return r(n)?null:t.computed&&e(n,a)?n:null},f=t=>{if(t?.type!==`MemberExpression`||t.computed)return null;let n=t.object;return t.property?.type!==`Identifier`||t.property.name!==`length`||r(n)?null:e(n,a)?n:null},p=(e,t)=>{if(u(e))return;let n=d(t);if(n){a.report({node:e,messageId:`elementAssignment`,data:{name:i(n,l)}});return}let r=f(t);r&&a.report({node:e,messageId:`lengthAssignment`,data:{name:i(r,l)}})};return{CallExpression(t){let o=t.callee;if(o.type!==`MemberExpression`||o.computed)return;let s=o.property?.type===`Identifier`?o.property.name:null;if(s===null||!n.has(s))return;let c=o.object;r(c)||u(t)||e(c,a)&&a.report({node:t,messageId:`mutatingMethod`,data:{name:i(c,l),method:s}})},AssignmentExpression(e){p(e,e.left)},UpdateExpression(e){p(e,e.argument)},UnaryExpression(e){e.operator===`delete`&&p(e,e.argument)}}}};export{a as default};
1
+ import{isInsideTaggedDeclaration as e}from"../utils/boundary-tags.js";import{isMutableArrayExpression as t}from"../utils/array-mutation.js";const n=/* @__PURE__ */ new Set([`push`,`pop`,`shift`,`unshift`,`splice`,`sort`,`reverse`,`fill`,`copyWithin`]),r=e=>e.type===`ArrayExpression`||e.type===`CallExpression`||e.type===`NewExpression`||e.type===`AwaitExpression`&&r(e.argument),i=(e,t)=>{let n=t.getText(e);return n.length>40?`${n.slice(0,37)}…`:n},a={meta:{type:`problem`,docs:{description:`Disallow changing an array in place — build a new one`,recommended:!0},schema:[{type:`object`,properties:{allowInTests:{type:`boolean`,default:!0},allowInteropMarker:{type:`boolean`,default:!0}},additionalProperties:!1}],messages:{mutatingMethod:`{{name}}.{{method}}() changes the array in place. Build a new one instead: [...{{name}}, x], map / filter / flatMap / toSorted, a List, or a fold`,elementAssignment:`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`,lengthAssignment:`Setting {{name}}.length changes the array in place. Build a new one instead: {{name}}.slice(0, n), or start from []`}},create(a){let o=a.options[0]||{},s=o.allowInTests!==!1,c=o.allowInteropMarker!==!1,l=a.sourceCode;if(s&&(()=>{let e=a.filename;return/\.(test|spec)\.(ts|js|tsx|jsx)$/.test(e)||e.includes(`__tests__`)||e.includes(`/test/`)||e.includes(`/tests/`)})())return{};let u=t=>c&&e(t,`interop`,l),d=e=>{if(e?.type!==`MemberExpression`)return null;let n=e.object;return r(n)?null:e.computed&&t(n,a)?n:null},f=e=>{if(e?.type!==`MemberExpression`||e.computed)return null;let n=e.object;return e.property?.type!==`Identifier`||e.property.name!==`length`||r(n)?null:t(n,a)?n:null},p=(e,t)=>{if(u(e))return;let n=d(t);if(n){a.report({node:e,messageId:`elementAssignment`,data:{name:i(n,l)}});return}let r=f(t);r&&a.report({node:e,messageId:`lengthAssignment`,data:{name:i(r,l)}})};return{CallExpression(e){let o=e.callee;if(o.type!==`MemberExpression`||o.computed)return;let s=o.property?.type===`Identifier`?o.property.name:null;if(s===null||!n.has(s))return;let c=o.object;r(c)||u(e)||t(c,a)&&a.report({node:e,messageId:`mutatingMethod`,data:{name:i(c,l),method:s}})},AssignmentExpression(e){p(e,e.left)},UpdateExpression(e){p(e,e.argument)},UnaryExpression(e){e.operator===`delete`&&p(e,e.argument)}}}};export{a as default};
2
2
  //# sourceMappingURL=no-array-mutation.js.map
@@ -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":"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,EAAOC,EAAW,QAAQH,CAAI,EACpC,OAAOE,EAAK,OAAS,GAAK,GAAGA,EAAK,MAAM,EAAG,EAAE,EAAE,GAAKA,CACtD,EAaME,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,wDACb,YAAa,EACf,EACA,OAAQ,CACN,CACE,KAAM,SACN,WAAY,CACV,aAAc,CAAE,KAAM,UAAW,QAAS,EAAK,EAC/C,mBAAoB,CAAE,KAAM,UAAW,QAAS,EAAK,CACvD,EACA,qBAAsB,EACxB,CACF,EACA,SAAU,CACR,eACE,oJACF,kBACE,uIACF,iBACE,qHACJ,CACF,EAEA,OAAO,EAAS,CACd,IAAMC,EAAUC,EAAQ,QAAQ,IAAM,CAAC,EACjCC,EAAeF,EAAQ,eAAiB,GACxCG,EAAqBH,EAAQ,qBAAuB,GACpDF,EAAaG,EAAQ,WAW3B,GAAIC,QATgC,CAClC,IAAME,EAAWH,EAAQ,SACzB,MACE,kCAAkC,KAAKG,CAAQ,GAC/CA,EAAS,SAAS,WAAW,GAC7BA,EAAS,SAAS,QAAQ,GAC1BA,EAAS,SAAS,SAAS,CAE/B,EACoB,CAAa,EAAG,MAAO,CAAC,EAG5C,IAAMC,EAAY,GAChBF,GAAsB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AAOV,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"}
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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AAK,QAAmB,CAC5E,CACF,CACF,CACF,E"}
@@ -1,5 +1,4 @@
1
1
  import { Rule } from "eslint";
2
- //#region src/rules/no-floating-io.d.ts
3
2
  /**
4
3
  * Reports an `IO` that is built and then dropped, so it never runs:
5
4
  *
@@ -13,6 +12,5 @@ import { Rule } from "eslint";
13
12
  * Type-aware only: without type information it reports nothing.
14
13
  */
15
14
  declare const rule: Rule.RuleModule;
16
- //#endregion
17
15
  export { rule as default };
18
16
  //# sourceMappingURL=no-floating-io.d.ts.map