@sshkeda/check 2.0.0 → 2.2.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 (31) hide show
  1. package/README.md +1 -1
  2. package/docs/how-to-make-check-pass.md +2 -0
  3. package/package.json +1 -1
  4. package/src/internal/ban-abbreviated-words-in-declared-names.ts +4 -5
  5. package/src/internal/ban-deadlines-inside-tests.ts +4 -5
  6. package/src/internal/ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts +4 -5
  7. package/src/internal/ban-failures-collected-as-results.ts +4 -5
  8. package/src/internal/ban-fallbacks-of-named-recoveries.ts +6 -7
  9. package/src/internal/ban-fixed-values-in-recoveries.ts +331 -0
  10. package/src/internal/ban-reading-the-clock-and-sleeping-outside-effect.ts +4 -5
  11. package/src/internal/ban-recovering-file-system-exists.ts +12 -79
  12. package/src/internal/ban-timer-schedules-without-deadlines.ts +5 -6
  13. package/src/internal/ban-type-predicates.ts +4 -5
  14. package/src/internal/ban-what-a-file-is-not-granted.ts +9 -9
  15. package/src/internal/define-the-lint-plugin-and-configs.ts +6 -0
  16. package/src/internal/follow-the-steps-applied-to-an-effect.ts +100 -0
  17. package/src/internal/recognize-fixed-values.ts +318 -0
  18. package/src/internal/recognize-whole-library-error-tags.ts +6 -0
  19. package/src/internal/report-code-grants-nothing-uses.ts +122 -0
  20. package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/read-effect-tsgo-json-report.ts +13 -9
  21. package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +1 -1
  22. package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +3 -1
  23. package/src/lib/tasks/lib/enforce-file-layout/internal/find-module-layout-violations.ts +6 -4
  24. package/src/lib/tasks/lib/format-with-bun-fmt/internal/check-formatting-with-bun-fmt.ts +1 -1
  25. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-the-importer-graph.ts +12 -3
  26. package/src/lib/tasks/shared/check-each-nested-package.ts +1 -1
  27. package/src/lib/tasks/shared/classify-files-by-role.ts +7 -2
  28. package/src/lib/tasks/shared/list-package-files.ts +15 -2
  29. package/src/shared/bans-each-permission-lifts.ts +3 -0
  30. package/src/shared/record-and-grant-permissions-by-path.ts +59 -6
  31. /package/src/lib/tasks/{lib/format-with-bun-fmt/internal → shared}/find-symbolic-links.ts +0 -0
package/README.md CHANGED
@@ -4,7 +4,7 @@ Check sends your AI slop code back to the kitchen!
4
4
 
5
5
  Check holds your TypeScript code to a strict standard built around Effect and Bun, so the code stays type-safe, observable and predictable.
6
6
 
7
- It runs about 308 lint rules, 65 of them its own, and about 80 checks on your project's layout, imports and config. It also runs oxfmt, Effect's diagnostics and `bun check`. Your agent keeps fixing what it reports until the slop is gone.
7
+ It runs about 310 lint rules, 67 of them its own, and about 80 checks on your project's layout, imports and config. It also runs oxfmt, Effect's diagnostics and `bun check`. Your agent keeps fixing what it reports until the slop is gone.
8
8
 
