@stateward/plugin-errors 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +20 -2
  3. package/dist/async-handler-unhandled.d.ts +7 -0
  4. package/dist/async-handler-unhandled.js +342 -0
  5. package/dist/catch-hides-unexpected.d.ts +6 -0
  6. package/dist/catch-hides-unexpected.js +260 -0
  7. package/dist/catch-misses-error.d.ts +6 -0
  8. package/dist/catch-misses-error.js +208 -0
  9. package/dist/catch-without-intent.d.ts +10 -0
  10. package/dist/catch-without-intent.js +590 -0
  11. package/dist/exhaustive-catch.d.ts +6 -0
  12. package/dist/exhaustive-catch.js +190 -0
  13. package/dist/exhaustive-fallback.d.ts +6 -0
  14. package/dist/exhaustive-fallback.js +157 -0
  15. package/dist/finally-can-throw.d.ts +6 -0
  16. package/dist/finally-can-throw.js +184 -0
  17. package/dist/finally-may-throw.d.ts +6 -0
  18. package/dist/finally-may-throw.js +184 -0
  19. package/dist/hover.d.ts +11 -0
  20. package/dist/hover.js +62 -0
  21. package/dist/index.d.ts +7 -0
  22. package/dist/index.js +2 -0
  23. package/dist/inference/builtins.d.ts +52 -0
  24. package/dist/inference/builtins.js +179 -0
  25. package/dist/inference/catches.d.ts +9 -0
  26. package/dist/inference/catches.js +33 -0
  27. package/dist/inference/deps.d.ts +12 -0
  28. package/dist/inference/deps.js +79 -0
  29. package/dist/inference/format.d.ts +25 -0
  30. package/dist/inference/format.js +72 -0
  31. package/dist/inference/packages.d.ts +40 -0
  32. package/dist/inference/packages.js +723 -0
  33. package/dist/inference/project.d.ts +8 -0
  34. package/dist/inference/project.js +22 -0
  35. package/dist/inference/solve.d.ts +128 -0
  36. package/dist/inference/solve.js +575 -0
  37. package/dist/inference/summarize.d.ts +50 -0
  38. package/dist/inference/summarize.js +1324 -0
  39. package/dist/inference/summary.d.ts +191 -0
  40. package/dist/inference/summary.js +237 -0
  41. package/dist/inlay.d.ts +19 -0
  42. package/dist/inlay.js +168 -0
  43. package/dist/must-handle-error.d.ts +55 -0
  44. package/dist/must-handle-error.js +794 -0
  45. package/dist/narrow-try.d.ts +52 -0
  46. package/dist/narrow-try.js +641 -0
  47. package/dist/no-swallow.d.ts +8 -0
  48. package/dist/no-swallow.js +320 -0
  49. package/dist/plugin.d.ts +116 -0
  50. package/dist/plugin.js +39 -0
  51. package/dist/react/boundaries.d.ts +83 -0
  52. package/dist/react/boundaries.js +371 -0
  53. package/dist/react/fallbacks.d.ts +12 -0
  54. package/dist/react/fallbacks.js +83 -0
  55. package/dist/react/render-guards.d.ts +24 -0
  56. package/dist/react/render-guards.js +271 -0
  57. package/dist/react/tree.d.ts +98 -0
  58. package/dist/react/tree.js +863 -0
  59. package/dist/refactors.d.ts +15 -0
  60. package/dist/refactors.js +69 -0
  61. package/dist/render-throw-without-boundary.d.ts +11 -0
  62. package/dist/render-throw-without-boundary.js +223 -0
  63. package/dist/render-throws-without-boundary.d.ts +6 -0
  64. package/dist/render-throws-without-boundary.js +151 -0
  65. package/dist/result-ignored.d.ts +6 -0
  66. package/dist/result-ignored.js +167 -0
  67. package/dist/result-type.d.ts +18 -0
  68. package/dist/result-type.js +55 -0
  69. package/dist/result-unchecked.d.ts +2 -0
  70. package/dist/result-unchecked.js +746 -0
  71. package/dist/rethrow-unknown.d.ts +6 -0
  72. package/dist/rethrow-unknown.js +260 -0
  73. package/dist/rules.meta.d.ts +214 -0
  74. package/dist/rules.meta.js +212 -0
  75. package/dist/syntax.d.ts +41 -0
  76. package/dist/syntax.js +171 -0
  77. package/dist/text.d.ts +22 -0
  78. package/dist/text.js +43 -0
  79. package/dist/throw-in-hook.d.ts +8 -0
  80. package/dist/throw-in-hook.js +510 -0
  81. package/dist/throws-doc-mismatch.d.ts +7 -0
  82. package/dist/throws-doc-mismatch.js +188 -0
  83. package/dist/throws-matches-doc.d.ts +7 -0
  84. package/dist/throws-matches-doc.js +188 -0
  85. package/package.json +34 -3
