eslint-plugin-functype 2.127.2 → 2.201.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +109 -75
  2. package/dist/cli/list-rules.js.map +1 -1
  3. package/dist/configs/recommended.d.ts +43 -45
  4. package/dist/configs/recommended.js +1 -1
  5. package/dist/configs/recommended.js.map +1 -1
  6. package/dist/configs/tests.d.ts +8 -5
  7. package/dist/configs/tests.js +1 -1
  8. package/dist/configs/tests.js.map +1 -1
  9. package/dist/index.d.ts +2 -4
  10. package/dist/index.js +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/rules/collection-naming.d.ts +1 -4
  13. package/dist/rules/collection-naming.js.map +1 -1
  14. package/dist/rules/index.d.ts +13 -14
  15. package/dist/rules/index.js +1 -1
  16. package/dist/rules/index.js.map +1 -1
  17. package/dist/rules/must-fold-on-component-return.d.ts +1 -4
  18. package/dist/rules/must-fold-on-component-return.js.map +1 -1
  19. package/dist/rules/no-array-mutation.d.ts +1 -4
  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 +1 -4
  23. package/dist/rules/no-floating-io.js.map +1 -1
  24. package/dist/rules/no-floating-result.d.ts +1 -4
  25. package/dist/rules/no-floating-result.js.map +1 -1
  26. package/dist/rules/no-get-unsafe.d.ts +1 -4
  27. package/dist/rules/no-get-unsafe.js +1 -1
  28. package/dist/rules/no-get-unsafe.js.map +1 -1
  29. package/dist/rules/no-getOrThrow-in-render.d.ts +1 -4
  30. package/dist/rules/no-getOrThrow-in-render.js +1 -1
  31. package/dist/rules/no-getOrThrow-in-render.js.map +1 -1
  32. package/dist/rules/no-imperative-loops.d.ts +1 -4
  33. package/dist/rules/no-imperative-loops.js +1 -1
  34. package/dist/rules/no-imperative-loops.js.map +1 -1
  35. package/dist/rules/no-let.d.ts +1 -4
  36. package/dist/rules/no-let.js.map +1 -1
  37. package/dist/rules/no-serialize-container.d.ts +1 -4
  38. package/dist/rules/no-serialize-container.js.map +1 -1
  39. package/dist/rules/no-uncalled-method.d.ts +16 -0
  40. package/dist/rules/no-uncalled-method.js +2 -0
  41. package/dist/rules/no-uncalled-method.js.map +1 -0
  42. package/dist/rules/prefer-do-notation.d.ts +1 -4
  43. package/dist/rules/prefer-do-notation.js +1 -1
  44. package/dist/rules/prefer-do-notation.js.map +1 -1
  45. package/dist/rules/prefer-either.d.ts +1 -4
  46. package/dist/rules/prefer-either.js.map +1 -1
  47. package/dist/rules/prefer-flatmap.d.ts +1 -4
  48. package/dist/rules/prefer-flatmap.js +1 -1
  49. package/dist/rules/prefer-flatmap.js.map +1 -1
  50. package/dist/rules/prefer-fold.d.ts +1 -4
  51. package/dist/rules/prefer-fold.js +1 -1
  52. package/dist/rules/prefer-fold.js.map +1 -1
  53. package/dist/rules/prefer-functype-map.d.ts +1 -4
  54. package/dist/rules/prefer-functype-map.js.map +1 -1
  55. package/dist/rules/prefer-functype-set.d.ts +1 -4
  56. package/dist/rules/prefer-functype-set.js.map +1 -1
  57. package/dist/rules/prefer-list.d.ts +1 -4
  58. package/dist/rules/prefer-list.js +2 -2
  59. package/dist/rules/prefer-list.js.map +1 -1
  60. package/dist/rules/prefer-map.d.ts +1 -4
  61. package/dist/rules/prefer-map.js.map +1 -1
  62. package/dist/rules/prefer-option.d.ts +1 -4
  63. package/dist/rules/prefer-option.js.map +1 -1
  64. package/dist/rules/prefer-try.d.ts +1 -4
  65. package/dist/rules/prefer-try.js +1 -1
  66. package/dist/rules/prefer-try.js.map +1 -1
  67. package/dist/types/ast.d.ts +1 -4
  68. package/dist/utils/array-mutation.d.ts +2 -5
  69. package/dist/utils/array-mutation.js.map +1 -1
  70. package/dist/utils/ast-walk.d.ts +1 -4
  71. package/dist/utils/ast-walk.js.map +1 -1
  72. package/dist/utils/async-detection.d.ts +1 -4
  73. package/dist/utils/async-detection.js.map +1 -1
  74. package/dist/utils/boundary-tags.d.ts +2 -5
  75. package/dist/utils/boundary-tags.js.map +1 -1
  76. package/dist/utils/collection-binding.d.ts +2 -5
  77. package/dist/utils/collection-binding.js.map +1 -1
  78. package/dist/utils/dependency-validator.d.ts +1 -3
  79. package/dist/utils/dependency-validator.js.map +1 -1
  80. package/dist/utils/functype-detection.d.ts +2 -5
  81. package/dist/utils/functype-detection.js +1 -1
  82. package/dist/utils/functype-detection.js.map +1 -1
  83. package/dist/utils/functype-predicates.d.ts +2 -5
  84. package/dist/utils/functype-predicates.js.map +1 -1
  85. package/dist/utils/host-throws.d.ts +2 -5
  86. package/dist/utils/host-throws.js.map +1 -1
  87. package/dist/utils/import-fixer.d.ts +1 -4
  88. package/dist/utils/import-fixer.js.map +1 -1
  89. package/dist/utils/mutable-collection.d.ts +2 -5
  90. package/dist/utils/mutable-collection.js.map +1 -1
  91. package/dist/utils/react-render.d.ts +1 -4
  92. package/dist/utils/react-render.js.map +1 -1
  93. package/dist/utils/readonly-contract.d.ts +1 -4
  94. package/dist/utils/readonly-contract.js.map +1 -1
  95. package/dist/utils/type-aware.d.ts +15 -6
  96. package/dist/utils/type-aware.js +1 -1
  97. package/dist/utils/type-aware.js.map +1 -1
  98. package/dist/utils/wire-types.d.ts +1 -4
  99. package/dist/utils/wire-types.js.map +1 -1
  100. package/package.json +6 -6
  101. package/dist/configs/agent.d.ts +0 -45
  102. package/dist/configs/agent.js +0 -2
  103. package/dist/configs/agent.js.map +0 -1
  104. package/dist/configs/strict.d.ts +0 -26
  105. package/dist/configs/strict.js +0 -2
  106. package/dist/configs/strict.js.map +0 -1
@@ -1,12 +1,15 @@
1
- //#region src/configs/tests.d.ts
2
1
  /** The same files as eslint-config-functype's `test-overrides`. A test in tests/configs.test.ts keeps the two equal. */
3
2
  export declare const testFiles: string[];
4
- /** Tests call plain `T | undefined` APIs and assert on thrown errors. */
3
+ /**
4
+ * Tests call plain `T | undefined` APIs and assert on thrown errors. They also drop a result on
5
+ * purpose, such as `await io.run()` run for its side effect, and assert on a container's
6
+ * `JSON.stringify` envelope.
7
+ */
5
8
  declare const _default: {
6
9
  "functype/prefer-option": string;
7
10
  "functype/prefer-either": string;
8
11
  "functype/prefer-try": string;
12
+ "functype/no-floating-result": string;
13
+ "functype/no-serialize-container": string;
9
14
  };
10
- //#endregion
11
- export { _default as default };
12
- //# sourceMappingURL=tests.d.ts.map
15
+ export { _default as default };
@@ -1,2 +1,2 @@
1
- const e=[`**/*.{test,spec}.{ts,tsx,mts,cts}`,`**/test/**`,`**/tests/**`,`**/__tests__/**`];var t={"functype/prefer-option":`off`,"functype/prefer-either":`off`,"functype/prefer-try":`off`};export{t as default,e as testFiles};
1
+ const e=[`**/*.{test,spec}.{ts,tsx,mts,cts}`,`**/test/**`,`**/tests/**`,`**/__tests__/**`];var t={"functype/prefer-option":`off`,"functype/prefer-either":`off`,"functype/prefer-try":`off`,"functype/no-floating-result":`off`,"functype/no-serialize-container":`off`};export{t as default,e as testFiles};
2
2
  //# sourceMappingURL=tests.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tests.js","names":["testFiles","tests_default"],"sources":["../../src/configs/tests.ts"],"sourcesContent":["/** The same files as eslint-config-functype's `test-overrides`. A test in tests/configs.test.ts keeps the two equal. */\nexport const testFiles = [\"**/*.{test,spec}.{ts,tsx,mts,cts}\", \"**/test/**\", \"**/tests/**\", \"**/__tests__/**\"]\n\n/** Tests call plain `T | undefined` APIs and assert on thrown errors. */\nexport default {\n \"functype/prefer-option\": \"off\",\n \"functype/prefer-either\": \"off\",\n \"functype/prefer-try\": \"off\",\n}\n"],"mappings":"AACA,MAAaA,EAAY,CAAC,oCAAqC,aAAc,cAAe,iBAAiB,EAG7G,IAAAC,EAAe,CACb,yBAA0B,MAC1B,yBAA0B,MAC1B,sBAAuB,KACzB"}
1
+ {"version":3,"file":"tests.js","names":["testFiles","tests_default"],"sources":["../../src/configs/tests.ts"],"sourcesContent":["/** The same files as eslint-config-functype's `test-overrides`. A test in tests/configs.test.ts keeps the two equal. */\nexport const testFiles = [\"**/*.{test,spec}.{ts,tsx,mts,cts}\", \"**/test/**\", \"**/tests/**\", \"**/__tests__/**\"]\n\n/**\n * Tests call plain `T | undefined` APIs and assert on thrown errors. They also drop a result on\n * purpose, such as `await io.run()` run for its side effect, and assert on a container's\n * `JSON.stringify` envelope.\n */\nexport default {\n \"functype/prefer-option\": \"off\",\n \"functype/prefer-either\": \"off\",\n \"functype/prefer-try\": \"off\",\n \"functype/no-floating-result\": \"off\",\n \"functype/no-serialize-container\": \"off\",\n}\n"],"mappings":"AACA,MAAaA,EAAY,CAAC,oCAAqC,aAAc,cAAe,iBAAiB,EAO7G,IAAAC,EAAe,CACb,yBAA0B,MAC1B,yBAA0B,MAC1B,sBAAuB,MACvB,8BAA+B,MAC/B,kCAAmC,KACrC,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;
@@ -19,6 +18,7 @@ declare const plugin: {
19
18
  "no-floating-io": import("eslint").Rule.RuleModule;
20
19
  "no-floating-result": import("eslint").Rule.RuleModule;
21
20
  "no-serialize-container": import("eslint").Rule.RuleModule;
21
+ "no-uncalled-method": import("eslint").Rule.RuleModule;
22
22
  "no-getOrThrow-in-render": import("eslint").Rule.RuleModule;
23
23
  "must-fold-on-component-return": import("eslint").Rule.RuleModule;
24
24
  };
@@ -28,6 +28,4 @@ declare const plugin: {
28
28
  };
29
29
  configs: Record<string, unknown>;
30
30
  };