9
9
  No comment or setting turns a rule off everywhere. A small set of rules was picked to allow an override, and you grant each one to a single file in `oxlint.config.ts`. See [Grant a permission](docs/how-to-make-check-pass.md#grant-a-permission).
10
10
 
@@ -7,6 +7,7 @@ Check may not catch every violation of these principles. Review your code agains
7
7
  ## Meet the requirement behind the error
8
8
 
9
9
  - Use a grant only for an unavoidable exception.
10
+ - Move the code that needs a grant into its own small file and grant that file. A grant covers the whole file, so Check stops reporting that ban for everything else in it.
10
11
  - Design for the current requirement as if you were starting fresh. Delete code the new design doesn't need.
11
12
  - Grant `isGeneratedByATool` only to a file a tool generates.
12
13
 
@@ -36,6 +37,7 @@ export default lintConfig({
36
37
  - `patchesADependency`: Allows a patch file from `bun patch`.
37
38
  - `trustsUnverifiedTypes`: Allows trusting a value's type without checking it, through `Schema.declare`.
38
39
  - `handlesEveryFailure`: Allows catching every error, through `Effect.catch`, `Effect.exit`, a forked fiber or `Effect.runPromise`.
40
+ - `fallsBackToFixedValues`: Allows answering every failure, or a whole library error such as `PlatformError`, with a fixed value that never reads the failure.
39
41
  - `isGeneratedByATool`: Check skips this path, so it can't have any other permission.
40
42
 
41
43
  ## Make the code explain itself
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sshkeda/check",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "homepage": "https://github.com/sshkeda/check#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/sshkeda/check/issues"
@@ -1,5 +1,4 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- import type { ESTree } from "@oxlint/plugins";
1
+ import type { Context, CreateRule, ESTree } from "@oxlint/plugins";
3
2
  import { Schema } from "effect";
4
3
 
5
4
  import { decodeRuleOptions, ruleOptionsJsonSchema } from "./describe-and-decode-rule-options.ts";
@@ -128,7 +127,7 @@ const allowList = (options: readonly unknown[]): ReadonlySet<string> =>
128
127
  ),
129
128
  );
130
129
 
131
- export const noAbbreviations = defineRule({
130
+ export const noAbbreviations = {
132
131
  meta: {
133
132
  type: "suggestion",
134
133
  messages: {
@@ -136,7 +135,7 @@ export const noAbbreviations = defineRule({
136
135
  },
137
136
  schema: ruleOptionsJsonSchema(ABBREVIATION_OPTIONS),
138
137
  },
139
- create(context) {
138
+ create(context: Pick<Context, "options" | "report">) {
140
139
  const allowed = allowList(context.options);
141
140
 
142
141
  const check = (node: ESTree.Node) => {
@@ -158,4 +157,4 @@ export const noAbbreviations = defineRule({
158
157
 
159
158
  return declaredNameListeners(check);
160
159
  },
161
- });
160
+ } satisfies CreateRule;
@@ -1,5 +1,4 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- import type { ESTree } from "@oxlint/plugins";
1
+ import type { Context, CreateRule, ESTree } from "@oxlint/plugins";
3
2
 
4
3
  import { SCHEDULE_MESSAGES } from "../shared/lint-rule-messages-and-patterns.ts";
5
4
  import { scheduleVisitors } from "./ban-timer-schedules-without-deadlines.ts";
@@ -7,12 +6,12 @@ import { effectModuleReference } from "./resolve-what-an-expression-imports.ts";
7
6
 
8
7
  const TIMEOUT = "timeout";
9
8
 
10
- export const noTestTimeouts = defineRule({
9
+ export const noTestTimeouts = {
11
10
  meta: {
12
11
  type: "problem",
13
12
  messages: { ...SCHEDULE_MESSAGES, timeout: "{{usage}} sets a deadline inside a test" },
14
13
  },
15
- create(context) {
14
+ create(context: Pick<Context, "report" | "sourceCode">) {
16
15
  const schedules = scheduleVisitors({ context, timedSchedules: "banned" });
17
16
  const reportEffectTimeout = (node: ESTree.Node) => {
18
17
  const usage = effectModuleReference(node, context.sourceCode, "Effect");
@@ -37,4 +36,4 @@ export const noTestTimeouts = defineRule({
37
36
  },
38
37
  };
39
38
  },
40
- });
39
+ } satisfies CreateRule;
@@ -1,5 +1,4 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- import type { ESTree } from "@oxlint/plugins";
1
+ import type { Context, CreateRule, ESTree } from "@oxlint/plugins";
3
2
 
4
3
  import { EFFECT_OPERATION_RULES } from "../shared/lint-rule-messages-and-patterns.ts";
5
4
  import { effectModuleOperation, moduleExportName } from "./resolve-what-an-expression-imports.ts";
@@ -17,14 +16,14 @@ export const effectOperationRule = (ruleName: keyof typeof EFFECT_OPERATION_RULE
17
16
  const bannedModules: ReadonlySet<string> = new Set(
18
17
  bannedOperations.flatMap(([, operations]) => [...operations.keys()]),
19
18
  );
20
- return defineRule({
19
+ return {
21
20
  meta: {
22
21
  type: "problem",
23
22
  messages: {
24
23
  operation: "{{moduleName}}.{{operation}} is banned",
25
24
  },
26
25
  },
27
- create(context) {
26
+ create(context: Pick<Context, "report" | "sourceCode">) {
28
27
  const report = (node: ESTree.Node, moduleName: string, operation: string | undefined) => {
29
28
  if (operation === undefined) {
30
29
  return;
@@ -61,5 +60,5 @@ export const effectOperationRule = (ruleName: keyof typeof EFFECT_OPERATION_RULE
61
60
  },
62
61
  };
63
62
  },
64
- });
63
+ } satisfies CreateRule;
65
64
  };
@@ -1,5 +1,4 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- import type { ESTree } from "@oxlint/plugins";
1
+ import type { Context, CreateRule, ESTree } from "@oxlint/plugins";
3
2
 
4
3
  import { effectModuleOperation, propertyKeyName } from "./resolve-what-an-expression-imports.ts";
5
4
 
@@ -28,7 +27,7 @@ const unsafeOptionsMessage = (options: ESTree.Node | undefined) => {
28
27
  return isDefaultMode ? undefined : "results";
29
28
  };
30
29
 
31
- export const noFailuresAsResults = defineRule({
30
+ export const noFailuresAsResults = {
32
31
  meta: {
33
32
  type: "problem",
34
33
  messages: {
@@ -36,7 +35,7 @@ export const noFailuresAsResults = defineRule({
36
35
  opaqueOptions: "Effect.all is given options that are not written inline",
37
36
  },
38
37
  },
39
- create(context) {
38
+ create(context: Pick<Context, "report" | "sourceCode">) {
40
39
  return {
41
40
  CallExpression(node) {
42
41
  const operation = effectModuleOperation(node.callee, context.sourceCode, "Effect");
@@ -50,4 +49,4 @@ export const noFailuresAsResults = defineRule({
50
49
  },
51
50
  };
52
51
  },
53
- });
52
+ } satisfies CreateRule;
@@ -1,14 +1,13 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- import type { ESTree, SourceCode } from "@oxlint/plugins";
1
+ import type { Context, CreateRule, ESTree, SourceCode } from "@oxlint/plugins";
3
2
 
4
3
  import { constantValue, effectModuleOperation } from "./resolve-what-an-expression-imports.ts";
5
4
 
6
5
  const NAMED_RECOVERY_MODULES = ["Effect", "Stream", "Channel"] as const;
7
6
 
8
- const isTagText = (node: ESTree.Node) =>
7
+ export const isTagText = (node: ESTree.Node) =>
9
8
  (node.type === "Literal" && typeof node.value === "string") || node.type === "TemplateLiteral";
10
9
 
11
- const isTagList = (node: ESTree.Node) => isTagText(node) || node.type === "ArrayExpression";
10
+ export const isTagList = (node: ESTree.Node) => isTagText(node) || node.type === "ArrayExpression";
12
11
 
13
12
  const isHandlerObject = (node: ESTree.Node) => node.type === "ObjectExpression";
14
13
 
@@ -61,14 +60,14 @@ const hasFallback = (
61
60
  return isDataLastWithFallback || !isDataFirstWithoutFallback;
62
61
  };
63
62
 
64
- export const noUnnamedFallbacks = defineRule({
63
+ export const noUnnamedFallbacks = {
65
64
  meta: {
66
65
  type: "problem",
67
66
  messages: {
68
67
  fallback: "{{member}} is given a fallback for failures it does not name",
69
68
  },
70
69
  },
71
- create(context) {
70
+ create(context: Pick<Context, "report" | "sourceCode">) {
72
71
  return {
73
72
  CallExpression(node) {
74
73
  for (const moduleName of NAMED_RECOVERY_MODULES) {
@@ -87,4 +86,4 @@ export const noUnnamedFallbacks = defineRule({
87
86
  },
88
87
  };
89
88
  },
90
- });
89
+ } satisfies CreateRule;
@@ -0,0 +1,331 @@
1
+ import { defineRule } from "@oxlint/plugins";
2
+ import type { ESTree, SourceCode } from "@oxlint/plugins";
3
+ import { Schema } from "effect";
4
+
5
+ import { unusedGrantMessage } from "../shared/bans-each-permission-lifts.ts";
6
+ import {
7
+ FIXED_FALLBACKS,
8
+ FIXED_FALLBACKS_GRANTED,
9
+ } from "../shared/record-and-grant-permissions-by-path.ts";
10
+ import { isTagList, isTagText } from "./ban-fallbacks-of-named-recoveries.ts";
11
+ import { decodeRuleOptions, ruleOptionsJsonSchema } from "./describe-and-decode-rule-options.ts";
12
+ import { stepsAfter, stepsAppliedTo } from "./follow-the-steps-applied-to-an-effect.ts";
13
+ import {
14
+ fixedOutcomeOf,
15
+ handlerFunction,
16
+ returnedBranches,
17
+ returnedValuesIn,
18
+ } from "./recognize-fixed-values.ts";
19
+ import { isWholeLibraryErrorTag } from "./recognize-whole-library-error-tags.ts";
20
+ import {
21
+ constantValue,
22
+ effectModuleOperation,
23
+ effectOperation,
24
+ memberName,
25
+ propertyKeyName,
26
+ resolvedVariable,
27
+ staticKeyName,
28
+ textOnOneLine,
29
+ unwrappedExpression,
30
+ } from "./resolve-what-an-expression-imports.ts";
31
+
32
+ const RECOVERY_MODULES = ["Effect", "Stream", "Channel"] as const;
33
+
34
+ const EVERY_FAILURE = "every failure";
35
+
36
+ const EVERY_CAUSE = "every cause";
37
+
38
+ const UNNAMED_FAILURES = "the failures it does not name";
39
+
40
+ const ON_FAILURE = "onFailure";
41
+
42
+ const CATCH = "catch";
43
+
44
+ const OPTION = "option";
45
+
46
+ const ALWAYS_FIXED_RECOVERY = "orElseSucceed";
47
+
48
+ const FALLBACK_AFTER_A_NAME_AND_A_HANDLER = 2;
49
+
50
+ const FALLBACK_AFTER_A_TAG_A_REASON_AND_A_HANDLER = 3;
51
+
52
+ const FIXED_FALLBACK_OPTIONS = Schema.Struct({
53
+ fixedFallbacks: Schema.optionalKey(Schema.Literal(FIXED_FALLBACKS_GRANTED)),
54
+ });
55
+
56
+ const firstNamingArgument = (
57
+ callArguments: readonly ESTree.Node[],
58
+ isNaming: (node: ESTree.Node) => boolean,
59
+ sourceCode: SourceCode,
60
+ ) => {
61
+ const [first] = callArguments;
62
+ const isFirstNaming = first !== undefined && isNaming(constantValue(first, sourceCode));
63
+ return isFirstNaming ? 0 : 1;
64
+ };
65
+
66
+ const tagNamesOf = (node: ESTree.Node | undefined, sourceCode: SourceCode) => {
67
+ if (node === undefined) {
68
+ return [];
69
+ }
70
+ const value = constantValue(node, sourceCode);
71
+ const names =
72
+ value.type === "ArrayExpression"
73
+ ? value.elements.map((element) =>
74
+ element === null ? undefined : staticKeyName(constantValue(element, sourceCode)),
75
+ )
76
+ : [staticKeyName(value)];
77
+ return names.filter((name) => name !== undefined);
78
+ };
79
+
80
+ const handler = (node: ESTree.Node | undefined, failure: string) => {
81
+ const isMissing = node === undefined || node.type === "SpreadElement";
82
+ return isMissing ? [] : [{ node, failure }];
83
+ };
84
+
85
+ const effectiveProperties = (handlers: ESTree.Node | undefined, sourceCode: SourceCode) => {
86
+ const value = handlers === undefined ? undefined : constantValue(handlers, sourceCode);
87
+ if (value?.type !== "ObjectExpression") {
88
+ return [];
89
+ }
90
+ return value.properties.flatMap((property, position) => {
91
+ const key = propertyKeyName(property);
92
+ const isOverridden = value.properties.slice(position + 1).some((later) => {
93
+ const laterKey = propertyKeyName(later);
94
+ return laterKey === undefined || laterKey === key;
95
+ });
96
+ const isEffective = key !== undefined && !isOverridden && property.type === "Property";
97
+ return isEffective ? [{ key, value: property.value }] : [];
98
+ });
99
+ };
100
+
101
+ const catchTagHandlers = (callArguments: readonly ESTree.Node[], sourceCode: SourceCode) => {
102
+ const offset = firstNamingArgument(callArguments, isTagList, sourceCode);
103
+ const libraryTags = tagNamesOf(callArguments[offset], sourceCode).filter((tag) =>
104
+ isWholeLibraryErrorTag(tag),
105
+ );
106
+ return [
107
+ ...(libraryTags.length > 0 ? handler(callArguments[offset + 1], libraryTags.join(" or ")) : []),
108
+ ...handler(callArguments[offset + FALLBACK_AFTER_A_NAME_AND_A_HANDLER], UNNAMED_FAILURES),
109
+ ];
110
+ };
111
+
112
+ const catchTagsHandlers = (callArguments: readonly ESTree.Node[], sourceCode: SourceCode) => {
113
+ const offset = firstNamingArgument(
114
+ callArguments,
115
+ (node) => node.type === "ObjectExpression",
116
+ sourceCode,
117
+ );
118
+ return [
119
+ ...effectiveProperties(callArguments[offset], sourceCode)
120
+ .filter(({ key }) => isWholeLibraryErrorTag(key))
121
+ .flatMap(({ key, value }) => handler(value, key)),
122
+ ...handler(callArguments[offset + 1], UNNAMED_FAILURES),
123
+ ];
124
+ };
125
+
126
+ const catchReasonHandlers = (callArguments: readonly ESTree.Node[], sourceCode: SourceCode) => {
127
+ const offset = firstNamingArgument(callArguments, isTagText, sourceCode);
128
+ return handler(
129
+ callArguments[offset + FALLBACK_AFTER_A_TAG_A_REASON_AND_A_HANDLER],
130
+ UNNAMED_FAILURES,
131
+ );
132
+ };
133
+
134
+ const catchReasonsHandlers = (callArguments: readonly ESTree.Node[], sourceCode: SourceCode) => {
135
+ const offset = firstNamingArgument(callArguments, isTagText, sourceCode);
136
+ return handler(callArguments[offset + FALLBACK_AFTER_A_NAME_AND_A_HANDLER], UNNAMED_FAILURES);
137
+ };
138
+
139
+ const lastHandlerFor = (failure: string) => (callArguments: readonly ESTree.Node[]) =>
140
+ handler(callArguments.at(-1), failure);
141
+
142
+ const onFailureHandlersFor =
143
+ (failure: string) => (callArguments: readonly ESTree.Node[], sourceCode: SourceCode) =>
144
+ effectiveProperties(callArguments.at(-1), sourceCode)
145
+ .filter(({ key }) => key === ON_FAILURE)
146
+ .flatMap(({ value }) => handler(value, failure));
147
+
148
+ const RECOVERIES: ReadonlyMap<
149
+ string,
150
+ (callArguments: readonly ESTree.Node[], sourceCode: SourceCode) => ReturnType<typeof handler>
151
+ > = new Map([
152
+ ["catchTag", catchTagHandlers],
153
+ ["catchTags", catchTagsHandlers],
154
+ ["catchReason", catchReasonHandlers],
155
+ ["catchReasons", catchReasonsHandlers],
156
+ ["catch", lastHandlerFor(EVERY_FAILURE)],
157
+ ["catchEager", lastHandlerFor(EVERY_FAILURE)],
158
+ ["orElse", lastHandlerFor(EVERY_FAILURE)],
159
+ ["catchCause", lastHandlerFor(EVERY_CAUSE)],
160
+ ["match", onFailureHandlersFor(EVERY_FAILURE)],
161
+ ["matchEager", onFailureHandlersFor(EVERY_FAILURE)],
162
+ ["matchEffect", onFailureHandlersFor(EVERY_FAILURE)],
163
+ ["matchCause", onFailureHandlersFor(EVERY_CAUSE)],
164
+ ["matchCauseEager", onFailureHandlersFor(EVERY_CAUSE)],
165
+ ["matchCauseEffect", onFailureHandlersFor(EVERY_CAUSE)],
166
+ ["matchCauseEffectEager", onFailureHandlersFor(EVERY_CAUSE)],
167
+ ]);
168
+
169
+ const boundNamesOf = (pattern: ESTree.Node | null): readonly ESTree.Node[] => {
170
+ if (pattern === null) {
171
+ return [];
172
+ }
173
+ if (pattern.type === "Identifier") {
174
+ return [pattern];
175
+ }
176
+ if (pattern.type === "ObjectPattern") {
177
+ return pattern.properties.flatMap((property) =>
178
+ boundNamesOf(property.type === "Property" ? property.value : property.argument),
179
+ );
180
+ }
181
+ if (pattern.type === "ArrayPattern") {
182
+ return pattern.elements.flatMap((element) => boundNamesOf(element));
183
+ }
184
+ if (pattern.type === "AssignmentPattern") {
185
+ return boundNamesOf(pattern.left);
186
+ }
187
+ return pattern.type === "RestElement" ? boundNamesOf(pattern.argument) : [pattern];
188
+ };
189
+
190
+ const isRead = (binding: ESTree.Node, sourceCode: SourceCode) => {
191
+ const variable = resolvedVariable(binding, sourceCode);
192
+ return variable === undefined || variable.references.some((reference) => reference.isRead());
193
+ };
194
+
195
+ const ignoresTheFailure = (parameters: readonly ESTree.Node[], sourceCode: SourceCode) =>
196
+ parameters
197
+ .flatMap((parameter) => boundNamesOf(parameter))
198
+ .every((binding) => !isRead(binding, sourceCode));
199
+
200
+ const parametersOf = (node: ESTree.Node, sourceCode: SourceCode) =>
201
+ handlerFunction(node, sourceCode)?.params;
202
+
203
+ const fixedBranchesOf = (branches: readonly ESTree.Node[], sourceCode: SourceCode) =>
204
+ branches.flatMap((branch) => {
205
+ const value = fixedOutcomeOf(branch, sourceCode);
206
+ return value === undefined ? [] : [{ branch, value }];
207
+ });
208
+
209
+ const fixedBranchOf = (node: ESTree.Node, sourceCode: SourceCode) => {
210
+ const parameters = parametersOf(node, sourceCode);
211
+ const isIgnored = parameters !== undefined && ignoresTheFailure(parameters, sourceCode);
212
+ return isIgnored ? fixedBranchesOf(returnedBranches(node, sourceCode), sourceCode)[0] : undefined;
213
+ };
214
+
215
+ const getOrElseDefault = (steps: ReturnType<typeof stepsAppliedTo>, sourceCode: SourceCode) => {
216
+ const [next] = steps;
217
+ const [mapped] = next?.callArguments ?? [];
218
+ const isMappedOnce = next?.operation === "map" && next.callArguments.length === 1;
219
+ const isMappedThroughOneFunction = isMappedOnce && mapped !== undefined;
220
+ const getOrElse = isMappedThroughOneFunction ? constantValue(mapped, sourceCode) : undefined;
221
+ const isGetOrElse =
222
+ getOrElse?.type === "CallExpression" &&
223
+ getOrElse.arguments.length === 1 &&
224
+ effectModuleOperation(getOrElse.callee, sourceCode, "Option") === "getOrElse";
225
+ return isGetOrElse ? getOrElse.arguments[0] : undefined;
226
+ };
227
+
228
+ const optionStepsOf = (node: ESTree.CallExpression, sourceCode: SourceCode) => {
229
+ const isDataFirstOption =
230
+ effectOperation(node.callee, sourceCode) === OPTION && node.arguments.length === 1;
231
+ const bareOptions = node.arguments.filter(
232
+ (argument) => effectOperation(argument, sourceCode) === OPTION,
233
+ );
234
+ return [
235
+ ...(isDataFirstOption ? [stepsAppliedTo(node, sourceCode)] : []),
236
+ ...bareOptions.map((argument) => stepsAfter(argument, sourceCode)),
237
+ ];
238
+ };
239
+
240
+ export const noFixedFallbacks = defineRule({
241
+ meta: {
242
+ type: "problem",
243
+ messages: {
244
+ fixed:
245
+ "{{operation}} answers {{failure}} with the fixed value {{value}} and never reads the failure. Name the reason you expect, or fail",
246
+ unusedGrant: unusedGrantMessage(FIXED_FALLBACKS),
247
+ },
248
+ schema: ruleOptionsJsonSchema(FIXED_FALLBACK_OPTIONS),
249
+ },
250
+ create(context) {
251
+ const { sourceCode } = context;
252
+ const options = decodeRuleOptions(FIXED_FALLBACK_OPTIONS, context.options);
253
+ const isGranted = options?.fixedFallbacks === FIXED_FALLBACKS_GRANTED;
254
+ const fixedFallbacks = new Set<ESTree.Node>();
255
+ const reportFixed = (
256
+ { branch, value }: { readonly branch: ESTree.Node; readonly value: ESTree.Node },
257
+ data: { readonly operation: string; readonly failure: string },
258
+ ) => {
259
+ fixedFallbacks.add(branch);
260
+ if (!isGranted) {
261
+ context.report({
262
+ node: branch,
263
+ messageId: "fixed",
264
+ data: { ...data, value: textOnOneLine(unwrappedExpression(value), sourceCode) },
265
+ });
266
+ }
267
+ };
268
+ const reportHandlers = (handlers: ReturnType<typeof handler>, operation: string) => {
269
+ for (const recovery of handlers) {
270
+ const fixed = fixedBranchOf(recovery.node, sourceCode);
271
+ if (fixed !== undefined) {
272
+ reportFixed(fixed, { operation, failure: recovery.failure });
273
+ }
274
+ }
275
+ };
276
+ const reportEffectRecovery = (node: ESTree.CallExpression) =>
277
+ RECOVERY_MODULES.some((moduleName) => {
278
+ const operation = effectModuleOperation(node.callee, sourceCode, moduleName);
279
+ if (operation === undefined) {
280
+ return false;
281
+ }
282
+ const recovery = RECOVERIES.get(operation);
283
+ if (recovery !== undefined) {
284
+ reportHandlers(recovery(node.arguments, sourceCode), `${moduleName}.${operation}`);
285
+ }
286
+ const fallback = node.arguments.at(-1);
287
+ const isAlwaysFixed = operation === ALWAYS_FIXED_RECOVERY && fallback !== undefined;
288
+ if (isAlwaysFixed) {
289
+ const [returned = fallback] = returnedBranches(fallback, sourceCode);
290
+ reportFixed(
291
+ { branch: returned, value: returned },
292
+ { operation: `${moduleName}.${operation}`, failure: EVERY_FAILURE },
293
+ );
294
+ }
295
+ return true;
296
+ });
297
+ return {
298
+ CallExpression(node) {
299
+ const isEffectOperation = reportEffectRecovery(node);
300
+ for (const steps of optionStepsOf(node, sourceCode)) {
301
+ reportHandlers(
302
+ handler(getOrElseDefault(steps, sourceCode), EVERY_FAILURE),
303
+ `Effect.${OPTION}`,
304
+ );
305
+ }
306
+ const isPromiseCatch =
307
+ !isEffectOperation &&
308
+ node.callee.type === "MemberExpression" &&
309
+ memberName(node.callee) === CATCH &&
310
+ node.arguments.length === 1;
311
+ if (isPromiseCatch) {
312
+ reportHandlers(handler(node.arguments[0], "every rejection"), CATCH);
313
+ }
314
+ },
315
+ CatchClause(node) {
316
+ if (!ignoresTheFailure(node.param === null ? [] : [node.param], sourceCode)) {
317
+ return;
318
+ }
319
+ for (const fixed of fixedBranchesOf(returnedValuesIn(node.body), sourceCode)) {
320
+ reportFixed(fixed, { operation: CATCH, failure: "every thrown error" });
321
+ }
322
+ },
323
+ "Program:exit"(node) {
324
+ const isGrantUnused = isGranted && fixedFallbacks.size === 0;
325
+ if (isGrantUnused) {
326
+ context.report({ node, messageId: "unusedGrant" });
327
+ }
328
+ },
329
+ };
330
+ },
331
+ });
@@ -1,5 +1,4 @@
1
- import { defineRule } from "@oxlint/plugins";
2
- import type { ESTree, SourceCode } from "@oxlint/plugins";
1
+ import type { Context, CreateRule, ESTree, SourceCode } from "@oxlint/plugins";
3
2
  import { Schema } from "effect";
4
3
 
5
4
  import { moduleSpecifiersOfGlobalObject } from "../shared/bans-each-permission-lifts.ts";
@@ -119,7 +118,7 @@ const isPipeFunction = (node: ESTree.Node, sourceCode: SourceCode) => {
119
118
  return imported?.module.startsWith("effect") === true && imported.members.at(-1) === PIPE;
120
119
  };
121
120
 
122
- export const noClockReadsAndSleeps = defineRule({
121
+ export const noClockReadsAndSleeps = {
123
122
  meta: {
124
123
  type: "problem",
125
124
  messages: {
@@ -133,7 +132,7 @@ export const noClockReadsAndSleeps = defineRule({
133
132
  },
134
133
  schema: ruleOptionsJsonSchema(CLOCK_OPTIONS),
135
134
  },
136
- create(context) {
135
+ create(context: Pick<Context, "options" | "report" | "sourceCode">) {
137
136
  const { sourceCode } = context;
138
137
  const clockServiceSleeps =
139
138
  decodeRuleOptions(CLOCK_OPTIONS, context.options)?.clockServiceSleeps ?? "banned";
@@ -320,4 +319,4 @@ export const noClockReadsAndSleeps = defineRule({
320
319
  },
321
320
  };
322
321
  },
323
- });
322
+ } satisfies CreateRule;