@@ -0,0 +1,18 @@
1
+ import type ts from "@stateward/core/typescript";
2
+ import { type TypeQueries } from "@stateward/core";
3
+ /**
4
+ * How a value says it failed, read from its type (the project's own `Result`, no helper library): a union with `ok: true | false`, one with `success: true | false` (zod's
5
+ * `safeParse`), or a type with `isOk()` and `isErr()` (neverthrow). `named` is a type the
6
+ * `resultTypes` option names, whatever its shape.
7
+ */
8
+ export type ResultShape = "ok" | "success" | "isErr" | "named";
9
+ /**
10
+ * The shape of a Result an expression gives (once awaited), or undefined when it is not one.
11
+ * `names`: the `resultTypes` option (names or globs).
12
+ */
13
+ export declare function resultShapeOf(node: ts.Node, types: TypeQueries, names: readonly string[]): ResultShape | undefined;
14
+ /** Cuts `text` to `max` characters, ending in `…`, for a headline or an example line. */
15
+ export declare function shorten(text: string, max: number): string;
16
+ /** A hint's example: indented 4 spaces, one line per entry. */
17
+ export declare function example(lines: readonly string[]): string;
18
+ //# sourceMappingURL=result-type.d.ts.map
@@ -0,0 +1,55 @@
1
+ import { matchesName } from "@stateward/core";
2
+ /**
3
+ * Whether a property tells the members of a union apart by `true` and `false`. An object with
4
+ * `ok: boolean` (a fetch `Response`) is not a union, so it is not a Result.
5
+ */
6
+ function isBooleanTag(node, property, types) {
7
+ const found = types.awaitedTagsOf(node, property);
8
+ if (found === "missing" || found.members < 2 || typeof found.tags === "string")
9
+ return false;
10
+ return found.tags.map((tag) => tag.label).join(",") === "false,true";
11
+ }
12
+ /** Whether every member of a union (two or more) has the property: `isOk` on neverthrow's `Ok | Err`. */
13
+ function hasOnEveryMember(node, property, types) {
14
+ const found = types.awaitedTagsOf(node, property);
15
+ return found !== "missing" && found.members >= 2;
16
+ }
17
+ /** The name a type is printed with, after the `Promise<…>` around it: `Result` in `Promise<Result<A, B>>`. */
18
+ function printedName(node, types) {
19
+ let text = types.typeTextOf(node).trim();
20
+ while (/^(?:Promise|PromiseLike)</.test(text))
21
+ text = text.slice(text.indexOf("<") + 1);
22
+ return /^[A-Za-z_$][\w$.]*/.exec(text)?.[0];
23
+ }
24
+ /**
25
+ * The shape of a Result an expression gives (once awaited), or undefined when it is not one.
26
+ * `names`: the `resultTypes` option (names or globs).
27
+ */
28
+ export function resultShapeOf(node, types, names) {
29
+ // A primitive (most calls written as a statement give `void`) has no property to tell its
30
+ // members apart: one question instead of four.
31
+ const primitive = types.isPrimitive(node);
32
+ if (!primitive) {
33
+ if (isBooleanTag(node, "ok", types))
34
+ return "ok";
35
+ if (isBooleanTag(node, "success", types))
36
+ return "success";
37
+ if (hasOnEveryMember(node, "isOk", types) && hasOnEveryMember(node, "isErr", types)) {
38
+ return "isErr";
39
+ }
40
+ }
41
+ if (names.length === 0)
42
+ return undefined;
43
+ const alias = types.awaitedAliasOf(node)?.name ?? printedName(node, types);
44
+ return alias !== undefined && matchesName(alias, names) ? "named" : undefined;
45
+ }
46
+ /** Cuts `text` to `max` characters, ending in `…`, for a headline or an example line. */
47
+ export function shorten(text, max) {
48
+ const flat = text.replace(/\s+/g, " ").trim();
49
+ return flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;
50
+ }
51
+ /** A hint's example: indented 4 spaces, one line per entry. */
52
+ export function example(lines) {
53
+ return lines.map((line) => ` ${line}`).join("\n");
54
+ }
55
+ //# sourceMappingURL=result-type.js.map
@@ -0,0 +1,2 @@
1
+ export declare const resultUnchecked: import("@stateward/core").FileRule<Readonly<Record<string, never>>, "callers">;
2
+ //# sourceMappingURL=result-unchecked.d.ts.map