31
- //#endregion
32
- export { plugin as default };
33
- //# sourceMappingURL=index.d.ts.map
31
+ export { plugin as default };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import e from"./configs/recommended.js";import t from"./configs/strict.js";import n from"./configs/agent.js";import r,{testFiles as i}from"./configs/tests.js";import a from"./rules/index.js";const o={rules:a,meta:{name:`eslint-plugin-functype`,version:`2.127.2`},configs:{}};o.configs={recommended:{name:`functype-plugin/recommended`,plugins:{functype:o},rules:e},strict:{name:`functype-plugin/strict`,plugins:{functype:o},rules:t},agent:{name:`functype-plugin/agent`,plugins:{functype:o},rules:n},tests:{name:`functype-plugin/tests`,plugins:{functype:o},files:i,rules:r}};export{o as default};
1
+ import e from"./configs/recommended.js";import t,{testFiles as n}from"./configs/tests.js";import r from"./rules/index.js";const i={rules:r,meta:{name:`eslint-plugin-functype`,version:`2.201.0`},configs:{}};i.configs={recommended:{name:`functype-plugin/recommended`,plugins:{functype:i},rules:e},tests:{name:`functype-plugin/tests`,plugins:{functype:i},files:n,rules:t}};export{i as default};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["testRules","recommendedRules","strictRules","agentRules","tests_default","rules_default","plugin","testFiles"],"sources":["../src/index.ts"],"sourcesContent":["import agentRules from \"./configs/agent\"\nimport recommendedRules from \"./configs/recommended\"\nimport strictRules from \"./configs/strict\"\nimport testRules, { testFiles } from \"./configs/tests\"\nimport rules from \"./rules\"\n\n/** Set from package.json at build time by tsdown.config.ts, and in tests by vitest.config.ts. */\ndeclare const __VERSION__: string\n\nconst plugin = {\n rules,\n meta: {\n name: \"eslint-plugin-functype\",\n version: typeof __VERSION__ === \"undefined\" ? \"0.0.0-dev\" : __VERSION__,\n },\n configs: {} as Record<string, unknown>,\n}\n\n// Self-referencing plugin in configs (ESLint flat config pattern)\nplugin.configs = {\n recommended: {\n name: \"functype-plugin/recommended\",\n plugins: { functype: plugin },\n rules: recommendedRules,\n },\n strict: {\n name: \"functype-plugin/strict\",\n plugins: { functype: plugin },\n rules: strictRules,\n },\n agent: {\n name: \"functype-plugin/agent\",\n plugins: { functype: plugin },\n rules: agentRules,\n },\n tests: {\n name: \"functype-plugin/tests\",\n plugins: { functype: plugin },\n files: testFiles,\n rules: testRules,\n },\n}\n\nexport default plugin\n"],"mappings":"+LASA,MAAMM,EAAS,CACb,MAAAD,EACA,KAAM,CACJ,KAAM,yBACN,QAAA,SACF,EACA,QAAS,CAAC,CACZ,EAGA,EAAO,QAAU,CACf,YAAa,CACX,KAAM,8BACN,QAAS,CAAE,SAAUC,CAAO,EAC5B,MAAOL,CACT,EACA,OAAQ,CACN,KAAM,yBACN,QAAS,CAAE,SAAUK,CAAO,EAC5B,MAAOJ,CACT,EACA,MAAO,CACL,KAAM,wBACN,QAAS,CAAE,SAAUI,CAAO,EAC5B,MAAOH,CACT,EACA,MAAO,CACL,KAAM,wBACN,QAAS,CAAE,SAAUG,CAAO,EAC5B,MAAOC,EACP,MAAOP,CACT,CACF"}
1
+ {"version":3,"file":"index.js","names":["rules","testRules","recommendedRules","tests_default","testFiles","rules_default","plugin"],"sources":["../src/index.ts"],"sourcesContent":["import recommendedRules from \"./configs/recommended\"\nimport testRules, { testFiles } from \"./configs/tests\"\nimport rules from \"./rules\"\n\n/** Set from package.json at build time by tsdown.config.ts, and in tests by vitest.config.ts. */\ndeclare const __VERSION__: string\n\nconst plugin = {\n rules,\n meta: {\n name: \"eslint-plugin-functype\",\n version: typeof __VERSION__ === \"undefined\" ? \"0.0.0-dev\" : __VERSION__,\n },\n configs: {} as Record<string, unknown>,\n}\n\n// Self-referencing plugin in configs (ESLint flat config pattern)\nplugin.configs = {\n recommended: {\n name: \"functype-plugin/recommended\",\n plugins: { functype: plugin },\n rules: recommendedRules,\n },\n tests: {\n name: \"functype-plugin/tests\",\n plugins: { functype: plugin },\n files: testFiles,\n rules: testRules,\n },\n}\n\nexport default plugin\n"],"mappings":"A,0HAOA,MAAMM,EAAS,CACbN,MAAAA,EACA,KAAM,CACJ,KAAM,yBACN,QAAA,SACF,EACA,QAAS,CAAC,CACZ,EAGAM,EAAO,QAAU,CACf,YAAa,CACX,KAAM,8BACN,QAAS,CAAE,SAAUA,CAAO,EAC5B,MAAOJ,CACT,EACA,MAAO,CACL,KAAM,wBACN,QAAS,CAAE,SAAUI,CAAO,EAC5B,MAAOF,EACP,MAAOH,CACT,CACF,E"}
@@ -1,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,4 @@ 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
- export { rule as default };
19
- //# sourceMappingURL=collection-naming.d.ts.map
16
+ export { rule as default };
@@ -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":["COLLECTION_NAMES","functypeCollectionAt","rule","context","allowAlias","node","hit","source","spec"],"sources":["../../src/rules/collection-naming.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { COLLECTION_NAMES, functypeCollectionAt } from \"../utils/collection-binding\"\n\n/**\n * functype's `Map` / `Set` are the default collections (Scala-style): import them under their own names,\n * and spell the built-in `globalThis.Map` / `globalThis.Set` where it is genuinely needed.\n *\n * Two defects:\n * - `new Map()` on functype's Map. It's a factory, so TypeScript only says TS7009 (\"target lacks a construct\n * signature, implicitly has an 'any' type\"), or TS2350 (\"Only a void function can be called with the 'new'\n * keyword\") when `noImplicitAny` is off. Neither says what to write instead. This message does.\n * - `import { Map as FMap } from \"functype\"`. Aliases let a file keep the built-in under the plain name,\n * which inverts the convention and drifts (`FMap`, `FMapOf`, `IMap`…). `allowAlias: true` opts out.\n *\n * Applies in test files too: tests are read as examples, by people and agents.\n */\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Use functype's Map/Set under their own names; spell the built-in globalThis.Map/globalThis.Set\",\n recommended: true,\n },\n schema: [\n {\n type: \"object\",\n properties: {\n allowAlias: {\n type: \"boolean\",\n default: false,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n newFunctypeCollection:\n \"functype's {{name}} is a factory, not a class: use {{local}}(…) or {{local}}.empty(). For the built-in, write new globalThis.{{name}}(…)\",\n aliasedImport:\n \"Import functype's {{name}} as {{name}}, not {{local}}: functype's {{name}} is the default collection. Spell the built-in globalThis.{{name}}\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n const allowAlias = options.allowAlias === true\n\n return {\n NewExpression(node: ASTNode) {\n const hit = functypeCollectionAt(node.callee, context.sourceCode)\n if (hit === null) return\n context.report({ node, messageId: \"newFunctypeCollection\", data: hit })\n },\n\n ImportDeclaration(node: ASTNode) {\n if (allowAlias) return\n const source = node.source?.value\n if (typeof source !== \"string\" || !(source === \"functype\" || source.startsWith(\"functype/\"))) return\n ;(node.specifiers as ReadonlyArray<ASTNode>)\n .filter(\n (spec) =>\n spec.type === \"ImportSpecifier\" &&\n spec.imported?.type === \"Identifier\" &&\n COLLECTION_NAMES.includes(spec.imported.name) &&\n spec.local.name !== spec.imported.name,\n )\n .forEach((spec) =>\n context.report({\n node: spec,\n messageId: \"aliasedImport\",\n data: { name: spec.imported.name, local: spec.local.name },\n }),\n )\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,4FAkBA,MAAME,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,iGACb,YAAa,EACf,EACA,OAAQ,CACN,CACE,KAAM,SACN,WAAY,CACV,WAAY,CACV,KAAM,UACN,QAAS,EACX,CACF,EACA,qBAAsB,EACxB,CACF,EACA,SAAU,CACR,sBACE,2IACF,cACE,8IACJ,CACF,EAEA,OAAOC,EAAS,CAEd,IAAMC,GADUD,EAAQ,QAAQ,IAAM,CAAC,EAAA,CACZ,aAAe,GAE1C,MAAO,CACL,cAAcE,EAAe,CAC3B,IAAMC,EAAML,EAAqBI,EAAK,OAAQF,EAAQ,UAAU,EAC5DG,IAAQ,MACZH,EAAQ,OAAO,CAAEE,OAAM,UAAW,wBAAyB,KAAMC,CAAI,CAAC,CACxE,EAEA,kBAAkBD,EAAe,CAC/B,GAAID,EAAY,OAChB,IAAMG,EAASF,EAAK,QAAQ,MACxB,OAAOE,GAAW,WAAcA,IAAW,YAAcA,EAAO,WAAW,WAAW,IACxFF,EAAK,WACJ,OACEG,GACCA,EAAK,OAAS,mBACdA,EAAK,UAAU,OAAS,cACxBR,EAAiB,SAASQ,EAAK,SAAS,IAAI,GAC5CA,EAAK,MAAM,OAASA,EAAK,SAAS,IACtC,CAAC,CACA,QAASA,GACRL,EAAQ,OAAO,CACb,KAAMK,EACN,UAAW,gBACX,KAAM,CAAE,KAAMA,EAAK,SAAS,KAAM,MAAOA,EAAK,MAAM,IAAK,CAC3D,CAAC,CACH,CACJ,CACF,CACF,CACF,E"}
@@ -8,17 +8,17 @@ import rule$5 from "./no-getOrThrow-in-render.js";
8
8
  import rule$7 from "./no-imperative-loops.js";
9
9
  import rule$8 from "./no-let.js";
10
10
  import rule$9 from "./no-serialize-container.js";
11
- import rule$10 from "./prefer-do-notation.js";
12
- import rule$11 from "./prefer-either.js";
13
- import rule$12 from "./prefer-flatmap.js";
14
- import rule$13 from "./prefer-fold.js";
15
- import rule$14 from "./prefer-functype-map.js";
16
- import rule$15 from "./prefer-functype-set.js";
17
- import rule$16 from "./prefer-list.js";
18
- import rule$17 from "./prefer-map.js";
19
- import rule$18 from "./prefer-option.js";
20
- import rule$19 from "./prefer-try.js";
21
- //#region src/rules/index.d.ts
11
+ import rule$10 from "./no-uncalled-method.js";
12
+ import rule$11 from "./prefer-do-notation.js";
13
+ import rule$12 from "./prefer-either.js";
14
+ import rule$13 from "./prefer-flatmap.js";
15
+ import rule$14 from "./prefer-fold.js";
16
+ import rule$15 from "./prefer-functype-map.js";
17
+ import rule$16 from "./prefer-functype-set.js";
18
+ import rule$17 from "./prefer-list.js";
19
+ import rule$18 from "./prefer-map.js";
20
+ import rule$19 from "./prefer-option.js";
21
+ import rule$20 from "./prefer-try.js";
22
22
  declare const _default: {
23
23
  "prefer-option": import("eslint").Rule.RuleModule;
24
24
  "prefer-either": import("eslint").Rule.RuleModule;
@@ -38,9 +38,8 @@ declare const _default: {
38
38
  "no-floating-io": import("eslint").Rule.RuleModule;
39
39
  "no-floating-result": import("eslint").Rule.RuleModule;
40
40
  "no-serialize-container": import("eslint").Rule.RuleModule;
41
+ "no-uncalled-method": import("eslint").Rule.RuleModule;
41
42
  "no-getOrThrow-in-render": import("eslint").Rule.RuleModule;
42
43
  "must-fold-on-component-return": import("eslint").Rule.RuleModule;
43
44
  };
44
- //#endregion
45
- export { rule as collectionNaming, _default as default, rule$1 as mustFoldOnComponentReturn, rule$2 as noArrayMutation, rule$3 as noFloatingIo, rule$4 as noFloatingResult, rule$5 as noGetOrThrowInRender, rule$6 as noGetUnsafe, rule$7 as noImperativeLoops, rule$8 as noLet, rule$9 as noSerializeContainer, rule$10 as preferDoNotation, rule$11 as preferEither, rule$12 as preferFlatmap, rule$13 as preferFold, rule$14 as preferFunctypeMap, rule$15 as preferFunctypeSet, rule$16 as preferList, rule$17 as preferMap, rule$18 as preferOption, rule$19 as preferTry };
46
- //# sourceMappingURL=index.d.ts.map
45
+ export { rule as collectionNaming, _default as default, rule$1 as mustFoldOnComponentReturn, rule$2 as noArrayMutation, rule$3 as noFloatingIo, rule$4 as noFloatingResult, rule$5 as noGetOrThrowInRender, rule$6 as noGetUnsafe, rule$7 as noImperativeLoops, rule$8 as noLet, rule$9 as noSerializeContainer, rule$10 as noUncalledMethod, rule$11 as preferDoNotation, rule$12 as preferEither, rule$13 as preferFlatmap, rule$14 as preferFold, rule$15 as preferFunctypeMap, rule$16 as preferFunctypeSet, rule$17 as preferList, rule$18 as preferMap, rule$19 as preferOption, rule$20 as preferTry };
@@ -1,2 +1,2 @@
1
- import e from"./collection-naming.js";import t from"./must-fold-on-component-return.js";import n from"./no-array-mutation.js";import r from"./no-floating-io.js";import i from"./no-floating-result.js";import a from"./no-get-unsafe.js";import o from"./no-getOrThrow-in-render.js";import s from"./no-imperative-loops.js";import c from"./no-let.js";import l from"./no-serialize-container.js";import u from"./prefer-do-notation.js";import d from"./prefer-either.js";import f from"./prefer-flatmap.js";import p from"./prefer-fold.js";import m from"./prefer-functype-map.js";import h from"./prefer-functype-set.js";import g from"./prefer-list.js";import _ from"./prefer-map.js";import v from"./prefer-option.js";import y from"./prefer-try.js";var b={"prefer-option":v,"prefer-either":d,"prefer-try":y,"prefer-list":g,"no-get-unsafe":a,"no-let":c,"prefer-fold":p,"prefer-map":_,"prefer-flatmap":f,"prefer-functype-map":m,"prefer-functype-set":h,"no-imperative-loops":s,"prefer-do-notation":u,"collection-naming":e,"no-array-mutation":n,"no-floating-io":r,"no-floating-result":i,"no-serialize-container":l,"no-getOrThrow-in-render":o,"must-fold-on-component-return":t};export{e as collectionNaming,b as default,t as mustFoldOnComponentReturn,n as noArrayMutation,r as noFloatingIo,i as noFloatingResult,o as noGetOrThrowInRender,a as noGetUnsafe,s as noImperativeLoops,c as noLet,l as noSerializeContainer,u as preferDoNotation,d as preferEither,f as preferFlatmap,p as preferFold,m as preferFunctypeMap,h as preferFunctypeSet,g as preferList,_ as preferMap,v as preferOption,y as preferTry};
1
+ import e from"./collection-naming.js";import t from"./must-fold-on-component-return.js";import n from"./no-array-mutation.js";import r from"./no-floating-io.js";import i from"./no-floating-result.js";import a from"./no-get-unsafe.js";import o from"./no-getOrThrow-in-render.js";import s from"./no-imperative-loops.js";import c from"./no-let.js";import l from"./no-serialize-container.js";import u from"./no-uncalled-method.js";import d from"./prefer-do-notation.js";import f from"./prefer-either.js";import p from"./prefer-flatmap.js";import m from"./prefer-fold.js";import h from"./prefer-functype-map.js";import g from"./prefer-functype-set.js";import _ from"./prefer-list.js";import v from"./prefer-map.js";import y from"./prefer-option.js";import b from"./prefer-try.js";var x={"prefer-option":y,"prefer-either":f,"prefer-try":b,"prefer-list":_,"no-get-unsafe":a,"no-let":c,"prefer-fold":m,"prefer-map":v,"prefer-flatmap":p,"prefer-functype-map":h,"prefer-functype-set":g,"no-imperative-loops":s,"prefer-do-notation":d,"collection-naming":e,"no-array-mutation":n,"no-floating-io":r,"no-floating-result":i,"no-serialize-container":l,"no-uncalled-method":u,"no-getOrThrow-in-render":o,"must-fold-on-component-return":t};export{e as collectionNaming,x as default,t as mustFoldOnComponentReturn,n as noArrayMutation,r as noFloatingIo,i as noFloatingResult,o as noGetOrThrowInRender,a as noGetUnsafe,s as noImperativeLoops,c as noLet,l as noSerializeContainer,u as noUncalledMethod,d as preferDoNotation,f as preferEither,p as preferFlatmap,m as preferFold,h as preferFunctypeMap,g as preferFunctypeSet,_ as preferList,v as preferMap,y as preferOption,b as preferTry};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["preferOption","preferEither","preferTry","preferList","noGetUnsafe","noLet","preferFold","preferMap","preferFlatmap","preferFunctypeMap","preferFunctypeSet","noImperativeLoops","preferDoNotation","collectionNaming","noArrayMutation","noFloatingIo","noFloatingResult","noSerializeContainer","noGetOrThrowInRender","mustFoldOnComponentReturn","rule","rule$1","rule$2","rule$3","rule$4","rule$6","rule$5","rule$7","rule$8","rule$9","rule$10","rule$11","rule$12","rule$13","rule$14","rule$15","rule$16","rule$17","rule$18","rule$19","rules_default"],"sources":["../../src/rules/index.ts"],"sourcesContent":["import collectionNaming from \"./collection-naming\"\nimport mustFoldOnComponentReturn from \"./must-fold-on-component-return\"\nimport noArrayMutation from \"./no-array-mutation\"\nimport noFloatingIo from \"./no-floating-io\"\nimport noFloatingResult from \"./no-floating-result\"\nimport noGetUnsafe from \"./no-get-unsafe\"\nimport noGetOrThrowInRender from \"./no-getOrThrow-in-render\"\nimport noImperativeLoops from \"./no-imperative-loops\"\nimport noLet from \"./no-let\"\nimport noSerializeContainer from \"./no-serialize-container\"\nimport preferDoNotation from \"./prefer-do-notation\"\nimport preferEither from \"./prefer-either\"\nimport preferFlatmap from \"./prefer-flatmap\"\nimport preferFold from \"./prefer-fold\"\nimport preferFunctypeMap from \"./prefer-functype-map\"\nimport preferFunctypeSet from \"./prefer-functype-set\"\nimport preferList from \"./prefer-list\"\nimport preferMap from \"./prefer-map\"\nimport preferOption from \"./prefer-option\"\nimport preferTry from \"./prefer-try\"\n\nexport {\n collectionNaming,\n mustFoldOnComponentReturn,\n noArrayMutation,\n noFloatingIo,\n noFloatingResult,\n noGetOrThrowInRender,\n noGetUnsafe,\n noImperativeLoops,\n noLet,\n noSerializeContainer,\n preferDoNotation,\n preferEither,\n preferFlatmap,\n preferFold,\n preferFunctypeMap,\n preferFunctypeSet,\n preferList,\n preferMap,\n preferOption,\n preferTry,\n}\n\nexport default {\n \"prefer-option\": preferOption,\n \"prefer-either\": preferEither,\n \"prefer-try\": preferTry,\n \"prefer-list\": preferList,\n \"no-get-unsafe\": noGetUnsafe,\n \"no-let\": noLet,\n \"prefer-fold\": preferFold,\n \"prefer-map\": preferMap,\n \"prefer-flatmap\": preferFlatmap,\n \"prefer-functype-map\": preferFunctypeMap,\n \"prefer-functype-set\": preferFunctypeSet,\n \"no-imperative-loops\": noImperativeLoops,\n \"prefer-do-notation\": preferDoNotation,\n \"collection-naming\": collectionNaming,\n \"no-array-mutation\": noArrayMutation,\n \"no-floating-io\": noFloatingIo,\n \"no-floating-result\": noFloatingResult,\n \"no-serialize-container\": noSerializeContainer,\n \"no-getOrThrow-in-render\": noGetOrThrowInRender,\n \"must-fold-on-component-return\": mustFoldOnComponentReturn,\n}\n"],"mappings":"guBA4CA,IAAAwC,EAAe,CACb,gBAAiBxC,EACjB,gBAAiBC,EACjB,aAAcC,EACd,cAAeC,EACf,gBAAiBC,EACjB,SAAUC,EACV,cAAeC,EACf,aAAcC,EACd,iBAAkBC,EAClB,sBAAuBC,EACvB,sBAAuBC,EACvB,sBAAuBC,EACvB,qBAAsBC,EACtB,oBAAqBC,EACrB,oBAAqBC,EACrB,iBAAkBC,EAClB,qBAAsBC,EACtB,yBAA0BC,EAC1B,0BAA2BC,EAC3B,gCAAiCC,CACnC"}
1
+ {"version":3,"file":"index.js","names":["preferOption","preferEither","preferTry","preferList","noGetUnsafe","noLet","preferFold","preferMap","preferFlatmap","preferFunctypeMap","preferFunctypeSet","noImperativeLoops","preferDoNotation","collectionNaming","noArrayMutation","noFloatingIo","noFloatingResult","noSerializeContainer","noUncalledMethod","noGetOrThrowInRender","mustFoldOnComponentReturn","rule","rule$1","rule$2","rule$3","rule$4","rule$6","rule$5","rule$7","rule$8","rule$9","rule$10","rule$11","rule$12","rule$13","rule$14","rule$15","rule$16","rule$17","rule$18","rule$19","rule$20","rules_default"],"sources":["../../src/rules/index.ts"],"sourcesContent":["import collectionNaming from \"./collection-naming\"\nimport mustFoldOnComponentReturn from \"./must-fold-on-component-return\"\nimport noArrayMutation from \"./no-array-mutation\"\nimport noFloatingIo from \"./no-floating-io\"\nimport noFloatingResult from \"./no-floating-result\"\nimport noGetUnsafe from \"./no-get-unsafe\"\nimport noGetOrThrowInRender from \"./no-getOrThrow-in-render\"\nimport noImperativeLoops from \"./no-imperative-loops\"\nimport noLet from \"./no-let\"\nimport noSerializeContainer from \"./no-serialize-container\"\nimport noUncalledMethod from \"./no-uncalled-method\"\nimport preferDoNotation from \"./prefer-do-notation\"\nimport preferEither from \"./prefer-either\"\nimport preferFlatmap from \"./prefer-flatmap\"\nimport preferFold from \"./prefer-fold\"\nimport preferFunctypeMap from \"./prefer-functype-map\"\nimport preferFunctypeSet from \"./prefer-functype-set\"\nimport preferList from \"./prefer-list\"\nimport preferMap from \"./prefer-map\"\nimport preferOption from \"./prefer-option\"\nimport preferTry from \"./prefer-try\"\n\nexport {\n collectionNaming,\n mustFoldOnComponentReturn,\n noArrayMutation,\n noFloatingIo,\n noFloatingResult,\n noGetOrThrowInRender,\n noGetUnsafe,\n noImperativeLoops,\n noLet,\n noSerializeContainer,\n noUncalledMethod,\n preferDoNotation,\n preferEither,\n preferFlatmap,\n preferFold,\n preferFunctypeMap,\n preferFunctypeSet,\n preferList,\n preferMap,\n preferOption,\n preferTry,\n}\n\nexport default {\n \"prefer-option\": preferOption,\n \"prefer-either\": preferEither,\n \"prefer-try\": preferTry,\n \"prefer-list\": preferList,\n \"no-get-unsafe\": noGetUnsafe,\n \"no-let\": noLet,\n \"prefer-fold\": preferFold,\n \"prefer-map\": preferMap,\n \"prefer-flatmap\": preferFlatmap,\n \"prefer-functype-map\": preferFunctypeMap,\n \"prefer-functype-set\": preferFunctypeSet,\n \"no-imperative-loops\": noImperativeLoops,\n \"prefer-do-notation\": preferDoNotation,\n \"collection-naming\": collectionNaming,\n \"no-array-mutation\": noArrayMutation,\n \"no-floating-io\": noFloatingIo,\n \"no-floating-result\": noFloatingResult,\n \"no-serialize-container\": noSerializeContainer,\n \"no-uncalled-method\": noUncalledMethod,\n \"no-getOrThrow-in-render\": noGetOrThrowInRender,\n \"must-fold-on-component-return\": mustFoldOnComponentReturn,\n}\n"],"mappings":"A,uwBA8CA,IAAA0C,EAAe,CACb,gBAAiB1C,EACjB,gBAAiBC,EACjB,aAAcC,EACd,cAAeC,EACf,gBAAiBC,EACjB,SAAUC,EACV,cAAeC,EACf,aAAcC,EACd,iBAAkBC,EAClB,sBAAuBC,EACvB,sBAAuBC,EACvB,sBAAuBC,EACvB,qBAAsBC,EACtB,oBAAqBC,EACrB,oBAAqBC,EACrB,iBAAkBC,EAClB,qBAAsBC,EACtB,yBAA0BC,EAC1B,qBAAsBC,EACtB,0BAA2BC,EAC3B,gCAAiCC,CACnC,E"}
@@ -1,6 +1,3 @@
1
1
  import { Rule } from "eslint";
