eslint-plugin-functype 2.116.1 → 2.117.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.
- package/README.md +22 -0
- package/dist/configs/recommended.d.ts +5 -0
- package/dist/configs/recommended.js +1 -1
- package/dist/configs/recommended.js.map +1 -1
- package/dist/configs/strict.d.ts +1 -0
- package/dist/configs/strict.js +1 -1
- package/dist/configs/strict.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/rules/index.d.ts +16 -14
- package/dist/rules/index.js +1 -1
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/no-floating-io.d.ts +18 -0
- package/dist/rules/no-floating-io.js +2 -0
- package/dist/rules/no-floating-io.js.map +1 -0
- package/dist/rules/prefer-list.js +2 -2
- package/dist/rules/prefer-list.js.map +1 -1
- package/dist/utils/type-aware.d.ts +9 -0
- package/dist/utils/type-aware.js +1 -1
- package/dist/utils/type-aware.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -44,6 +44,7 @@ export default [functype.configs.strict]
|
|
|
44
44
|
| `functype/no-get-unsafe` | off | error | Disallow unsafe extraction (`.orThrow()`, `.expect()`) |
|
|
45
45
|
| `functype/prefer-list` | off | warn | Use `List` instead of native arrays |
|
|
46
46
|
| `functype/no-array-mutation` | off | error | Don't change an array in place (`push`, `sort`, `xs[i] = v`…); build a new one |
|
|
47
|
+
| `functype/no-floating-io` | off | warn | Don't build an `IO` and drop it, or `await` it unrun; run, return or `yield*` it |
|
|
47
48
|
|
|
48
49
|
### Severity policy
|
|
49
50
|
|
|
@@ -174,6 +175,27 @@ For a host that has to mutate, such as a charting library that takes the array i
|
|
|
174
175
|
|
|
175
176
|
Measured on five consumers (2026-10-10): 91 hits, every one a real in-place mutation. Most were `push` accumulators building a list or a Markdown body line by line; the rest were `sort` on a named array and element assignment. It's `off` in `recommended` until 2.0, to avoid failing builds on a 1.x upgrade.
|
|
176
177
|
|
|
178
|
+
### `functype/no-floating-io`
|
|
179
|
+
|
|
180
|
+
Reports an `IO` that is built and never run, so it does nothing:
|
|
181
|
+
|
|
182
|
+
- an expression statement whose value is an `IO`;
|
|
183
|
+
- `await` on an `IO`. `IO` is not a Promise, so `await io` hands back the `IO` itself, unrun.
|
|
184
|
+
|
|
185
|
+
`no-floating-promises` and `await-thenable` miss both, because `IO` isn't thenable.
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
log.info("saved") // reported, when info returns an IO → yield* it, or .run() it
|
|
189
|
+
save(user).tap(audit) // reported → return it, or run it
|
|
190
|
+
const user = await loadUser(id) // reported: user is the IO → await loadUser(id).runOrThrow()
|
|
191
|
+
return save(user) // fine: the caller runs it
|
|
192
|
+
void save(user) // fine: a deliberate drop
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**It only runs with type-aware linting** (`parserOptions.projectService`). It recognizes `IO` by its type (it has `runExit` and `provideLayer`), whatever the call is named. Without type information it reports nothing.
|
|
196
|
+
|
|
197
|
+
Measured (2026-10-16) on functype's own source and tests, functype-log, functype-react, agent-todo's agent-gate-api and civala.ai's API: 0 false positives across about 1,340 IO-typed calls. The only hits were four deliberate drops in type-only tests. It's `off` in `recommended` and `warn` in `strict` while it is measured further.
|
|
198
|
+
|
|
177
199
|
### `functype/no-get-unsafe`
|
|
178
200
|
|
|
179
201
|
| Option | Default | Description |
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
* no-array-mutation is off here only because turning a new error on in a 1.x minor would fail consumers'
|
|
23
23
|
* builds on upgrade (91 hits across five consumers, every one a real in-place mutation). It's `error` in
|
|
24
24
|
* strict, and planned for `error` here in 2.0. It is type-aware: without type information it reports nothing.
|
|
25
|
+
*
|
|
26
|
+
* no-floating-io (1.17) is off here and `warn` in strict while it is measured: 0 false positives across
|
|
27
|
+
* ~1,340 IO-typed calls in five codebases, but no real hits yet either. 2.0 decides `recommended` after
|
|
28
|
+
* measuring it against functype-os, whose async methods return IO there. Type-aware, like no-array-mutation.
|
|
25
29
|
*/
|
|
26
30
|
declare const recommendedRules: {
|
|
27
31
|
"functype/no-let": string;
|
|
@@ -39,6 +43,7 @@ declare const recommendedRules: {
|
|
|
39
43
|
"functype/no-get-unsafe": string;
|
|
40
44
|
"functype/prefer-list": string;
|
|
41
45
|
"functype/no-array-mutation": string;
|
|
46
|
+
"functype/no-floating-io": string;
|
|
42
47
|
};
|
|
43
48
|
//#endregion
|
|
44
49
|
export { recommendedRules as default };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={"functype/no-let":`error`,"functype/no-imperative-loops":`error`,"functype/prefer-functype-map":`error`,"functype/prefer-functype-set":`error`,"functype/prefer-map":`error`,"functype/prefer-fold":`error`,"functype/collection-naming":`error`,"functype/prefer-option":`warn`,"functype/prefer-either":`warn`,"functype/prefer-try":`warn`,"functype/prefer-flatmap":`warn`,"functype/prefer-do-notation":`warn`,"functype/no-get-unsafe":`off`,"functype/prefer-list":`off`,"functype/no-array-mutation":`off`};export{e as default};
|
|
1
|
+
const e={"functype/no-let":`error`,"functype/no-imperative-loops":`error`,"functype/prefer-functype-map":`error`,"functype/prefer-functype-set":`error`,"functype/prefer-map":`error`,"functype/prefer-fold":`error`,"functype/collection-naming":`error`,"functype/prefer-option":`warn`,"functype/prefer-either":`warn`,"functype/prefer-try":`warn`,"functype/prefer-flatmap":`warn`,"functype/prefer-do-notation":`warn`,"functype/no-get-unsafe":`off`,"functype/prefer-list":`off`,"functype/no-array-mutation":`off`,"functype/no-floating-io":`off`};export{e as default};
|
|
2
2
|
//# sourceMappingURL=recommended.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recommended.js","names":["recommendedRules"],"sources":["../../src/configs/recommended.ts"],"sourcesContent":["/**\n * Severity policy (#325): a rule is `error` once it is right on ~95–99% of real code and its known\n * false-positive classes are closed; it stays `warn` only while those classes are still open. FP here\n * is governance — a rule that is reliably right should fail the build, not print advice nobody reads\n * (CivalaOS shipped 85 new violations under \"lint OK\" because every rule but `no-let` warned).\n *\n * Still `warn`, and why:\n * - prefer-option / prefer-either / prefer-try: fire on correct code at serialization boundaries\n * (JSON rows, DTOs) and on throws that are correct (bug checks, host contracts). Wire<T> (#325 B),\n * invariant() and @interop (#342) close those; graduating them is a measured decision.\n * - prefer-flatmap / prefer-do-notation: heuristics without type information; precision unmeasured.\n *\n * Graduated with a precision condition: prefer-fold checks functype predicate calls (`isSome()`,\n * `isLeft()`) only; its null-check heuristic is opt-in (`checkNullable`) because it fired on plain\n * nullables — 31 of 31 hits in CivalaOS. prefer-map leaves loops to no-imperative-loops (`checkForLoops`\n * off), so one loop is one error.\n *\n * collection-naming is a convention, not a heuristic — functype's Map/Set imported under their own names,\n * the built-in spelled globalThis.Map — so it has no false-positive class and starts at error.\n *\n * no-array-mutation is off here only because turning a new error on in a 1.x minor would fail consumers'\n * builds on upgrade (91 hits across five consumers, every one a real in-place mutation). It's `error` in\n * strict, and planned for `error` here in 2.0. It is type-aware: without type information it reports nothing.\n */\nconst recommendedRules = {\n \"functype/no-let\": \"error\",\n \"functype/no-imperative-loops\": \"error\",\n \"functype/prefer-functype-map\": \"error\",\n \"functype/prefer-functype-set\": \"error\",\n \"functype/prefer-map\": \"error\",\n \"functype/prefer-fold\": \"error\",\n \"functype/collection-naming\": \"error\",\n \"functype/prefer-option\": \"warn\",\n \"functype/prefer-either\": \"warn\",\n \"functype/prefer-try\": \"warn\",\n \"functype/prefer-flatmap\": \"warn\",\n \"functype/prefer-do-notation\": \"warn\",\n \"functype/no-get-unsafe\": \"off\",\n \"functype/prefer-list\": \"off\",\n \"functype/no-array-mutation\": \"off\",\n}\n\nexport default recommendedRules\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"recommended.js","names":["recommendedRules"],"sources":["../../src/configs/recommended.ts"],"sourcesContent":["/**\n * Severity policy (#325): a rule is `error` once it is right on ~95–99% of real code and its known\n * false-positive classes are closed; it stays `warn` only while those classes are still open. FP here\n * is governance — a rule that is reliably right should fail the build, not print advice nobody reads\n * (CivalaOS shipped 85 new violations under \"lint OK\" because every rule but `no-let` warned).\n *\n * Still `warn`, and why:\n * - prefer-option / prefer-either / prefer-try: fire on correct code at serialization boundaries\n * (JSON rows, DTOs) and on throws that are correct (bug checks, host contracts). Wire<T> (#325 B),\n * invariant() and @interop (#342) close those; graduating them is a measured decision.\n * - prefer-flatmap / prefer-do-notation: heuristics without type information; precision unmeasured.\n *\n * Graduated with a precision condition: prefer-fold checks functype predicate calls (`isSome()`,\n * `isLeft()`) only; its null-check heuristic is opt-in (`checkNullable`) because it fired on plain\n * nullables — 31 of 31 hits in CivalaOS. prefer-map leaves loops to no-imperative-loops (`checkForLoops`\n * off), so one loop is one error.\n *\n * collection-naming is a convention, not a heuristic — functype's Map/Set imported under their own names,\n * the built-in spelled globalThis.Map — so it has no false-positive class and starts at error.\n *\n * no-array-mutation is off here only because turning a new error on in a 1.x minor would fail consumers'\n * builds on upgrade (91 hits across five consumers, every one a real in-place mutation). It's `error` in\n * strict, and planned for `error` here in 2.0. It is type-aware: without type information it reports nothing.\n *\n * no-floating-io (1.17) is off here and `warn` in strict while it is measured: 0 false positives across\n * ~1,340 IO-typed calls in five codebases, but no real hits yet either. 2.0 decides `recommended` after\n * measuring it against functype-os, whose async methods return IO there. Type-aware, like no-array-mutation.\n */\nconst recommendedRules = {\n \"functype/no-let\": \"error\",\n \"functype/no-imperative-loops\": \"error\",\n \"functype/prefer-functype-map\": \"error\",\n \"functype/prefer-functype-set\": \"error\",\n \"functype/prefer-map\": \"error\",\n \"functype/prefer-fold\": \"error\",\n \"functype/collection-naming\": \"error\",\n \"functype/prefer-option\": \"warn\",\n \"functype/prefer-either\": \"warn\",\n \"functype/prefer-try\": \"warn\",\n \"functype/prefer-flatmap\": \"warn\",\n \"functype/prefer-do-notation\": \"warn\",\n \"functype/no-get-unsafe\": \"off\",\n \"functype/prefer-list\": \"off\",\n \"functype/no-array-mutation\": \"off\",\n \"functype/no-floating-io\": \"off\",\n}\n\nexport default recommendedRules\n"],"mappings":"AA4BA,MAAMA,EAAmB,CACvB,kBAAmB,QACnB,+BAAgC,QAChC,+BAAgC,QAChC,+BAAgC,QAChC,sBAAuB,QACvB,uBAAwB,QACxB,6BAA8B,QAC9B,yBAA0B,OAC1B,yBAA0B,OAC1B,sBAAuB,OACvB,0BAA2B,OAC3B,8BAA+B,OAC/B,yBAA0B,MAC1B,uBAAwB,MACxB,6BAA8B,MAC9B,0BAA2B,KAC7B"}
|
package/dist/configs/strict.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ declare const strictRules: {
|
|
|
6
6
|
"functype/no-get-unsafe": string;
|
|
7
7
|
"functype/prefer-list": string;
|
|
8
8
|
"functype/no-array-mutation": string;
|
|
9
|
+
"functype/no-floating-io": string;
|
|
9
10
|
"functype/prefer-functype-map": string;
|
|
10
11
|
"functype/prefer-functype-set": string;
|
|
11
12
|
"functype/no-imperative-loops": string;
|
package/dist/configs/strict.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"./recommended.js";const t={...e,"functype/prefer-option":`error`,"functype/prefer-either":`error`,"functype/prefer-try":`error`,"functype/no-get-unsafe":`error`,"functype/prefer-list":`warn`,"functype/no-array-mutation":`error`,"functype/prefer-functype-map":`error`,"functype/prefer-functype-set":`error`,"functype/no-imperative-loops":`error`};export{t as default};
|
|
1
|
+
import e from"./recommended.js";const t={...e,"functype/prefer-option":`error`,"functype/prefer-either":`error`,"functype/prefer-try":`error`,"functype/no-get-unsafe":`error`,"functype/prefer-list":`warn`,"functype/no-array-mutation":`error`,"functype/no-floating-io":`warn`,"functype/prefer-functype-map":`error`,"functype/prefer-functype-set":`error`,"functype/no-imperative-loops":`error`};export{t as default};
|
|
2
2
|
//# sourceMappingURL=strict.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strict.js","names":["recommendedRules","strictRules"],"sources":["../../src/configs/strict.ts"],"sourcesContent":["import recommendedRules from \"./recommended\"\n\nconst strictRules = {\n ...recommendedRules,\n \"functype/prefer-option\": \"error\",\n \"functype/prefer-either\": \"error\",\n \"functype/prefer-try\": \"error\",\n \"functype/no-get-unsafe\": \"error\",\n \"functype/prefer-list\": \"warn\",\n \"functype/no-array-mutation\": \"error\",\n \"functype/prefer-functype-map\": \"error\",\n \"functype/prefer-functype-set\": \"error\",\n \"functype/no-imperative-loops\": \"error\",\n}\n\nexport default strictRules\n"],"mappings":"gCAEA,MAAMC,EAAc,CAClB,GAAGD,EACH,yBAA0B,QAC1B,yBAA0B,QAC1B,sBAAuB,QACvB,yBAA0B,QAC1B,uBAAwB,OACxB,6BAA8B,QAC9B,+BAAgC,QAChC,+BAAgC,QAChC,+BAAgC,OAClC"}
|
|
1
|
+
{"version":3,"file":"strict.js","names":["recommendedRules","strictRules"],"sources":["../../src/configs/strict.ts"],"sourcesContent":["import recommendedRules from \"./recommended\"\n\nconst strictRules = {\n ...recommendedRules,\n \"functype/prefer-option\": \"error\",\n \"functype/prefer-either\": \"error\",\n \"functype/prefer-try\": \"error\",\n \"functype/no-get-unsafe\": \"error\",\n \"functype/prefer-list\": \"warn\",\n \"functype/no-array-mutation\": \"error\",\n \"functype/no-floating-io\": \"warn\",\n \"functype/prefer-functype-map\": \"error\",\n \"functype/prefer-functype-set\": \"error\",\n \"functype/no-imperative-loops\": \"error\",\n}\n\nexport default strictRules\n"],"mappings":"gCAEA,MAAMC,EAAc,CAClB,GAAGD,EACH,yBAA0B,QAC1B,yBAA0B,QAC1B,sBAAuB,QACvB,yBAA0B,QAC1B,uBAAwB,OACxB,6BAA8B,QAC9B,0BAA2B,OAC3B,+BAAgC,QAChC,+BAAgC,QAChC,+BAAgC,OAClC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ declare const plugin: {
|
|
|
16
16
|
"prefer-do-notation": import("eslint").Rule.RuleModule;
|
|
17
17
|
"collection-naming": import("eslint").Rule.RuleModule;
|
|
18
18
|
"no-array-mutation": import("eslint").Rule.RuleModule;
|
|
19
|
+
"no-floating-io": import("eslint").Rule.RuleModule;
|
|
19
20
|
};
|
|
20
21
|
meta: {
|
|
21
22
|
name: string;
|
package/dist/rules/index.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import rule from "./collection-naming.js";
|
|
2
2
|
import rule$1 from "./no-array-mutation.js";
|
|
3
|
-
import rule$2 from "./no-
|
|
4
|
-
import rule$3 from "./no-
|
|
5
|
-
import rule$4 from "./no-
|
|
6
|
-
import rule$5 from "./
|
|
7
|
-
import rule$6 from "./prefer-
|
|
8
|
-
import rule$7 from "./prefer-
|
|
9
|
-
import rule$8 from "./prefer-
|
|
10
|
-
import rule$9 from "./prefer-
|
|
11
|
-
import rule$10 from "./prefer-functype-
|
|
12
|
-
import rule$11 from "./prefer-
|
|
13
|
-
import rule$12 from "./prefer-
|
|
14
|
-
import rule$13 from "./prefer-
|
|
15
|
-
import rule$14 from "./prefer-
|
|
3
|
+
import rule$2 from "./no-floating-io.js";
|
|
4
|
+
import rule$3 from "./no-get-unsafe.js";
|
|
5
|
+
import rule$4 from "./no-imperative-loops.js";
|
|
6
|
+
import rule$5 from "./no-let.js";
|
|
7
|
+
import rule$6 from "./prefer-do-notation.js";
|
|
8
|
+
import rule$7 from "./prefer-either.js";
|
|
9
|
+
import rule$8 from "./prefer-flatmap.js";
|
|
10
|
+
import rule$9 from "./prefer-fold.js";
|
|
11
|
+
import rule$10 from "./prefer-functype-map.js";
|
|
12
|
+
import rule$11 from "./prefer-functype-set.js";
|
|
13
|
+
import rule$12 from "./prefer-list.js";
|
|
14
|
+
import rule$13 from "./prefer-map.js";
|
|
15
|
+
import rule$14 from "./prefer-option.js";
|
|
16
|
+
import rule$15 from "./prefer-try.js";
|
|
16
17
|
//#region src/rules/index.d.ts
|
|
17
18
|
declare const _default: {
|
|
18
19
|
"prefer-option": import("eslint").Rule.RuleModule;
|
|
@@ -30,7 +31,8 @@ declare const _default: {
|
|
|
30
31
|
"prefer-do-notation": import("eslint").Rule.RuleModule;
|
|
31
32
|
"collection-naming": import("eslint").Rule.RuleModule;
|
|
32
33
|
"no-array-mutation": import("eslint").Rule.RuleModule;
|
|
34
|
+
"no-floating-io": import("eslint").Rule.RuleModule;
|
|
33
35
|
};
|
|
34
36
|
//#endregion
|
|
35
|
-
export { rule as collectionNaming, _default as default, rule$1 as noArrayMutation, rule$2 as
|
|
37
|
+
export { rule as collectionNaming, _default as default, rule$1 as noArrayMutation, rule$2 as noFloatingIo, rule$3 as noGetUnsafe, rule$4 as noImperativeLoops, rule$5 as noLet, rule$6 as preferDoNotation, rule$7 as preferEither, rule$8 as preferFlatmap, rule$9 as preferFold, rule$10 as preferFunctypeMap, rule$11 as preferFunctypeSet, rule$12 as preferList, rule$13 as preferMap, rule$14 as preferOption, rule$15 as preferTry };
|
|
36
38
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/rules/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"./collection-naming.js";import t from"./no-array-mutation.js";import n from"./no-get-unsafe.js";import
|
|
1
|
+
import e from"./collection-naming.js";import t from"./no-array-mutation.js";import n from"./no-floating-io.js";import r from"./no-get-unsafe.js";import i from"./no-imperative-loops.js";import a from"./no-let.js";import o from"./prefer-do-notation.js";import s from"./prefer-either.js";import c from"./prefer-flatmap.js";import l from"./prefer-fold.js";import u from"./prefer-functype-map.js";import d from"./prefer-functype-set.js";import f from"./prefer-list.js";import p from"./prefer-map.js";import m from"./prefer-option.js";import h from"./prefer-try.js";var g={"prefer-option":m,"prefer-either":s,"prefer-try":h,"prefer-list":f,"no-get-unsafe":r,"no-let":a,"prefer-fold":l,"prefer-map":p,"prefer-flatmap":c,"prefer-functype-map":u,"prefer-functype-set":d,"no-imperative-loops":i,"prefer-do-notation":o,"collection-naming":e,"no-array-mutation":t,"no-floating-io":n};export{e as collectionNaming,g as default,t as noArrayMutation,n as noFloatingIo,r as noGetUnsafe,i as noImperativeLoops,a as noLet,o as preferDoNotation,s as preferEither,c as preferFlatmap,l as preferFold,u as preferFunctypeMap,d as preferFunctypeSet,f as preferList,p as preferMap,m as preferOption,h as preferTry};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/rules/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["preferOption","preferEither","preferTry","preferList","noGetUnsafe","noLet","preferFold","preferMap","preferFlatmap","preferFunctypeMap","preferFunctypeSet","noImperativeLoops","preferDoNotation","collectionNaming","noArrayMutation","rule","rule$1","rule$2","rule$3","rule$4","rule$5","rule$6","rule$7","rule$8","rule$9","rule$10","rule$11","rule$12","rule$13","rule$14","rules_default"],"sources":["../../src/rules/index.ts"],"sourcesContent":["import collectionNaming from \"./collection-naming\"\nimport noArrayMutation from \"./no-array-mutation\"\nimport noGetUnsafe from \"./no-get-unsafe\"\nimport noImperativeLoops from \"./no-imperative-loops\"\nimport noLet from \"./no-let\"\nimport preferDoNotation from \"./prefer-do-notation\"\nimport preferEither from \"./prefer-either\"\nimport preferFlatmap from \"./prefer-flatmap\"\nimport preferFold from \"./prefer-fold\"\nimport preferFunctypeMap from \"./prefer-functype-map\"\nimport preferFunctypeSet from \"./prefer-functype-set\"\nimport preferList from \"./prefer-list\"\nimport preferMap from \"./prefer-map\"\nimport preferOption from \"./prefer-option\"\nimport preferTry from \"./prefer-try\"\n\nexport {\n collectionNaming,\n noArrayMutation,\n noGetUnsafe,\n noImperativeLoops,\n noLet,\n preferDoNotation,\n preferEither,\n preferFlatmap,\n preferFold,\n preferFunctypeMap,\n preferFunctypeSet,\n preferList,\n preferMap,\n preferOption,\n preferTry,\n}\n\nexport default {\n \"prefer-option\": preferOption,\n \"prefer-either\": preferEither,\n \"prefer-try\": preferTry,\n \"prefer-list\": preferList,\n \"no-get-unsafe\": noGetUnsafe,\n \"no-let\": noLet,\n \"prefer-fold\": preferFold,\n \"prefer-map\": preferMap,\n \"prefer-flatmap\": preferFlatmap,\n \"prefer-functype-map\": preferFunctypeMap,\n \"prefer-functype-set\": preferFunctypeSet,\n \"no-imperative-loops\": noImperativeLoops,\n \"prefer-do-notation\": preferDoNotation,\n \"collection-naming\": collectionNaming,\n \"no-array-mutation\": noArrayMutation,\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["preferOption","preferEither","preferTry","preferList","noGetUnsafe","noLet","preferFold","preferMap","preferFlatmap","preferFunctypeMap","preferFunctypeSet","noImperativeLoops","preferDoNotation","collectionNaming","noArrayMutation","noFloatingIo","rule","rule$1","rule$2","rule$3","rule$4","rule$5","rule$6","rule$7","rule$8","rule$9","rule$10","rule$11","rule$12","rule$13","rule$14","rule$15","rules_default"],"sources":["../../src/rules/index.ts"],"sourcesContent":["import collectionNaming from \"./collection-naming\"\nimport noArrayMutation from \"./no-array-mutation\"\nimport noFloatingIo from \"./no-floating-io\"\nimport noGetUnsafe from \"./no-get-unsafe\"\nimport noImperativeLoops from \"./no-imperative-loops\"\nimport noLet from \"./no-let\"\nimport preferDoNotation from \"./prefer-do-notation\"\nimport preferEither from \"./prefer-either\"\nimport preferFlatmap from \"./prefer-flatmap\"\nimport preferFold from \"./prefer-fold\"\nimport preferFunctypeMap from \"./prefer-functype-map\"\nimport preferFunctypeSet from \"./prefer-functype-set\"\nimport preferList from \"./prefer-list\"\nimport preferMap from \"./prefer-map\"\nimport preferOption from \"./prefer-option\"\nimport preferTry from \"./prefer-try\"\n\nexport {\n collectionNaming,\n noArrayMutation,\n noFloatingIo,\n noGetUnsafe,\n noImperativeLoops,\n noLet,\n preferDoNotation,\n preferEither,\n preferFlatmap,\n preferFold,\n preferFunctypeMap,\n preferFunctypeSet,\n preferList,\n preferMap,\n preferOption,\n preferTry,\n}\n\nexport default {\n \"prefer-option\": preferOption,\n \"prefer-either\": preferEither,\n \"prefer-try\": preferTry,\n \"prefer-list\": preferList,\n \"no-get-unsafe\": noGetUnsafe,\n \"no-let\": noLet,\n \"prefer-fold\": preferFold,\n \"prefer-map\": preferMap,\n \"prefer-flatmap\": preferFlatmap,\n \"prefer-functype-map\": preferFunctypeMap,\n \"prefer-functype-set\": preferFunctypeSet,\n \"no-imperative-loops\": noImperativeLoops,\n \"prefer-do-notation\": preferDoNotation,\n \"collection-naming\": collectionNaming,\n \"no-array-mutation\": noArrayMutation,\n \"no-floating-io\": noFloatingIo,\n}\n"],"mappings":"gjBAoCA,IAAAgC,EAAe,CACb,gBAAiBhC,EACjB,gBAAiBC,EACjB,aAAcC,EACd,cAAeC,EACf,gBAAiBC,EACjB,SAAUC,EACV,cAAeC,EACf,aAAcC,EACd,iBAAkBC,EAClB,sBAAuBC,EACvB,sBAAuBC,EACvB,sBAAuBC,EACvB,qBAAsBC,EACtB,oBAAqBC,EACrB,oBAAqBC,EACrB,iBAAkBC,CACpB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Rule } from "eslint";
|
|
2
|
+
//#region src/rules/no-floating-io.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Reports an `IO` that is built and then dropped, so it never runs:
|
|
5
|
+
*
|
|
6
|
+
* - an expression statement whose value is an `IO` — `log.info("saved")`, `save(user).tap(audit)`;
|
|
7
|
+
* - `await` on an `IO`. `IO` is not a Promise, so `await io` hands back the `IO` itself, unrun.
|
|
8
|
+
*
|
|
9
|
+
* `no-floating-promises` and `await-thenable` don't see either case, because `IO` is not thenable.
|
|
10
|
+
* Returning, yielding, assigning or passing an `IO` along is fine: someone else runs it. `void io`
|
|
11
|
+
* marks a deliberate drop and isn't reported.
|
|
12
|
+
*
|
|
13
|
+
* Type-aware only: without type information it reports nothing.
|
|
14
|
+
*/
|
|
15
|
+
declare const rule: Rule.RuleModule;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { rule as default };
|
|
18
|
+
//# sourceMappingURL=no-floating-io.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{isIOByType as e}from"../utils/type-aware.js";const t={meta:{type:`problem`,docs:{description:`Disallow building an IO and never running it`,recommended:!1},schema:[],messages:{floatingIO:`This IO is built and never run, so it does nothing. Run it (.run(), .runOrThrow(), .runExit()), return it, or yield* it inside IO.gen`,awaitedIO:`await on an IO does nothing: IO is not a Promise, so this returns the IO unrun. Await .run() or .runOrThrow() instead`}},create(t){return{ExpressionStatement(n){let r=n.expression;r.type!==`AwaitExpression`&&(r.type!==`UnaryExpression`||r.operator!==`void`)&&e(r,t)&&t.report({node:r,messageId:`floatingIO`})},AwaitExpression(n){e(n.argument,t)&&t.report({node:n,messageId:`awaitedIO`})}}}};export{t as default};
|
|
2
|
+
//# sourceMappingURL=no-floating-io.js.map
|
|
@@ -0,0 +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,3 +1,3 @@
|
|
|
1
|
-
import{flowsIntoArraySlot as e,flowsIntoMutableArraySlot as t,hasTypeInformation as n,isUntypedExpression as r}from"../utils/type-aware.js";import{descendants as i}from"../utils/ast-walk.js";import{getFunctypeImportsLegacy as a,isFunctypeCall as o}from"../utils/functype-detection.js";import{createImportFixer as s,hasFunctypeSymbol as c}from"../utils/import-fixer.js";import{DEFAULT_WIRE_TYPES as l,WIRE_TYPES_SCHEMA as u,isInsideWireType as d}from"../utils/wire-types.js";const f=/* @__PURE__ */ new Set([`parent`,`loc`,`range`]);function p(e){return Object.entries(e).filter(([e])=>!f.has(e)).flatMap(([,e])=>Array.isArray(e)?e:[e]).filter(e=>typeof e==`object`&&!!e)}function m(e,t){let n=e?.parent;return n?t(n)||m(n,t):!1}function h(e){return e?.type===`CallExpression`&&e.callee.type===`MemberExpression`&&e.callee.object.type===`Identifier`&&e.callee.object.name===`List`&&[`from`,`of`].includes(e.callee.property.name)}function g(e){let t=e?.type===`TSAsExpression`?e.typeAnnotation:void 0,n=t?.type===`TSTypeOperator`?t.typeAnnotation:t;return n?.type===`TSTupleType`||n?.type===`TSTypeReference`&&n.typeName?.type===`Identifier`&&n.typeName.name===`const`}const _=/* @__PURE__ */ new Set([`push`,`pop`,`shift`,`unshift`,`splice`,`sort`,`reverse`,`fill`,`copyWithin`]);function v(e){let t=e.parent;return t?.type===`ConditionalExpression`&&t.test!==e||t?.type===`LogicalExpression`?v(t):e}const y=/* @__PURE__ */ new Set([`join`,`includes`,`indexOf`,`lastIndexOf`,`some`,`every`,`find`,`findIndex`,`findLast`,`findLastIndex`,`at`]);function b(e){let t=e.parent,n=t?.parent;return t?.type!==`MemberExpression`||t.object!==e?e:n?.type===`CallExpression`&&n.callee===t?b(n):e}function x(e){if(C(e))return!0;let t=e.parent,n=t?.parent;return t?.type!==`MemberExpression`||t.object!==e?!1:n?.type===`CallExpression`&&n.callee===t&&x(n)}function S(e){return e.parent?.type===`JSXExpressionContainer`}function C(e){let t=e.parent;if(t?.type!==`MemberExpression`||t.object!==e)return!1;let n=t.parent;if(n?.type===`AssignmentExpression`&&n.left===t)return!1;if(t.computed)return!0;let r=t.property?.type===`Identifier`?t.property.name:null;return r===`length`||r!==null&&y.has(r)&&n?.type===`CallExpression`&&n.callee===t}function w(e){let t=e.parent;return t?t.type===`ConditionalExpression`&&t.test!==e||t.type===`LogicalExpression`&&t.right===e?w(t):t.type===`SpreadElement`&&(t.parent?.type===`CallExpression`||t.parent?.type===`NewExpression`):!1}function T(e){let t=e=>e?e.type===`TSTypeAnnotation`?e.parent?.type===`Identifier`?e.parent:null:e.type===`TSAsExpression`||e.type===`TSSatisfiesExpression`||e.type.endsWith(`Statement`)?null:t(e.parent):null;return t(e.parent)}function E(e){let t=e.parent,n=t?.type===`TSTypeAnnotation`?t.parent:void 0;if(!n||n.returnType!==t)return null;if(n.type===`FunctionDeclaration`)return n.id?.type===`Identifier`?n.id:null;let r=n.parent;return(n.type===`ArrowFunctionExpression`||n.type===`FunctionExpression`)&&r?.type===`VariableDeclarator`&&r.init===n&&r.id?.type===`Identifier`?r.id:null}function D(e){let t=e.parent,n=t?.type===`TSTypeAnnotation`?t.parent:void 0;return n?.type!==`TSPropertySignature`&&n?.type!==`PropertyDefinition`?null:n.key?.type===`Identifier`&&!n.computed?n.key.name:null}function O(e){let t=(e,n)=>{if(!e||e.type===`TSTypeAnnotation`||e.type.endsWith(`Statement`))return null;if(e.type===`TSAsExpression`&&e.typeAnnotation===n){let t=e=>e.parent?.type===`TSAsExpression`?t(e.parent):e;return t(e)}return t(e.parent,e)};return t(e.parent,e)}function k(e){return e.type===`VariableDeclarator`&&!!e.id?.typeAnnotation||e.type===`TSTypeAnnotation`}const
|
|
2
|
-
`);if(/@generated|auto-generated|do not edit/i.test(f))return{};let y=u.options[0]||{},
|
|
1
|
+
import{flowsIntoArraySlot as e,flowsIntoMutableArraySlot as t,hasTypeInformation as n,isUntypedExpression as r}from"../utils/type-aware.js";import{descendants as i}from"../utils/ast-walk.js";import{getFunctypeImportsLegacy as a,isFunctypeCall as o}from"../utils/functype-detection.js";import{createImportFixer as s,hasFunctypeSymbol as c}from"../utils/import-fixer.js";import{DEFAULT_WIRE_TYPES as l,WIRE_TYPES_SCHEMA as u,isInsideWireType as d}from"../utils/wire-types.js";const f=/* @__PURE__ */ new Set([`parent`,`loc`,`range`]);function p(e){return Object.entries(e).filter(([e])=>!f.has(e)).flatMap(([,e])=>Array.isArray(e)?e:[e]).filter(e=>typeof e==`object`&&!!e)}function m(e,t){let n=e?.parent;return n?t(n)||m(n,t):!1}function h(e){return e?.type===`CallExpression`&&e.callee.type===`MemberExpression`&&e.callee.object.type===`Identifier`&&e.callee.object.name===`List`&&[`from`,`of`].includes(e.callee.property.name)}function g(e){let t=e?.type===`TSAsExpression`?e.typeAnnotation:void 0,n=t?.type===`TSTypeOperator`?t.typeAnnotation:t;return n?.type===`TSTupleType`||n?.type===`TSTypeReference`&&n.typeName?.type===`Identifier`&&n.typeName.name===`const`}const _=/* @__PURE__ */ new Set([`push`,`pop`,`shift`,`unshift`,`splice`,`sort`,`reverse`,`fill`,`copyWithin`]);function v(e){let t=e.parent;return t?.type===`ConditionalExpression`&&t.test!==e||t?.type===`LogicalExpression`?v(t):e}const y=/* @__PURE__ */ new Set([`join`,`includes`,`indexOf`,`lastIndexOf`,`some`,`every`,`find`,`findIndex`,`findLast`,`findLastIndex`,`at`]);function b(e){let t=e.parent,n=t?.parent;return t?.type!==`MemberExpression`||t.object!==e?e:n?.type===`CallExpression`&&n.callee===t?b(n):e}function x(e){if(C(e))return!0;let t=e.parent,n=t?.parent;return t?.type!==`MemberExpression`||t.object!==e?!1:n?.type===`CallExpression`&&n.callee===t&&x(n)}function S(e){return e.parent?.type===`JSXExpressionContainer`}function C(e){let t=e.parent;if(t?.type!==`MemberExpression`||t.object!==e)return!1;let n=t.parent;if(n?.type===`AssignmentExpression`&&n.left===t)return!1;if(t.computed)return!0;let r=t.property?.type===`Identifier`?t.property.name:null;return r===`length`||r!==null&&y.has(r)&&n?.type===`CallExpression`&&n.callee===t}function w(e){let t=e.parent;return t?t.type===`ConditionalExpression`&&t.test!==e||t.type===`LogicalExpression`&&t.right===e?w(t):t.type===`SpreadElement`&&(t.parent?.type===`CallExpression`||t.parent?.type===`NewExpression`):!1}function T(e){let t=e=>e?e.type===`TSTypeAnnotation`?e.parent?.type===`Identifier`?e.parent:null:e.type===`TSAsExpression`||e.type===`TSSatisfiesExpression`||e.type.endsWith(`Statement`)?null:t(e.parent):null;return t(e.parent)}function E(e){let t=e.parent,n=t?.type===`TSTypeAnnotation`?t.parent:void 0;if(!n||n.returnType!==t)return null;if(n.type===`FunctionDeclaration`)return n.id?.type===`Identifier`?n.id:null;let r=n.parent;return(n.type===`ArrowFunctionExpression`||n.type===`FunctionExpression`)&&r?.type===`VariableDeclarator`&&r.init===n&&r.id?.type===`Identifier`?r.id:null}function D(e){let t=e.parent,n=t?.type===`TSTypeAnnotation`?t.parent:void 0;return n?.type!==`TSPropertySignature`&&n?.type!==`PropertyDefinition`?null:n.key?.type===`Identifier`&&!n.computed?n.key.name:null}function O(e){let t=(e,n)=>{if(!e||e.type===`TSTypeAnnotation`||e.type.endsWith(`Statement`))return null;if(e.type===`TSAsExpression`&&e.typeAnnotation===n){let t=e=>e.parent?.type===`TSAsExpression`?t(e.parent):e;return t(e)}return t(e.parent,e)};return t(e.parent,e)}function k(e){let t=e.type===`ExportNamedDeclaration`?e.declaration:null;if(t?.type===`TSTypeAliasDeclaration`||t?.type===`TSInterfaceDeclaration`)return t.id?.name}function A(e){let t=new Set(e.body.map(k));return t.has(`Json`)&&t.has(`Database`)}function j(e){return e.type===`VariableDeclarator`&&!!e.id?.typeAnnotation||e.type===`TSTypeAnnotation`}const M={meta:{type:`suggestion`,hasSuggestions:!0,docs:{description:`Prefer List<T> over native arrays for immutable collections`,recommended:!0},schema:[{type:`object`,properties:{allowArraysInTests:{type:`boolean`,default:!0},wireTypes:u,allowReadonlyArrays:{type:`boolean`,default:!0},allowArrayLiterals:{type:`boolean`,default:!1}},additionalProperties:!1}],messages:{preferList:`Prefer List<{{type}}> over array type {{arrayType}}`,preferReadonlyOrList:`Mutable array type {{arrayType}}: anything holding it can change it. Use ReadonlyArray<{{type}}>, which every caller and library accepts, or List<{{type}}> for a collection you transform`,preferWireCast:`Cast to the mutable array {{arrayType}}: this is data decoded from outside. Declare its shape once as Wire<ReadonlyArray<{{type}}>> (functype's boundary marker) and cast to that`,mutatedArray:`{{name}} is a mutable array changed in place (.{{how}}()). Build it without mutation instead: map/filter/flatMap, a List, or a fold`,preferListLiteral:`Prefer List.of(...) or List.from([...]) over array literal`,suggestListType:`Replace with List<{{type}}>`,suggestReadonlyArray:`Replace with ReadonlyArray<{{type}}>`,suggestListOf:`Replace with List.of(...)`,suggestAddImport:`Add {{symbol}} import from functype`}},create(u){let f=u.sourceCode.getAllComments().slice(0,3).map(e=>e.value).join(`
|
|
2
|
+
`);if(/@generated|auto-generated|do not edit/i.test(f)||A(u.sourceCode.ast))return{};let y=u.options[0]||{},k=y.wireTypes??l,M=y.allowArraysInTests!==!1,N=y.allowReadonlyArrays!==!1,P=y.allowArrayLiterals===!0,F=a(u);function I(){let e=u.filename;return/\.(test|spec)\.(ts|js|tsx|jsx)$/.test(e)||e.includes(`__tests__`)||e.includes(`/test/`)||e.includes(`/tests/`)}function L(e,t){function n(e){return e.type===`TSTypeParameterInstantiation`&&e.params&&e.params[0]?t.getText(e.params[0]):p(e).filter(e=>typeof e?.type==`string`).map(e=>n(e)).find(e=>e!==null)??null}return n(e)}function R(e,t){return t?.type===`CallExpression`&&t.callee.type===`Identifier`&&F.has(t.callee.name)&&t.arguments.includes(e)}function z(t){if(e(t,u)===!0||w(t))return!0;let n=t.parent;return n?.type===`SpreadElement`&&n.parent?.type===`ArrayExpression`&&e(n.parent,u)===!0}function B(e){if(e?.type!==`VariableDeclarator`||e.id?.type!==`Identifier`)return!1;let t=u.sourceCode.getDeclaredVariables(e).flatMap(e=>e.references.filter(e=>!e.init));return t.length>0&&t.every(e=>z(e.identifier)||C(e.identifier))}function V(e){let t=e.parent??e;return((u.sourceCode.getDeclaredVariables(t).find(t=>t.name===e.name)??u.sourceCode.getScope(e).set.get(e.name))?.references??[]).filter(t=>!t.init&&t.identifier!==e).map(e=>({identifier:e.identifier}))}function H(e){return V(e).map(({identifier:e})=>{let t=e.parent;if(t?.type!==`MemberExpression`||t.object!==e)return null;let n=t.parent;if(n?.type===`AssignmentExpression`&&n.left===t)return`[index] =`;let r=t.property?.type===`Identifier`&&!t.computed?t.property.name:null;return r&&_.has(r)&&n?.type===`CallExpression`&&n.callee===t?r:null}).find(e=>e!==null)??null}let U={};function W(e){if(!U.map){let e=i(u.sourceCode.ast).flatMap(e=>{if(e.type!==`CallExpression`||e.callee?.type!==`MemberExpression`)return[];let t=e.callee.property?.type===`Identifier`?e.callee.property.name:null,n=e.callee.object,r=n?.type===`MemberExpression`&&n.property?.type===`Identifier`&&!n.computed?n.property.name:null;return t&&r&&_.has(t)?[[r,t]]:[]});U.map=new globalThis.Map(e.reverse())}return U.map.get(e)??null}function G(e){return V(e).some(({identifier:e})=>t(e,u)===!0)}function K(e,n,i){let a=O(e),o=e=>e.type===`TSAsExpression`?o(e.expression):e;if(a&&t(a,u)===!0)return;let s=a?o(a):null,c=s!==null&&s.type!==`ArrayExpression`&&r(s,u)===!0;if(a&&c){u.report({node:e,messageId:`preferWireCast`,data:{type:n,arrayType:i},suggest:[{messageId:`suggestReadonlyArray`,data:{type:n},fix:t=>t.replaceText(e,`ReadonlyArray<${n}>`)}]});return}let l=E(e);if(l!==null&&V(l).some(({identifier:e})=>{let n=e.parent;return n?.type===`CallExpression`&&n.callee===e&&t(n,u)===!0}))return;let d=D(e),f=d===null?null:W(d);if(d!==null&&f!==null){u.report({node:e,messageId:`mutatedArray`,data:{name:d,how:f}});return}let p=T(e);if(p){if(G(p))return;let t=H(p);if(t){u.report({node:e,messageId:`mutatedArray`,data:{name:p.name,how:t}});return}}q(e,n,i)}function q(e,t,n){let r=u.sourceCode,i=[{messageId:`suggestReadonlyArray`,data:{type:t},fix:n=>n.replaceText(e,`ReadonlyArray<${t}>`)},{messageId:`suggestListType`,data:{type:t},fix:n=>n.replaceText(e,`List<${t}>`)}];c(r,`List`)||i.push({messageId:`suggestAddImport`,data:{symbol:`List`},fix:s(r,`List`)}),u.report({node:e,messageId:`preferReadonlyOrList`,data:{type:t,arrayType:n},suggest:i})}return{TSArrayType(e){if(d(e,k)||M&&I())return;let t=e.parent;if(t?.type===`TSRestType`||t?.type===`TSTypeAnnotation`&&t.parent?.type===`RestElement`)return;let n=t?.type===`TSTypeOperator`&&t.operator===`readonly`;if(n&&N)return;let r=u.sourceCode,i=r.getText(e.elementType),a=n?t:e,o=r.getText(a);if(!n){K(a,i,o);return}let l=[{messageId:`suggestListType`,data:{type:i},fix(e){return e.replaceText(a,`List<${i}>`)}}];c(r,`List`)||l.push({messageId:`suggestAddImport`,data:{symbol:`List`},fix:s(r,`List`)}),u.report({node:a,messageId:`preferList`,data:{type:i,arrayType:o},suggest:l})},TSTypeReference(e){if(d(e,k)||M&&I())return;let t=u.sourceCode;if(!e.typeName)return;let n=e.typeName.type===`Identifier`?e.typeName.name:t.getText(e.typeName);if(n===`Array`){K(e,L(e,t)||`T`,t.getText(e));return}if(n===`ReadonlyArray`){if(N)return;let n=L(e,t),r=t.getText(e),i=n||`T`,a=[{messageId:`suggestListType`,data:{type:i},fix(t){return t.replaceText(e,`List<${i}>`)}}];c(t,`List`)||a.push({messageId:`suggestAddImport`,data:{symbol:`List`},fix:s(t,`List`)}),u.report({node:e,messageId:`preferList`,data:{type:i,arrayType:r},suggest:a})}},ArrayExpression(t){if(M&&I()||P||t.elements.length===0)return;let r=t.parent;if(r&&o(r,F)||h(r)||m(t,e=>e.type===`ArrayExpression`)||m(t,j))return;let i=v(t),a=i.parent;if(g(r)||e(t,u)===!0||e(i,u)===!0||R(i,a)||x(t)||x(i))return;let l=b(i);if(l!==i&&(S(l)||e(l,u)===!0)||w(t))return;if(a?.type===`VariableDeclarator`&&a.id?.type===`Identifier`){let e=H(a.id);if(e){u.report({node:t,messageId:`mutatedArray`,data:{name:a.id.name,how:e}});return}}if(!n(u)||B(a))return;if(t.elements.some(e=>e!==null&&e.type===`SpreadElement`)){u.report({node:t,messageId:`preferListLiteral`});return}let d=u.sourceCode,f=t.elements.filter(e=>e!==null).map(e=>d.getText(e)),p=[{messageId:`suggestListOf`,fix(e){return e.replaceText(t,`List.of(${f.join(`, `)})`)}}];c(d,`List`)||p.push({messageId:`suggestAddImport`,data:{symbol:`List`},fix:s(d,`List`)}),u.report({node:t,messageId:`preferListLiteral`,suggest:p})}}}};export{M as default};
|
|
3
3
|
//# sourceMappingURL=prefer-list.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefer-list.js","names":["NON_CHILD_KEYS","astChildren","node","k","v","ancestorSatisfies","parent","pred","isListFactoryArg","isTupleAssertion","raw","annotation","MUTATING_METHODS","throughConditionals","TERMINAL_METHODS","chainEnd","member","receiver","call","chainEndsInSingleValue","isTerminalRead","isJsxChild","grand","name","isSpreadIntoCall","annotatedBinding","climb","n","typeNode","returningFunctionName","fn","declarator","annotatedFieldName","field","castOf","child","outer","current","hasOwnTypeAnnotation","rule","WIRE_TYPES_SCHEMA","header","context","comment","options","wireTypes","DEFAULT_WIRE_TYPES","allowArraysInTests","allowReadonlyArrays","allowArrayLiterals","functypeImports","getFunctypeImportsLegacy","isInTestFile","filename","findTypeParameter","findInNode","sourceCode","c","r","isFunctypeConstructorArg","reachesArraySlot","flowsIntoArraySlot","isOnlyHandedToArraySlots","uses","variable","ref","usesOf","owner","binding","mutationOf","identifier","how","mutatedFields","fieldMutationIn","entries","descendants","method","target","feedsMutableSlot","flowsIntoMutableArraySlot","checkMutable","cast","reportNode","castSource","source","decodes","isUntypedExpression","elementType","fullType","fixer","fnName","fieldMutation","reportMutable","suggest","hasFunctypeSymbol","createImportFixer","isInsideWireType","isReadonly","typeName","typeParam","resolvedType","isFunctypeCall","targetParent","end","hasTypeInformation","el","elementTexts"],"sources":["../../src/rules/prefer-list.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { descendants } from \"../utils/ast-walk\"\nimport { getFunctypeImportsLegacy, isFunctypeCall } from \"../utils/functype-detection\"\nimport { createImportFixer, hasFunctypeSymbol } from \"../utils/import-fixer\"\nimport {\n flowsIntoArraySlot,\n flowsIntoMutableArraySlot,\n hasTypeInformation,\n isUntypedExpression,\n} from \"../utils/type-aware\"\nimport { DEFAULT_WIRE_TYPES, isInsideWireType, WIRE_TYPES_SCHEMA } from \"../utils/wire-types\"\n\n/** AST keys that don't represent syntax children — back-edges and source metadata. */\nconst NON_CHILD_KEYS: ReadonlySet<string> = new Set([\"parent\", \"loc\", \"range\"])\n\n/** AST children of `node`: drops back-edges, flattens array-valued keys, filters non-object leaves. */\nfunction astChildren(node: ASTNode): readonly unknown[] {\n return Object.entries(node)\n .filter(([k]) => !NON_CHILD_KEYS.has(k))\n .flatMap(([, v]) => (Array.isArray(v) ? v : [v]))\n .filter((v) => v !== null && typeof v === \"object\")\n}\n\n/** True iff any ancestor of `node` satisfies `pred`. Pure tail recursion. */\nfunction ancestorSatisfies(node: ASTNode | null | undefined, pred: (n: ASTNode) => boolean): boolean {\n const parent = node?.parent as ASTNode | undefined\n if (!parent) return false\n return pred(parent) || ancestorSatisfies(parent, pred)\n}\n\n/** `parent` is `List.from(arr)` or `List.of(...arr)`. */\nfunction isListFactoryArg(parent: ASTNode | null | undefined): boolean {\n return (\n parent?.type === \"CallExpression\" &&\n parent.callee.type === \"MemberExpression\" &&\n parent.callee.object.type === \"Identifier\" &&\n parent.callee.object.name === \"List\" &&\n [\"from\", \"of\"].includes(parent.callee.property.name)\n )\n}\n\n/**\n * `[…] as const` or `[…] as [string, ...string[]]`: the literal is asserted to a tuple, a fixed shape that\n * `List` can't express (an enum's values, the argument zod's `z.enum` requires).\n */\nfunction isTupleAssertion(parent: ASTNode | null | undefined): boolean {\n const raw = parent?.type === \"TSAsExpression\" ? parent.typeAnnotation : undefined\n const annotation = raw?.type === \"TSTypeOperator\" ? raw.typeAnnotation : raw\n if (annotation?.type === \"TSTupleType\") return true\n return (\n annotation?.type === \"TSTypeReference\" &&\n annotation.typeName?.type === \"Identifier\" &&\n annotation.typeName.name === \"const\"\n )\n}\n\n/** Array methods that change the array in place. */\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 * The expression a literal stands in for once conditionals are looked through: `[x]` in\n * `List(c ? xs : [x])` or `const args = c ? [a] : [\"--fix\", a]` behaves like the whole conditional.\n */\nfunction throughConditionals(node: ASTNode): ASTNode {\n const parent = node.parent as ASTNode | undefined\n if (parent?.type === \"ConditionalExpression\" && parent.test !== node) return throughConditionals(parent)\n if (parent?.type === \"LogicalExpression\") return throughConditionals(parent)\n return node\n}\n\n/**\n * Methods that turn an array into a single value: using a collection only through these makes it a\n * temporary (`lines.join(\"\\n\")`, `[a, b].includes(x)`). Methods that produce another collection\n * (`map`, `filter`, `slice`, `concat`, `reduce`…) are collection work, which is what `List` is for.\n */\nconst TERMINAL_METHODS: ReadonlySet<string> = new Set([\n \"join\",\n \"includes\",\n \"indexOf\",\n \"lastIndexOf\",\n \"some\",\n \"every\",\n \"find\",\n \"findIndex\",\n \"findLast\",\n \"findLastIndex\",\n \"at\",\n])\n\n/**\n * The end of a method chain that starts at `receiver`: `[…].map(f).filter(g)` → the `.filter(g)` call.\n * `receiver` itself when no method is called on it.\n */\nfunction chainEnd(receiver: ASTNode): ASTNode {\n const member = receiver.parent as ASTNode | undefined\n const call = member?.parent as ASTNode | undefined\n if (member?.type !== \"MemberExpression\" || member.object !== receiver) return receiver\n return call?.type === \"CallExpression\" && call.callee === member ? chainEnd(call) : receiver\n}\n\n/**\n * Does the method chain starting at `receiver` end in a single value: `[a, b].filter(Boolean).length`,\n * `[name, email].filter(nonEmpty).join(\"\\n\")`, `[...xs].sort(byRank)[0]`? Then every array in it is a\n * temporary, the same as `lines.join(\"\\n\")`.\n */\nfunction chainEndsInSingleValue(receiver: ASTNode): boolean {\n if (isTerminalRead(receiver)) return true\n const member = receiver.parent as ASTNode | undefined\n const call = member?.parent as ASTNode | undefined\n if (member?.type !== \"MemberExpression\" || member.object !== receiver) return false\n return call?.type === \"CallExpression\" && call.callee === member && chainEndsInSingleValue(call)\n}\n\n/** `{items.map((i) => <Row />)}`: an expression rendered as JSX children, which React takes as an array. */\nfunction isJsxChild(node: ASTNode): boolean {\n return (node.parent as ASTNode | undefined)?.type === \"JSXExpressionContainer\"\n}\n\n/**\n * Is `receiver` read down to a single value on the spot: `.length`, `[i]`, or a terminal method call?\n * The same test applies to a literal (`[a, b].includes(x)`) and to every use of a const (`lines.join`).\n */\nfunction isTerminalRead(receiver: ASTNode): boolean {\n const member = receiver.parent as ASTNode | undefined\n if (member?.type !== \"MemberExpression\" || member.object !== receiver) return false\n const grand = member.parent as ASTNode | undefined\n if (grand?.type === \"AssignmentExpression\" && grand.left === member) return false\n if (member.computed) return true\n const name = member.property?.type === \"Identifier\" ? member.property.name : null\n if (name === \"length\") return true\n return name !== null && TERMINAL_METHODS.has(name) && grand?.type === \"CallExpression\" && grand.callee === member\n}\n\n/**\n * Is `node` spread straight into a call's arguments, `and(...conds)` or `and(...(c ? [x] : []))`?\n * The function receives the elements one by one; the array is never a collection of your own.\n */\nfunction isSpreadIntoCall(node: ASTNode): boolean {\n const parent = node.parent as ASTNode | undefined\n if (!parent) return false\n if (parent.type === \"ConditionalExpression\" && parent.test !== node) return isSpreadIntoCall(parent)\n if (parent.type === \"LogicalExpression\" && parent.right === node) return isSpreadIntoCall(parent)\n return (\n parent.type === \"SpreadElement\" &&\n (parent.parent?.type === \"CallExpression\" || parent.parent?.type === \"NewExpression\")\n )\n}\n\n/** The `x` in `const x: T[] = …` or `(x: T[]) => …`, when the array type is (part of) its annotation. */\nfunction annotatedBinding(typeNode: ASTNode): ASTNode | null {\n const climb = (n: ASTNode | null | undefined): ASTNode | null => {\n if (!n) return null\n if (n.type === \"TSTypeAnnotation\") return n.parent?.type === \"Identifier\" ? (n.parent as ASTNode) : null\n if (n.type === \"TSAsExpression\" || n.type === \"TSSatisfiesExpression\" || n.type.endsWith(\"Statement\")) return null\n return climb(n.parent as ASTNode | undefined)\n }\n return climb(typeNode.parent as ASTNode | undefined)\n}\n\n/**\n * The name of the function whose declared return type *is* this array type: `f` in\n * `function f(): T[]` or `const f = (): T[] => …`. Null for anything nested (`(): { nodes: T[] }`).\n */\nfunction returningFunctionName(typeNode: ASTNode): ASTNode | null {\n const annotation = typeNode.parent as ASTNode | undefined\n const fn = annotation?.type === \"TSTypeAnnotation\" ? (annotation.parent as ASTNode | undefined) : undefined\n if (!fn || fn.returnType !== annotation) return null\n if (fn.type === \"FunctionDeclaration\") return fn.id?.type === \"Identifier\" ? (fn.id as ASTNode) : null\n const declarator = fn.parent as ASTNode | undefined\n return (fn.type === \"ArrowFunctionExpression\" || fn.type === \"FunctionExpression\") &&\n declarator?.type === \"VariableDeclarator\" &&\n declarator.init === fn &&\n declarator.id?.type === \"Identifier\"\n ? (declarator.id as ASTNode)\n : null\n}\n\n/** The property name when the array type annotates a field: `errors` in `{ errors: string[] }` or `class { errors: T[] }`. */\nfunction annotatedFieldName(typeNode: ASTNode): string | null {\n const annotation = typeNode.parent as ASTNode | undefined\n const field = annotation?.type === \"TSTypeAnnotation\" ? (annotation.parent as ASTNode | undefined) : undefined\n if (field?.type !== \"TSPropertySignature\" && field?.type !== \"PropertyDefinition\") return null\n return field.key?.type === \"Identifier\" && !field.computed ? field.key.name : null\n}\n\n/** The outermost `x as … as T[]` around an array type used as a cast target, or null. */\nfunction castOf(typeNode: ASTNode): ASTNode | null {\n const climb = (n: ASTNode | null | undefined, child: ASTNode): ASTNode | null => {\n if (!n || n.type === \"TSTypeAnnotation\" || n.type.endsWith(\"Statement\")) return null\n if (n.type === \"TSAsExpression\" && n.typeAnnotation === child) {\n const outer = (current: ASTNode): ASTNode =>\n current.parent?.type === \"TSAsExpression\" ? outer(current.parent as ASTNode) : current\n return outer(n)\n }\n return climb(n.parent as ASTNode | undefined, n)\n }\n return climb(typeNode.parent as ASTNode | undefined, typeNode)\n}\n\n/** `node` is a VariableDeclarator with its own type annotation, or a TSTypeAnnotation node directly. */\nfunction hasOwnTypeAnnotation(node: ASTNode): boolean {\n return (node.type === \"VariableDeclarator\" && Boolean(node.id?.typeAnnotation)) || node.type === \"TSTypeAnnotation\"\n}\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"suggestion\",\n hasSuggestions: true,\n docs: {\n description: \"Prefer List<T> over native arrays for immutable collections\",\n recommended: true,\n },\n schema: [\n {\n type: \"object\",\n properties: {\n allowArraysInTests: {\n type: \"boolean\",\n default: true,\n },\n wireTypes: WIRE_TYPES_SCHEMA,\n allowReadonlyArrays: {\n type: \"boolean\",\n default: true,\n },\n allowArrayLiterals: {\n type: \"boolean\",\n default: false,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n preferList: \"Prefer List<{{type}}> over array type {{arrayType}}\",\n preferReadonlyOrList:\n \"Mutable array type {{arrayType}}: anything holding it can change it. Use ReadonlyArray<{{type}}>, which every caller and library accepts, or List<{{type}}> for a collection you transform\",\n preferWireCast:\n \"Cast to the mutable array {{arrayType}}: this is data decoded from outside. Declare its shape once as Wire<ReadonlyArray<{{type}}>> (functype's boundary marker) and cast to that\",\n mutatedArray:\n \"{{name}} is a mutable array changed in place (.{{how}}()). Build it without mutation instead: map/filter/flatMap, a List, or a fold\",\n preferListLiteral: \"Prefer List.of(...) or List.from([...]) over array literal\",\n suggestListType: \"Replace with List<{{type}}>\",\n suggestReadonlyArray: \"Replace with ReadonlyArray<{{type}}>\",\n suggestListOf: \"Replace with List.of(...)\",\n suggestAddImport: \"Add {{symbol}} import from functype\",\n },\n },\n\n create(context) {\n // A generated file (`// @generated`, \"Auto-generated … DO NOT EDIT\") isn't edited by hand, so there's\n // nothing for its author to fix. Generators without a marker (Supabase types) need a config ignore.\n const header = context.sourceCode\n .getAllComments()\n .slice(0, 3)\n .map((comment) => comment.value)\n .join(\"\\n\")\n if (/@generated|auto-generated|do not edit/i.test(header)) return {}\n\n const options = context.options[0] || {}\n // Everything inside `Wire<…>` is the declared serialization shape (#325 B).\n const wireTypes: ReadonlyArray<string> = options.wireTypes ?? DEFAULT_WIRE_TYPES\n const allowArraysInTests = options.allowArraysInTests !== false\n const allowReadonlyArrays = options.allowReadonlyArrays !== false\n const allowArrayLiterals = options.allowArrayLiterals === true\n\n // Get functype imports if available (but still apply rule even without explicit import)\n const functypeImports = getFunctypeImportsLegacy(context)\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 findTypeParameter(node: ASTNode, sourceCode: typeof context.sourceCode): string | null {\n // Pure pre-order search: look at this node, then recursively at each\n // child until we find a TSTypeParameterInstantiation with a first param.\n function findInNode(n: ASTNode): string | null {\n if (n.type === \"TSTypeParameterInstantiation\" && n.params && n.params[0]) {\n return sourceCode.getText(n.params[0])\n }\n const results = astChildren(n)\n .filter((c): c is ASTNode => typeof (c as ASTNode)?.type === \"string\")\n .map((child) => findInNode(child))\n return results.find((r) => r !== null) ?? null\n }\n return findInNode(node)\n }\n\n /** `List([...x])`, `Set([a, b])`: the literal is already being captured into a functype value. */\n function isFunctypeConstructorArg(node: ASTNode, parent: ASTNode | null | undefined): boolean {\n return (\n parent?.type === \"CallExpression\" &&\n parent.callee.type === \"Identifier\" &&\n functypeImports.has(parent.callee.name) &&\n parent.arguments.includes(node)\n )\n }\n\n /** Is `node` handed straight to an array-typed slot, directly or spread into a literal that is? */\n function reachesArraySlot(node: ASTNode): boolean {\n if (flowsIntoArraySlot(node, context) === true) return true\n if (isSpreadIntoCall(node)) return true\n const parent = node.parent as ASTNode | undefined\n return (\n parent?.type === \"SpreadElement\" &&\n parent.parent?.type === \"ArrayExpression\" &&\n flowsIntoArraySlot(parent.parent as ASTNode, context) === true\n )\n }\n\n /**\n * `const OPTIONS = [...]` whose every use hands it to an array-typed slot (`<Select data={OPTIONS} />`,\n * `db.insert(t).values(ROWS)`) or reads it down to a single value (`lines.join(\"\\n\")`, `xs.length`): data\n * built to give to a library, or a temporary, declared before it's used. Needs at least one local use; an exported\n * constant with no local use is still reported, because its consumers aren't visible here.\n */\n function isOnlyHandedToArraySlots(declarator: ASTNode | null | undefined): boolean {\n if (declarator?.type !== \"VariableDeclarator\" || declarator.id?.type !== \"Identifier\") return false\n const uses = context.sourceCode\n .getDeclaredVariables(declarator)\n .flatMap((variable) => variable.references.filter((ref) => !ref.init))\n return (\n uses.length > 0 &&\n uses.every((ref) => reachesArraySlot(ref.identifier as ASTNode) || isTerminalRead(ref.identifier as ASTNode))\n )\n }\n\n /** References to `binding` other than its declaration. */\n function usesOf(binding: ASTNode): ReadonlyArray<{ identifier: ASTNode }> {\n // The declaring node: a VariableDeclarator, a FunctionDeclaration (its name lives in the outer\n // scope) or, for a parameter, its function. getDeclaredVariables on it yields the binding.\n const owner = (binding.parent as ASTNode | undefined) ?? binding\n const variable =\n context.sourceCode.getDeclaredVariables(owner).find((v) => v.name === binding.name) ??\n context.sourceCode.getScope(binding).set.get(binding.name)\n return (variable?.references ?? [])\n .filter((ref) => !ref.init && ref.identifier !== binding)\n .map((ref) => ({ identifier: ref.identifier as ASTNode }))\n }\n\n /** The in-place mutation applied to `binding` (`push`, `sort`, `x[i] = …`), if any. */\n function mutationOf(binding: ASTNode): string | null {\n const found = usesOf(binding)\n .map(({ identifier }) => {\n const parent = identifier.parent as ASTNode | undefined\n if (parent?.type !== \"MemberExpression\" || parent.object !== identifier) return null\n const grand = parent.parent as ASTNode | undefined\n if (grand?.type === \"AssignmentExpression\" && grand.left === parent) return \"[index] =\"\n const name = parent.property?.type === \"Identifier\" && !parent.computed ? parent.property.name : null\n return name && MUTATING_METHODS.has(name) && grand?.type === \"CallExpression\" && grand.callee === parent\n ? name\n : null\n })\n .find((how) => how !== null)\n return found ?? null\n }\n\n /**\n * Fields mutated in place anywhere in the file, `errors` → `push` for `t.errors.push(e)`. Built once per\n * file, on first use, from the syntax tree.\n */\n const mutatedFields: { map?: ReadonlyMap<string, string> } = {}\n function fieldMutationIn(field: string): string | null {\n if (!mutatedFields.map) {\n const entries = descendants(context.sourceCode.ast as unknown as ASTNode).flatMap(\n (node): [string, string][] => {\n if (node.type !== \"CallExpression\" || node.callee?.type !== \"MemberExpression\") return []\n const method = node.callee.property?.type === \"Identifier\" ? node.callee.property.name : null\n const target = node.callee.object as ASTNode\n const name =\n target?.type === \"MemberExpression\" && target.property?.type === \"Identifier\" && !target.computed\n ? target.property.name\n : null\n return method && name && MUTATING_METHODS.has(method) ? [[name, method]] : []\n },\n )\n mutatedFields.map = new globalThis.Map(entries.reverse())\n }\n return mutatedFields.map.get(field) ?? null\n }\n\n /** Is `binding` handed to a slot that requires a mutable array (pg `query` values, ReactFlow `nodes`)? */\n function feedsMutableSlot(binding: ASTNode): boolean {\n return usesOf(binding).some(({ identifier }) => flowsIntoMutableArraySlot(identifier, context) === true)\n }\n\n /**\n * Report a mutable array type, unless a library demands it. The order matters: a library slot that\n * requires `T[]` makes the type correct as written; a binding mutated in place can't take\n * `ReadonlyArray` without a rewrite, so it gets advice instead of a suggestion that wouldn't compile;\n * a cast is decoded outside data, so it points at `Wire`.\n */\n function checkMutable(reportNode: ASTNode, elementType: string, fullType: string): void {\n const cast = castOf(reportNode)\n // The value under every `as`: `JSON.parse(raw)` in `JSON.parse(raw) as unknown as T[]`.\n const castSource = (n: ASTNode): ASTNode =>\n n.type === \"TSAsExpression\" ? castSource(n.expression as ASTNode) : n\n if (cast && flowsIntoMutableArraySlot(cast, context) === true) return\n // Only a cast of an untyped value (`JSON.parse`, `res.json()`, a raw row) is decoding outside data,\n // the Wire case. It needs type evidence: without it the rule can't tell decoding from re-casting a\n // typed value, so it gives the plain message rather than advice that flips when types are turned on.\n const source = cast ? castSource(cast) : null\n const decodes =\n source !== null && source.type !== \"ArrayExpression\" && isUntypedExpression(source, context) === true\n if (cast && decodes) {\n context.report({\n node: reportNode,\n messageId: \"preferWireCast\",\n data: { type: elementType, arrayType: fullType },\n suggest: [\n {\n messageId: \"suggestReadonlyArray\",\n data: { type: elementType },\n fix: (fixer: Rule.RuleFixer) => fixer.replaceText(reportNode, `ReadonlyArray<${elementType}>`),\n },\n ],\n })\n return\n }\n // `function allowedTools(): string[]` whose result goes to an SDK option typed `string[]`.\n const fnName = returningFunctionName(reportNode)\n const feedsFromCall =\n fnName !== null &&\n usesOf(fnName).some(({ identifier }) => {\n const call = identifier.parent as ASTNode | undefined\n return (\n call?.type === \"CallExpression\" &&\n call.callee === identifier &&\n flowsIntoMutableArraySlot(call, context) === true\n )\n })\n if (feedsFromCall) return\n // A field mutated somewhere in the file (`result.errors.push(e)`, `this.events.push(e)`): a\n // ReadonlyArray suggestion wouldn't compile, so give the mutation advice. Matched by name, which only\n // picks the message, never whether to report.\n const field = annotatedFieldName(reportNode)\n const fieldMutation = field === null ? null : fieldMutationIn(field)\n if (field !== null && fieldMutation !== null) {\n context.report({ node: reportNode, messageId: \"mutatedArray\", data: { name: field, how: fieldMutation } })\n return\n }\n const binding = annotatedBinding(reportNode)\n if (binding) {\n if (feedsMutableSlot(binding)) return\n const how = mutationOf(binding)\n if (how) {\n context.report({ node: reportNode, messageId: \"mutatedArray\", data: { name: binding.name, how } })\n return\n }\n }\n reportMutable(reportNode, elementType, fullType)\n }\n\n /**\n * A mutable `T[]` / `Array<T>` is the real defect: anything holding it can push, sort or splice.\n * `ReadonlyArray<T>` fixes that and still fits wherever a library expects an array, so it's offered\n * first; `List<T>` is for collections that live inside your own code.\n */\n function reportMutable(reportNode: ASTNode, elementType: string, fullType: string): void {\n const sourceCode = context.sourceCode\n const suggest: Rule.SuggestionReportDescriptor[] = [\n {\n messageId: \"suggestReadonlyArray\",\n data: { type: elementType },\n fix: (fixer: Rule.RuleFixer) => fixer.replaceText(reportNode, `ReadonlyArray<${elementType}>`),\n },\n {\n messageId: \"suggestListType\",\n data: { type: elementType },\n fix: (fixer: Rule.RuleFixer) => fixer.replaceText(reportNode, `List<${elementType}>`),\n },\n ]\n if (!hasFunctypeSymbol(sourceCode, \"List\")) {\n suggest.push({\n messageId: \"suggestAddImport\",\n data: { symbol: \"List\" },\n fix: createImportFixer(sourceCode, \"List\"),\n })\n }\n context.report({\n node: reportNode,\n messageId: \"preferReadonlyOrList\",\n data: { type: elementType, arrayType: fullType },\n suggest,\n })\n }\n\n return {\n TSArrayType(node: ASTNode) {\n if (isInsideWireType(node, wireTypes)) return\n if (allowArraysInTests && isInTestFile()) return\n\n // `readonly T[]` parses as TSTypeOperator(operator: \"readonly\") wrapping TSArrayType.\n // When the parent is that readonly wrapper, we treat the whole `readonly T[]` as\n // the reported unit — both for gating (parity with the ReadonlyArray<T> branch\n // below) and for the suggestion's replacement range. Replacing only the inner\n // TSArrayType would leave `readonly List<T>` behind, which is invalid TS\n // (TS1354: `readonly` only applies to array/tuple types).\n const parent = node.parent as ASTNode | undefined\n // `[string, ...string[]]`: a tuple's rest element must be written as an array type, and libraries\n // such as zod's `z.enum` require exactly that shape. The tuple is the type; its rest isn't a list.\n if (parent?.type === \"TSRestType\") return\n // `(...args: string[])`: a rest parameter is a fresh array on every call, owned by the callee.\n if (parent?.type === \"TSTypeAnnotation\" && parent.parent?.type === \"RestElement\") return\n\n const isReadonly =\n parent?.type === \"TSTypeOperator\" && (parent as { operator?: string }).operator === \"readonly\"\n\n if (isReadonly && allowReadonlyArrays) return\n\n const sourceCode = context.sourceCode\n const elementType = sourceCode.getText(node.elementType)\n const reportNode = isReadonly ? (parent as ASTNode) : node\n const fullType = sourceCode.getText(reportNode)\n\n if (!isReadonly) {\n checkMutable(reportNode, elementType, fullType)\n return\n }\n\n const suggest: Rule.SuggestionReportDescriptor[] = [\n {\n messageId: \"suggestListType\",\n data: { type: elementType },\n fix(fixer: Rule.RuleFixer) {\n return fixer.replaceText(reportNode, `List<${elementType}>`)\n },\n },\n ]\n\n if (!hasFunctypeSymbol(sourceCode, \"List\")) {\n suggest.push({\n messageId: \"suggestAddImport\",\n data: { symbol: \"List\" },\n fix: createImportFixer(sourceCode, \"List\"),\n })\n }\n\n context.report({\n node: reportNode,\n messageId: \"preferList\",\n data: {\n type: elementType,\n arrayType: fullType,\n },\n suggest,\n })\n },\n\n TSTypeReference(node: ASTNode) {\n if (isInsideWireType(node, wireTypes)) return\n if (allowArraysInTests && isInTestFile()) return\n\n const sourceCode = context.sourceCode\n\n // Get type name - handle both simple identifiers and member expressions\n if (!node.typeName) return // No type name found\n\n const typeName = node.typeName.type === \"Identifier\" ? node.typeName.name : sourceCode.getText(node.typeName)\n\n // Handle Array<T> syntax: mutable, same as T[]\n if (typeName === \"Array\") {\n const typeParam = findTypeParameter(node, sourceCode)\n checkMutable(node, typeParam || \"T\", sourceCode.getText(node))\n return\n }\n\n // Handle ReadonlyArray<T> — gated on allowReadonlyArrays (parity with `readonly T[]`).\n if (typeName === \"ReadonlyArray\") {\n if (allowReadonlyArrays) return\n\n const typeParam = findTypeParameter(node, sourceCode)\n const fullType = sourceCode.getText(node)\n const resolvedType = typeParam || \"T\"\n\n const suggest: Rule.SuggestionReportDescriptor[] = [\n {\n messageId: \"suggestListType\",\n data: { type: resolvedType },\n fix(fixer: Rule.RuleFixer) {\n return fixer.replaceText(node, `List<${resolvedType}>`)\n },\n },\n ]\n\n if (!hasFunctypeSymbol(sourceCode, \"List\")) {\n suggest.push({\n messageId: \"suggestAddImport\",\n data: { symbol: \"List\" },\n fix: createImportFixer(sourceCode, \"List\"),\n })\n }\n\n context.report({\n node,\n messageId: \"preferList\",\n data: {\n type: resolvedType,\n arrayType: fullType,\n },\n suggest,\n })\n }\n },\n\n ArrayExpression(node: ASTNode) {\n if (allowArraysInTests && isInTestFile()) return\n if (allowArrayLiterals) return\n\n // Only flag non-empty arrays to avoid noise\n if (node.elements.length === 0) return\n\n const parent = node.parent\n\n // Don't flag arrays that are already arguments to functype calls.\n if (parent && isFunctypeCall(parent, functypeImports)) return\n\n // Don't flag arrays that are arguments to List.from / List.of.\n if (isListFactoryArg(parent)) return\n\n // Don't flag nested array literals — let the outermost one handle it.\n if (ancestorSatisfies(node, (n) => n.type === \"ArrayExpression\")) return\n\n // Don't flag array literals that already live in a type-annotated\n // context (those are handled by the type-checking rules).\n if (ancestorSatisfies(node, hasOwnTypeAnnotation)) return\n\n // Look through `c ? xs : [x]` / `xs ?? [x]`: the checks below apply to the whole expression.\n const target = throughConditionals(node)\n const targetParent = target.parent as ASTNode | undefined\n\n // A literal asserted to a tuple (`as const`, `as [string, ...string[]]`) is a fixed shape.\n if (isTupleAssertion(parent)) return\n\n // With type information: a literal passed where an array is expected — drizzle's\n // `.values([...])`, an index definition, a schema `target: [...]` — is handed straight to code\n // that requires an array. It never becomes a collection in your own code, so it's the\n // boundary itself and `List` can't go there.\n if (flowsIntoArraySlot(node, context) === true || flowsIntoArraySlot(target, context) === true) return\n if (isFunctypeConstructorArg(target, targetParent)) return\n // Read down to one value on the spot (`[a, b].includes(x)`, `[a, b].filter(Boolean).join(\" \")`):\n // nothing is stored.\n if (chainEndsInSingleValue(node) || chainEndsInSingleValue(target)) return\n // A chain whose result goes to React or a library (`{[\"PDF\", \"DOCX\"].map((f) => <Chip />)}`,\n // `marks={[3, 4].map(…)}`): the transformed array is what's handed over, so the literal is too.\n const end = chainEnd(target)\n if (end !== target && (isJsxChild(end) || flowsIntoArraySlot(end, context) === true)) return\n // Spread into a call (`and(...(c ? [x] : []))`): the function gets the elements one by one.\n if (isSpreadIntoCall(node)) return\n // `const acc = [...]; acc.push(x)`: an accumulator. The defect is the mutation, so it gets the same\n // advice as a mutated `T[]` binding, not a List.of suggestion that has no push.\n if (targetParent?.type === \"VariableDeclarator\" && targetParent.id?.type === \"Identifier\") {\n const how = mutationOf(targetParent.id as ASTNode)\n if (how) {\n context.report({ node, messageId: \"mutatedArray\", data: { name: targetParent.id.name, how } })\n return\n }\n }\n // Without type information the rule can't tell a literal handed to a library (drizzle\n // `.values([...])`) from a collection of your own, so it reports neither rather than guess.\n if (!hasTypeInformation(context)) return\n if (isOnlyHandedToArraySlots(targetParent)) return\n\n // Check if any element is a SpreadElement — ambiguous semantics, skip suggestions\n const hasSpread = node.elements.some((el) => el !== null && el.type === \"SpreadElement\")\n\n if (hasSpread) {\n context.report({\n node,\n messageId: \"preferListLiteral\",\n })\n return\n }\n\n const sourceCode = context.sourceCode\n const elementTexts = node.elements.filter((el) => el !== null).map((el) => sourceCode.getText(el))\n\n const suggest: Rule.SuggestionReportDescriptor[] = [\n {\n messageId: \"suggestListOf\",\n fix(fixer: Rule.RuleFixer) {\n return fixer.replaceText(node, `List.of(${elementTexts.join(\", \")})`)\n },\n },\n ]\n\n if (!hasFunctypeSymbol(sourceCode, \"List\")) {\n suggest.push({\n messageId: \"suggestAddImport\",\n data: { symbol: \"List\" },\n fix: createImportFixer(sourceCode, \"List\"),\n })\n }\n\n context.report({\n node,\n messageId: \"preferListLiteral\",\n suggest,\n })\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"0dAeA,MAAMA,kBAAsC,IAAI,IAAI,CAAC,SAAU,MAAO,OAAO,CAAC,EAG9E,SAASC,EAAY,EAAmC,CACtD,OAAO,OAAO,QAAQC,CAAI,CAAC,CACxB,QAAQ,CAACC,KAAO,CAACH,EAAe,IAAIG,CAAC,CAAC,CAAC,CACvC,SAAS,EAAGC,KAAQ,MAAM,QAAQA,CAAC,EAAIA,EAAI,CAACA,CAAC,CAAE,CAAC,CAChD,OAAQ,GAAoB,OAAOA,GAAM,YAA3BA,CAAmC,CACtD,CAGA,SAASC,EAAkB,EAAkC,EAAwC,CACnG,IAAMC,EAASJ,GAAM,OAErB,OADKI,EACEC,EAAKD,CAAM,GAAKD,EAAkBC,EAAQC,CAAI,EADjC,EAEtB,CAGA,SAASC,EAAiB,EAA6C,CACrE,OACEF,GAAQ,OAAS,kBACjBA,EAAO,OAAO,OAAS,oBACvBA,EAAO,OAAO,OAAO,OAAS,cAC9BA,EAAO,OAAO,OAAO,OAAS,QAC9B,CAAC,OAAQ,IAAI,CAAC,CAAC,SAASA,EAAO,OAAO,SAAS,IAAI,CAEvD,CAMA,SAASG,EAAiB,EAA6C,CACrE,IAAMC,EAAMJ,GAAQ,OAAS,iBAAmBA,EAAO,eAAiB,IAAA,GAClEK,EAAaD,GAAK,OAAS,iBAAmBA,EAAI,eAAiBA,EAEzE,OADIC,GAAY,OAAS,eAEvBA,GAAY,OAAS,mBACrBA,EAAW,UAAU,OAAS,cAC9BA,EA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"version":3,"file":"prefer-list.js","names":["NON_CHILD_KEYS","astChildren","node","k","v","ancestorSatisfies","parent","pred","isListFactoryArg","isTupleAssertion","raw","annotation","MUTATING_METHODS","throughConditionals","TERMINAL_METHODS","chainEnd","member","receiver","call","chainEndsInSingleValue","isTerminalRead","isJsxChild","grand","name","isSpreadIntoCall","annotatedBinding","climb","n","typeNode","returningFunctionName","fn","declarator","annotatedFieldName","field","castOf","child","outer","current","exportedTypeName","declaration","statement","isSupabaseGeneratedTypes","names","program","hasOwnTypeAnnotation","rule","WIRE_TYPES_SCHEMA","header","context","comment","options","wireTypes","DEFAULT_WIRE_TYPES","allowArraysInTests","allowReadonlyArrays","allowArrayLiterals","functypeImports","getFunctypeImportsLegacy","isInTestFile","filename","findTypeParameter","findInNode","sourceCode","c","r","isFunctypeConstructorArg","reachesArraySlot","flowsIntoArraySlot","isOnlyHandedToArraySlots","uses","variable","ref","usesOf","owner","binding","mutationOf","identifier","how","mutatedFields","fieldMutationIn","entries","descendants","method","target","feedsMutableSlot","flowsIntoMutableArraySlot","checkMutable","cast","reportNode","castSource","source","decodes","isUntypedExpression","elementType","fullType","fixer","fnName","fieldMutation","reportMutable","suggest","hasFunctypeSymbol","createImportFixer","isInsideWireType","isReadonly","typeName","typeParam","resolvedType","isFunctypeCall","targetParent","end","hasTypeInformation","el","elementTexts"],"sources":["../../src/rules/prefer-list.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\nimport { descendants } from \"../utils/ast-walk\"\nimport { getFunctypeImportsLegacy, isFunctypeCall } from \"../utils/functype-detection\"\nimport { createImportFixer, hasFunctypeSymbol } from \"../utils/import-fixer\"\nimport {\n flowsIntoArraySlot,\n flowsIntoMutableArraySlot,\n hasTypeInformation,\n isUntypedExpression,\n} from \"../utils/type-aware\"\nimport { DEFAULT_WIRE_TYPES, isInsideWireType, WIRE_TYPES_SCHEMA } from \"../utils/wire-types\"\n\n/** AST keys that don't represent syntax children — back-edges and source metadata. */\nconst NON_CHILD_KEYS: ReadonlySet<string> = new Set([\"parent\", \"loc\", \"range\"])\n\n/** AST children of `node`: drops back-edges, flattens array-valued keys, filters non-object leaves. */\nfunction astChildren(node: ASTNode): readonly unknown[] {\n return Object.entries(node)\n .filter(([k]) => !NON_CHILD_KEYS.has(k))\n .flatMap(([, v]) => (Array.isArray(v) ? v : [v]))\n .filter((v) => v !== null && typeof v === \"object\")\n}\n\n/** True iff any ancestor of `node` satisfies `pred`. Pure tail recursion. */\nfunction ancestorSatisfies(node: ASTNode | null | undefined, pred: (n: ASTNode) => boolean): boolean {\n const parent = node?.parent as ASTNode | undefined\n if (!parent) return false\n return pred(parent) || ancestorSatisfies(parent, pred)\n}\n\n/** `parent` is `List.from(arr)` or `List.of(...arr)`. */\nfunction isListFactoryArg(parent: ASTNode | null | undefined): boolean {\n return (\n parent?.type === \"CallExpression\" &&\n parent.callee.type === \"MemberExpression\" &&\n parent.callee.object.type === \"Identifier\" &&\n parent.callee.object.name === \"List\" &&\n [\"from\", \"of\"].includes(parent.callee.property.name)\n )\n}\n\n/**\n * `[…] as const` or `[…] as [string, ...string[]]`: the literal is asserted to a tuple, a fixed shape that\n * `List` can't express (an enum's values, the argument zod's `z.enum` requires).\n */\nfunction isTupleAssertion(parent: ASTNode | null | undefined): boolean {\n const raw = parent?.type === \"TSAsExpression\" ? parent.typeAnnotation : undefined\n const annotation = raw?.type === \"TSTypeOperator\" ? raw.typeAnnotation : raw\n if (annotation?.type === \"TSTupleType\") return true\n return (\n annotation?.type === \"TSTypeReference\" &&\n annotation.typeName?.type === \"Identifier\" &&\n annotation.typeName.name === \"const\"\n )\n}\n\n/** Array methods that change the array in place. */\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 * The expression a literal stands in for once conditionals are looked through: `[x]` in\n * `List(c ? xs : [x])` or `const args = c ? [a] : [\"--fix\", a]` behaves like the whole conditional.\n */\nfunction throughConditionals(node: ASTNode): ASTNode {\n const parent = node.parent as ASTNode | undefined\n if (parent?.type === \"ConditionalExpression\" && parent.test !== node) return throughConditionals(parent)\n if (parent?.type === \"LogicalExpression\") return throughConditionals(parent)\n return node\n}\n\n/**\n * Methods that turn an array into a single value: using a collection only through these makes it a\n * temporary (`lines.join(\"\\n\")`, `[a, b].includes(x)`). Methods that produce another collection\n * (`map`, `filter`, `slice`, `concat`, `reduce`…) are collection work, which is what `List` is for.\n */\nconst TERMINAL_METHODS: ReadonlySet<string> = new Set([\n \"join\",\n \"includes\",\n \"indexOf\",\n \"lastIndexOf\",\n \"some\",\n \"every\",\n \"find\",\n \"findIndex\",\n \"findLast\",\n \"findLastIndex\",\n \"at\",\n])\n\n/**\n * The end of a method chain that starts at `receiver`: `[…].map(f).filter(g)` → the `.filter(g)` call.\n * `receiver` itself when no method is called on it.\n */\nfunction chainEnd(receiver: ASTNode): ASTNode {\n const member = receiver.parent as ASTNode | undefined\n const call = member?.parent as ASTNode | undefined\n if (member?.type !== \"MemberExpression\" || member.object !== receiver) return receiver\n return call?.type === \"CallExpression\" && call.callee === member ? chainEnd(call) : receiver\n}\n\n/**\n * Does the method chain starting at `receiver` end in a single value: `[a, b].filter(Boolean).length`,\n * `[name, email].filter(nonEmpty).join(\"\\n\")`, `[...xs].sort(byRank)[0]`? Then every array in it is a\n * temporary, the same as `lines.join(\"\\n\")`.\n */\nfunction chainEndsInSingleValue(receiver: ASTNode): boolean {\n if (isTerminalRead(receiver)) return true\n const member = receiver.parent as ASTNode | undefined\n const call = member?.parent as ASTNode | undefined\n if (member?.type !== \"MemberExpression\" || member.object !== receiver) return false\n return call?.type === \"CallExpression\" && call.callee === member && chainEndsInSingleValue(call)\n}\n\n/** `{items.map((i) => <Row />)}`: an expression rendered as JSX children, which React takes as an array. */\nfunction isJsxChild(node: ASTNode): boolean {\n return (node.parent as ASTNode | undefined)?.type === \"JSXExpressionContainer\"\n}\n\n/**\n * Is `receiver` read down to a single value on the spot: `.length`, `[i]`, or a terminal method call?\n * The same test applies to a literal (`[a, b].includes(x)`) and to every use of a const (`lines.join`).\n */\nfunction isTerminalRead(receiver: ASTNode): boolean {\n const member = receiver.parent as ASTNode | undefined\n if (member?.type !== \"MemberExpression\" || member.object !== receiver) return false\n const grand = member.parent as ASTNode | undefined\n if (grand?.type === \"AssignmentExpression\" && grand.left === member) return false\n if (member.computed) return true\n const name = member.property?.type === \"Identifier\" ? member.property.name : null\n if (name === \"length\") return true\n return name !== null && TERMINAL_METHODS.has(name) && grand?.type === \"CallExpression\" && grand.callee === member\n}\n\n/**\n * Is `node` spread straight into a call's arguments, `and(...conds)` or `and(...(c ? [x] : []))`?\n * The function receives the elements one by one; the array is never a collection of your own.\n */\nfunction isSpreadIntoCall(node: ASTNode): boolean {\n const parent = node.parent as ASTNode | undefined\n if (!parent) return false\n if (parent.type === \"ConditionalExpression\" && parent.test !== node) return isSpreadIntoCall(parent)\n if (parent.type === \"LogicalExpression\" && parent.right === node) return isSpreadIntoCall(parent)\n return (\n parent.type === \"SpreadElement\" &&\n (parent.parent?.type === \"CallExpression\" || parent.parent?.type === \"NewExpression\")\n )\n}\n\n/** The `x` in `const x: T[] = …` or `(x: T[]) => …`, when the array type is (part of) its annotation. */\nfunction annotatedBinding(typeNode: ASTNode): ASTNode | null {\n const climb = (n: ASTNode | null | undefined): ASTNode | null => {\n if (!n) return null\n if (n.type === \"TSTypeAnnotation\") return n.parent?.type === \"Identifier\" ? (n.parent as ASTNode) : null\n if (n.type === \"TSAsExpression\" || n.type === \"TSSatisfiesExpression\" || n.type.endsWith(\"Statement\")) return null\n return climb(n.parent as ASTNode | undefined)\n }\n return climb(typeNode.parent as ASTNode | undefined)\n}\n\n/**\n * The name of the function whose declared return type *is* this array type: `f` in\n * `function f(): T[]` or `const f = (): T[] => …`. Null for anything nested (`(): { nodes: T[] }`).\n */\nfunction returningFunctionName(typeNode: ASTNode): ASTNode | null {\n const annotation = typeNode.parent as ASTNode | undefined\n const fn = annotation?.type === \"TSTypeAnnotation\" ? (annotation.parent as ASTNode | undefined) : undefined\n if (!fn || fn.returnType !== annotation) return null\n if (fn.type === \"FunctionDeclaration\") return fn.id?.type === \"Identifier\" ? (fn.id as ASTNode) : null\n const declarator = fn.parent as ASTNode | undefined\n return (fn.type === \"ArrowFunctionExpression\" || fn.type === \"FunctionExpression\") &&\n declarator?.type === \"VariableDeclarator\" &&\n declarator.init === fn &&\n declarator.id?.type === \"Identifier\"\n ? (declarator.id as ASTNode)\n : null\n}\n\n/** The property name when the array type annotates a field: `errors` in `{ errors: string[] }` or `class { errors: T[] }`. */\nfunction annotatedFieldName(typeNode: ASTNode): string | null {\n const annotation = typeNode.parent as ASTNode | undefined\n const field = annotation?.type === \"TSTypeAnnotation\" ? (annotation.parent as ASTNode | undefined) : undefined\n if (field?.type !== \"TSPropertySignature\" && field?.type !== \"PropertyDefinition\") return null\n return field.key?.type === \"Identifier\" && !field.computed ? field.key.name : null\n}\n\n/** The outermost `x as … as T[]` around an array type used as a cast target, or null. */\nfunction castOf(typeNode: ASTNode): ASTNode | null {\n const climb = (n: ASTNode | null | undefined, child: ASTNode): ASTNode | null => {\n if (!n || n.type === \"TSTypeAnnotation\" || n.type.endsWith(\"Statement\")) return null\n if (n.type === \"TSAsExpression\" && n.typeAnnotation === child) {\n const outer = (current: ASTNode): ASTNode =>\n current.parent?.type === \"TSAsExpression\" ? outer(current.parent as ASTNode) : current\n return outer(n)\n }\n return climb(n.parent as ASTNode | undefined, n)\n }\n return climb(typeNode.parent as ASTNode | undefined, typeNode)\n}\n\n/** Names a top-level `export type X = …` or `export interface X` declares. */\nfunction exportedTypeName(statement: ASTNode): string | undefined {\n const declaration = statement.type === \"ExportNamedDeclaration\" ? (statement.declaration as ASTNode | null) : null\n if (declaration?.type !== \"TSTypeAliasDeclaration\" && declaration?.type !== \"TSInterfaceDeclaration\") return undefined\n return (declaration.id as ASTNode | undefined)?.name as string | undefined\n}\n\n/**\n * Supabase's generated types (`supabase gen types typescript`) carry no generated-file marker, but\n * always export both `type Json` and `Database` (a type alias, or an interface from older CLIs) at\n * the top level. No hand-written module exports that pair, so the shape identifies the file.\n */\nfunction isSupabaseGeneratedTypes(program: ASTNode): boolean {\n const names = new Set((program.body as ASTNode[]).map(exportedTypeName))\n return names.has(\"Json\") && names.has(\"Database\")\n}\n\n/** `node` is a VariableDeclarator with its own type annotation, or a TSTypeAnnotation node directly. */\nfunction hasOwnTypeAnnotation(node: ASTNode): boolean {\n return (node.type === \"VariableDeclarator\" && Boolean(node.id?.typeAnnotation)) || node.type === \"TSTypeAnnotation\"\n}\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"suggestion\",\n hasSuggestions: true,\n docs: {\n description: \"Prefer List<T> over native arrays for immutable collections\",\n recommended: true,\n },\n schema: [\n {\n type: \"object\",\n properties: {\n allowArraysInTests: {\n type: \"boolean\",\n default: true,\n },\n wireTypes: WIRE_TYPES_SCHEMA,\n allowReadonlyArrays: {\n type: \"boolean\",\n default: true,\n },\n allowArrayLiterals: {\n type: \"boolean\",\n default: false,\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n preferList: \"Prefer List<{{type}}> over array type {{arrayType}}\",\n preferReadonlyOrList:\n \"Mutable array type {{arrayType}}: anything holding it can change it. Use ReadonlyArray<{{type}}>, which every caller and library accepts, or List<{{type}}> for a collection you transform\",\n preferWireCast:\n \"Cast to the mutable array {{arrayType}}: this is data decoded from outside. Declare its shape once as Wire<ReadonlyArray<{{type}}>> (functype's boundary marker) and cast to that\",\n mutatedArray:\n \"{{name}} is a mutable array changed in place (.{{how}}()). Build it without mutation instead: map/filter/flatMap, a List, or a fold\",\n preferListLiteral: \"Prefer List.of(...) or List.from([...]) over array literal\",\n suggestListType: \"Replace with List<{{type}}>\",\n suggestReadonlyArray: \"Replace with ReadonlyArray<{{type}}>\",\n suggestListOf: \"Replace with List.of(...)\",\n suggestAddImport: \"Add {{symbol}} import from functype\",\n },\n },\n\n create(context) {\n // A generated file (`// @generated`, \"Auto-generated … DO NOT EDIT\") isn't edited by hand, so there's\n // nothing for its author to fix. Supabase's types have no marker and are recognized by shape.\n const header = context.sourceCode\n .getAllComments()\n .slice(0, 3)\n .map((comment) => comment.value)\n .join(\"\\n\")\n if (/@generated|auto-generated|do not edit/i.test(header)) return {}\n if (isSupabaseGeneratedTypes(context.sourceCode.ast as unknown as ASTNode)) return {}\n\n const options = context.options[0] || {}\n // Everything inside `Wire<…>` is the declared serialization shape (#325 B).\n const wireTypes: ReadonlyArray<string> = options.wireTypes ?? DEFAULT_WIRE_TYPES\n const allowArraysInTests = options.allowArraysInTests !== false\n const allowReadonlyArrays = options.allowReadonlyArrays !== false\n const allowArrayLiterals = options.allowArrayLiterals === true\n\n // Get functype imports if available (but still apply rule even without explicit import)\n const functypeImports = getFunctypeImportsLegacy(context)\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 findTypeParameter(node: ASTNode, sourceCode: typeof context.sourceCode): string | null {\n // Pure pre-order search: look at this node, then recursively at each\n // child until we find a TSTypeParameterInstantiation with a first param.\n function findInNode(n: ASTNode): string | null {\n if (n.type === \"TSTypeParameterInstantiation\" && n.params && n.params[0]) {\n return sourceCode.getText(n.params[0])\n }\n const results = astChildren(n)\n .filter((c): c is ASTNode => typeof (c as ASTNode)?.type === \"string\")\n .map((child) => findInNode(child))\n return results.find((r) => r !== null) ?? null\n }\n return findInNode(node)\n }\n\n /** `List([...x])`, `Set([a, b])`: the literal is already being captured into a functype value. */\n function isFunctypeConstructorArg(node: ASTNode, parent: ASTNode | null | undefined): boolean {\n return (\n parent?.type === \"CallExpression\" &&\n parent.callee.type === \"Identifier\" &&\n functypeImports.has(parent.callee.name) &&\n parent.arguments.includes(node)\n )\n }\n\n /** Is `node` handed straight to an array-typed slot, directly or spread into a literal that is? */\n function reachesArraySlot(node: ASTNode): boolean {\n if (flowsIntoArraySlot(node, context) === true) return true\n if (isSpreadIntoCall(node)) return true\n const parent = node.parent as ASTNode | undefined\n return (\n parent?.type === \"SpreadElement\" &&\n parent.parent?.type === \"ArrayExpression\" &&\n flowsIntoArraySlot(parent.parent as ASTNode, context) === true\n )\n }\n\n /**\n * `const OPTIONS = [...]` whose every use hands it to an array-typed slot (`<Select data={OPTIONS} />`,\n * `db.insert(t).values(ROWS)`) or reads it down to a single value (`lines.join(\"\\n\")`, `xs.length`): data\n * built to give to a library, or a temporary, declared before it's used. Needs at least one local use; an exported\n * constant with no local use is still reported, because its consumers aren't visible here.\n */\n function isOnlyHandedToArraySlots(declarator: ASTNode | null | undefined): boolean {\n if (declarator?.type !== \"VariableDeclarator\" || declarator.id?.type !== \"Identifier\") return false\n const uses = context.sourceCode\n .getDeclaredVariables(declarator)\n .flatMap((variable) => variable.references.filter((ref) => !ref.init))\n return (\n uses.length > 0 &&\n uses.every((ref) => reachesArraySlot(ref.identifier as ASTNode) || isTerminalRead(ref.identifier as ASTNode))\n )\n }\n\n /** References to `binding` other than its declaration. */\n function usesOf(binding: ASTNode): ReadonlyArray<{ identifier: ASTNode }> {\n // The declaring node: a VariableDeclarator, a FunctionDeclaration (its name lives in the outer\n // scope) or, for a parameter, its function. getDeclaredVariables on it yields the binding.\n const owner = (binding.parent as ASTNode | undefined) ?? binding\n const variable =\n context.sourceCode.getDeclaredVariables(owner).find((v) => v.name === binding.name) ??\n context.sourceCode.getScope(binding).set.get(binding.name)\n return (variable?.references ?? [])\n .filter((ref) => !ref.init && ref.identifier !== binding)\n .map((ref) => ({ identifier: ref.identifier as ASTNode }))\n }\n\n /** The in-place mutation applied to `binding` (`push`, `sort`, `x[i] = …`), if any. */\n function mutationOf(binding: ASTNode): string | null {\n const found = usesOf(binding)\n .map(({ identifier }) => {\n const parent = identifier.parent as ASTNode | undefined\n if (parent?.type !== \"MemberExpression\" || parent.object !== identifier) return null\n const grand = parent.parent as ASTNode | undefined\n if (grand?.type === \"AssignmentExpression\" && grand.left === parent) return \"[index] =\"\n const name = parent.property?.type === \"Identifier\" && !parent.computed ? parent.property.name : null\n return name && MUTATING_METHODS.has(name) && grand?.type === \"CallExpression\" && grand.callee === parent\n ? name\n : null\n })\n .find((how) => how !== null)\n return found ?? null\n }\n\n /**\n * Fields mutated in place anywhere in the file, `errors` → `push` for `t.errors.push(e)`. Built once per\n * file, on first use, from the syntax tree.\n */\n const mutatedFields: { map?: ReadonlyMap<string, string> } = {}\n function fieldMutationIn(field: string): string | null {\n if (!mutatedFields.map) {\n const entries = descendants(context.sourceCode.ast as unknown as ASTNode).flatMap(\n (node): [string, string][] => {\n if (node.type !== \"CallExpression\" || node.callee?.type !== \"MemberExpression\") return []\n const method = node.callee.property?.type === \"Identifier\" ? node.callee.property.name : null\n const target = node.callee.object as ASTNode\n const name =\n target?.type === \"MemberExpression\" && target.property?.type === \"Identifier\" && !target.computed\n ? target.property.name\n : null\n return method && name && MUTATING_METHODS.has(method) ? [[name, method]] : []\n },\n )\n mutatedFields.map = new globalThis.Map(entries.reverse())\n }\n return mutatedFields.map.get(field) ?? null\n }\n\n /** Is `binding` handed to a slot that requires a mutable array (pg `query` values, ReactFlow `nodes`)? */\n function feedsMutableSlot(binding: ASTNode): boolean {\n return usesOf(binding).some(({ identifier }) => flowsIntoMutableArraySlot(identifier, context) === true)\n }\n\n /**\n * Report a mutable array type, unless a library demands it. The order matters: a library slot that\n * requires `T[]` makes the type correct as written; a binding mutated in place can't take\n * `ReadonlyArray` without a rewrite, so it gets advice instead of a suggestion that wouldn't compile;\n * a cast is decoded outside data, so it points at `Wire`.\n */\n function checkMutable(reportNode: ASTNode, elementType: string, fullType: string): void {\n const cast = castOf(reportNode)\n // The value under every `as`: `JSON.parse(raw)` in `JSON.parse(raw) as unknown as T[]`.\n const castSource = (n: ASTNode): ASTNode =>\n n.type === \"TSAsExpression\" ? castSource(n.expression as ASTNode) : n\n if (cast && flowsIntoMutableArraySlot(cast, context) === true) return\n // Only a cast of an untyped value (`JSON.parse`, `res.json()`, a raw row) is decoding outside data,\n // the Wire case. It needs type evidence: without it the rule can't tell decoding from re-casting a\n // typed value, so it gives the plain message rather than advice that flips when types are turned on.\n const source = cast ? castSource(cast) : null\n const decodes =\n source !== null && source.type !== \"ArrayExpression\" && isUntypedExpression(source, context) === true\n if (cast && decodes) {\n context.report({\n node: reportNode,\n messageId: \"preferWireCast\",\n data: { type: elementType, arrayType: fullType },\n suggest: [\n {\n messageId: \"suggestReadonlyArray\",\n data: { type: elementType },\n fix: (fixer: Rule.RuleFixer) => fixer.replaceText(reportNode, `ReadonlyArray<${elementType}>`),\n },\n ],\n })\n return\n }\n // `function allowedTools(): string[]` whose result goes to an SDK option typed `string[]`.\n const fnName = returningFunctionName(reportNode)\n const feedsFromCall =\n fnName !== null &&\n usesOf(fnName).some(({ identifier }) => {\n const call = identifier.parent as ASTNode | undefined\n return (\n call?.type === \"CallExpression\" &&\n call.callee === identifier &&\n flowsIntoMutableArraySlot(call, context) === true\n )\n })\n if (feedsFromCall) return\n // A field mutated somewhere in the file (`result.errors.push(e)`, `this.events.push(e)`): a\n // ReadonlyArray suggestion wouldn't compile, so give the mutation advice. Matched by name, which only\n // picks the message, never whether to report.\n const field = annotatedFieldName(reportNode)\n const fieldMutation = field === null ? null : fieldMutationIn(field)\n if (field !== null && fieldMutation !== null) {\n context.report({ node: reportNode, messageId: \"mutatedArray\", data: { name: field, how: fieldMutation } })\n return\n }\n const binding = annotatedBinding(reportNode)\n if (binding) {\n if (feedsMutableSlot(binding)) return\n const how = mutationOf(binding)\n if (how) {\n context.report({ node: reportNode, messageId: \"mutatedArray\", data: { name: binding.name, how } })\n return\n }\n }\n reportMutable(reportNode, elementType, fullType)\n }\n\n /**\n * A mutable `T[]` / `Array<T>` is the real defect: anything holding it can push, sort or splice.\n * `ReadonlyArray<T>` fixes that and still fits wherever a library expects an array, so it's offered\n * first; `List<T>` is for collections that live inside your own code.\n */\n function reportMutable(reportNode: ASTNode, elementType: string, fullType: string): void {\n const sourceCode = context.sourceCode\n const suggest: Rule.SuggestionReportDescriptor[] = [\n {\n messageId: \"suggestReadonlyArray\",\n data: { type: elementType },\n fix: (fixer: Rule.RuleFixer) => fixer.replaceText(reportNode, `ReadonlyArray<${elementType}>`),\n },\n {\n messageId: \"suggestListType\",\n data: { type: elementType },\n fix: (fixer: Rule.RuleFixer) => fixer.replaceText(reportNode, `List<${elementType}>`),\n },\n ]\n if (!hasFunctypeSymbol(sourceCode, \"List\")) {\n suggest.push({\n messageId: \"suggestAddImport\",\n data: { symbol: \"List\" },\n fix: createImportFixer(sourceCode, \"List\"),\n })\n }\n context.report({\n node: reportNode,\n messageId: \"preferReadonlyOrList\",\n data: { type: elementType, arrayType: fullType },\n suggest,\n })\n }\n\n return {\n TSArrayType(node: ASTNode) {\n if (isInsideWireType(node, wireTypes)) return\n if (allowArraysInTests && isInTestFile()) return\n\n // `readonly T[]` parses as TSTypeOperator(operator: \"readonly\") wrapping TSArrayType.\n // When the parent is that readonly wrapper, we treat the whole `readonly T[]` as\n // the reported unit — both for gating (parity with the ReadonlyArray<T> branch\n // below) and for the suggestion's replacement range. Replacing only the inner\n // TSArrayType would leave `readonly List<T>` behind, which is invalid TS\n // (TS1354: `readonly` only applies to array/tuple types).\n const parent = node.parent as ASTNode | undefined\n // `[string, ...string[]]`: a tuple's rest element must be written as an array type, and libraries\n // such as zod's `z.enum` require exactly that shape. The tuple is the type; its rest isn't a list.\n if (parent?.type === \"TSRestType\") return\n // `(...args: string[])`: a rest parameter is a fresh array on every call, owned by the callee.\n if (parent?.type === \"TSTypeAnnotation\" && parent.parent?.type === \"RestElement\") return\n\n const isReadonly =\n parent?.type === \"TSTypeOperator\" && (parent as { operator?: string }).operator === \"readonly\"\n\n if (isReadonly && allowReadonlyArrays) return\n\n const sourceCode = context.sourceCode\n const elementType = sourceCode.getText(node.elementType)\n const reportNode = isReadonly ? (parent as ASTNode) : node\n const fullType = sourceCode.getText(reportNode)\n\n if (!isReadonly) {\n checkMutable(reportNode, elementType, fullType)\n return\n }\n\n const suggest: Rule.SuggestionReportDescriptor[] = [\n {\n messageId: \"suggestListType\",\n data: { type: elementType },\n fix(fixer: Rule.RuleFixer) {\n return fixer.replaceText(reportNode, `List<${elementType}>`)\n },\n },\n ]\n\n if (!hasFunctypeSymbol(sourceCode, \"List\")) {\n suggest.push({\n messageId: \"suggestAddImport\",\n data: { symbol: \"List\" },\n fix: createImportFixer(sourceCode, \"List\"),\n })\n }\n\n context.report({\n node: reportNode,\n messageId: \"preferList\",\n data: {\n type: elementType,\n arrayType: fullType,\n },\n suggest,\n })\n },\n\n TSTypeReference(node: ASTNode) {\n if (isInsideWireType(node, wireTypes)) return\n if (allowArraysInTests && isInTestFile()) return\n\n const sourceCode = context.sourceCode\n\n // Get type name - handle both simple identifiers and member expressions\n if (!node.typeName) return // No type name found\n\n const typeName = node.typeName.type === \"Identifier\" ? node.typeName.name : sourceCode.getText(node.typeName)\n\n // Handle Array<T> syntax: mutable, same as T[]\n if (typeName === \"Array\") {\n const typeParam = findTypeParameter(node, sourceCode)\n checkMutable(node, typeParam || \"T\", sourceCode.getText(node))\n return\n }\n\n // Handle ReadonlyArray<T> — gated on allowReadonlyArrays (parity with `readonly T[]`).\n if (typeName === \"ReadonlyArray\") {\n if (allowReadonlyArrays) return\n\n const typeParam = findTypeParameter(node, sourceCode)\n const fullType = sourceCode.getText(node)\n const resolvedType = typeParam || \"T\"\n\n const suggest: Rule.SuggestionReportDescriptor[] = [\n {\n messageId: \"suggestListType\",\n data: { type: resolvedType },\n fix(fixer: Rule.RuleFixer) {\n return fixer.replaceText(node, `List<${resolvedType}>`)\n },\n },\n ]\n\n if (!hasFunctypeSymbol(sourceCode, \"List\")) {\n suggest.push({\n messageId: \"suggestAddImport\",\n data: { symbol: \"List\" },\n fix: createImportFixer(sourceCode, \"List\"),\n })\n }\n\n context.report({\n node,\n messageId: \"preferList\",\n data: {\n type: resolvedType,\n arrayType: fullType,\n },\n suggest,\n })\n }\n },\n\n ArrayExpression(node: ASTNode) {\n if (allowArraysInTests && isInTestFile()) return\n if (allowArrayLiterals) return\n\n // Only flag non-empty arrays to avoid noise\n if (node.elements.length === 0) return\n\n const parent = node.parent\n\n // Don't flag arrays that are already arguments to functype calls.\n if (parent && isFunctypeCall(parent, functypeImports)) return\n\n // Don't flag arrays that are arguments to List.from / List.of.\n if (isListFactoryArg(parent)) return\n\n // Don't flag nested array literals — let the outermost one handle it.\n if (ancestorSatisfies(node, (n) => n.type === \"ArrayExpression\")) return\n\n // Don't flag array literals that already live in a type-annotated\n // context (those are handled by the type-checking rules).\n if (ancestorSatisfies(node, hasOwnTypeAnnotation)) return\n\n // Look through `c ? xs : [x]` / `xs ?? [x]`: the checks below apply to the whole expression.\n const target = throughConditionals(node)\n const targetParent = target.parent as ASTNode | undefined\n\n // A literal asserted to a tuple (`as const`, `as [string, ...string[]]`) is a fixed shape.\n if (isTupleAssertion(parent)) return\n\n // With type information: a literal passed where an array is expected — drizzle's\n // `.values([...])`, an index definition, a schema `target: [...]` — is handed straight to code\n // that requires an array. It never becomes a collection in your own code, so it's the\n // boundary itself and `List` can't go there.\n if (flowsIntoArraySlot(node, context) === true || flowsIntoArraySlot(target, context) === true) return\n if (isFunctypeConstructorArg(target, targetParent)) return\n // Read down to one value on the spot (`[a, b].includes(x)`, `[a, b].filter(Boolean).join(\" \")`):\n // nothing is stored.\n if (chainEndsInSingleValue(node) || chainEndsInSingleValue(target)) return\n // A chain whose result goes to React or a library (`{[\"PDF\", \"DOCX\"].map((f) => <Chip />)}`,\n // `marks={[3, 4].map(…)}`): the transformed array is what's handed over, so the literal is too.\n const end = chainEnd(target)\n if (end !== target && (isJsxChild(end) || flowsIntoArraySlot(end, context) === true)) return\n // Spread into a call (`and(...(c ? [x] : []))`): the function gets the elements one by one.\n if (isSpreadIntoCall(node)) return\n // `const acc = [...]; acc.push(x)`: an accumulator. The defect is the mutation, so it gets the same\n // advice as a mutated `T[]` binding, not a List.of suggestion that has no push.\n if (targetParent?.type === \"VariableDeclarator\" && targetParent.id?.type === \"Identifier\") {\n const how = mutationOf(targetParent.id as ASTNode)\n if (how) {\n context.report({ node, messageId: \"mutatedArray\", data: { name: targetParent.id.name, how } })\n return\n }\n }\n // Without type information the rule can't tell a literal handed to a library (drizzle\n // `.values([...])`) from a collection of your own, so it reports neither rather than guess.\n if (!hasTypeInformation(context)) return\n if (isOnlyHandedToArraySlots(targetParent)) return\n\n // Check if any element is a SpreadElement — ambiguous semantics, skip suggestions\n const hasSpread = node.elements.some((el) => el !== null && el.type === \"SpreadElement\")\n\n if (hasSpread) {\n context.report({\n node,\n messageId: \"preferListLiteral\",\n })\n return\n }\n\n const sourceCode = context.sourceCode\n const elementTexts = node.elements.filter((el) => el !== null).map((el) => sourceCode.getText(el))\n\n const suggest: Rule.SuggestionReportDescriptor[] = [\n {\n messageId: \"suggestListOf\",\n fix(fixer: Rule.RuleFixer) {\n return fixer.replaceText(node, `List.of(${elementTexts.join(\", \")})`)\n },\n },\n ]\n\n if (!hasFunctypeSymbol(sourceCode, \"List\")) {\n suggest.push({\n messageId: \"suggestAddImport\",\n data: { symbol: \"List\" },\n fix: createImportFixer(sourceCode, \"List\"),\n })\n }\n\n context.report({\n node,\n messageId: \"preferListLiteral\",\n suggest,\n })\n },\n }\n },\n}\n\nexport default rule\n"],"mappings":"0dAeA,MAAMA,kBAAsC,IAAI,IAAI,CAAC,SAAU,MAAO,OAAO,CAAC,EAG9E,SAASC,EAAY,EAAmC,CACtD,OAAO,OAAO,QAAQC,CAAI,CAAC,CACxB,QAAQ,CAACC,KAAO,CAACH,EAAe,IAAIG,CAAC,CAAC,CAAC,CACvC,SAAS,EAAGC,KAAQ,MAAM,QAAQA,CAAC,EAAIA,EAAI,CAACA,CAAC,CAAE,CAAC,CAChD,OAAQ,GAAoB,OAAOA,GAAM,YAA3BA,CAAmC,CACtD,C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S,sBAAwBA,EAAa,IAAI,OAAS,aAAc,CACzF,IAAM/B,EAAMF,EAAWiC,EAAa,EAAa,EACjD,GAAI/B,EAAK,CACP7B,EAAQ,OAAO,CAAE,OAAM,UAAW,eAAgB,KAAM,CAAE,KAAM4D,EAAa,GAAG,KAAM,KAAI,CAAE,CAAC,EAC7F,MACF,CACF,CAIA,GADI,CAACE,EAAmB9D,CAAO,GAC3BoB,EAAyBwC,CAAY,EAAG,OAK5C,GAFkB1G,EAAK,SAAS,KAAM,GAAO6G,IAAO,MAAQA,EAAG,OAAS,eAE5D,EAAG,CACb/D,EAAQ,OAAO,CACb,OACA,UAAW,mBACb,CAAC,EACD,MACF,CAEA,IAAMc,EAAad,EAAQ,WACrBgE,EAAe9G,EAAK,SAAS,OAAQ,GAAO6G,IAAO,IAAI,CAAC,CAAC,IAAK,GAAOjD,EAAW,QAAQiD,CAAE,CAAC,EAE3FZ,EAA6C,CACjD,CACE,UAAW,gBACX,IAAI,EAAuB,CACzB,OAAOJ,EAAM,YAAY7F,EAAM,WAAW8G,EAAa,KAAK,IAAI,EAAE,EAAE,CACtE,CACF,CACF,EAEKZ,EAAkBtC,EAAY,MAAM,GACvCqC,EAAQ,KAAK,CACX,UAAW,mBACX,KAAM,CAAE,OAAQ,MAAO,EACvB,IAAKE,EAAkBvC,EAAY,MAAM,CAC3C,CAAC,EAGHd,EAAQ,OAAO,CACb,OACA,UAAW,oBACX,SACF,CAAC,CACH,CACF,CACF,CACF"}
|
|
@@ -10,6 +10,15 @@ import { Rule } from "eslint";
|
|
|
10
10
|
* `undefined` when type information isn't available, so the caller can fall back.
|
|
11
11
|
*/
|
|
12
12
|
export declare const isExtractableByType: (node: ASTNode, context: Rule.RuleContext) => boolean | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Is `node`'s type a functype `IO`? Structural: the type has both `runExit` and `provideLayer`, which
|
|
15
|
+
* only `IO` carries — `Task`, `Lazy` and the other containers have neither — and has carried since
|
|
16
|
+
* well before 1.9, so older functype versions are recognized too. A union of IOs counts.
|
|
17
|
+
* `any` and `unknown` have no properties, so they don't.
|
|
18
|
+
*
|
|
19
|
+
* `undefined` when type information isn't available.
|
|
20
|
+
*/
|
|
21
|
+
export declare const isIOByType: (node: ASTNode, context: Rule.RuleContext) => boolean | undefined;
|
|
13
22
|
/**
|
|
14
23
|
* Does `node` (an expression) flow into a slot that is typed as an array, a tuple or `any`/`unknown`?
|
|
15
24
|
* That's the expected type TypeScript checks it against: the parameter it is passed to, the property
|
package/dist/utils/type-aware.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=/* @__PURE__ */ new Set([`Iterable`,`AsyncIterable`,`IterableIterator`,`ArrayLike`]),t=e=>{let t=e.sourceCode.parserServices;return t?.program&&t.esTreeNodeToTSNodeMap?t:void 0},n=(e,n)=>{let r=t(n);if(!r)return;let i=r.esTreeNodeToTSNodeMap.get(e);if(!i)return;let a=r.program.getTypeChecker(),o=a.getNonNullableType(a.getTypeAtLocation(i));return a.getPropertyOfType(o,`orThrow`)!==void 0&&a.getPropertyOfType(o,`fold`)!==void 0},r=e=>e.isTypeParameter?.()===!0,
|
|
1
|
+
const e=/* @__PURE__ */ new Set([`Iterable`,`AsyncIterable`,`IterableIterator`,`ArrayLike`]),t=e=>{let t=e.sourceCode.parserServices;return t?.program&&t.esTreeNodeToTSNodeMap?t:void 0},n=(e,n)=>{let r=t(n);if(!r)return;let i=r.esTreeNodeToTSNodeMap.get(e);if(!i)return;let a=r.program.getTypeChecker(),o=a.getNonNullableType(a.getTypeAtLocation(i));return a.getPropertyOfType(o,`orThrow`)!==void 0&&a.getPropertyOfType(o,`fold`)!==void 0},r=(e,n)=>{let r=t(n);if(!r)return;let i=r.esTreeNodeToTSNodeMap.get(e);if(!i)return;let a=r.program.getTypeChecker(),o=a.getNonNullableType(a.getTypeAtLocation(i));return a.getPropertyOfType(o,`runExit`)!==void 0&&a.getPropertyOfType(o,`provideLayer`)!==void 0},i=e=>e.isTypeParameter?.()===!0,a=e=>{let t=e.parent;if(!t)return null;if((t.type===`CallExpression`||t.type===`NewExpression`)&&t.callee!==e){let n=t.arguments.indexOf(e);return n<0?null:{call:t,argument:e,index:n}}return t.type===`TSAsExpression`||t.type===`TSSatisfiesExpression`||t.type===`ConditionalExpression`&&t.test!==e||t.type===`LogicalExpression`||t.type===`Property`||t.type===`ObjectExpression`||t.type===`ArrayExpression`||t.type===`SpreadElement`?a(t):null},o=(e,t,n)=>{let r=a(n),o=r?t.esTreeNodeToTSNodeMap.get(r.call):void 0,s=o?e.getResolvedSignature(o)?.getDeclaration()?.parameters:void 0;if(!r||!s||s.length===0)return!1;let c=s[Math.min(r.index,s.length-1)];if(c?.type===void 0)return!1;let l=e.getTypeAtLocation(c.type);return(l.types??[l]).some(i)},s=(e,t,n)=>{let r=a(n),i=r?t.esTreeNodeToTSNodeMap.get(r.call):void 0,o=i?e.getResolvedSignature(i):void 0,s=r?t.esTreeNodeToTSNodeMap.get(r.argument):void 0;if(!o||!s)return!1;let c=e.getTypeAtLocation(s),l=t=>t===c||e.isTypeAssignableTo(c,t)&&e.isTypeAssignableTo(t,c),u=(t,n)=>{if(n>3)return!1;if(l(t))return!0;let{types:r,target:i}=t;if(r)return r.some(e=>u(e,n+1));if(i!==void 0&&(e.isTupleType(t)||e.isArrayLikeType(t)))return e.getTypeArguments(t).some(e=>u(e,n+1));let a=e.getAwaitedType(t);return a!==void 0&&a!==t&&u(a,n+1)};return u(e.getReturnTypeOfSignature(o),0)},c=(e,t,n)=>u(n.type)||i(n.type)&&!s(e,t,n.at),l=(t,n,r)=>{if(c(t,n,r))return!0;let{types:a,symbol:o}=r.type;return a?a.some(e=>l(t,n,{type:e,at:r.at})):o?.name!==void 0&&e.has(o.name)?!0:!i(r.type)&&t.isArrayLikeType(r.type)},u=e=>{let{flags:t}=e;return t!==void 0&&!!(t&3)},d=(e,t)=>{let{types:n,symbol:r}=t;return n?n.some(t=>d(e,t)):r?.name===`Array`&&e.isArrayLikeType(t)},f=e=>e.computed?null:e.key?.type===`Identifier`?e.key.name:e.key?.type===`Literal`&&typeof e.key.value==`string`?e.key.value:null,p=(e,t,n,r,i=0)=>{if(i>4)return;let a=t.esTreeNodeToTSNodeMap.get(n),o=a?e.getContextualType(a):void 0;if(o!==void 0)return{type:o,at:n};let s=n.parent;if(s?.type===`ArrowFunctionExpression`&&s.body===n){let n=s.parent;if(n?.type===`VariableDeclarator`&&n.init===s&&n.id?.type===`Identifier`)return(r.sourceCode.getDeclaredVariables(n)[0]?.references??[]).map(e=>e.identifier.parent).filter(e=>e?.type===`CallExpression`).map(n=>p(e,t,n,r,i+1)).find(e=>e!==void 0)}if((s?.type===`CallExpression`||s?.type===`NewExpression`)&&s.callee!==n){let r=s.arguments.indexOf(n),i=t.esTreeNodeToTSNodeMap.get(s),a=r>=0&&i?e.getResolvedSignature(i)?.parameters[r]:void 0;return a===void 0?void 0:{type:e.getTypeOfSymbolAtLocation(a,i),at:n}}let l=s?.type===`Property`&&s.value===n?s.parent:void 0;if(l?.type!==`ObjectExpression`)return;let u=p(e,t,l,r,i+1);if(u===void 0||c(e,t,u))return u;let d=u.type,m=f(s);if(m===null){let r=s.key,i=r?t.esTreeNodeToTSNodeMap.get(r):void 0,o=i?e.getTypeAtLocation(i):void 0,c=o?.value??o?.types?.[0]?.value,l=typeof c==`string`?e.getPropertyOfType(d,c):void 0,u=l===void 0?e.getIndexInfoOfType(d,0)?.type:e.getTypeOfSymbolAtLocation(l,a);return u===void 0?void 0:{type:u,at:n}}let h=e.getPropertyOfType(d,m);return h===void 0?void 0:{type:e.getTypeOfSymbolAtLocation(h,a),at:n}},m=(e,n)=>{let r=t(n);if(!r)return;let i=r.program.getTypeChecker(),a=p(i,r,e,n);if(a!==void 0)return o(i,r,a.at)?!s(i,r,a.at):l(i,r,a)},h=(e,n)=>{let r=t(n);if(!r)return;let i=r.program.getTypeChecker(),a=p(i,r,e,n);return a===void 0||o(i,r,a.at)?!1:d(i,a.type)},g=(e,n)=>{let r=t(n);if(!r)return;let i=r.esTreeNodeToTSNodeMap.get(e);if(!i)return;let a=r.program.getTypeChecker(),o=a.getTypeAtLocation(i);if(u(o))return!0;if(!a.isArrayLikeType(o))return!1;let s=a.getTypeArguments(o)[0];return s!==void 0&&u(s)},_=e=>t(e)!==void 0;export{m as flowsIntoArraySlot,h as flowsIntoMutableArraySlot,_ as hasTypeInformation,n as isExtractableByType,r as isIOByType,g as isUntypedExpression};
|
|
2
2
|
//# sourceMappingURL=type-aware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-aware.js","names":["CONSUMED_COLLECTION_TYPES","typedServices","services","context","isExtractableByType","tsNode","node","checker","type","isTypeParameter","enclosingCall","parent","at","index","isGenericParameterArgument","found","callTs","parameters","declared","annotated","handsArgumentBack","signature","argTs","argType","sameAsArgument","candidate","search","depth","types","member","target","element","awaited","isOpaqueSink","isUntyped","slot","isArrayLikeOrUntyped","symbol","flags","isMutableArrayType","propertyKey","property","expectedSlot","own","declarator","ref","call","parameter","objectLiteral","outerSlot","outer","key","keyNode","keyTs","keyType","literal","named","flowsIntoArraySlot","flowsIntoMutableArraySlot","isUntypedExpression","hasTypeInformation"],"sources":["../../src/utils/type-aware.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\n\n/**\n * Type-aware helpers that work only when the consumer turns on type-aware linting\n * (`parserOptions.projectService` or `project`). Without it they report \"unknown\", and a rule\n * falls back to its syntactic heuristic.\n *\n * The checker is reached through `parserServices` and typed structurally here, so the plugin\n * takes no runtime dependency on `typescript`.\n */\n\ntype TypeLike = object\n\ntype CheckerLike = {\n getTypeAtLocation(node: unknown): TypeLike\n getNonNullableType(type: TypeLike): TypeLike\n getPropertyOfType(type: TypeLike, name: string): unknown\n getContextualType(node: unknown): TypeLike | undefined\n isArrayLikeType(type: TypeLike): boolean\n getTypeOfSymbolAtLocation(symbol: unknown, node: unknown): TypeLike\n getTypeArguments(type: TypeLike): ReadonlyArray<TypeLike>\n getResolvedSignature(node: unknown): SignatureLike | undefined\n getIndexInfoOfType(type: TypeLike, kind: number): { readonly type: TypeLike } | undefined\n getReturnTypeOfSignature(signature: unknown): TypeLike\n getAwaitedType(type: TypeLike): TypeLike | undefined\n isTupleType(type: TypeLike): boolean\n isTypeAssignableTo(source: TypeLike, target: TypeLike): boolean\n}\n\ntype SignatureLike = {\n readonly parameters: ReadonlyArray<unknown>\n getDeclaration(): { readonly parameters?: ReadonlyArray<unknown> } | undefined\n}\n\n/** `ts.TypeFlags.Any` / `Unknown`, inlined so the plugin needs no runtime `typescript` import. */\nconst ANY_OR_UNKNOWN_FLAGS = 1 | 2\n\n/** Interfaces a consumer reads through rather than keeps: `importKey(…, usages: Iterable<KeyUsage>)`, `new Set(values)`. */\nconst CONSUMED_COLLECTION_TYPES: ReadonlySet<string> = new Set([\n \"Iterable\",\n \"AsyncIterable\",\n \"IterableIterator\",\n \"ArrayLike\",\n])\n\ntype TypedServices = {\n readonly program: { getTypeChecker(): CheckerLike }\n readonly esTreeNodeToTSNodeMap: { get(node: unknown): unknown }\n}\n\nconst typedServices = (context: Rule.RuleContext): TypedServices | undefined => {\n const services = context.sourceCode.parserServices as Partial<TypedServices> | undefined\n return services?.program && services.esTreeNodeToTSNodeMap ? (services as TypedServices) : undefined\n}\n\n/**\n * Is `node`'s type a functype extractable container (Option, Either, Try, Lazy, …)? Structural:\n * the type, after stripping `null` / `undefined`, has both `orThrow` and `fold` — true of every\n * functype container, including union types like `Either` (each member has both). Native\n * collections (`Map#get`) and arbitrary objects don't.\n *\n * `undefined` when type information isn't available, so the caller can fall back.\n */\nexport const isExtractableByType = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const tsNode = services.esTreeNodeToTSNodeMap.get(node)\n if (!tsNode) return undefined\n const checker = services.program.getTypeChecker()\n const type = checker.getNonNullableType(checker.getTypeAtLocation(tsNode))\n return (\n checker.getPropertyOfType(type, \"orThrow\") !== undefined && checker.getPropertyOfType(type, \"fold\") !== undefined\n )\n}\n\n/** A slot's expected type and the expression TypeScript computed it for. */\ntype Slot = { readonly type: TypeLike; readonly at: ASTNode }\n\n/**\n * Uses the `Type` object's own predicate rather than a `TypeFlags` bit: TypeScript renumbers its flags\n * between majors (TypeParameter is `1 << 19` in TS 6, `1 << 18` before), and the plugin has no runtime\n * `typescript` import to read them from.\n */\nconst isTypeParameter = (type: TypeLike): boolean =>\n (type as { isTypeParameter?: () => boolean }).isTypeParameter?.() === true\n\n/**\n * `f(…, arg, …)` where `at` is `arg` or sits inside it (an object property, an array element, a spread,\n * a conditional branch, an `as`): the call, the whole argument, and its index.\n */\nconst enclosingCall = (\n at: ASTNode,\n): { readonly call: ASTNode; readonly argument: ASTNode; readonly index: number } | null => {\n const parent = at.parent as ASTNode | undefined\n if (!parent) return null\n if ((parent.type === \"CallExpression\" || parent.type === \"NewExpression\") && parent.callee !== at) {\n const index = (parent.arguments as ReadonlyArray<ASTNode>).indexOf(at)\n return index < 0 ? null : { call: parent, argument: at, index }\n }\n const passesThrough =\n parent.type === \"TSAsExpression\" ||\n parent.type === \"TSSatisfiesExpression\" ||\n (parent.type === \"ConditionalExpression\" && parent.test !== at) ||\n parent.type === \"LogicalExpression\" ||\n parent.type === \"Property\" ||\n parent.type === \"ObjectExpression\" ||\n parent.type === \"ArrayExpression\" ||\n parent.type === \"SpreadElement\"\n return passesThrough ? enclosingCall(parent) : null\n}\n\n/**\n * Is the parameter that `at` is passed to (directly or nested) declared as a type parameter, or a union\n * containing one — `json<T>(data: T)`, `useState<S>(init: S | (() => S))`? Then TypeScript's expected type for `at` is only an echo of what it inferred from\n * `at` itself (`[1, 2]` → `number[]`), not a shape the library demands.\n */\nconst isGenericParameterArgument = (checker: CheckerLike, services: TypedServices, at: ASTNode): boolean => {\n const found = enclosingCall(at)\n const callTs = found ? services.esTreeNodeToTSNodeMap.get(found.call) : undefined\n const parameters = callTs ? checker.getResolvedSignature(callTs)?.getDeclaration()?.parameters : undefined\n if (!found || !parameters || parameters.length === 0) return false\n const declared = parameters[Math.min(found.index, parameters.length - 1)] as { readonly type?: unknown } | undefined\n // The parameter's type annotation node (`T` in `value: T`); asking for the declaration node's type gives `any`.\n if (declared?.type === undefined) return false\n const annotated = checker.getTypeAtLocation(declared.type)\n // React's `useState<S>(init: S | (() => S))`: a union that contains the type parameter is generic too.\n const members = (annotated as { types?: ReadonlyArray<TypeLike> }).types ?? [annotated]\n return members.some(isTypeParameter)\n}\n\n/**\n * Does the generic call around `at` hand the argument straight back to the caller — `useState(init)`\n * returning `[init, set]`, `identity(x)`, a `Promise` of it? Then the shape stays the caller's, and a\n * type parameter isn't a sink. Looks only at the return type itself, union / intersection members,\n * tuple and array elements, and an awaited Promise, not object properties: Hono's `c.json<T>` returns a\n * `Response` that carries a *parsed* copy of `T` for its RPC client, which the caller doesn't get back.\n */\nconst handsArgumentBack = (checker: CheckerLike, services: TypedServices, at: ASTNode): boolean => {\n const found = enclosingCall(at)\n const callTs = found ? services.esTreeNodeToTSNodeMap.get(found.call) : undefined\n const signature = callTs ? checker.getResolvedSignature(callTs) : undefined\n const argTs = found ? services.esTreeNodeToTSNodeMap.get(found.argument) : undefined\n if (!signature || !argTs) return false\n const argType = checker.getTypeAtLocation(argTs)\n const sameAsArgument = (candidate: TypeLike): boolean =>\n candidate === argType ||\n (checker.isTypeAssignableTo(argType, candidate) && checker.isTypeAssignableTo(candidate, argType))\n const search = (type: TypeLike, depth: number): boolean => {\n if (depth > 3) return false\n if (sameAsArgument(type)) return true\n const { types, target } = type as { types?: ReadonlyArray<TypeLike>; target?: unknown }\n if (types) return types.some((member) => search(member, depth + 1))\n if (target !== undefined && (checker.isTupleType(type) || checker.isArrayLikeType(type))) {\n return checker.getTypeArguments(type).some((element) => search(element, depth + 1))\n }\n const awaited = checker.getAwaitedType(type)\n return awaited !== undefined && awaited !== type && search(awaited, depth + 1)\n }\n return search(checker.getReturnTypeOfSignature(signature), 0)\n}\n\n/**\n * Untyped, or a type parameter of a call that doesn't hand the argument back: an object handed to\n * `c.json<T>(data: T)` or `JSON.stringify` goes to a sink. `useState<T>(init: T)` is not one.\n */\nconst isOpaqueSink = (checker: CheckerLike, services: TypedServices, slot: Slot): boolean =>\n isUntyped(slot.type) || (isTypeParameter(slot.type) && !handsArgumentBack(checker, services, slot.at))\n\nconst isArrayLikeOrUntyped = (checker: CheckerLike, services: TypedServices, slot: Slot): boolean => {\n if (isOpaqueSink(checker, services, slot)) return true\n const { types, symbol } = slot.type as { types?: ReadonlyArray<TypeLike>; symbol?: { name?: string } }\n if (types) return types.some((member) => isArrayLikeOrUntyped(checker, services, { type: member, at: slot.at }))\n if (symbol?.name !== undefined && CONSUMED_COLLECTION_TYPES.has(symbol.name)) return true\n return !isTypeParameter(slot.type) && checker.isArrayLikeType(slot.type)\n}\n\nconst isUntyped = (type: TypeLike): boolean => {\n const { flags } = type as { flags?: number }\n return flags !== undefined && (flags & ANY_OR_UNKNOWN_FLAGS) !== 0\n}\n\n/** The mutable `Array` type, as opposed to `ReadonlyArray`: the one a `ReadonlyArray` can't be passed to. */\nconst isMutableArrayType = (checker: CheckerLike, type: TypeLike): boolean => {\n const { types, symbol } = type as { types?: ReadonlyArray<TypeLike>; symbol?: { name?: string } }\n if (types) return types.some((member) => isMutableArrayType(checker, member))\n return symbol?.name === \"Array\" && checker.isArrayLikeType(type)\n}\n\n/** The name a property is written under: `params` in `{ params }`, `parts` in `{ parts: … }` or `{ \"parts\": … }`. */\nconst propertyKey = (property: ASTNode): string | null => {\n if (property.computed) return null\n if (property.key?.type === \"Identifier\") return property.key.name\n return property.key?.type === \"Literal\" && typeof property.key.value === \"string\" ? property.key.value : null\n}\n\n/**\n * The expected type of `node`, looking through object literals when TypeScript gives the value none of\n * its own. Two cases: a shorthand `{ params }` passed to a function, where the expected type is that\n * property's type on the parameter; and `[…]` in `JSON.stringify({ parts: [...] })`, where the object is\n * passed to an `any` parameter, so the whole object is going to an untyped host.\n */\nconst expectedSlot = (\n checker: CheckerLike,\n services: TypedServices,\n node: ASTNode,\n context: Rule.RuleContext,\n depth = 0,\n): Slot | undefined => {\n if (depth > 4) return undefined\n const tsNode = services.esTreeNodeToTSNodeMap.get(node)\n const own = tsNode ? checker.getContextualType(tsNode) : undefined\n if (own !== undefined) return { type: own, at: node }\n const parent = node.parent as ASTNode | undefined\n // `const metadata = (url) => ({ … })` with no declared return type: the object goes wherever the\n // calls' results go (`c.json(metadata(url))`), so take the expected type at the first call site.\n if (parent?.type === \"ArrowFunctionExpression\" && parent.body === node) {\n const declarator = parent.parent as ASTNode | undefined\n if (\n declarator?.type === \"VariableDeclarator\" &&\n declarator.init === parent &&\n declarator.id?.type === \"Identifier\"\n ) {\n const variable = context.sourceCode.getDeclaredVariables(declarator)[0]\n const calls = (variable?.references ?? [])\n .map((ref) => (ref.identifier as unknown as ASTNode).parent as ASTNode | undefined)\n .filter((call): call is ASTNode => call?.type === \"CallExpression\")\n return calls\n .map((call) => expectedSlot(checker, services, call, context, depth + 1))\n .find((slot) => slot !== undefined)\n }\n }\n // An argument to an overloaded function (`crypto.subtle.importKey(…, [\"decrypt\"])`) gets no contextual\n // type; the parameter of the overload TypeScript picked is the expected type.\n if ((parent?.type === \"CallExpression\" || parent?.type === \"NewExpression\") && parent.callee !== node) {\n const index = (parent.arguments as ReadonlyArray<ASTNode>).indexOf(node)\n const call = services.esTreeNodeToTSNodeMap.get(parent)\n const parameter = index >= 0 && call ? checker.getResolvedSignature(call)?.parameters[index] : undefined\n return parameter === undefined ? undefined : { type: checker.getTypeOfSymbolAtLocation(parameter, call), at: node }\n }\n const objectLiteral = parent?.type === \"Property\" && parent.value === node ? (parent.parent as ASTNode) : undefined\n if (objectLiteral?.type !== \"ObjectExpression\") return undefined\n const outerSlot = expectedSlot(checker, services, objectLiteral, context, depth + 1)\n if (outerSlot === undefined || isOpaqueSink(checker, services, outerSlot)) return outerSlot\n const outer = outerSlot.type\n const key = propertyKey(parent as ASTNode)\n // `{ [k]: [...] }` (a reduce accumulator keyed by category): the property named by the key's literal\n // type, else the string index signature's type.\n if (key === null) {\n const keyNode = (parent as ASTNode).key\n const keyTs = keyNode ? services.esTreeNodeToTSNodeMap.get(keyNode) : undefined\n const keyType = keyTs\n ? (checker.getTypeAtLocation(keyTs) as { value?: unknown; types?: ReadonlyArray<{ value?: unknown }> })\n : undefined\n const literal = keyType?.value ?? keyType?.types?.[0]?.value\n const named = typeof literal === \"string\" ? checker.getPropertyOfType(outer, literal) : undefined\n const type =\n named !== undefined\n ? checker.getTypeOfSymbolAtLocation(named, tsNode)\n : checker.getIndexInfoOfType(outer, 0)?.type\n return type === undefined ? undefined : { type, at: node }\n }\n const member = checker.getPropertyOfType(outer, key)\n return member === undefined ? undefined : { type: checker.getTypeOfSymbolAtLocation(member, tsNode), at: node }\n}\n\n/**\n * Does `node` (an expression) flow into a slot that is typed as an array, a tuple or `any`/`unknown`?\n * That's the expected type TypeScript checks it against: the parameter it is passed to, the property\n * it initialises, the declared return type. A literal in such a slot is handed to code that requires an\n * array, such as drizzle's `.values([...])` or an index definition, so `List` can't go there. A literal\n * inside an object passed to an `any` parameter (a `JSON.stringify` request body) counts too.\n *\n * `undefined` when type information isn't available, or when there is no expected type (a free-standing\n * literal), so the caller can fall back.\n */\nexport const flowsIntoArraySlot = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const checker = services.program.getTypeChecker()\n const slot = expectedSlot(checker, services, node, context)\n if (slot === undefined) return undefined\n // A bare `T` parameter: a sink unless the call hands the argument straight back (`useState`, `identity`).\n if (isGenericParameterArgument(checker, services, slot.at)) return !handsArgumentBack(checker, services, slot.at)\n return isArrayLikeOrUntyped(checker, services, slot)\n}\n\n/**\n * Does `node` flow into a slot that requires a *mutable* array — a parameter typed `T[]`, such as pg's\n * `query(text, values: unknown[])`, drizzle's `inArray(col, values)` or ReactFlow's `nodes`? There a\n * `ReadonlyArray` won't type-check, so a mutable annotation is what the library demands.\n *\n * `undefined` when type information isn't available.\n */\nexport const flowsIntoMutableArraySlot = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const checker = services.program.getTypeChecker()\n const slot = expectedSlot(checker, services, node, context)\n if (slot === undefined || isGenericParameterArgument(checker, services, slot.at)) return false\n return isMutableArrayType(checker, slot.type)\n}\n\n/**\n * Is `node`'s own type `any` / `unknown`, or an array of them — `JSON.parse(raw)`, `await res.json()`,\n * `raw` after `Array.isArray(raw)` (narrowed to `any[]`)? `undefined` when type information isn't available.\n */\nexport const isUntypedExpression = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const tsNode = services.esTreeNodeToTSNodeMap.get(node)\n if (!tsNode) return undefined\n const checker = services.program.getTypeChecker()\n const type = checker.getTypeAtLocation(tsNode)\n if (isUntyped(type)) return true\n if (!checker.isArrayLikeType(type)) return false\n const element = checker.getTypeArguments(type)[0]\n return element !== undefined && isUntyped(element)\n}\n\n/** Is type-aware linting on for this file (`parserOptions.projectService` or `project`)? */\nexport const hasTypeInformation = (context: Rule.RuleContext): boolean => typedServices(context) !== undefined\n"],"mappings":"AAqCA,MAGMA,kBAAiD,IAAI,IAAI,CAC7D,WACA,gBACA,mBACA,WACF,CAAC,EAOKC,EAAiB,GAAyD,CAC9E,IAAMC,EAAWC,EAAQ,WAAW,eACpC,OAAOD,GAAU,SAAWA,EAAS,sBAAyBA,EAA6B,IAAA,EAC7F,EAUaE,GAAuB,EAAe,IAAmD,CACpG,IAAMF,EAAWD,EAAcE,CAAO,EACtC,GAAI,CAACD,EAAU,OACf,IAAMG,EAASH,EAAS,sBAAsB,IAAII,CAAI,EACtD,GAAI,CAACD,EAAQ,OACb,IAAME,EAAUL,EAAS,QAAQ,eAAe,EAC1CM,EAAOD,EAAQ,mBAAmBA,EAAQ,kBAAkBF,CAAM,CAAC,EACzE,OACEE,EAAQ,kBAAkBC,EAAM,SAAS,IAAM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EAAG,MAAO,GAC5B,GAAI,CAACD,EAAQ,gBAAgBC,CAAI,EAAG,MAAO,GAC3C,IAAMuB,EAAUxB,EAAQ,iBAAiBC,CAAI,CAAC,CAAC,GAC/C,OAAOuB,IAAY,IAAA,IAAaG,EAAUH,CAAO,CACnD,EAGa6B,EAAsB,GAAuC3D,EAAcE,CAAO,IAAM,IAAA"}
|
|
1
|
+
{"version":3,"file":"type-aware.js","names":["CONSUMED_COLLECTION_TYPES","typedServices","services","context","isExtractableByType","tsNode","node","checker","type","isIOByType","isTypeParameter","enclosingCall","parent","at","index","isGenericParameterArgument","found","callTs","parameters","declared","annotated","handsArgumentBack","signature","argTs","argType","sameAsArgument","candidate","search","depth","types","member","target","element","awaited","isOpaqueSink","isUntyped","slot","isArrayLikeOrUntyped","symbol","flags","isMutableArrayType","propertyKey","property","expectedSlot","own","declarator","ref","call","parameter","objectLiteral","outerSlot","outer","key","keyNode","keyTs","keyType","literal","named","flowsIntoArraySlot","flowsIntoMutableArraySlot","isUntypedExpression","hasTypeInformation"],"sources":["../../src/utils/type-aware.ts"],"sourcesContent":["import type { Rule } from \"eslint\"\n\nimport type { ASTNode } from \"../types/ast\"\n\n/**\n * Type-aware helpers that work only when the consumer turns on type-aware linting\n * (`parserOptions.projectService` or `project`). Without it they report \"unknown\", and a rule\n * falls back to its syntactic heuristic.\n *\n * The checker is reached through `parserServices` and typed structurally here, so the plugin\n * takes no runtime dependency on `typescript`.\n */\n\ntype TypeLike = object\n\ntype CheckerLike = {\n getTypeAtLocation(node: unknown): TypeLike\n getNonNullableType(type: TypeLike): TypeLike\n getPropertyOfType(type: TypeLike, name: string): unknown\n getContextualType(node: unknown): TypeLike | undefined\n isArrayLikeType(type: TypeLike): boolean\n getTypeOfSymbolAtLocation(symbol: unknown, node: unknown): TypeLike\n getTypeArguments(type: TypeLike): ReadonlyArray<TypeLike>\n getResolvedSignature(node: unknown): SignatureLike | undefined\n getIndexInfoOfType(type: TypeLike, kind: number): { readonly type: TypeLike } | undefined\n getReturnTypeOfSignature(signature: unknown): TypeLike\n getAwaitedType(type: TypeLike): TypeLike | undefined\n isTupleType(type: TypeLike): boolean\n isTypeAssignableTo(source: TypeLike, target: TypeLike): boolean\n}\n\ntype SignatureLike = {\n readonly parameters: ReadonlyArray<unknown>\n getDeclaration(): { readonly parameters?: ReadonlyArray<unknown> } | undefined\n}\n\n/** `ts.TypeFlags.Any` / `Unknown`, inlined so the plugin needs no runtime `typescript` import. */\nconst ANY_OR_UNKNOWN_FLAGS = 1 | 2\n\n/** Interfaces a consumer reads through rather than keeps: `importKey(…, usages: Iterable<KeyUsage>)`, `new Set(values)`. */\nconst CONSUMED_COLLECTION_TYPES: ReadonlySet<string> = new Set([\n \"Iterable\",\n \"AsyncIterable\",\n \"IterableIterator\",\n \"ArrayLike\",\n])\n\ntype TypedServices = {\n readonly program: { getTypeChecker(): CheckerLike }\n readonly esTreeNodeToTSNodeMap: { get(node: unknown): unknown }\n}\n\nconst typedServices = (context: Rule.RuleContext): TypedServices | undefined => {\n const services = context.sourceCode.parserServices as Partial<TypedServices> | undefined\n return services?.program && services.esTreeNodeToTSNodeMap ? (services as TypedServices) : undefined\n}\n\n/**\n * Is `node`'s type a functype extractable container (Option, Either, Try, Lazy, …)? Structural:\n * the type, after stripping `null` / `undefined`, has both `orThrow` and `fold` — true of every\n * functype container, including union types like `Either` (each member has both). Native\n * collections (`Map#get`) and arbitrary objects don't.\n *\n * `undefined` when type information isn't available, so the caller can fall back.\n */\nexport const isExtractableByType = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const tsNode = services.esTreeNodeToTSNodeMap.get(node)\n if (!tsNode) return undefined\n const checker = services.program.getTypeChecker()\n const type = checker.getNonNullableType(checker.getTypeAtLocation(tsNode))\n return (\n checker.getPropertyOfType(type, \"orThrow\") !== undefined && checker.getPropertyOfType(type, \"fold\") !== undefined\n )\n}\n\n/**\n * Is `node`'s type a functype `IO`? Structural: the type has both `runExit` and `provideLayer`, which\n * only `IO` carries — `Task`, `Lazy` and the other containers have neither — and has carried since\n * well before 1.9, so older functype versions are recognized too. A union of IOs counts.\n * `any` and `unknown` have no properties, so they don't.\n *\n * `undefined` when type information isn't available.\n */\nexport const isIOByType = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const tsNode = services.esTreeNodeToTSNodeMap.get(node)\n if (!tsNode) return undefined\n const checker = services.program.getTypeChecker()\n const type = checker.getNonNullableType(checker.getTypeAtLocation(tsNode))\n return (\n checker.getPropertyOfType(type, \"runExit\") !== undefined &&\n checker.getPropertyOfType(type, \"provideLayer\") !== undefined\n )\n}\n\n/** A slot's expected type and the expression TypeScript computed it for. */\ntype Slot = { readonly type: TypeLike; readonly at: ASTNode }\n\n/**\n * Uses the `Type` object's own predicate rather than a `TypeFlags` bit: TypeScript renumbers its flags\n * between majors (TypeParameter is `1 << 19` in TS 6, `1 << 18` before), and the plugin has no runtime\n * `typescript` import to read them from.\n */\nconst isTypeParameter = (type: TypeLike): boolean =>\n (type as { isTypeParameter?: () => boolean }).isTypeParameter?.() === true\n\n/**\n * `f(…, arg, …)` where `at` is `arg` or sits inside it (an object property, an array element, a spread,\n * a conditional branch, an `as`): the call, the whole argument, and its index.\n */\nconst enclosingCall = (\n at: ASTNode,\n): { readonly call: ASTNode; readonly argument: ASTNode; readonly index: number } | null => {\n const parent = at.parent as ASTNode | undefined\n if (!parent) return null\n if ((parent.type === \"CallExpression\" || parent.type === \"NewExpression\") && parent.callee !== at) {\n const index = (parent.arguments as ReadonlyArray<ASTNode>).indexOf(at)\n return index < 0 ? null : { call: parent, argument: at, index }\n }\n const passesThrough =\n parent.type === \"TSAsExpression\" ||\n parent.type === \"TSSatisfiesExpression\" ||\n (parent.type === \"ConditionalExpression\" && parent.test !== at) ||\n parent.type === \"LogicalExpression\" ||\n parent.type === \"Property\" ||\n parent.type === \"ObjectExpression\" ||\n parent.type === \"ArrayExpression\" ||\n parent.type === \"SpreadElement\"\n return passesThrough ? enclosingCall(parent) : null\n}\n\n/**\n * Is the parameter that `at` is passed to (directly or nested) declared as a type parameter, or a union\n * containing one — `json<T>(data: T)`, `useState<S>(init: S | (() => S))`? Then TypeScript's expected type for `at` is only an echo of what it inferred from\n * `at` itself (`[1, 2]` → `number[]`), not a shape the library demands.\n */\nconst isGenericParameterArgument = (checker: CheckerLike, services: TypedServices, at: ASTNode): boolean => {\n const found = enclosingCall(at)\n const callTs = found ? services.esTreeNodeToTSNodeMap.get(found.call) : undefined\n const parameters = callTs ? checker.getResolvedSignature(callTs)?.getDeclaration()?.parameters : undefined\n if (!found || !parameters || parameters.length === 0) return false\n const declared = parameters[Math.min(found.index, parameters.length - 1)] as { readonly type?: unknown } | undefined\n // The parameter's type annotation node (`T` in `value: T`); asking for the declaration node's type gives `any`.\n if (declared?.type === undefined) return false\n const annotated = checker.getTypeAtLocation(declared.type)\n // React's `useState<S>(init: S | (() => S))`: a union that contains the type parameter is generic too.\n const members = (annotated as { types?: ReadonlyArray<TypeLike> }).types ?? [annotated]\n return members.some(isTypeParameter)\n}\n\n/**\n * Does the generic call around `at` hand the argument straight back to the caller — `useState(init)`\n * returning `[init, set]`, `identity(x)`, a `Promise` of it? Then the shape stays the caller's, and a\n * type parameter isn't a sink. Looks only at the return type itself, union / intersection members,\n * tuple and array elements, and an awaited Promise, not object properties: Hono's `c.json<T>` returns a\n * `Response` that carries a *parsed* copy of `T` for its RPC client, which the caller doesn't get back.\n */\nconst handsArgumentBack = (checker: CheckerLike, services: TypedServices, at: ASTNode): boolean => {\n const found = enclosingCall(at)\n const callTs = found ? services.esTreeNodeToTSNodeMap.get(found.call) : undefined\n const signature = callTs ? checker.getResolvedSignature(callTs) : undefined\n const argTs = found ? services.esTreeNodeToTSNodeMap.get(found.argument) : undefined\n if (!signature || !argTs) return false\n const argType = checker.getTypeAtLocation(argTs)\n const sameAsArgument = (candidate: TypeLike): boolean =>\n candidate === argType ||\n (checker.isTypeAssignableTo(argType, candidate) && checker.isTypeAssignableTo(candidate, argType))\n const search = (type: TypeLike, depth: number): boolean => {\n if (depth > 3) return false\n if (sameAsArgument(type)) return true\n const { types, target } = type as { types?: ReadonlyArray<TypeLike>; target?: unknown }\n if (types) return types.some((member) => search(member, depth + 1))\n if (target !== undefined && (checker.isTupleType(type) || checker.isArrayLikeType(type))) {\n return checker.getTypeArguments(type).some((element) => search(element, depth + 1))\n }\n const awaited = checker.getAwaitedType(type)\n return awaited !== undefined && awaited !== type && search(awaited, depth + 1)\n }\n return search(checker.getReturnTypeOfSignature(signature), 0)\n}\n\n/**\n * Untyped, or a type parameter of a call that doesn't hand the argument back: an object handed to\n * `c.json<T>(data: T)` or `JSON.stringify` goes to a sink. `useState<T>(init: T)` is not one.\n */\nconst isOpaqueSink = (checker: CheckerLike, services: TypedServices, slot: Slot): boolean =>\n isUntyped(slot.type) || (isTypeParameter(slot.type) && !handsArgumentBack(checker, services, slot.at))\n\nconst isArrayLikeOrUntyped = (checker: CheckerLike, services: TypedServices, slot: Slot): boolean => {\n if (isOpaqueSink(checker, services, slot)) return true\n const { types, symbol } = slot.type as { types?: ReadonlyArray<TypeLike>; symbol?: { name?: string } }\n if (types) return types.some((member) => isArrayLikeOrUntyped(checker, services, { type: member, at: slot.at }))\n if (symbol?.name !== undefined && CONSUMED_COLLECTION_TYPES.has(symbol.name)) return true\n return !isTypeParameter(slot.type) && checker.isArrayLikeType(slot.type)\n}\n\nconst isUntyped = (type: TypeLike): boolean => {\n const { flags } = type as { flags?: number }\n return flags !== undefined && (flags & ANY_OR_UNKNOWN_FLAGS) !== 0\n}\n\n/** The mutable `Array` type, as opposed to `ReadonlyArray`: the one a `ReadonlyArray` can't be passed to. */\nconst isMutableArrayType = (checker: CheckerLike, type: TypeLike): boolean => {\n const { types, symbol } = type as { types?: ReadonlyArray<TypeLike>; symbol?: { name?: string } }\n if (types) return types.some((member) => isMutableArrayType(checker, member))\n return symbol?.name === \"Array\" && checker.isArrayLikeType(type)\n}\n\n/** The name a property is written under: `params` in `{ params }`, `parts` in `{ parts: … }` or `{ \"parts\": … }`. */\nconst propertyKey = (property: ASTNode): string | null => {\n if (property.computed) return null\n if (property.key?.type === \"Identifier\") return property.key.name\n return property.key?.type === \"Literal\" && typeof property.key.value === \"string\" ? property.key.value : null\n}\n\n/**\n * The expected type of `node`, looking through object literals when TypeScript gives the value none of\n * its own. Two cases: a shorthand `{ params }` passed to a function, where the expected type is that\n * property's type on the parameter; and `[…]` in `JSON.stringify({ parts: [...] })`, where the object is\n * passed to an `any` parameter, so the whole object is going to an untyped host.\n */\nconst expectedSlot = (\n checker: CheckerLike,\n services: TypedServices,\n node: ASTNode,\n context: Rule.RuleContext,\n depth = 0,\n): Slot | undefined => {\n if (depth > 4) return undefined\n const tsNode = services.esTreeNodeToTSNodeMap.get(node)\n const own = tsNode ? checker.getContextualType(tsNode) : undefined\n if (own !== undefined) return { type: own, at: node }\n const parent = node.parent as ASTNode | undefined\n // `const metadata = (url) => ({ … })` with no declared return type: the object goes wherever the\n // calls' results go (`c.json(metadata(url))`), so take the expected type at the first call site.\n if (parent?.type === \"ArrowFunctionExpression\" && parent.body === node) {\n const declarator = parent.parent as ASTNode | undefined\n if (\n declarator?.type === \"VariableDeclarator\" &&\n declarator.init === parent &&\n declarator.id?.type === \"Identifier\"\n ) {\n const variable = context.sourceCode.getDeclaredVariables(declarator)[0]\n const calls = (variable?.references ?? [])\n .map((ref) => (ref.identifier as unknown as ASTNode).parent as ASTNode | undefined)\n .filter((call): call is ASTNode => call?.type === \"CallExpression\")\n return calls\n .map((call) => expectedSlot(checker, services, call, context, depth + 1))\n .find((slot) => slot !== undefined)\n }\n }\n // An argument to an overloaded function (`crypto.subtle.importKey(…, [\"decrypt\"])`) gets no contextual\n // type; the parameter of the overload TypeScript picked is the expected type.\n if ((parent?.type === \"CallExpression\" || parent?.type === \"NewExpression\") && parent.callee !== node) {\n const index = (parent.arguments as ReadonlyArray<ASTNode>).indexOf(node)\n const call = services.esTreeNodeToTSNodeMap.get(parent)\n const parameter = index >= 0 && call ? checker.getResolvedSignature(call)?.parameters[index] : undefined\n return parameter === undefined ? undefined : { type: checker.getTypeOfSymbolAtLocation(parameter, call), at: node }\n }\n const objectLiteral = parent?.type === \"Property\" && parent.value === node ? (parent.parent as ASTNode) : undefined\n if (objectLiteral?.type !== \"ObjectExpression\") return undefined\n const outerSlot = expectedSlot(checker, services, objectLiteral, context, depth + 1)\n if (outerSlot === undefined || isOpaqueSink(checker, services, outerSlot)) return outerSlot\n const outer = outerSlot.type\n const key = propertyKey(parent as ASTNode)\n // `{ [k]: [...] }` (a reduce accumulator keyed by category): the property named by the key's literal\n // type, else the string index signature's type.\n if (key === null) {\n const keyNode = (parent as ASTNode).key\n const keyTs = keyNode ? services.esTreeNodeToTSNodeMap.get(keyNode) : undefined\n const keyType = keyTs\n ? (checker.getTypeAtLocation(keyTs) as { value?: unknown; types?: ReadonlyArray<{ value?: unknown }> })\n : undefined\n const literal = keyType?.value ?? keyType?.types?.[0]?.value\n const named = typeof literal === \"string\" ? checker.getPropertyOfType(outer, literal) : undefined\n const type =\n named !== undefined\n ? checker.getTypeOfSymbolAtLocation(named, tsNode)\n : checker.getIndexInfoOfType(outer, 0)?.type\n return type === undefined ? undefined : { type, at: node }\n }\n const member = checker.getPropertyOfType(outer, key)\n return member === undefined ? undefined : { type: checker.getTypeOfSymbolAtLocation(member, tsNode), at: node }\n}\n\n/**\n * Does `node` (an expression) flow into a slot that is typed as an array, a tuple or `any`/`unknown`?\n * That's the expected type TypeScript checks it against: the parameter it is passed to, the property\n * it initialises, the declared return type. A literal in such a slot is handed to code that requires an\n * array, such as drizzle's `.values([...])` or an index definition, so `List` can't go there. A literal\n * inside an object passed to an `any` parameter (a `JSON.stringify` request body) counts too.\n *\n * `undefined` when type information isn't available, or when there is no expected type (a free-standing\n * literal), so the caller can fall back.\n */\nexport const flowsIntoArraySlot = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const checker = services.program.getTypeChecker()\n const slot = expectedSlot(checker, services, node, context)\n if (slot === undefined) return undefined\n // A bare `T` parameter: a sink unless the call hands the argument straight back (`useState`, `identity`).\n if (isGenericParameterArgument(checker, services, slot.at)) return !handsArgumentBack(checker, services, slot.at)\n return isArrayLikeOrUntyped(checker, services, slot)\n}\n\n/**\n * Does `node` flow into a slot that requires a *mutable* array — a parameter typed `T[]`, such as pg's\n * `query(text, values: unknown[])`, drizzle's `inArray(col, values)` or ReactFlow's `nodes`? There a\n * `ReadonlyArray` won't type-check, so a mutable annotation is what the library demands.\n *\n * `undefined` when type information isn't available.\n */\nexport const flowsIntoMutableArraySlot = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const checker = services.program.getTypeChecker()\n const slot = expectedSlot(checker, services, node, context)\n if (slot === undefined || isGenericParameterArgument(checker, services, slot.at)) return false\n return isMutableArrayType(checker, slot.type)\n}\n\n/**\n * Is `node`'s own type `any` / `unknown`, or an array of them — `JSON.parse(raw)`, `await res.json()`,\n * `raw` after `Array.isArray(raw)` (narrowed to `any[]`)? `undefined` when type information isn't available.\n */\nexport const isUntypedExpression = (node: ASTNode, context: Rule.RuleContext): boolean | undefined => {\n const services = typedServices(context)\n if (!services) return undefined\n const tsNode = services.esTreeNodeToTSNodeMap.get(node)\n if (!tsNode) return undefined\n const checker = services.program.getTypeChecker()\n const type = checker.getTypeAtLocation(tsNode)\n if (isUntyped(type)) return true\n if (!checker.isArrayLikeType(type)) return false\n const element = checker.getTypeArguments(type)[0]\n return element !== undefined && isUntyped(element)\n}\n\n/** Is type-aware linting on for this file (`parserOptions.projectService` or `project`)? */\nexport const hasTypeInformation = (context: Rule.RuleContext): boolean => typedServices(context) !== undefined\n"],"mappings":"AAqCA,MAGMA,kBAAiD,IAAI,IAAI,CAC7D,WACA,gBACA,mBACA,WACF,CAAC,EAOKC,EAAiB,GAAyD,CAC9E,IAAMC,EAAWC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I,EAAMH,CAAO,EAC1D,GAAIiC,IAAS,IAAA,GAGb,OADIrB,EAA2BR,EAASL,EAAUkC,EAAK,EAAE,EAAU,CAACf,EAAkBd,EAASL,EAAUkC,EAAK,EAAE,EACzGC,EAAqB9B,EAASL,EAAUkC,CAAI,CACrD,EASauB,GAA6B,EAAe,IAAmD,CAC1G,IAAMzD,EAAWD,EAAcE,CAAO,EACtC,GAAI,CAACD,EAAU,OACf,IAAMK,EAAUL,EAAS,QAAQ,eAAe,EAC1CkC,EAAOO,EAAapC,EAASL,EAAUI,EAAMH,CAAO,EAE1D,OADIiC,IAAS,IAAA,IAAarB,EAA2BR,EAASL,EAAUkC,EAAK,EAAE,EAAU,GAClFI,EAAmBjC,EAAS6B,EAAK,IAAI,CAC9C,EAMawB,GAAuB,EAAe,IAAmD,CACpG,IAAM1D,EAAWD,EAAcE,CAAO,EACtC,GAAI,CAACD,EAAU,OACf,IAAMG,EAASH,EAAS,sBAAsB,IAAII,CAAI,EACtD,GAAI,CAACD,EAAQ,OACb,IAAME,EAAUL,EAAS,QAAQ,eAAe,EAC1CM,EAAOD,EAAQ,kBAAkBF,CAAM,EAC7C,GAAI8B,EAAU3B,CAAI,EAAG,MAAO,GAC5B,GAAI,CAACD,EAAQ,gBAAgBC,CAAI,EAAG,MAAO,GAC3C,IAAMwB,EAAUzB,EAAQ,iBAAiBC,CAAI,CAAC,CAAC,GAC/C,OAAOwB,IAAY,IAAA,IAAaG,EAAUH,CAAO,CACnD,EAGa6B,EAAsB,GAAuC5D,EAAcE,CAAO,IAAM,IAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-functype",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.117.0",
|
|
4
4
|
"description": "Custom ESLint rules for functional TypeScript programming with functype library patterns including Do notation (ESLint 10+)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@types/node": "^24.19.1",
|
|
43
43
|
"@typescript-eslint/rule-tester": "^8.71.0",
|
|
44
44
|
"eslint-config-prettier": "^10.1.8",
|
|
45
|
-
"functype": "^1.
|
|
45
|
+
"functype": "^1.17.0",
|
|
46
46
|
"ts-builds": "^3.4.3",
|
|
47
47
|
"tsdown": "^0.23.0"
|
|
48
48
|
},
|