@sshkeda/check 2.1.0 → 3.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.
- package/README.md +52 -22
- package/docs/how-to-make-check-pass.md +3 -0
- package/package.json +7 -10
- package/scripts/check.ts +10 -0
- package/src/internal/ban-abbreviated-words-in-declared-names.ts +4 -5
- package/src/internal/ban-deadlines-inside-tests.ts +4 -5
- package/src/internal/ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts +4 -5
- package/src/internal/ban-failures-collected-as-results.ts +4 -5
- package/src/internal/ban-fallbacks-of-named-recoveries.ts +6 -7
- package/src/internal/ban-fixed-values-in-recoveries.ts +331 -0
- package/src/internal/ban-re-exports.ts +14 -1
- package/src/internal/ban-reading-the-clock-and-sleeping-outside-effect.ts +4 -5
- package/src/internal/ban-recovering-file-system-exists.ts +12 -79
- package/src/internal/ban-timer-schedules-without-deadlines.ts +5 -6
- package/src/internal/ban-type-predicates.ts +4 -5
- package/src/internal/ban-what-a-file-is-not-granted.ts +9 -9
- package/src/internal/define-the-lint-plugin-and-configs.ts +6 -2
- package/src/internal/follow-the-steps-applied-to-an-effect.ts +100 -0
- package/src/internal/recognize-fixed-values.ts +318 -0
- package/src/internal/recognize-whole-library-error-tags.ts +6 -0
- package/src/internal/report-code-grants-nothing-uses.ts +122 -0
- package/src/lib/project-directory/index.ts +5 -0
- package/src/lib/project-directory/internal/read-the-project-directory.ts +13 -0
- package/src/lib/tasks/internal/declare-the-check-task.ts +18 -10
- package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +3 -1
- package/src/lib/tasks/internal/verify-where-check-was-started.ts +50 -0
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +1 -1
- package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/read-effect-tsgo-json-report.ts +13 -9
- package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +6 -36
- package/src/lib/tasks/lib/detect-duplicate-functions/internal/find-duplicate-functions.ts +2 -3
- package/src/lib/tasks/lib/enforce-file-layout/internal/check-the-layout-of-each-package.ts +1 -1
- package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +19 -2
- package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +53 -19
- package/src/lib/tasks/lib/enforce-file-types/internal/find-file-type-violations.ts +1 -1
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/check-formatting-with-bun-fmt.ts +17 -16
- package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +22 -14
- package/src/lib/tasks/lib/lint-with-oxlint/index.ts +1 -1
- package/src/lib/tasks/lib/lint-with-oxlint/internal/check-lint-rules-with-oxlint.ts +7 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/find-shebangs-outside-bin.ts +38 -0
- package/src/lib/tasks/lib/lint-with-oxlint/internal/shebang-errors.ts +22 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-export-placement-violations.ts +9 -1
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-the-importer-graph.ts +21 -0
- package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/recognise-task-default-exports.ts +76 -0
- package/src/lib/tasks/lib/refuse-disable-directives/index.ts +1 -1
- package/src/lib/tasks/lib/refuse-forks-whose-failures-nothing-observes/index.ts +1 -0
- package/src/lib/tasks/lib/refuse-forks-whose-failures-nothing-observes/internal/find-unobserved-fork-failures.ts +402 -0
- package/src/lib/tasks/lib/refuse-forks-whose-failures-nothing-observes/internal/fork-failure-errors.ts +28 -0
- package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/find-linted-files-not-type-checked.ts +15 -9
- package/src/lib/tasks/lib/type-check-with-bun-check/index.ts +1 -1
- package/src/lib/tasks/shared/check-each-nested-package.ts +13 -5
- package/src/lib/tasks/shared/declare-lint-config-task.ts +1 -1
- package/src/lib/tasks/shared/declare-typescript-config-task.ts +1 -1
- package/src/lib/tasks/shared/find-installed-package-binaries.ts +10 -0
- package/src/lib/tasks/shared/list-package-files.ts +15 -2
- package/src/lib/tasks/shared/read-piped-steps-through-wrappers.ts +41 -0
- package/src/lib/tasks/shared/report-paths-from-the-project.ts +56 -0
- package/src/shared/bans-each-permission-lifts.ts +3 -0
- package/src/shared/format-reported-failures.ts +8 -6
- package/src/shared/record-and-grant-permissions-by-path.ts +63 -7
- package/src/internal/ban-shebang-lines.ts +0 -22
- /package/src/lib/tasks/{lib/format-with-bun-fmt/internal → shared}/find-symbolic-links.ts +0 -0
|
@@ -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,8 +1,10 @@
|
|
|
1
1
|
import { defineRule } from "@oxlint/plugins";
|
|
2
2
|
import type { ESTree } from "@oxlint/plugins";
|
|
3
|
+
import { Schema } from "effect";
|
|
3
4
|
|
|
4
5
|
import { FORMAT_CONFIG_BINDING, FORMAT_CONFIG_FILE } from "../shared/config-file-names.ts";
|
|
5
6
|
import { fileNameOf, isEntryFileName } from "../shared/match-file-names-and-path-prefixes.ts";
|
|
7
|
+
import { decodeRuleOptions, ruleOptionsJsonSchema } from "./describe-and-decode-rule-options.ts";
|
|
6
8
|
import {
|
|
7
9
|
DEFAULT_EXPORT,
|
|
8
10
|
importedBindingOf,
|
|
@@ -13,6 +15,12 @@ import {
|
|
|
13
15
|
unwrappedExpression,
|
|
14
16
|
} from "./resolve-what-an-expression-imports.ts";
|
|
15
17
|
|
|
18
|
+
const DEFAULT_EXPORTS_OF_IMPORTS = ["banned", "allowed"] as const;
|
|
19
|
+
|
|
20
|
+
const RE_EXPORTS_OPTIONS = Schema.Struct({
|
|
21
|
+
defaultExportOfAnImport: Schema.optionalKey(Schema.Literals(DEFAULT_EXPORTS_OF_IMPORTS)),
|
|
22
|
+
});
|
|
23
|
+
|
|
16
24
|
export const noReExports = defineRule({
|
|
17
25
|
meta: {
|
|
18
26
|
type: "suggestion",
|
|
@@ -30,8 +38,11 @@ export const noReExports = defineRule({
|
|
|
30
38
|
importEquals: "export import {{name}} re-exports another module",
|
|
31
39
|
exportAssignment: "export = replaces the module's exports",
|
|
32
40
|
},
|
|
41
|
+
schema: ruleOptionsJsonSchema(RE_EXPORTS_OPTIONS),
|
|
33
42
|
},
|
|
34
43
|
create(context) {
|
|
44
|
+
const defaultExportOfAnImport =
|
|
45
|
+
decodeRuleOptions(RE_EXPORTS_OPTIONS, context.options)?.defaultExportOfAnImport ?? "banned";
|
|
35
46
|
const isIndexFile = isEntryFileName(fileNameOf(context.filename));
|
|
36
47
|
const isFormatConfigFile = fileNameOf(context.filename) === FORMAT_CONFIG_FILE;
|
|
37
48
|
const reportImport = (
|
|
@@ -195,7 +206,9 @@ export const noReExports = defineRule({
|
|
|
195
206
|
statement.declaration.name === FORMAT_CONFIG_BINDING &&
|
|
196
207
|
importedExpression(statement.declaration, context.sourceCode)?.members.join() ===
|
|
197
208
|
FORMAT_CONFIG_BINDING;
|
|
198
|
-
|
|
209
|
+
const isAllowedDefaultExport =
|
|
210
|
+
exportsTheFormatConfig || defaultExportOfAnImport === "allowed";
|
|
211
|
+
if (!isAllowedDefaultExport) {
|
|
199
212
|
reportImported(statement, DEFAULT_EXPORT, statement.declaration);
|
|
200
213
|
}
|
|
201
214
|
} else if (statement.type === "TSExportAssignment") {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 =
|
|
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;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { defineRule } from "@oxlint/plugins";
|
|
2
2
|
import type { ESTree, SourceCode } from "@oxlint/plugins";
|
|
3
3
|
|
|
4
|
+
import { stepsAppliedTo } from "./follow-the-steps-applied-to-an-effect.ts";
|
|
4
5
|
import {
|
|
5
6
|
constantValue,
|
|
6
7
|
effectOperation,
|
|
7
8
|
importedExpression,
|
|
8
|
-
isPipeFunction,
|
|
9
9
|
memberName,
|
|
10
10
|
propertyKeyName,
|
|
11
11
|
resolvedVariable,
|
|
@@ -16,8 +16,6 @@ import {
|
|
|
16
16
|
|
|
17
17
|
const EXISTS = "exists";
|
|
18
18
|
|
|
19
|
-
const PIPE = "pipe";
|
|
20
|
-
|
|
21
19
|
const PLATFORM_ERROR = "PlatformError";
|
|
22
20
|
|
|
23
21
|
const OPERATIONS_THAT_KEEP_THE_FAILURES = new Set(["map", "as"]);
|
|
@@ -167,17 +165,6 @@ const RECOVERIES = new Map([
|
|
|
167
165
|
["option", { arity: 0, swallows: alwaysSwallows }],
|
|
168
166
|
]);
|
|
169
167
|
|
|
170
|
-
const stepOperation = (step: ESTree.Node, sourceCode: SourceCode) => {
|
|
171
|
-
const node = constantValue(step, sourceCode);
|
|
172
|
-
if (node.type === "CallExpression") {
|
|
173
|
-
return {
|
|
174
|
-
operation: effectOperation(node.callee, sourceCode),
|
|
175
|
-
callArguments: node.arguments,
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
return { operation: effectOperation(node, sourceCode), callArguments: [] };
|
|
179
|
-
};
|
|
180
|
-
|
|
181
168
|
const swallowingRecovery = (
|
|
182
169
|
operation: string | undefined,
|
|
183
170
|
callArguments: readonly ESTree.Node[],
|
|
@@ -199,79 +186,25 @@ const keepsTheFailures = (operation: string | undefined, callArguments: readonly
|
|
|
199
186
|
callArguments.length === 1;
|
|
200
187
|
|
|
201
188
|
const recoveryAmongSteps = (
|
|
202
|
-
steps:
|
|
189
|
+
steps: ReturnType<typeof stepsAppliedTo>,
|
|
203
190
|
sourceCode: SourceCode,
|
|
204
|
-
):
|
|
191
|
+
): string | undefined => {
|
|
205
192
|
const [step, ...rest] = steps;
|
|
206
193
|
if (step === undefined) {
|
|
207
|
-
return { isEveryStepKeepingTheFailures: true };
|
|
208
|
-
}
|
|
209
|
-
const { operation, callArguments } = stepOperation(step, sourceCode);
|
|
210
|
-
const recovery = swallowingRecovery(operation, callArguments, sourceCode);
|
|
211
|
-
if (recovery !== undefined) {
|
|
212
|
-
return { recovery, isEveryStepKeepingTheFailures: false };
|
|
213
|
-
}
|
|
214
|
-
return keepsTheFailures(operation, callArguments)
|
|
215
|
-
? recoveryAmongSteps(rest, sourceCode)
|
|
216
|
-
: { isEveryStepKeepingTheFailures: false };
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const recoveryOf = (effect: ESTree.Node, sourceCode: SourceCode): string | undefined => {
|
|
220
|
-
const { parent } = effect;
|
|
221
|
-
const isWrappedByTypeScript =
|
|
222
|
-
parent?.type === "TSAsExpression" ||
|
|
223
|
-
parent?.type === "TSSatisfiesExpression" ||
|
|
224
|
-
parent?.type === "TSNonNullExpression";
|
|
225
|
-
if (isWrappedByTypeScript) {
|
|
226
|
-
return recoveryOf(parent, sourceCode);
|
|
227
|
-
}
|
|
228
|
-
const call = parent?.parent;
|
|
229
|
-
const isPipeMethod =
|
|
230
|
-
parent?.type === "MemberExpression" &&
|
|
231
|
-
parent.object === effect &&
|
|
232
|
-
memberName(parent) === PIPE &&
|
|
233
|
-
call?.type === "CallExpression" &&
|
|
234
|
-
call.callee === parent;
|
|
235
|
-
if (isPipeMethod) {
|
|
236
|
-
const { recovery, isEveryStepKeepingTheFailures } = recoveryAmongSteps(
|
|
237
|
-
call.arguments,
|
|
238
|
-
sourceCode,
|
|
239
|
-
);
|
|
240
|
-
return isEveryStepKeepingTheFailures ? recoveryOf(call, sourceCode) : recovery;
|
|
241
|
-
}
|
|
242
|
-
const isFirstArgument = parent?.type === "CallExpression" && parent.arguments[0] === effect;
|
|
243
|
-
if (!isFirstArgument) {
|
|
244
194
|
return;
|
|
245
195
|
}
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
sourceCode,
|
|
253
|
-
);
|
|
254
|
-
return isEveryStepKeepingTheFailures ? recoveryOf(parent, sourceCode) : recovery;
|
|
255
|
-
}
|
|
256
|
-
if (isPipeFunction(parent.callee, sourceCode)) {
|
|
257
|
-
const { recovery, isEveryStepKeepingTheFailures } = recoveryAmongSteps(
|
|
258
|
-
parent.arguments.slice(1),
|
|
259
|
-
sourceCode,
|
|
260
|
-
);
|
|
261
|
-
return isEveryStepKeepingTheFailures ? recoveryOf(parent, sourceCode) : recovery;
|
|
262
|
-
}
|
|
263
|
-
const operation = effectOperation(parent.callee, sourceCode);
|
|
264
|
-
const dataLastArguments = parent.arguments.slice(1);
|
|
265
|
-
const isDataFirstRecovery =
|
|
266
|
-
operation !== undefined && RECOVERIES.get(operation)?.arity === dataLastArguments.length;
|
|
267
|
-
const recovery = isDataFirstRecovery
|
|
268
|
-
? swallowingRecovery(operation, dataLastArguments, sourceCode)
|
|
196
|
+
const { operation, callArguments, isDataFirst } = step;
|
|
197
|
+
const isRecoveryShape =
|
|
198
|
+
!isDataFirst ||
|
|
199
|
+
(operation !== undefined && RECOVERIES.get(operation)?.arity === callArguments.length);
|
|
200
|
+
const recovery = isRecoveryShape
|
|
201
|
+
? swallowingRecovery(operation, callArguments, sourceCode)
|
|
269
202
|
: undefined;
|
|
270
203
|
if (recovery !== undefined) {
|
|
271
204
|
return recovery;
|
|
272
205
|
}
|
|
273
|
-
return keepsTheFailures(operation,
|
|
274
|
-
?
|
|
206
|
+
return keepsTheFailures(operation, callArguments)
|
|
207
|
+
? recoveryAmongSteps(rest, sourceCode)
|
|
275
208
|
: undefined;
|
|
276
209
|
};
|
|
277
210
|
|
|
@@ -290,7 +223,7 @@ export const noExistsRecovery = defineRule({
|
|
|
290
223
|
if (!isFileSystemExists(node.callee, sourceCode)) {
|
|
291
224
|
return;
|
|
292
225
|
}
|
|
293
|
-
const recovery =
|
|
226
|
+
const recovery = recoveryAmongSteps(stepsAppliedTo(node, sourceCode), sourceCode);
|
|
294
227
|
if (recovery !== undefined) {
|
|
295
228
|
context.report({ node, messageId: "recovered", data: { recovery } });
|
|
296
229
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Context, ESTree } from "@oxlint/plugins";
|
|
1
|
+
import type { Context, CreateRule, ESTree } from "@oxlint/plugins";
|
|
3
2
|
import { Schema } from "effect";
|
|
4
3
|
|
|
5
4
|
import { SCHEDULE_MESSAGES } from "../shared/lint-rule-messages-and-patterns.ts";
|
|
@@ -63,7 +62,7 @@ export const scheduleVisitors = ({
|
|
|
63
62
|
context,
|
|
64
63
|
timedSchedules,
|
|
65
64
|
}: {
|
|
66
|
-
readonly context: Context
|
|
65
|
+
readonly context: Pick<Context, "report" | "sourceCode">;
|
|
67
66
|
readonly timedSchedules: (typeof TIMED_SCHEDULES)[number];
|
|
68
67
|
}) => {
|
|
69
68
|
const isDeadlineCall = (node: ESTree.Node) => {
|
|
@@ -308,17 +307,17 @@ export const scheduleVisitors = ({
|
|
|
308
307
|
};
|
|
309
308
|
};
|
|
310
309
|
|
|
311
|
-
export const noSchedules =
|
|
310
|
+
export const noSchedules = {
|
|
312
311
|
meta: {
|
|
313
312
|
type: "problem",
|
|
314
313
|
messages: SCHEDULE_MESSAGES,
|
|
315
314
|
schema: ruleOptionsJsonSchema(SCHEDULE_OPTIONS),
|
|
316
315
|
},
|
|
317
|
-
create(context) {
|
|
316
|
+
create(context: Pick<Context, "options" | "report" | "sourceCode">) {
|
|
318
317
|
return scheduleVisitors({
|
|
319
318
|
context,
|
|
320
319
|
timedSchedules:
|
|
321
320
|
decodeRuleOptions(SCHEDULE_OPTIONS, context.options)?.timedSchedules ?? "banned",
|
|
322
321
|
});
|
|
323
322
|
},
|
|
324
|
-
}
|
|
323
|
+
} satisfies CreateRule;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 { decodeRuleOptions, ruleOptionsJsonSchema } from "./describe-and-decode-rule-options.ts";
|
|
@@ -47,7 +46,7 @@ const isSchemaDeclarationCallback = (predicate: ESTree.TSTypePredicate, sourceCo
|
|
|
47
46
|
);
|
|
48
47
|
};
|
|
49
48
|
|
|
50
|
-
export const noTypePredicates =
|
|
49
|
+
export const noTypePredicates = {
|
|
51
50
|
meta: {
|
|
52
51
|
type: "problem",
|
|
53
52
|
messages: {
|
|
@@ -55,7 +54,7 @@ export const noTypePredicates = defineRule({
|
|
|
55
54
|
},
|
|
56
55
|
schema: ruleOptionsJsonSchema(TYPE_PREDICATE_OPTIONS),
|
|
57
56
|
},
|
|
58
|
-
create(context) {
|
|
57
|
+
create(context: Pick<Context, "options" | "report" | "sourceCode">) {
|
|
59
58
|
const schemaDeclarations =
|
|
60
59
|
decodeRuleOptions(TYPE_PREDICATE_OPTIONS, context.options)?.schemaDeclarations ?? "banned";
|
|
61
60
|
return {
|
|
@@ -75,4 +74,4 @@ export const noTypePredicates = defineRule({
|
|
|
75
74
|
},
|
|
76
75
|
};
|
|
77
76
|
},
|
|
78
|
-
}
|
|
77
|
+
} satisfies CreateRule;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Context, ESTree, SourceCode, Visitor } from "@oxlint/plugins";
|
|
1
|
+
import type { Context, CreateRule, ESTree, SourceCode, Visitor } from "@oxlint/plugins";
|
|
3
2
|
import { Schema } from "effect";
|
|
4
3
|
|
|
5
4
|
import {
|
|
@@ -11,6 +10,7 @@ import {
|
|
|
11
10
|
moduleSpecifiersOfGlobalObject,
|
|
12
11
|
PERMISSION_BANS,
|
|
13
12
|
UNUSED_GRANT_REPORTED,
|
|
13
|
+
unusedGrantMessage,
|
|
14
14
|
} from "../shared/bans-each-permission-lifts.ts";
|
|
15
15
|
import type { importsBan } from "../shared/bans-each-permission-lifts.ts";
|
|
16
16
|
import { decodeRuleOptions, ruleOptionsJsonSchema } from "./describe-and-decode-rule-options.ts";
|
|
@@ -147,7 +147,7 @@ const isGlobalObjectReference = (
|
|
|
147
147
|
);
|
|
148
148
|
};
|
|
149
149
|
|
|
150
|
-
const mergedVisitors = (visitors: readonly Visitor[]): Visitor => {
|
|
150
|
+
export const mergedVisitors = (visitors: readonly Visitor[]): Visitor => {
|
|
151
151
|
const handlers = new Map<string, ((node: never) => void)[]>();
|
|
152
152
|
for (const visitor of visitors) {
|
|
153
153
|
for (const [key, handler] of Object.entries(visitor)) {
|
|
@@ -192,7 +192,7 @@ const isInATypeQuery = (node: ESTree.Node): boolean => {
|
|
|
192
192
|
};
|
|
193
193
|
|
|
194
194
|
const createdRequireVisitors = (
|
|
195
|
-
context: Context,
|
|
195
|
+
context: Pick<Context, "sourceCode">,
|
|
196
196
|
createdRequires: readonly {
|
|
197
197
|
readonly matchesModule: (specifier: string) => boolean;
|
|
198
198
|
readonly importNames: readonly string[];
|
|
@@ -328,7 +328,7 @@ const compiledBans = (bans: Parameters<typeof bansByKind>[0]) => {
|
|
|
328
328
|
};
|
|
329
329
|
|
|
330
330
|
const banVisitors = (
|
|
331
|
-
context: Context,
|
|
331
|
+
context: Pick<Context, "sourceCode">,
|
|
332
332
|
{
|
|
333
333
|
isBannedModule,
|
|
334
334
|
bannedImport,
|
|
@@ -489,17 +489,17 @@ export const permissionBanRule = (permission: keyof typeof PERMISSION_BANS) => {
|
|
|
489
489
|
const messageEvenWhenGranted =
|
|
490
490
|
"bannedEvenWhenGranted" in entry ? entry.bannedEvenWhenGranted.message : message;
|
|
491
491
|
|
|
492
|
-
return
|
|
492
|
+
return {
|
|
493
493
|
meta: {
|
|
494
494
|
type: "problem",
|
|
495
495
|
messages: {
|
|
496
496
|
banned: message,
|
|
497
497
|
bannedEvenWhenGranted: messageEvenWhenGranted,
|
|
498
|
-
unusedGrant:
|
|
498
|
+
unusedGrant: unusedGrantMessage(permission),
|
|
499
499
|
},
|
|
500
500
|
schema: ruleOptionsJsonSchema(BAN_OPTIONS),
|
|
501
501
|
},
|
|
502
|
-
create(context) {
|
|
502
|
+
create(context: Pick<Context, "options" | "report" | "sourceCode">) {
|
|
503
503
|
const options = decodeRuleOptions(BAN_OPTIONS, context.options);
|
|
504
504
|
const isGranted = options?.bans === BANS_NO_GRANT_LIFTS;
|
|
505
505
|
const reporterOf =
|
|
@@ -531,5 +531,5 @@ export const permissionBanRule = (permission: keyof typeof PERMISSION_BANS) => {
|
|
|
531
531
|
: []),
|
|
532
532
|
]);
|
|
533
533
|
},
|
|
534
|
-
}
|
|
534
|
+
} satisfies CreateRule;
|
|
535
535
|
};
|