2
- //#region src/rules/must-fold-on-component-return.d.ts
3
2
  declare const rule: Rule.RuleModule;
4
- //#endregion
5
- export { rule as default };
6
- //# sourceMappingURL=must-fold-on-component-return.d.ts.map
3
+ export { rule as default };
@@ -1 +1 @@
1
- {"version":3,"file":"must-fold-on-component-return.js","names":["returnedValue","statement","consequent","isNullLiteral","node","rule","allowInteropMarker","context","sourceCode","componentPredicate","predicate","testedPredicate","test","fn","enclosingFunction","renderKind","isExtractableByType","isInsideTaggedDeclaration","report","MATCH_COMPONENT","returned","producesJSX"],"sources":["../../src/rules/must-fold-on-component-return.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { INTEROP_TAG, isInsideTaggedDeclaration } from \"../utils/boundary-tags\"\nimport { MATCH_COMPONENT, testedPredicate } from \"../utils/functype-predicates\"\nimport { enclosingFunction, producesJSX, renderKind } from \"../utils/react-render\"\nimport { isExtractableByType } from \"../utils/type-aware\"\n\n/**\n * Reports a component that chooses what it renders by asking an Option / Either / Try which case it\n * holds, in the two shapes `prefer-fold` leaves alone:\n *\n * - an early return: `if (user.isNone()) return <SignIn />`, then the other case below it;\n * - a short-circuit: `{user.isSome() && <Profile />}`, which renders one case and drops the other.\n *\n * A ternary or an if/else on `isSome()` / `isLeft()` / … is `prefer-fold`'s, everywhere, so this rule\n * doesn't report it a second time.\n *\n * The test may wrap the call: `if (!o.isSome()) return null`, `if (busy || o.isNone()) return <S />`.\n * Only a functype predicate *call* counts. `state.isPending` (a `useIO` result) and `items.isEmpty` are\n * properties, never calls, so they're not reported. With type information the receiver must also be a\n * functype container.\n */\n\n/** `return x` alone, or as the only statement of a block: what an early-return guard hands back. */\nconst returnedValue = (consequent: ASTNode): ASTNode | null | undefined => {\n const statement =\n consequent.type === \"BlockStatement\" && consequent.body.length === 1 ? consequent.body[0] : consequent\n return statement?.type === \"ReturnStatement\" ? (statement.argument ?? null) : undefined\n}\n\nconst isNullLiteral = (node: ASTNode): boolean => node?.type === \"Literal\" && node.value === null\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"suggestion\",\n docs: {\n description:\n \"Require a React component to render an Option, Either or Try with fold or a Match component, not an isSome()/isLeft() guard or &&\",\n recommended: false,\n },\n schema: [\n {\n type: \"object\",\n properties: {\n allowInteropMarker: {\n type: \"boolean\",\n default: true,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n guardReturn:\n \"This component picks what it renders with an early return on {{receiver}}.{{method}}(). Render both cases in one expression: {{receiver}}.fold(…) or <{{matcher}}>, so neither branch reads a value that isn't there.\",\n shortCircuit:\n \"{{receiver}}.{{method}}() && … renders one case and drops the other. Use {{receiver}}.fold(…) with null for the case that renders nothing, or <{{matcher}}>.\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n const allowInteropMarker = options.allowInteropMarker !== false\n const sourceCode = context.sourceCode\n\n /** The predicate `test` calls, when `node` sits directly in a component's body (not a nested callback). */\n const componentPredicate = (node: ASTNode, test: ASTNode) => {\n const predicate = testedPredicate(test, sourceCode)\n if (!predicate) return null\n const fn = enclosingFunction(node)\n if (!fn || renderKind(fn) !== \"component\") return null\n if (isExtractableByType(predicate.receiver, context) === false) return null\n if (allowInteropMarker && isInsideTaggedDeclaration(node, INTEROP_TAG, sourceCode)) return null\n return predicate\n }\n\n const report = (node: ASTNode, messageId: string, predicate: NonNullable<ReturnType<typeof componentPredicate>>) =>\n context.report({\n node,\n messageId,\n data: {\n receiver: sourceCode.getText(predicate.receiver),\n method: predicate.method,\n matcher: MATCH_COMPONENT[predicate.method] ?? \"Match\",\n },\n })\n\n return {\n IfStatement(node: ASTNode) {\n // An if/else is prefer-fold's. A guard is an `if` with no `else` that returns JSX or `null`.\n if (node.alternate) return\n const returned = returnedValue(node.consequent)\n if (returned === undefined || !(producesJSX(returned) || isNullLiteral(returned))) return\n const predicate = componentPredicate(node, node.test)\n if (predicate) report(node, \"guardReturn\", predicate)\n },\n\n LogicalExpression(node: ASTNode) {\n if (node.operator !== \"&&\" || !producesJSX(node.right)) return\n const predicate = componentPredicate(node, node.left)\n if (predicate) report(node, \"shortCircuit\", predicate)\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"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,GAA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,EAAK,IAAI,EAChDM,GAAWQ,EAAOd,EAAM,eAAgBM,CAAS,CACvD,CACF,CACF,CACF"}
1
+ {"version":3,"file":"must-fold-on-component-return.js","names":["isInsideTaggedDeclaration","MATCH_COMPONENT","testedPredicate","enclosingFunction","producesJSX","renderKind","isExtractableByType","returnedValue","consequent","statement","isNullLiteral","node","rule","context","allowInteropMarker","sourceCode","componentPredicate","test","predicate","fn","report","messageId","returned"],"sources":["../../src/rules/must-fold-on-component-return.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { INTEROP_TAG, isInsideTaggedDeclaration } from \"../utils/boundary-tags\"\nimport { MATCH_COMPONENT, testedPredicate } from \"../utils/functype-predicates\"\nimport { enclosingFunction, producesJSX, renderKind } from \"../utils/react-render\"\nimport { isExtractableByType } from \"../utils/type-aware\"\n\n/**\n * Reports a component that chooses what it renders by asking an Option / Either / Try which case it\n * holds, in the two shapes `prefer-fold` leaves alone:\n *\n * - an early return: `if (user.isNone()) return <SignIn />`, then the other case below it;\n * - a short-circuit: `{user.isSome() && <Profile />}`, which renders one case and drops the other.\n *\n * A ternary or an if/else on `isSome()` / `isLeft()` / … is `prefer-fold`'s, everywhere, so this rule\n * doesn't report it a second time.\n *\n * The test may wrap the call: `if (!o.isSome()) return null`, `if (busy || o.isNone()) return <S />`.\n * Only a functype predicate *call* counts. `state.isPending` (a `useIO` result) and `items.isEmpty` are\n * properties, never calls, so they're not reported. With type information the receiver must also be a\n * functype container.\n */\n\n/** `return x` alone, or as the only statement of a block: what an early-return guard hands back. */\nconst returnedValue = (consequent: ASTNode): ASTNode | null | undefined => {\n const statement =\n consequent.type === \"BlockStatement\" && consequent.body.length === 1 ? consequent.body[0] : consequent\n return statement?.type === \"ReturnStatement\" ? (statement.argument ?? null) : undefined\n}\n\nconst isNullLiteral = (node: ASTNode): boolean => node?.type === \"Literal\" && node.value === null\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"suggestion\",\n docs: {\n description:\n \"Require a React component to render an Option, Either or Try with fold or a Match component, not an isSome()/isLeft() guard or &&\",\n recommended: false,\n },\n schema: [\n {\n type: \"object\",\n properties: {\n allowInteropMarker: {\n type: \"boolean\",\n default: true,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n guardReturn:\n \"This component picks what it renders with an early return on {{receiver}}.{{method}}(). Render both cases in one expression: {{receiver}}.fold(…) or <{{matcher}}>, so neither branch reads a value that isn't there.\",\n shortCircuit:\n \"{{receiver}}.{{method}}() && … renders one case and drops the other. Use {{receiver}}.fold(…) with null for the case that renders nothing, or <{{matcher}}>.\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n const allowInteropMarker = options.allowInteropMarker !== false\n const sourceCode = context.sourceCode\n\n /** The predicate `test` calls, when `node` sits directly in a component's body (not a nested callback). */\n const componentPredicate = (node: ASTNode, test: ASTNode) => {\n const predicate = testedPredicate(test, sourceCode)\n if (!predicate) return null\n const fn = enclosingFunction(node)\n if (!fn || renderKind(fn) !== \"component\") return null\n if (isExtractableByType(predicate.receiver, context) === false) return null\n if (allowInteropMarker && isInsideTaggedDeclaration(node, INTEROP_TAG, sourceCode)) return null\n return predicate\n }\n\n const report = (node: ASTNode, messageId: string, predicate: NonNullable<ReturnType<typeof componentPredicate>>) =>\n context.report({\n node,\n messageId,\n data: {\n receiver: sourceCode.getText(predicate.receiver),\n method: predicate.method,\n matcher: MATCH_COMPONENT[predicate.method] ?? \"Match\",\n },\n })\n\n return {\n IfStatement(node: ASTNode) {\n // An if/else is prefer-fold's. A guard is an `if` with no `else` that returns JSX or `null`.\n if (node.alternate) return\n const returned = returnedValue(node.consequent)\n if (returned === undefined || !(producesJSX(returned) || isNullLiteral(returned))) return\n const predicate = componentPredicate(node, node.test)\n if (predicate) report(node, \"guardReturn\", predicate)\n },\n\n LogicalExpression(node: ASTNode) {\n if (node.operator !== \"&&\" || !producesJSX(node.right)) return\n const predicate = componentPredicate(node, node.left)\n if (predicate) report(node, \"short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IAAa,EAAElB,EAAYkB,CAAQ,GAAKZ,EAAcY,CAAQ,GAAI,OACnF,IAAMJ,EAAYF,EAAmBL,EAAMA,EAAK,IAAI,EAChDO,GAAWE,EAAOT,EAAM,cAAeO,CAAS,CACtD,EAEA,kBAAkBP,EAAe,CAC/B,GAAIA,EAAK,WAAa,MAAQ,CAACP,EAAYO,EAAK,KAAK,EAAG,OACxD,IAAMO,EAAYF,EAAmBL,EAAMA,EAAK,IAAI,EAChDO,GAAWE,EAAOT,EAAM,eAAgBO,CAAS,CACvD,CACF,CACF,CACF,E"}
@@ -1,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,4 @@ 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
- export { rule as default };
17
- //# sourceMappingURL=no-array-mutation.d.ts.map
14
+ export { rule as default };
@@ -1,2 +1,2 @@
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};
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};
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,EA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AASV,CAAI,EAAG,OACpB,IAAMiB,EAAUL,EAAcM,CAAM,EACpC,GAAID,EAAS,CACXX,EAAQ,OAAO,CAAE,OAAM,UAAW,oBAAqB,KAAM,CAAE,KAAML,EAAOgB,EAASd,CAAU,CAAE,CAAE,CAAC,EACpG,MACF,CACA,IAAMgB,EAASJ,EAAaG,CAAM,EAC9BC,GACFb,EAAQ,OAAO,CAAE,OAAM,UAAW,mBAAoB,KAAM,CAAE,KAAML,EAAOkB,EAAQhB,CAAU,CAAE,CAAE,CAAC,CAEtG,EAEA,MAAO,CACL,eAAe,EAAe,CAC5B,IAAMiB,EAASpB,EAAK,OACpB,GAAIoB,EAAO,OAAS,oBAAsBA,EAAO,SAAU,OAC3D,IAAMC,EAASD,EAAO,UAAU,OAAS,aAAeA,EAAO,SAAS,KAAO,KAC/E,GAAIC,IAAW,MAAQ,CAACvB,EAAiB,IAAIuB,CAAM,EAAG,OACtD,IAAMR,EAAQO,EAAO,OACjBrB,EAAac,CAAK,GAAKH,EAASV,CAAI,GACnCc,EAAyBD,EAAOP,CAAO,GAC5CA,EAAQ,OAAO,CACb,OACA,UAAW,iBACX,KAAM,CAAE,KAAML,EAAOY,EAAOV,CAAU,EAAG,QAAO,CAClD,CAAC,CACH,EAEA,qBAAqB,EAAe,CAClCa,EAAYhB,EAAMA,EAAK,IAAe,CACxC,EAEA,iBAAiB,EAAe,CAC9BgB,EAAYhB,EAAMA,EAAK,QAAmB,CAC5C,EAEA,gBAAgB,EAAe,CACzBA,EAAK,WAAa,UAAUgB,EAAYhB,EAAMA,EAAK,QAAmB,CAC5E,CACF,CACF,CACF"}
1
+ {"version":3,"file":"no-array-mutation.js","names":["isMutableArrayExpression","isInsideTaggedDeclaration","MUTATING_METHODS","isFreshValue","node","nameOf","sourceCode","text","rule","context","options","allowInTests","allowInteropMarker","filename","isExempt","elementTarget","array","lengthTarget","reportWrite","target","element","length","callee","method"],"sources":["../../src/rules/no-array-mutation.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { isMutableArrayExpression } from \"../utils/array-mutation\"\nimport { INTEROP_TAG, isInsideTaggedDeclaration } from \"../utils/boundary-tags\"\n\n/** Array methods that change the array they're called on. */\nconst MUTATING_METHODS: ReadonlySet<string> = new Set([\n \"push\",\n \"pop\",\n \"shift\",\n \"unshift\",\n \"splice\",\n \"sort\",\n \"reverse\",\n \"fill\",\n \"copyWithin\",\n])\n\n/**\n * Is `node` assumed to be a value nothing else can see yet — `[...xs]`, `xs.slice()`, `Array.from(it)`,\n * `items.map(f)`? Mutating it on the spot (`[...xs].sort(byRank)`) is the common copy-then-sort idiom.\n * Every call result is assumed fresh, so `getSharedCache().push(x)` is missed too: a recall gap the rule\n * accepts to keep false positives at zero. Only a named array (a binding or a property) is reported.\n */\nconst isFreshValue = (node: ASTNode): boolean =>\n node.type === \"ArrayExpression\" ||\n node.type === \"CallExpression\" ||\n node.type === \"NewExpression\" ||\n (node.type === \"AwaitExpression\" && isFreshValue(node.argument as ASTNode))\n\n/** The variable or property name of a mutated array, for the message: `rows`, `this.events`, `acc.errors`. */\nconst nameOf = (node: ASTNode, sourceCode: Rule.RuleContext[\"sourceCode\"]): string => {\n const text = sourceCode.getText(node)\n return text.length > 40 ? `${text.slice(0, 37)}…` : text\n}\n\n/**\n * Reports in-place mutation of a mutable array: `push` / `pop` / `shift` / `unshift` / `splice` / `sort` /\n * `reverse` / `fill` / `copyWithin`, assignment to an element (`xs[i] = v`, `xs[i] += 1`, `xs[i]++`),\n * `delete xs[i]`, and setting `length`.\n *\n * This is the mutation itself, wherever the array came from — an inferred `const rows = load()` included,\n * which `prefer-list` can't see because it has no annotation or literal to hook onto. Type-aware only:\n * without type information it reports nothing, so `push` on a custom class or a `Set` is never mistaken\n * for an array. Mutating a literal or a call result on the spot (`[...xs].sort(byRank)`) isn't reported:\n * it's assumed to be a fresh copy (see isFreshValue for the recall gap that leaves).\n */\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Disallow changing an array in place — build a new one\",\n recommended: true,\n },\n schema: [\n {\n type: \"object\",\n properties: {\n allowInTests: { type: \"boolean\", default: true },\n allowInteropMarker: { type: \"boolean\", default: true },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n mutatingMethod:\n \"{{name}}.{{method}}() changes the array in place. Build a new one instead: [...{{name}}, x], map / filter / flatMap / toSorted, a List, or a fold\",\n elementAssignment:\n \"Assigning to an element of {{name}} changes the array in place. Build a new one instead: {{name}}.with(i, v), map, a List, or a fold\",\n lengthAssignment:\n \"Setting {{name}}.length changes the array in place. Build a new one instead: {{name}}.slice(0, n), or start from []\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n const allowInTests = options.allowInTests !== false\n const allowInteropMarker = options.allowInteropMarker !== false\n const sourceCode = context.sourceCode\n\n const isInTestFile = (): boolean => {\n const filename = context.filename\n return (\n /\\.(test|spec)\\.(ts|js|tsx|jsx)$/.test(filename) ||\n filename.includes(\"__tests__\") ||\n filename.includes(\"/test/\") ||\n filename.includes(\"/tests/\")\n )\n }\n if (allowInTests && isInTestFile()) return {}\n\n /** `@interop <reason>` on an enclosing declaration marks a host boundary that has to mutate. */\n const isExempt = (node: ASTNode): boolean =>\n allowInteropMarker && isInsideTaggedDeclaration(node, INTEROP_TAG, sourceCode)\n\n /** `xs[i]` (a computed member) on a named mutable array, or null. */\n const elementTarget = (node: ASTNode | null | undefined): ASTNode | null => {\n if (node?.type !== \"MemberExpression\") return null\n const array = node.object as ASTNode\n if (isFreshValue(array)) return null\n if (node.computed) return isMutableArrayExpression(array, context) ? array : null\n return null\n }\n\n /** `xs.length` on a named mutable array, or null. */\n const lengthTarget = (node: ASTNode | null | undefined): ASTNode | null => {\n if (node?.type !== \"MemberExpression\" || node.computed) return null\n const array = node.object as ASTNode\n if (node.property?.type !== \"Identifier\" || node.property.name !== \"length\" || isFreshValue(array)) return null\n return isMutableArrayExpression(array, context) ? array : null\n }\n\n const reportWrite = (node: ASTNode, target: ASTNode): void => {\n if (isExempt(node)) return\n const element = elementTarget(target)\n if (element) {\n context.report({ node, messageId: \"elementAssignment\", data: { name: nameOf(element, sourceCode) } })\n return\n }\n const length = lengthTarget(target)\n if (length) {\n context.report({ node, messageId: \"lengthAssignment\", data: { name: nameOf(length, sourceCode) } })\n }\n }\n\n return {\n CallExpression(node: ASTNode) {\n const callee = node.callee as ASTNode\n if (callee.type !== \"MemberExpression\" || callee.computed) return\n const method = callee.property?.type === \"Identifier\" ? callee.property.name : null\n if (method === null || !MUTATING_METHODS.has(method)) return\n const array = callee.object as ASTNode\n if (isFreshValue(array) || isExempt(node)) return\n if (!isMutableArrayExpression(array, context)) return\n context.report({\n node,\n messageId: \"mutatingMethod\",\n data: { name: nameOf(array, sourceCode), method },\n })\n },\n\n AssignmentExpression(node: ASTNode) {\n reportWrite(node, node.left as ASTNode)\n },\n\n UpdateExpression(node: ASTNode) {\n reportWrite(node, node.argument as ASTNode)\n },\n\n UnaryExpression(node: ASTNode) {\n if (node.operator === \"delete\") reportWrite(node, node.argument as ASTNode)\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,4IAOA,MAAME,kBAAwC,IAAI,IAAI,CACpD,OACA,MACA,QACA,UACA,SACA,OACA,UACA,OACA,YACF,CAAC,EAQKC,EAAgBC,GACpBA,EAAK,OAAS,mBACdA,EAAK,OAAS,kBACdA,EAAK,OAAS,iBACbA,EAAK,OAAS,mBAAqBD,EAAaC,EAAK,QAAmB,EAGrEC,GAAUD,EAAeE,IAAuD,CACpF,IAAMC,EAAOD,EAAW,QAAQF,CAAI,EACpC,OAAOG,EAAK,OAAS,GAAK,GAAGA,EAAK,MAAM,EAAG,EAAE,EAAE,GAAKA,CACtD,EAaMC,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,wDACb,YAAa,EACf,EACA,OAAQ,CACN,CACE,KAAM,SACN,WAAY,CACV,aAAc,CAAE,KAAM,UAAW,QAAS,EAAK,EAC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AAM,EAC9BE,GACFZ,EAAQ,OAAO,CAAEL,OAAM,UAAW,mBAAoB,KAAM,CAAE,KAAMC,EAAOgB,EAAQf,CAAU,CAAE,CAAE,CAAC,CAEtG,EAEA,MAAO,CACL,eAAeF,EAAe,CAC5B,IAAMkB,EAASlB,EAAK,OACpB,GAAIkB,EAAO,OAAS,oBAAsBA,EAAO,SAAU,OAC3D,IAAMC,EAASD,EAAO,UAAU,OAAS,aAAeA,EAAO,SAAS,KAAO,KAC/E,GAAIC,IAAW,MAAQ,CAACrB,EAAiB,IAAIqB,CAAM,EAAG,OACtD,IAAMP,EAAQM,EAAO,OACjBnB,EAAaa,CAAK,GAAKF,EAASV,CAAI,GACnCJ,EAAyBgB,EAAOP,CAAO,GAC5CA,EAAQ,OAAO,CACbL,OACA,UAAW,iBACX,KAAM,CAAE,KAAMC,EAAOW,EAAOV,CAAU,EAAGiB,QAAO,CAClD,CAAC,CACH,EAEA,qBAAqBnB,EAAe,CAClCc,EAAYd,EAAMA,EAAK,IAAe,CACxC,EAEA,iBAAiBA,EAAe,CAC9Bc,EAAYd,EAAMA,EAAK,QAAmB,CAC5C,EAEA,gBAAgBA,EAAe,CACzBA,EAAK,WAAa,UAAUc,EAAYd,EAAMA,EAAK,QAAmB,CAC5E,CACF,CACF,CACF,E"}
@@ -1,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,4 @@ 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
- export { rule as default };
18
- //# sourceMappingURL=no-floating-io.d.ts.map
15
+ export { rule as default };
@@ -1 +1 @@
1
- {"version":3,"file":"no-floating-io.js","names":["rule","expression","node","isIOByType","context"],"sources":["../../src/rules/no-floating-io.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { isIOByType } from \"../utils/type-aware\"\n\n/**\n * Reports an `IO` that is built and then dropped, so it never runs:\n *\n * - an expression statement whose value is an `IO` — `log.info(\"saved\")`, `save(user).tap(audit)`;\n * - `await` on an `IO`. `IO` is not a Promise, so `await io` hands back the `IO` itself, unrun.\n *\n * `no-floating-promises` and `await-thenable` don't see either case, because `IO` is not thenable.\n * Returning, yielding, assigning or passing an `IO` along is fine: someone else runs it. `void io`\n * marks a deliberate drop and isn't reported.\n *\n * Type-aware only: without type information it reports nothing.\n */\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Disallow building an IO and never running it\",\n recommended: false,\n },\n schema: [],\n messages: {\n floatingIO:\n \"This IO is built and never run, so it does nothing. Run it (.run(), .runOrThrow(), .runExit()), return it, or yield* it inside IO.gen\",\n awaitedIO:\n \"await on an IO does nothing: IO is not a Promise, so this returns the IO unrun. Await .run() or .runOrThrow() instead\",\n },\n },\n\n create(context) {\n return {\n ExpressionStatement(node: ASTNode) {\n const expression = node.expression as ASTNode\n // `void io` is a deliberate drop; `await io` is reported by the AwaitExpression visitor.\n if (expression.type === \"AwaitExpression\") return\n if (expression.type === \"UnaryExpression\" && expression.operator === \"void\") return\n if (isIOByType(expression, context)) context.report({ node: expression, messageId: \"floatingIO\" })\n },\n AwaitExpression(node: ASTNode) {\n if (isIOByType(node.argument as ASTNode, context)) context.report({ node, messageId: \"awaitedIO\" })\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"oDAiBA,MAAMA,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,+CACb,YAAa,EACf,EACA,OAAQ,CAAC,EACT,SAAU,CACR,WACE,wIACF,UACE,uHACJ,CACF,EAEA,OAAO,EAAS,CACd,MAAO,CACL,oBAAoB,EAAe,CACjC,IAAMC,EAAaC,EAAK,WAEpBD,EAAW,OAAS,oBACpBA,EAAW,OAAS,mBAAqBA,EAAW,WAAa,SACjEE,EAAWF,EAAYG,CAAO,GAAGA,EAAQ,OAAO,CAAE,KAAMH,EAAY,UAAW,YAAa,CAAC,CACnG,EACA,gBAAgB,EAAe,CACzBE,EAAWD,EAAK,SAAqBE,CAAO,GAAGA,EAAQ,OAAO,CAAE,OAAM,UAAW,WAAY,CAAC,CACpG,CACF,CACF,CACF"}
1
+ {"version":3,"file":"no-floating-io.js","names":["isIOByType","rule","context","node","expression"],"sources":["../../src/rules/no-floating-io.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { isIOByType } from \"../utils/type-aware\"\n\n/**\n * Reports an `IO` that is built and then dropped, so it never runs:\n *\n * - an expression statement whose value is an `IO` — `log.info(\"saved\")`, `save(user).tap(audit)`;\n * - `await` on an `IO`. `IO` is not a Promise, so `await io` hands back the `IO` itself, unrun.\n *\n * `no-floating-promises` and `await-thenable` don't see either case, because `IO` is not thenable.\n * Returning, yielding, assigning or passing an `IO` along is fine: someone else runs it. `void io`\n * marks a deliberate drop and isn't reported.\n *\n * Type-aware only: without type information it reports nothing.\n */\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Disallow building an IO and never running it\",\n recommended: false,\n },\n schema: [],\n messages: {\n floatingIO:\n \"This IO is built and never run, so it does nothing. Run it (.run(), .runOrThrow(), .runExit()), return it, or yield* it inside IO.gen\",\n awaitedIO:\n \"await on an IO does nothing: IO is not a Promise, so this returns the IO unrun. Await .run() or .runOrThrow() instead\",\n },\n },\n\n create(context) {\n return {\n ExpressionStatement(node: ASTNode) {\n const expression = node.expression as ASTNode\n // `void io` is a deliberate drop; `await io` is reported by the AwaitExpression visitor.\n if (expression.type === \"AwaitExpression\") return\n if (expression.type === \"UnaryExpression\" && expression.operator === \"void\") return\n if (isIOByType(expression, context)) context.report({ node: expression, messageId: \"floatingIO\" })\n },\n AwaitExpression(node: ASTNode) {\n if (isIOByType(node.argument as ASTNode, context)) context.report({ node, messageId: \"awaitedIO\" })\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,oDAiBA,MAAMC,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,+CACb,YAAa,EACf,EACA,OAAQ,CAAC,EACT,SAAU,CACR,WACE,wIACF,UACE,uHACJ,CACF,EAEA,OAAOC,EAAS,CACd,MAAO,CACL,oBAAoBC,EAAe,CACjC,IAAMC,EAAaD,EAAK,WAEpBC,EAAW,OAAS,oBACpBA,EAAW,OAAS,mBAAqBA,EAAW,WAAa,SACjEJ,EAAWI,EAAYF,CAAO,GAAGA,EAAQ,OAAO,CAAE,KAAME,EAAY,UAAW,YAAa,CAAC,CACnG,EACA,gBAAgBD,EAAe,CACzBH,EAAWG,EAAK,SAAqBD,CAAO,GAAGA,EAAQ,OAAO,CAAEC,OAAM,UAAW,WAAY,CAAC,CACpG,CACF,CACF,CACF,E"}
@@ -1,5 +1,4 @@
1
1
  import { Rule } from "eslint";
2
- //#region src/rules/no-floating-result.d.ts
3
2
  /**
4
3
  * Reports a statement that computes an Either, Try or other failure-carrying result and drops it:
5
4
  * `await userService.updateSubscription(id, plan)` on its own line, or `parse(input)`. A Left or a
@@ -14,6 +13,4 @@ import { Rule } from "eslint";
14
13
  * Type-aware only: without type information it reports nothing.
15
14
  */
16
15
  declare const rule: Rule.RuleModule;
17
- //#endregion
18
- export { rule as default };
19
- //# sourceMappingURL=no-floating-result.d.ts.map
16
+ export { rule as default };
@@ -1 +1 @@
1
- {"version":3,"file":"no-floating-result.js","names":["CHECKED","FAILURE_HANDLERS","FAILURE_SOURCES","handlesItsFailure","node","callee","property","name","rule","expression","canCarryFailureByType","context"],"sources":["../../src/rules/no-floating-result.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { canCarryFailureByType } from \"../utils/type-aware\"\n\n/** `f()`, `a?.f()`, `await …`, and `ok && f()` / `ok ? f() : g()`: statements whose only job is a value. */\nconst CHECKED: ReadonlySet<string> = new Set([\n \"CallExpression\",\n \"ChainExpression\",\n \"AwaitExpression\",\n \"LogicalExpression\",\n \"ConditionalExpression\",\n])\n\n/** Methods that run a callback on the failure, so a chain through one has handled it. */\nconst FAILURE_HANDLERS: ReadonlySet<string> = new Set([\"tapError\", \"tapLeft\"])\n\n/** Methods that can bring in a new failure, so a handler before one no longer covers the result. */\nconst FAILURE_SOURCES: ReadonlySet<string> = new Set([\"flatMap\", \"chain\", \"andThen\", \"flatMapError\", \"orElse\"])\n\n/**\n * Does the call chain in `node` handle its own failure? Walks the receiver chain from the outermost\n * call in: a `.tapError(…)` or `.tapLeft(…)` counts, unless a later `.flatMap(…)` can bring in a new,\n * unlogged failure. Arguments are never walked into.\n */\nconst handlesItsFailure = (node: ASTNode | undefined): boolean => {\n if (!node) return false\n if (node.type === \"AwaitExpression\") return handlesItsFailure(node.argument as ASTNode)\n if (node.type === \"ChainExpression\") return handlesItsFailure(node.expression as ASTNode)\n if (node.type !== \"CallExpression\") return false\n const callee = node.callee as ASTNode\n if (callee.type !== \"MemberExpression\") return false\n const property = callee.property as ASTNode\n const name = property.type === \"Identifier\" ? (property.name as string) : \"\"\n if (FAILURE_HANDLERS.has(name)) return true\n if (FAILURE_SOURCES.has(name)) return false\n return handlesItsFailure(callee.object as ASTNode)\n}\n\n/**\n * Reports a statement that computes an Either, Try or other failure-carrying result and drops it:\n * `await userService.updateSubscription(id, plan)` on its own line, or `parse(input)`. A Left or a\n * Failure in it is silently ignored. `no-floating-promises` doesn't help, because awaiting the promise\n * satisfies it while the result inside is thrown away.\n *\n * Only results that can carry a failure count: an ignored Option or List loses no error. A chain that\n * handles its own failure with `.tapError(…)` or `.tapLeft(…)` isn't reported: that is a best-effort\n * write that logs a failure on purpose, as in agent-todo's audit and cleanup writes. `void result`\n * marks any other deliberate drop. An `IO` that is never run is no-floating-io's.\n *\n * Type-aware only: without type information it reports nothing.\n */\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Disallow dropping an Either, Try or other result that can carry a failure\",\n recommended: false,\n },\n schema: [],\n messages: {\n floatingResult:\n \"This result is dropped, so a failure in it is silently ignored. Check isLeft() / isFailure(), fold it, or return it. Use void if dropping it is deliberate\",\n },\n },\n\n create(context) {\n return {\n ExpressionStatement(node: ASTNode) {\n const expression = node.expression as ASTNode\n // `void result` is a UnaryExpression, so a deliberate drop never gets this far.\n if (!CHECKED.has(expression.type) || handlesItsFailure(expression)) return\n if (canCarryFailureByType(expression, context))\n context.report({ node: expression, messageId: \"floatingResult\" })\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"+DAMA,MAAMA,kBAA+B,IAAI,IAAI,CAC3C,iBACA,kBACA,kBACA,oBACA,uBACF,CAAC,EAGKC,kBAAwC,IAAI,IAAI,CAAC,WAAY,SAAS,CAAC,EAGvEC,kBAAuC,IAAI,IAAI,CAAC,UAAW,QAAS,UAAW,eAAgB,QAAQ,CAAC,EAOxGC,EAAqB,GAAuC,CAChE,GAAI,CAACC,EAAM,MAAO,GAClB,GAAIA,EAAK,OAAS,kBAAmB,OAAOD,EAAkBC,EAAK,QAAmB,EACtF,GAAIA,EAAK,OAAS,kBAAmB,OAAOD,EAAkBC,EAAK,UAAqB,EACxF,GAAIA,EAAK,OAAS,iBAAkB,MAAO,GAC3C,IAAMC,EAASD,EAAK,OACpB,GAAIC,EAAO,OAAS,mBAAoB,MAAO,GAC/C,IAAMC,EAAWD,EAAO,SAClBE,EAAOD,EAAS,OAAS,aAAgBA,EAAS,KAAkB,GAG1E,OAFIL,EAAiB,IAAIM,CAAI,EAAU,GACvC,CAAIL,EAAgB,IAAIK,CAAI,GACrBJ,EAAkBE,EAAO,MAAiB,CACnD,EAeMG,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,4EACb,YAAa,EACf,EACA,OAAQ,CAAC,EACT,SAAU,CACR,eACE,4JACJ,CACF,EAEA,OAAO,EAAS,CACd,MAAO,CACL,oBAAoB,EAAe,CACjC,IAAMC,EAAaL,EAAK,WAEnBJ,EAAQ,IAAIS,EAAW,IAAI,GAAK,GAAkBA,CAAU,GAC7DC,EAAsBD,EAAYE,CAAO,GAC3CA,EAAQ,OAAO,CAAE,KAAMF,EAAY,UAAW,gBAAiB,CAAC,CACpE,CACF,CACF,CACF"}
1
+ {"version":3,"file":"no-floating-result.js","names":["canCarryFailureByType","CHECKED","FAILURE_HANDLERS","FAILURE_SOURCES","handlesItsFailure","node","callee","property","name","rule","context","expression"],"sources":["../../src/rules/no-floating-result.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { canCarryFailureByType } from \"../utils/type-aware\"\n\n/** `f()`, `a?.f()`, `await …`, and `ok && f()` / `ok ? f() : g()`: statements whose only job is a value. */\nconst CHECKED: ReadonlySet<string> = new Set([\n \"CallExpression\",\n \"ChainExpression\",\n \"AwaitExpression\",\n \"LogicalExpression\",\n \"ConditionalExpression\",\n])\n\n/** Methods that run a callback on the failure, so a chain through one has handled it. */\nconst FAILURE_HANDLERS: ReadonlySet<string> = new Set([\"tapError\", \"tapLeft\"])\n\n/** Methods that can bring in a new failure, so a handler before one no longer covers the result. */\nconst FAILURE_SOURCES: ReadonlySet<string> = new Set([\"flatMap\", \"chain\", \"andThen\", \"flatMapError\", \"orElse\"])\n\n/**\n * Does the call chain in `node` handle its own failure? Walks the receiver chain from the outermost\n * call in: a `.tapError(…)` or `.tapLeft(…)` counts, unless a later `.flatMap(…)` can bring in a new,\n * unlogged failure. Arguments are never walked into.\n */\nconst handlesItsFailure = (node: ASTNode | undefined): boolean => {\n if (!node) return false\n if (node.type === \"AwaitExpression\") return handlesItsFailure(node.argument as ASTNode)\n if (node.type === \"ChainExpression\") return handlesItsFailure(node.expression as ASTNode)\n if (node.type !== \"CallExpression\") return false\n const callee = node.callee as ASTNode\n if (callee.type !== \"MemberExpression\") return false\n const property = callee.property as ASTNode\n const name = property.type === \"Identifier\" ? (property.name as string) : \"\"\n if (FAILURE_HANDLERS.has(name)) return true\n if (FAILURE_SOURCES.has(name)) return false\n return handlesItsFailure(callee.object as ASTNode)\n}\n\n/**\n * Reports a statement that computes an Either, Try or other failure-carrying result and drops it:\n * `await userService.updateSubscription(id, plan)` on its own line, or `parse(input)`. A Left or a\n * Failure in it is silently ignored. `no-floating-promises` doesn't help, because awaiting the promise\n * satisfies it while the result inside is thrown away.\n *\n * Only results that can carry a failure count: an ignored Option or List loses no error. A chain that\n * handles its own failure with `.tapError(…)` or `.tapLeft(…)` isn't reported: that is a best-effort\n * write that logs a failure on purpose, as in agent-todo's audit and cleanup writes. `void result`\n * marks any other deliberate drop. An `IO` that is never run is no-floating-io's.\n *\n * Type-aware only: without type information it reports nothing.\n */\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Disallow dropping an Either, Try or other result that can carry a failure\",\n recommended: false,\n },\n schema: [],\n messages: {\n floatingResult:\n \"This result is dropped, so a failure in it is silently ignored. Check isLeft() / isFailure(), fold it, or return it. Use void if dropping it is deliberate\",\n },\n },\n\n create(context) {\n return {\n ExpressionStatement(node: ASTNode) {\n const expression = node.expression as ASTNode\n // `void result` is a UnaryExpression, so a deliberate drop never gets this far.\n if (!CHECKED.has(expression.type) || handlesItsFailure(expression)) return\n if (canCarryFailureByType(expression, context))\n context.report({ node: expression, messageId: \"floatingResult\" })\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,+DAMA,MAAMC,kBAA+B,IAAI,IAAI,CAC3C,iBACA,kBACA,kBACA,oBACA,uBACF,CAAC,EAGKC,kBAAwC,IAAI,IAAI,CAAC,WAAY,SAAS,CAAC,EAGvEC,kBAAuC,IAAI,IAAI,CAAC,UAAW,QAAS,UAAW,eAAgB,QAAQ,CAAC,EAOxGC,EAAqBC,GAAuC,CAChE,GAAI,CAACA,EAAM,MAAO,GAClB,GAAIA,EAAK,OAAS,kBAAmB,OAAOD,EAAkBC,EAAK,QAAmB,EACtF,GAAIA,EAAK,OAAS,kBAAmB,OAAOD,EAAkBC,EAAK,UAAqB,EACxF,GAAIA,EAAK,OAAS,iBAAkB,MAAO,GAC3C,IAAMC,EAASD,EAAK,OACpB,GAAIC,EAAO,OAAS,mBAAoB,MAAO,GAC/C,IAAMC,EAAWD,EAAO,SAClBE,EAAOD,EAAS,OAAS,aAAgBA,EAAS,KAAkB,GAG1E,OAFIL,EAAiB,IAAIM,CAAI,EAAU,GACvC,CAAIL,EAAgB,IAAIK,CAAI,GACrBJ,EAAkBE,EAAO,MAAiB,CACnD,EAeMG,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,4EACb,YAAa,EACf,EACA,OAAQ,CAAC,EACT,SAAU,CACR,eACE,4JACJ,CACF,EAEA,OAAOC,EAAS,CACd,MAAO,CACL,oBAAoBL,EAAe,CACjC,IAAMM,EAAaN,EAAK,WAEnBJ,EAAQ,IAAIU,EAAW,IAAI,GAAKP,GAAkBO,CAAU,GAC7DX,EAAsBW,EAAYD,CAAO,GAC3CA,EAAQ,OAAO,CAAE,KAAMC,EAAY,UAAW,gBAAiB,CAAC,CACpE,CACF,CACF,CACF,E"}
@@ -1,6 +1,3 @@
1
1
  import { Rule } from "eslint";
2
- //#region src/rules/no-get-unsafe.d.ts
3
2
  declare const rule: Rule.RuleModule;
4
- //#endregion
5
- export { rule as default };
6
- //# sourceMappingURL=no-get-unsafe.d.ts.map
3
+ export { rule as default };
@@ -1,2 +1,2 @@
1
- import{isInsideTaggedDeclaration as e}from"../utils/boundary-tags.js";import{isExtractableByType as t}from"../utils/type-aware.js";const n=[`orThrow`,`expect`,`get`,`getOrThrow`,`unwrap`],r={meta:{type:`problem`,docs:{description:`Avoid unsafe extractor calls on Option, Either, and other Extractable types`,recommended:!0},hasSuggestions:!0,schema:[{type:`object`,properties:{allowInTests:{type:`boolean`,default:!0},allowInteropMarker:{type:`boolean`,default:!0},unsafeMethods:{type:`array`,items:{type:`string`},default:[...n]}},additionalProperties:!1}],messages:{noUnsafeGet:`Avoid unsafe .{{method}}() call: it throws a generic error. Use .fold(), .map(), or .orElse() instead. If a host needs the throw, name the error: .orThrow((e) => new MyError(e))`,suggestOrElse:`Replace with .orElse(default) for a value fallback`,suggestFold:`Replace with .fold(onNone, onSome) for branch handling`}},create(r){let i=r.options[0]||{},a=i.allowInTests!==!1,o=i.unsafeMethods||n,s=i.allowInteropMarker!==!1,c=(e,t)=>e===`orThrow`&&t.arguments.length>0;function l(){let e=r.filename;return/\.(test|spec)\.(ts|js|tsx|jsx)$/.test(e)||e.includes(`__tests__`)||e.includes(`/test/`)||e.includes(`/tests/`)}function u(e){if(!e)return!1;let t=r.sourceCode.getText(e);if(/\b(Option|Either|Maybe|Result|Some|None|Left|Right)\b/.test(t)||/\.(map|flatMap|filter|fold)\s*\(/.test(t)||/\b(option|either|maybe|result|some|none|left|right)\w*\b/i.test(t))return!0;if(e.type===`Identifier`){let t=e.name.toLowerCase();if(/(option|either|maybe|result|some|none|left|right|opt)/.test(t))return!0}return e.type===`CallExpression`&&e.callee.type===`MemberExpression`&&e.callee.object?u(e.callee.object):!1}return{CallExpression(n){if(a&&l()||n.callee.type!==`MemberExpression`)return;let i=n.callee.property;if(!i||i.type!==`Identifier`)return;let d=i.name;if(o.includes(d)&&!c(d,n)&&!(s&&e(n,`interop`,r.sourceCode))&&(t(n.callee.object,r)??u(n.callee.object))){let e=r.sourceCode,t=e.getText(n.callee.object),i=n.arguments.map(t=>e.getText(t)).join(`, `),a=i?`; was ${d}(${i})`:``;r.report({node:n,messageId:`noUnsafeGet`,data:{method:d},suggest:[{messageId:`suggestOrElse`,fix(e){return e.replaceText(n,`${t}.orElse(undefined /* TODO: default${a} */)`)}},{messageId:`suggestFold`,fix(e){return e.replaceText(n,`${t}.fold(() => undefined /* TODO: onNone${a} */, (v) => v /* TODO: onSome */)`)}}]})}}}}};export{r as default};
1
+ import{isInsideTaggedDeclaration as e}from"../utils/boundary-tags.js";import{isExtractableByType as t}from"../utils/type-aware.js";const n=[`orThrow`,`expect`,`get`,`getOrThrow`,`unwrap`],r={meta:{type:`problem`,docs:{description:`Avoid unsafe extractor calls on Option, Either, and other Extractable types`,recommended:!0},hasSuggestions:!0,schema:[{type:`object`,properties:{allowInTests:{type:`boolean`,default:!0},allowInteropMarker:{type:`boolean`,default:!0},unsafeMethods:{type:`array`,items:{type:`string`},default:[...n]}},additionalProperties:!1}],messages:{noUnsafeGet:`Avoid unsafe .{{method}}() call: it throws a generic error. Use .fold(), .map(), or .getOrElse(() => default) instead. If a host needs the throw, name the error: .orThrow((e) => new MyError(e))`,suggestGetOrElse:`Replace with .getOrElse(() => default) for a value fallback`,suggestFold:`Replace with .fold(onNone, onSome) for branch handling`}},create(r){let i=r.options[0]||{},a=i.allowInTests!==!1,o=i.unsafeMethods||n,s=i.allowInteropMarker!==!1,c=(e,t)=>e===`orThrow`&&t.arguments.length>0;function l(){let e=r.filename;return/\.(test|spec)\.(ts|js|tsx|jsx)$/.test(e)||e.includes(`__tests__`)||e.includes(`/test/`)||e.includes(`/tests/`)}function u(e){if(!e)return!1;let t=r.sourceCode.getText(e);if(/\b(Option|Either|Maybe|Result|Some|None|Left|Right)\b/.test(t)||/\.(map|flatMap|filter|fold)\s*\(/.test(t)||/\b(option|either|maybe|result|some|none|left|right)\w*\b/i.test(t))return!0;if(e.type===`Identifier`){let t=e.name.toLowerCase();if(/(option|either|maybe|result|some|none|left|right|opt)/.test(t))return!0}return e.type===`CallExpression`&&e.callee.type===`MemberExpression`&&e.callee.object?u(e.callee.object):!1}return{CallExpression(n){if(a&&l()||n.callee.type!==`MemberExpression`)return;let i=n.callee.property;if(!i||i.type!==`Identifier`)return;let d=i.name;if(o.includes(d)&&!c(d,n)&&!(s&&e(n,`interop`,r.sourceCode))&&(t(n.callee.object,r)??u(n.callee.object))){let e=r.sourceCode,t=e.getText(n.callee.object),i=n.arguments.map(t=>e.getText(t)).join(`, `),a=i?`; was ${d}(${i})`:``;r.report({node:n,messageId:`noUnsafeGet`,data:{method:d},suggest:[{messageId:`suggestGetOrElse`,fix(e){return e.replaceText(n,`${t}.getOrElse(() => undefined /* TODO: default${a} */)`)}},{messageId:`suggestFold`,fix(e){return e.replaceText(n,`${t}.fold(() => undefined /* TODO: onNone${a} */, (v) => v /* TODO: onSome */)`)}}]})}}}}};export{r as default};
2
2
  //# sourceMappingURL=no-get-unsafe.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"no-get-unsafe.js","names":["DEFAULT_UNSAFE_METHODS","rule","options","context","allowInTests","unsafeMethods","allowInteropMarker","isChosenErrorThrow","methodName","node","isInTestFile","filename","isMonadicType","text","varName","property","isInsideTaggedDeclaration","isExtractableByType","sourceCode","objectText","argsText","a","wasSuffix","fixer"],"sources":["../../src/rules/no-get-unsafe.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { INTEROP_TAG, isInsideTaggedDeclaration } from \"../utils/boundary-tags\"\nimport { isExtractableByType } from \"../utils/type-aware\"\n\nconst DEFAULT_UNSAFE_METHODS: readonly string[] = [\"orThrow\", \"expect\", \"get\", \"getOrThrow\", \"unwrap\"]\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Avoid unsafe extractor calls on Option, Either, and other Extractable types\",\n recommended: true,\n },\n hasSuggestions: true,\n schema: [\n {\n type: \"object\",\n properties: {\n allowInTests: {\n type: \"boolean\",\n default: true,\n },\n allowInteropMarker: {\n type: \"boolean\",\n default: true,\n },\n unsafeMethods: {\n type: \"array\",\n items: { type: \"string\" },\n default: [...DEFAULT_UNSAFE_METHODS],\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n noUnsafeGet:\n \"Avoid unsafe .{{method}}() call: it throws a generic error. Use .fold(), .map(), or .orElse() instead. If a host needs the throw, name the error: .orThrow((e) => new MyError(e))\",\n suggestOrElse: \"Replace with .orElse(default) for a value fallback\",\n suggestFold: \"Replace with .fold(onNone, onSome) for branch handling\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n const allowInTests = options.allowInTests !== false\n const unsafeMethods: readonly string[] = options.unsafeMethods || DEFAULT_UNSAFE_METHODS\n // `@interop <reason>` on an enclosing declaration marks a host-contract boundary, as in prefer-either.\n const allowInteropMarker = options.allowInteropMarker !== false\n\n /**\n * `.orThrow(error)` / `.orThrow((e) => error)`: the caller chose the error. That is the documented way\n * to throw for a host that needs it, not an unsafe extraction; `prefer-either` and the README's\n * decision table both treat it that way. Only a bare `.orThrow()` throws a generic error.\n */\n const isChosenErrorThrow = (methodName: string, node: ASTNode): boolean =>\n methodName === \"orThrow\" && node.arguments.length > 0\n\n function isInTestFile() {\n const filename = context.filename\n return (\n /\\.(test|spec)\\.(ts|js|tsx|jsx)$/.test(filename) ||\n filename.includes(\"__tests__\") ||\n filename.includes(\"/test/\") ||\n filename.includes(\"/tests/\")\n )\n }\n\n function isMonadicType(node: ASTNode): boolean {\n // This is a simplified check - in a real implementation, you'd want\n // more sophisticated type checking using TypeScript's type checker\n if (!node) return false\n\n const sourceCode = context.sourceCode\n\n // Check for common patterns that indicate monadic types\n const text = sourceCode.getText(node)\n\n // Direct type checks - constructors or type names\n if (/\\b(Option|Either|Maybe|Result|Some|None|Left|Right)\\b/.test(text)) {\n return true\n }\n\n // Method chains that suggest monadic operations\n if (/\\.(map|flatMap|filter|fold)\\s*\\(/.test(text)) {\n return true\n }\n\n // Variable names that suggest monadic types (case insensitive)\n if (/\\b(option|either|maybe|result|some|none|left|right)\\w*\\b/i.test(text)) {\n return true\n }\n\n // Check the specific node type and name\n if (node.type === \"Identifier\") {\n const varName = node.name.toLowerCase()\n if (/(option|either|maybe|result|some|none|left|right|opt)/.test(varName)) {\n return true\n }\n }\n\n // Check for CallExpression pattern like Some(\"test\").map()\n if (node.type === \"CallExpression\" && node.callee.type === \"MemberExpression\" && node.callee.object) {\n return isMonadicType(node.callee.object)\n }\n\n return false\n }\n\n return {\n CallExpression(node: ASTNode) {\n if (allowInTests && isInTestFile()) return\n\n if (node.callee.type !== \"MemberExpression\") return\n\n const property = node.callee.property\n if (!property || property.type !== \"Identifier\") return\n\n const methodName = property.name\n if (!unsafeMethods.includes(methodName)) return\n if (isChosenErrorThrow(methodName, node)) return\n if (allowInteropMarker && isInsideTaggedDeclaration(node, INTEROP_TAG, context.sourceCode)) return\n\n // With type information, the receiver's type decides: no name guessing, so `missing.orThrow()`\n // on an Option is reported and `options.get(\"k\")` on a native Map is not. Without it, fall\n // back to the name/shape heuristic.\n const byType = isExtractableByType(node.callee.object, context)\n if (byType ?? isMonadicType(node.callee.object)) {\n const sourceCode = context.sourceCode\n const objectText = sourceCode.getText(node.callee.object)\n\n // Preserve the original call's argument text in the TODO comment so a suggestion\n // applied to `.expect(\"Should have a user here\")` or `.orThrow(new NotFound())`\n // doesn't silently drop information the developer intended to keep. Omit the\n // \"was\" suffix when the original call had no args (`.get()`, `.unwrap()`, etc.).\n const argsText = node.arguments.map((a: ASTNode) => sourceCode.getText(a)).join(\", \")\n const wasSuffix = argsText ? `; was ${methodName}(${argsText})` : \"\"\n\n context.report({\n node,\n messageId: \"noUnsafeGet\",\n data: { method: methodName },\n suggest: [\n {\n messageId: \"suggestOrElse\",\n fix(fixer) {\n return fixer.replaceText(node, `${objectText}.orElse(undefined /* TODO: default${wasSuffix} */)`)\n },\n },\n {\n messageId: \"suggestFold\",\n fix(fixer) {\n return fixer.replaceText(\n node,\n `${objectText}.fold(() => undefined /* TODO: onNone${wasSuffix} */, (v) => v /* TODO: onSome */)`,\n )\n },\n },\n ],\n })\n }\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"mIAMA,MAAMA,EAA4C,CAAC,UAAW,SAAU,MAAO,aAAc,QAAQ,EAE/FC,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,8EACb,YAAa,EACf,EACA,eAAgB,GAChB,OAAQ,CACN,CACE,KAAM,SACN,WAAY,CACV,aAAc,CACZ,KAAM,UACN,QAAS,EACX,EACA,mBA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AAaO,EAAS,KAC5B,GAAKV,EAAc,SAASG,CAAU,GAClC,GAAmBA,EAAYC,CAAI,GACnC,KAAsBO,EAA0BP,EAAA,UAAmBN,EAAQ,UAAU,KAK1Ec,EAAoBR,EAAK,OAAO,OAAQN,CAC9C,GAAKS,EAAcH,EAAK,OAAO,MAAM,GAAG,CAC/C,IAAMS,EAAaf,EAAQ,WACrBgB,EAAaD,EAAW,QAAQT,EAAK,OAAO,MAAM,EAMlDW,EAAWX,EAAK,UAAU,IAAK,GAAeS,EAAW,QAAQG,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAC9EC,EAAYF,EAAW,SAASZ,EAAW,GAAGY,EAAS,GAAK,GAElEjB,EAAQ,OAAO,CACb,OACA,UAAW,cACX,KAAM,CAAE,OAAQK,CAAW,EAC3B,QAAS,CACP,CACE,UAAW,gBACX,IAAI,EAAO,CACT,OAAOe,EAAM,YAAYd,EAAM,GAAGU,EAAW,oCAAoCG,EAAU,KAAK,CAClG,CACF,EACA,CACE,UAAW,cACX,IAAI,EAAO,CACT,OAAOC,EAAM,YACXd,EACA,GAAGU,EAAW,uCAAuCG,EAAU,kCACjE,CACF,CACF,CACF,CACF,CAAC,CACH,CACF,CACF,CACF,CACF"}
1
+ {"version":3,"file":"no-get-unsafe.js","names":["isInsideTaggedDeclaration","isExtractableByType","DEFAULT_UNSAFE_METHODS","rule","context","options","allowInTests","unsafeMethods","allowInteropMarker","isChosenErrorThrow","methodName","node","isInTestFile","filename","isMonadicType","text","varName","property","sourceCode","objectText","argsText","a","wasSuffix","fixer"],"sources":["../../src/rules/no-get-unsafe.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { INTEROP_TAG, isInsideTaggedDeclaration } from \"../utils/boundary-tags\"\nimport { isExtractableByType } from \"../utils/type-aware\"\n\nconst DEFAULT_UNSAFE_METHODS: readonly string[] = [\"orThrow\", \"expect\", \"get\", \"getOrThrow\", \"unwrap\"]\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Avoid unsafe extractor calls on Option, Either, and other Extractable types\",\n recommended: true,\n },\n hasSuggestions: true,\n schema: [\n {\n type: \"object\",\n properties: {\n allowInTests: {\n type: \"boolean\",\n default: true,\n },\n allowInteropMarker: {\n type: \"boolean\",\n default: true,\n },\n unsafeMethods: {\n type: \"array\",\n items: { type: \"string\" },\n default: [...DEFAULT_UNSAFE_METHODS],\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n noUnsafeGet:\n \"Avoid unsafe .{{method}}() call: it throws a generic error. Use .fold(), .map(), or .getOrElse(() => default) instead. If a host needs the throw, name the error: .orThrow((e) => new MyError(e))\",\n suggestGetOrElse: \"Replace with .getOrElse(() => default) for a value fallback\",\n suggestFold: \"Replace with .fold(onNone, onSome) for branch handling\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n const allowInTests = options.allowInTests !== false\n const unsafeMethods: readonly string[] = options.unsafeMethods || DEFAULT_UNSAFE_METHODS\n // `@interop <reason>` on an enclosing declaration marks a host-contract boundary, as in prefer-either.\n const allowInteropMarker = options.allowInteropMarker !== false\n\n /**\n * `.orThrow(error)` / `.orThrow((e) => error)`: the caller chose the error. That is the documented way\n * to throw for a host that needs it, not an unsafe extraction; `prefer-either` and the README's\n * decision table both treat it that way. Only a bare `.orThrow()` throws a generic error.\n */\n const isChosenErrorThrow = (methodName: string, node: ASTNode): boolean =>\n methodName === \"orThrow\" && node.arguments.length > 0\n\n function isInTestFile() {\n const filename = context.filename\n return (\n /\\.(test|spec)\\.(ts|js|tsx|jsx)$/.test(filename) ||\n filename.includes(\"__tests__\") ||\n filename.includes(\"/test/\") ||\n filename.includes(\"/tests/\")\n )\n }\n\n function isMonadicType(node: ASTNode): boolean {\n // This is a simplified check - in a real implementation, you'd want\n // more sophisticated type checking using TypeScript's type checker\n if (!node) return false\n\n const sourceCode = context.sourceCode\n\n // Check for common patterns that indicate monadic types\n const text = sourceCode.getText(node)\n\n // Direct type checks - constructors or type names\n if (/\\b(Option|Either|Maybe|Result|Some|None|Left|Right)\\b/.test(text)) {\n return true\n }\n\n // Method chains that suggest monadic operations\n if (/\\.(map|flatMap|filter|fold)\\s*\\(/.test(text)) {\n return true\n }\n\n // Variable names that suggest monadic types (case insensitive)\n if (/\\b(option|either|maybe|result|some|none|left|right)\\w*\\b/i.test(text)) {\n return true\n }\n\n // Check the specific node type and name\n if (node.type === \"Identifier\") {\n const varName = node.name.toLowerCase()\n if (/(option|either|maybe|result|some|none|left|right|opt)/.test(varName)) {\n return true\n }\n }\n\n // Check for CallExpression pattern like Some(\"test\").map()\n if (node.type === \"CallExpression\" && node.callee.type === \"MemberExpression\" && node.callee.object) {\n return isMonadicType(node.callee.object)\n }\n\n return false\n }\n\n return {\n CallExpression(node: ASTNode) {\n if (allowInTests && isInTestFile()) return\n\n if (node.callee.type !== \"MemberExpression\") return\n\n const property = node.callee.property\n if (!property || property.type !== \"Identifier\") return\n\n const methodName = property.name\n if (!unsafeMethods.includes(methodName)) return\n if (isChosenErrorThrow(methodName, node)) return\n if (allowInteropMarker && isInsideTaggedDeclaration(node, INTEROP_TAG, context.sourceCode)) return\n\n // With type information, the receiver's type decides: no name guessing, so `missing.orThrow()`\n // on an Option is reported and `options.get(\"k\")` on a native Map is not. Without it, fall\n // back to the name/shape heuristic.\n const byType = isExtractableByType(node.callee.object, context)\n if (byType ?? isMonadicType(node.callee.object)) {\n const sourceCode = context.sourceCode\n const objectText = sourceCode.getText(node.callee.object)\n\n // Preserve the original call's argument text in the TODO comment so a suggestion\n // applied to `.expect(\"Should have a user here\")` or `.orThrow(new NotFound())`\n // doesn't silently drop information the developer intended to keep. Omit the\n // \"was\" suffix when the original call had no args (`.get()`, `.unwrap()`, etc.).\n const argsText = node.arguments.map((a: ASTNode) => sourceCode.getText(a)).join(\", \")\n const wasSuffix = argsText ? `; was ${methodName}(${argsText})` : \"\"\n\n context.report({\n node,\n messageId: \"noUnsafeGet\",\n data: { method: methodName },\n suggest: [\n {\n messageId: \"suggestGetOrElse\",\n fix(fixer) {\n return fixer.replaceText(\n node,\n `${objectText}.getOrElse(() => undefined /* TODO: default${wasSuffix} */)`,\n )\n },\n },\n {\n messageId: \"suggestFold\",\n fix(fixer) {\n return fixer.replaceText(\n node,\n `${objectText}.fold(() => undefined /* TODO: onNone${wasSuffix} */, (v) => v /* TODO: onSome */)`,\n )\n },\n },\n ],\n })\n }\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,mIAMA,MAAME,EAA4C,CAAC,UAAW,SAAU,MAAO,aAAc,QAAQ,EAE/FC,EAAwB,CAC5B,KAAM,CACJ,KAAM,UACN,KAAM,CACJ,YAAa,8EACb,YAAa,EACf,EACA,eAAgB,GAChB,OAAQ,CACN,CACE,KAAM,SACN,WAAY,CACV,aAAc,CACZ,KAAM,UACN,QAAS,EACX,EACA,mBAAoB,CAClB,KAAM,UACN,QAAS,EACX,EACA,cAAe,CACb,KAAM,QACN,MAAO,CAAE,KAAM,QAAS,EACxB,QAAS,CAAC,GAAGD,CAAsB,CACrC,CACF,EACA,qBAAsB,EACxB,CACF,EACA,SAAU,CACR,YACE,oMACF,iBAAkB,8DAClB,YAAa,wDACf,CACF,EAEA,OAAOE,EAAS,CACd,IAAMC,EAAUD,EAAQ,QAAQ,IAAM,CAAC,EACjCE,EAAeD,EAAQ,eAAiB,GACxCE,EAAmCF,EAAQ,eAAiBH,EAE5DM,EAAqBH,EAAQ,qBAAuB,GAOpDI,GAAsBC,EAAoBC,IAC9CD,IAAe,WAAaC,EAAK,UAAU,OAAS,EAEtD,SAASC,GAAe,CACtB,IAAMC,EAAWT,EAAQ,SACzB,MACE,kCAAkC,KAAKS,CAAQ,GAC/CA,EAAS,SAAS,WAAW,GAC7BA,EAAS,SAAS,QAAQ,GAC1BA,EAAS,SAAS,SAAS,CAE/B,CAEA,SAASC,EAAcH,EAAwB,CAG7C,GAAI,CAACA,EAAM,MAAO,GAKlB,IAAMI,EAHaX,EAA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,EACA,GAAGQ,EAAW,uCAAuCG,EAAU,kCACjE,CACF,CACF,CACF,CACF,CAAC,CACH,CACF,CACF,CACF,CACF,E"}
@@ -1,6 +1,3 @@
1
1
  import { Rule } from "eslint";
2
- //#region src/rules/no-getOrThrow-in-render.d.ts
3
2
  declare const rule: Rule.RuleModule;
4
- //#endregion
5
- export { rule as default };
6
- //# sourceMappingURL=no-getOrThrow-in-render.d.ts.map
3
+ export { rule as default };
@@ -1,2 +1,2 @@
1
- import{isInsideTaggedDeclaration as e}from"../utils/boundary-tags.js";import{compact as t,provesWhen as n}from"../utils/functype-predicates.js";import{enclosingFunction as r,renderKind as i}from"../utils/react-render.js";import{isExtractableByType as a}from"../utils/type-aware.js";const o=/* @__PURE__ */ new Set([`orThrow`,`getOrThrow`]),s=e=>e.type===`ReturnStatement`||e.type===`ThrowStatement`||e.type===`BlockStatement`&&e.body.length>0&&s(e.body.at(-1)),c=(e,t,r)=>{if(e.type===`IfStatement`)return s(e.consequent)?n(e.test,!1,t,r)===`present`?!0:e.alternate?c(e.alternate,t,r):!1:!1;let i=e.type===`ExpressionStatement`?e.expression:null;return i?.type===`CallExpression`&&i.callee.type===`Identifier`&&i.callee.name===`invariant`&&i.arguments.length>0&&n(i.arguments[0],!0,t,r)===`present`},l=(e,t,r,i)=>{let a=(e,t)=>n(e,t,r,i)===`present`,o=(e,n)=>{if(!n||n===t)return!1;let s=n.type===`IfStatement`||n.type===`ConditionalExpression`;return s&&n.consequent===e&&a(n.test,!0)||s&&n.alternate===e&&a(n.test,!1)||n.type===`LogicalExpression`&&n.right===e&&(n.operator===`&&`&&a(n.left,!0)||n.operator===`||`&&a(n.left,!1))||n.type===`BlockStatement`&&n.body.slice(0,n.body.indexOf(e)).some(e=>c(e,r,i))?!0:o(n,n.parent)};return o(e,e.parent)},u={meta:{type:`problem`,docs:{description:`Disallow a throwing extractor (.orThrow(), .getOrThrow()) in a React component or hook body`,recommended:!1},schema:[{type:`object`,properties:{allowInteropMarker:{type:`boolean`,default:!0}},additionalProperties:!1}],messages:{throwInRender:`{{receiver}}.{{method}}() throws during render when the value is missing, and a throw in render unmounts the tree up to the nearest error boundary. Render both cases with .fold(…) or <MatchOption> / <MatchEither> / <MatchTry>, or read a fallback with .orElse(…). To reach an error boundary on purpose, name the error: .orThrow((e) => new MyError(e))`}},create(n){let s=(n.options[0]||{}).allowInteropMarker!==!1,c=n.sourceCode;return{CallExpression(u){let d=u.callee;if(d.type!==`MemberExpression`||d.computed||d.property.type!==`Identifier`)return;let f=d.property.name;if(!o.has(f)||u.arguments.length>0)return;let p=r(u);if(!p||i(p)===null||a(d.object,n)===!1)return;let m=t(c.getText(d.object));l(u,p,m,c)||s&&e(u,`interop`,c)||n.report({node:u,messageId:`throwInRender`,data:{receiver:c.getText(d.object),method:f}})}}}};export{u as default};
1
+ import{isInsideTaggedDeclaration as e}from"../utils/boundary-tags.js";import{compact as t,provesWhen as n}from"../utils/functype-predicates.js";import{enclosingFunction as r,renderKind as i}from"../utils/react-render.js";import{isExtractableByType as a}from"../utils/type-aware.js";const o=/* @__PURE__ */ new Set([`orThrow`,`getOrThrow`]),s=e=>e.type===`ReturnStatement`||e.type===`ThrowStatement`||e.type===`BlockStatement`&&e.body.length>0&&s(e.body.at(-1)),c=(e,t,r)=>{if(e.type===`IfStatement`)return s(e.consequent)?n(e.test,!1,t,r)===`present`?!0:e.alternate?c(e.alternate,t,r):!1:!1;let i=e.type===`ExpressionStatement`?e.expression:null;return i?.type===`CallExpression`&&i.callee.type===`Identifier`&&i.callee.name===`invariant`&&i.arguments.length>0&&n(i.arguments[0],!0,t,r)===`present`},l=(e,t,r,i)=>{let a=(e,t)=>n(e,t,r,i)===`present`,o=(e,n)=>{if(!n||n===t)return!1;let s=n.type===`IfStatement`||n.type===`ConditionalExpression`;return s&&n.consequent===e&&a(n.test,!0)||s&&n.alternate===e&&a(n.test,!1)||n.type===`LogicalExpression`&&n.right===e&&(n.operator===`&&`&&a(n.left,!0)||n.operator===`||`&&a(n.left,!1))||n.type===`BlockStatement`&&n.body.slice(0,n.body.indexOf(e)).some(e=>c(e,r,i))?!0:o(n,n.parent)};return o(e,e.parent)},u={meta:{type:`problem`,docs:{description:`Disallow a throwing extractor (.orThrow(), .getOrThrow()) in a React component or hook body`,recommended:!1},schema:[{type:`object`,properties:{allowInteropMarker:{type:`boolean`,default:!0}},additionalProperties:!1}],messages:{throwInRender:`{{receiver}}.{{method}}() throws during render when the value is missing, and a throw in render unmounts the tree up to the nearest error boundary. Render both cases with .fold(…) or <MatchOption> / <MatchEither> / <MatchTry>, or read a fallback with .getOrElse(() => …). To reach an error boundary on purpose, name the error: .orThrow((e) => new MyError(e))`}},create(n){let s=(n.options[0]||{}).allowInteropMarker!==!1,c=n.sourceCode;return{CallExpression(u){let d=u.callee;if(d.type!==`MemberExpression`||d.computed||d.property.type!==`Identifier`)return;let f=d.property.name;if(!o.has(f)||u.arguments.length>0)return;let p=r(u);if(!p||i(p)===null||a(d.object,n)===!1)return;let m=t(c.getText(d.object));l(u,p,m,c)||s&&e(u,`interop`,c)||n.report({node:u,messageId:`throwInRender`,data:{receiver:c.getText(d.object),method:f}})}}}};export{u as default};
2
2
  //# sourceMappingURL=no-getOrThrow-in-render.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"no-getOrThrow-in-render.js","names":["THROWING_METHODS","exits","statement","continuesWithValue","provesWhen","receiverText","sourceCode","call","isGuarded","present","test","outcome","walk","node","stop","branch","child","rule","allowInteropMarker","context","callee","method","fn","enclosingFunction","renderKind","isExtractableByType","compact","isInsideTaggedDeclaration"],"sources":["../../src/rules/no-getOrThrow-in-render.ts"],"sourcesContent":["import type { Rule, SourceCode } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { INTEROP_TAG, isInsideTaggedDeclaration } from \"../utils/boundary-tags\"\nimport { compact, provesWhen } from \"../utils/functype-predicates\"\nimport { enclosingFunction, renderKind } from \"../utils/react-render\"\nimport { isExtractableByType } from \"../utils/type-aware\"\n\n/**\n * The extractors that throw a generic error when the value is missing. `orThrow` is the one functype's\n * containers carry; `getOrThrow` is its older name, which the rule is named after. Each is reported only\n * bare: `orThrow(error)` names the error, the way to send a failure to an error boundary on purpose.\n * `expect(handler)` is never reported, because its handler is the chosen throw.\n */\nconst THROWING_METHODS: ReadonlySet<string> = new Set([\"orThrow\", \"getOrThrow\"])\n\n/** A statement that leaves the function: `return …`, `throw …`, or a block that ends in one. */\nconst exits = (statement: ASTNode): boolean =>\n statement.type === \"ReturnStatement\" ||\n statement.type === \"ThrowStatement\" ||\n (statement.type === \"BlockStatement\" && statement.body.length > 0 && exits(statement.body.at(-1)))\n\n/**\n * Does `statement` only let control continue past it once the value is known to be there?\n *\n * - an early exit on the missing case: `if (!o.isSome()) return null`, `if (busy || o.isNone()) return <S />`,\n * `if (o.isEmpty) throw …`;\n * - an if / else-if chain whose every branch exits, except the way out that proves it:\n * `if (x) return <B />; else if (o.isNone()) return null`;\n * - `invariant(o.isSome(), \"…\")` from functype, which narrows the code after it.\n */\nconst continuesWithValue = (statement: ASTNode, receiverText: string, sourceCode: SourceCode): boolean => {\n if (statement.type === \"IfStatement\") {\n if (!exits(statement.consequent)) return false\n if (provesWhen(statement.test, false, receiverText, sourceCode) === \"present\") return true\n return statement.alternate ? continuesWithValue(statement.alternate, receiverText, sourceCode) : false\n }\n const call = statement.type === \"ExpressionStatement\" ? statement.expression : null\n return (\n call?.type === \"CallExpression\" &&\n call.callee.type === \"Identifier\" &&\n call.callee.name === \"invariant\" &&\n call.arguments.length > 0 &&\n provesWhen(call.arguments[0], true, receiverText, sourceCode) === \"present\"\n )\n}\n\n/**\n * Is the call inside a branch that already proved the value is there? `o.isSome() ? o.orThrow() : …`,\n * `!o.isSome() ? null : o.orThrow()`, `if (e.isRight()) return e.orThrow()`, `t.isSuccess() && t.orThrow()`,\n * or after a statement in an enclosing block that only continues once it is (`continuesWithValue`). Then\n * the call cannot throw.\n */\nconst isGuarded = (call: ASTNode, stop: ASTNode, receiverText: string, sourceCode: SourceCode): boolean => {\n const present = (test: ASTNode, outcome: boolean): boolean =>\n provesWhen(test, outcome, receiverText, sourceCode) === \"present\"\n\n const walk = (child: ASTNode, node: ASTNode | undefined): boolean => {\n if (!node || node === stop) return false\n const branch = node.type === \"IfStatement\" || node.type === \"ConditionalExpression\"\n if (branch && node.consequent === child && present(node.test, true)) return true\n if (branch && node.alternate === child && present(node.test, false)) return true\n if (node.type === \"LogicalExpression\" && node.right === child) {\n if (node.operator === \"&&\" && present(node.left, true)) return true\n if (node.operator === \"||\" && present(node.left, false)) return true\n }\n if (node.type === \"BlockStatement\") {\n const before = (node.body as ReadonlyArray<ASTNode>).slice(0, node.body.indexOf(child))\n if (before.some((statement) => continuesWithValue(statement, receiverText, sourceCode))) return true\n }\n return walk(node, node.parent)\n }\n return walk(call, call.parent)\n}\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Disallow a throwing extractor (.orThrow(), .getOrThrow()) in a React component or hook body\",\n recommended: false,\n },\n schema: [\n {\n type: \"object\",\n properties: {\n allowInteropMarker: {\n type: \"boolean\",\n default: true,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n throwInRender:\n \"{{receiver}}.{{method}}() throws during render when the value is missing, and a throw in render unmounts the tree up to the nearest error boundary. Render both cases with .fold(…) or <MatchOption> / <MatchEither> / <MatchTry>, or read a fallback with .orElse(…). To reach an error boundary on purpose, name the error: .orThrow((e) => new MyError(e))\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n // `@interop <reason>` on an enclosing declaration marks a host contract, such as React's `use()`.\n const allowInteropMarker = options.allowInteropMarker !== false\n const sourceCode = context.sourceCode\n\n return {\n CallExpression(node: ASTNode) {\n const callee = node.callee as ASTNode\n if (callee.type !== \"MemberExpression\" || callee.computed || callee.property.type !== \"Identifier\") return\n const method = callee.property.name as string\n if (!THROWING_METHODS.has(method) || node.arguments.length > 0) return\n\n // Only the component's or hook's own body runs during render. An event handler, an effect or a\n // `.map` callback is a separate function, so a call there is not attributed to the render.\n const fn = enclosingFunction(node)\n if (!fn || renderKind(fn) === null) return\n\n // With type information the receiver must be a functype container (it has `orThrow` and `fold`);\n // without it, the method name decides — `orThrow()` is functype's own spelling.\n if (isExtractableByType(callee.object, context) === false) return\n const receiverText = compact(sourceCode.getText(callee.object))\n if (isGuarded(node, fn, receiverText, sourceCode)) return\n if (allowInteropMarker && isInsideTaggedDeclaration(node, INTEROP_TAG, sourceCode)) return\n\n context.report({\n node,\n messageId: \"throwInRender\",\n data: { receiver: sourceCode.getText(callee.object), method },\n })\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"0RAcA,MAAMA,kBAAwC,IAAI,IAAI,CAAC,UAAW,YAAY,CAAC,EAGzEC,EAAS,GACbC,EAAU,OAAS,mBACnBA,EAAU,OAAS,kBAClBA,EAAU,OAAS,kBAAoBA,EAAU,KAAK,OAAS,GAAKD,EAAMC,EAAU,KAAK,GAAG,EAAE,CAAC,EAW5FC,GAAsB,EAAoB,EAAsB,IAAoC,CACxG,GAAID,EAAU,OAAS,cAGrB,OAFKD,EAAMC,EAAU,UAAU,EAC3BE,EAAWF,EAAU,KAAM,GAAOG,EAAcC,CAAU,IAAM,UAAkB,GAC/EJ,EAAU,UAAYC,EAAmBD,EAAU,UAAWG,EAAcC,CAAU,EAAI,GAFxD,GAI3C,IAAMC,EAAOL,EAAU,OAAS,sBAAwBA,EAAU,WAAa,KAC/E,OACEK,GAAM,OAAS,kBACfA,EAAK,OAAO,OAAS,cACrBA,EAAK,OAAO,OAAS,aACrBA,EAAK,UAAU,OAAS,GACxBH,EAAWG,EAAK,UAAU,GAAI,GAAMF,EAAcC,CAAU,IAAM,SAEtE,EAQME,GAAa,EAAe,EAAe,EAAsB,IAAoC,CACzG,IAAMC,GAAW,EAAe,IAC9BL,EAAWM,EAAMC,EAASN,EAAcC,CAAU,IAAM,UAEpDM,GAAQ,EAAgB,IAAuC,CACnE,GAAI,CAACC,GAAQA,IAASC,EAAM,MAAO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AO,OAAQD,CAAO,IAAM,GAAO,OAC3D,IAAMd,EAAeqB,EAAQpB,EAAW,QAAQc,EAAO,MAAM,CAAC,EAC1DZ,EAAUK,EAAMS,EAAIjB,EAAcC,CAAU,GAC5CY,GAAsBS,EAA0Bd,EAAA,UAAmBP,CAAU,GAEjFa,EAAQ,OAAO,CACb,OACA,UAAW,gBACX,KAAM,CAAE,SAAUb,EAAW,QAAQc,EAAO,MAAM,EAAG,QAAO,CAC9D,CAAC,CACH,CACF,CACF,CACF"}
1
+ {"version":3,"file":"no-getOrThrow-in-render.js","names":["isInsideTaggedDeclaration","compact","provesWhen","enclosingFunction","renderKind","isExtractableByType","THROWING_METHODS","exits","statement","continuesWithValue","receiverText","sourceCode","call","isGuarded","stop","present","test","outcome","walk","child","node","branch","rule","context","allowInteropMarker","callee","method","fn"],"sources":["../../src/rules/no-getOrThrow-in-render.ts"],"sourcesContent":["import type { Rule, SourceCode } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { INTEROP_TAG, isInsideTaggedDeclaration } from \"../utils/boundary-tags\"\nimport { compact, provesWhen } from \"../utils/functype-predicates\"\nimport { enclosingFunction, renderKind } from \"../utils/react-render\"\nimport { isExtractableByType } from \"../utils/type-aware\"\n\n/**\n * The extractors that throw a generic error when the value is missing. `orThrow` is the one functype's\n * containers carry; `getOrThrow` is its older name, which the rule is named after. Each is reported only\n * bare: `orThrow(error)` names the error, the way to send a failure to an error boundary on purpose.\n * `expect(handler)` is never reported, because its handler is the chosen throw.\n */\nconst THROWING_METHODS: ReadonlySet<string> = new Set([\"orThrow\", \"getOrThrow\"])\n\n/** A statement that leaves the function: `return …`, `throw …`, or a block that ends in one. */\nconst exits = (statement: ASTNode): boolean =>\n statement.type === \"ReturnStatement\" ||\n statement.type === \"ThrowStatement\" ||\n (statement.type === \"BlockStatement\" && statement.body.length > 0 && exits(statement.body.at(-1)))\n\n/**\n * Does `statement` only let control continue past it once the value is known to be there?\n *\n * - an early exit on the missing case: `if (!o.isSome()) return null`, `if (busy || o.isNone()) return <S />`,\n * `if (o.isEmpty) throw …`;\n * - an if / else-if chain whose every branch exits, except the way out that proves it:\n * `if (x) return <B />; else if (o.isNone()) return null`;\n * - `invariant(o.isSome(), \"…\")` from functype, which narrows the code after it.\n */\nconst continuesWithValue = (statement: ASTNode, receiverText: string, sourceCode: SourceCode): boolean => {\n if (statement.type === \"IfStatement\") {\n if (!exits(statement.consequent)) return false\n if (provesWhen(statement.test, false, receiverText, sourceCode) === \"present\") return true\n return statement.alternate ? continuesWithValue(statement.alternate, receiverText, sourceCode) : false\n }\n const call = statement.type === \"ExpressionStatement\" ? statement.expression : null\n return (\n call?.type === \"CallExpression\" &&\n call.callee.type === \"Identifier\" &&\n call.callee.name === \"invariant\" &&\n call.arguments.length > 0 &&\n provesWhen(call.arguments[0], true, receiverText, sourceCode) === \"present\"\n )\n}\n\n/**\n * Is the call inside a branch that already proved the value is there? `o.isSome() ? o.orThrow() : …`,\n * `!o.isSome() ? null : o.orThrow()`, `if (e.isRight()) return e.orThrow()`, `t.isSuccess() && t.orThrow()`,\n * or after a statement in an enclosing block that only continues once it is (`continuesWithValue`). Then\n * the call cannot throw.\n */\nconst isGuarded = (call: ASTNode, stop: ASTNode, receiverText: string, sourceCode: SourceCode): boolean => {\n const present = (test: ASTNode, outcome: boolean): boolean =>\n provesWhen(test, outcome, receiverText, sourceCode) === \"present\"\n\n const walk = (child: ASTNode, node: ASTNode | undefined): boolean => {\n if (!node || node === stop) return false\n const branch = node.type === \"IfStatement\" || node.type === \"ConditionalExpression\"\n if (branch && node.consequent === child && present(node.test, true)) return true\n if (branch && node.alternate === child && present(node.test, false)) return true\n if (node.type === \"LogicalExpression\" && node.right === child) {\n if (node.operator === \"&&\" && present(node.left, true)) return true\n if (node.operator === \"||\" && present(node.left, false)) return true\n }\n if (node.type === \"BlockStatement\") {\n const before = (node.body as ReadonlyArray<ASTNode>).slice(0, node.body.indexOf(child))\n if (before.some((statement) => continuesWithValue(statement, receiverText, sourceCode))) return true\n }\n return walk(node, node.parent)\n }\n return walk(call, call.parent)\n}\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"problem\",\n docs: {\n description: \"Disallow a throwing extractor (.orThrow(), .getOrThrow()) in a React component or hook body\",\n recommended: false,\n },\n schema: [\n {\n type: \"object\",\n properties: {\n allowInteropMarker: {\n type: \"boolean\",\n default: true,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n throwInRender:\n \"{{receiver}}.{{method}}() throws during render when the value is missing, and a throw in render unmounts the tree up to the nearest error boundary. Render both cases with .fold(…) or <MatchOption> / <MatchEither> / <MatchTry>, or read a fallback with .getOrElse(() => …). To reach an error boundary on purpose, name the error: .orThrow((e) => new MyError(e))\",\n },\n },\n\n create(context) {\n const options = context.options[0] || {}\n // `@interop <reason>` on an enclosing declaration marks a host contract, such as React's `use()`.\n const allowInteropMarker = options.allowInteropMarker !== false\n const sourceCode = context.sourceCode\n\n return {\n CallExpression(node: ASTNode) {\n const callee = node.callee as ASTNode\n if (callee.type !== \"MemberExpression\" || callee.computed || callee.property.type !== \"Identifier\") return\n const method = callee.property.name as string\n if (!THROWING_METHODS.has(method) || node.arguments.length > 0) return\n\n // Only the component's or hook's own body runs during render. An event handler, an effect or a\n // `.map` callback is a separate function, so a call there is not attributed to the render.\n const fn = enclosingFunction(node)\n if (!fn || renderKind(fn) === null) return\n\n // With type information the receiver must be a functype container (it has `orThrow` and `fold`);\n // without it, the method name decides — `orThrow()` is functype's own spelling.\n if (isExtractableByType(callee.object, context) === false) return\n const receiverText = compact(sourceCode.getText(callee.object))\n if (isGuarded(node, fn, receiverText, sourceCode)) return\n if (allowInteropMarker && isInsideTaggedDeclaration(node, INTEROP_TAG, sourceCode)) return\n\n context.report({\n node,\n messageId: \"throwInRender\",\n data: { receiver: sourceCode.getText(callee.object), method },\n })\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"A,0RAcA,MAAMM,kBAAwC,IAAI,IAAI,CAAC,UAAW,YAAY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Module;
4
- //#endregion
5
- export { rule as default };
6
- //# sourceMappingURL=no-imperative-loops.d.ts.map
3
+ export { rule as default };