@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
@@ -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: readonly ESTree.Node[],
189
+ steps: ReturnType<typeof stepsAppliedTo>,
203
190
  sourceCode: SourceCode,
204
- ): { readonly recovery?: string; readonly isEveryStepKeepingTheFailures: boolean } => {
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 isAppliedStep =
247
- constantValue(parent.callee, sourceCode).type === "CallExpression" &&
248
- parent.arguments.length === 1;
249
- if (isAppliedStep) {
250
- const { recovery, isEveryStepKeepingTheFailures } = recoveryAmongSteps(
251
- [parent.callee],
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, dataLastArguments)
274
- ? recoveryOf(parent, sourceCode)
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 = recoveryOf(node, sourceCode);
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 { defineRule } from "@oxlint/plugins";
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 = defineRule({
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 { 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 { 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 = defineRule({
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 { defineRule } from "@oxlint/plugins";
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 defineRule({
492
+ return {
493
493
  meta: {
494
494
  type: "problem",
495
495
  messages: {
496
496
  banned: message,
497
497
  bannedEvenWhenGranted: messageEvenWhenGranted,
498
- unusedGrant: `this file is granted ${permission}, but uses nothing ${permission} allows`,
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
  };
@@ -17,9 +17,11 @@ import {
17
17
  grantPermissions,
18
18
  permissionBanRuleId,
19
19
  FAILURES_AS_RESULTS_RULE,
20
+ FIXED_FALLBACKS_RULE,
20
21
  STDIO_SERVICE_RULE,
21
22
  TEST_TIMEOUTS_RULE,
22
23
  TYPE_PREDICATES_RULE,
24
+ UNUSED_CODE_GRANTS_RULE,
23
25
  } from "../shared/record-and-grant-permissions-by-path.ts";
24
26
  import { noAbbreviations } from "./ban-abbreviated-words-in-declared-names.ts";
25
27
  import { noUncalledMembers } from "./ban-checked-members-outside-calls.ts";
@@ -30,6 +32,7 @@ import { noDeclaredValues } from "./ban-declared-values.ts";
30
32
  import { effectOperationRule } from "./ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts";
31
33
  import { noFailuresAsResults } from "./ban-failures-collected-as-results.ts";
32
34
  import { noUnnamedFallbacks } from "./ban-fallbacks-of-named-recoveries.ts";
35
+ import { noFixedFallbacks } from "./ban-fixed-values-in-recoveries.ts";
33
36
  import { noOverloads } from "./ban-function-overloads.ts";
34
37
  import { noPlainErrorFailures } from "./ban-global-error-in-failure-types.ts";
35
38
  import { noErrorInstanceof } from "./ban-instanceof-in-effect-recovery-callbacks.ts";
@@ -69,6 +72,7 @@ import {
69
72
  } from "./keep-assertions-in-the-test-home-and-ban-test-runners.ts";
70
73
  import { noTestingHelpers } from "./keep-effect-testing-helpers-in-test-files.ts";
71
74
  import { bansByKind } from "./match-banned-modules-and-globals.ts";
75
+ import { noUnusedCodeGrants } from "./report-code-grants-nothing-uses.ts";
72
76
  import { noUnnamedCompoundConditions } from "./require-a-named-const-for-compound-conditions.ts";
73
77
  import { noLooseLiteralConstants } from "./require-capital-snake-case-and-as-const-on-literal-constants.ts";
74
78
  import { noMismatchedServiceKeys } from "./require-service-keys-to-end-with-their-class-name.ts";
@@ -136,6 +140,7 @@ const NAMED_RULES = {
136
140
  "no-instant-retries": noInstantRetries,
137
141
  "no-service-declarations": noServiceDeclarations,
138
142
  "no-unused-service-grants": noUnusedServiceGrants,
143
+ [UNUSED_CODE_GRANTS_RULE]: noUnusedCodeGrants,
139
144
  "no-glob-scan": noGlobScan,
140
145
  "no-unknown-boundaries": noUnknownBoundaries,
141
146
  "no-loose-literal-constants": noLooseLiteralConstants,
@@ -158,6 +163,7 @@ const NAMED_RULES = {
158
163
  "no-uncalled-members": noUncalledMembers,
159
164
  "no-unnamed-fallbacks": noUnnamedFallbacks,
160
165
  "no-exists-recovery": noExistsRecovery,
166
+ [FIXED_FALLBACKS_RULE]: noFixedFallbacks,
161
167
  "no-namespace-aliases": noNamespaceAliases(
162
168
  new Set([
163
169
  ...RESTRICTED_PROPERTIES.map(({ object }) => object),
@@ -0,0 +1,100 @@
1
+ import type { ESTree, SourceCode } from "@oxlint/plugins";
2
+ import { Array as Arrays, Option } from "effect";
3
+
4
+ import {
5
+ constantValue,
6
+ effectOperation,
7
+ isPipeFunction,
8
+ memberName,
9
+ } from "./resolve-what-an-expression-imports.ts";
10
+
11
+ const PIPE = "pipe";
12
+
13
+ export const stepOf = (step: ESTree.Node, sourceCode: SourceCode) => {
14
+ const node = constantValue(step, sourceCode);
15
+ if (node.type === "CallExpression") {
16
+ return {
17
+ operation: effectOperation(node.callee, sourceCode),
18
+ callArguments: node.arguments,
19
+ isDataFirst: false,
20
+ };
21
+ }
22
+ return { operation: effectOperation(node, sourceCode), callArguments: [], isDataFirst: false };
23
+ };
24
+
25
+ const stepsOf = (steps: readonly ESTree.Node[], sourceCode: SourceCode) =>
26
+ steps.map((step) => stepOf(step, sourceCode));
27
+
28
+ const isPipeMethodCall = (call: ESTree.Node | null | undefined) =>
29
+ call?.type === "CallExpression" &&
30
+ call.callee.type === "MemberExpression" &&
31
+ memberName(call.callee) === PIPE;
32
+
33
+ export const stepsAppliedTo = (
34
+ effect: ESTree.Node,
35
+ sourceCode: SourceCode,
36
+ ): readonly ReturnType<typeof stepOf>[] => {
37
+ const { parent } = effect;
38
+ const isWrappedByTypeScript =
39
+ parent?.type === "TSAsExpression" ||
40
+ parent?.type === "TSSatisfiesExpression" ||
41
+ parent?.type === "TSNonNullExpression";
42
+ if (isWrappedByTypeScript) {
43
+ return stepsAppliedTo(parent, sourceCode);
44
+ }
45
+ const call = parent?.parent;
46
+ const isPipeMethod =
47
+ parent?.type === "MemberExpression" &&
48
+ parent.object === effect &&
49
+ call?.type === "CallExpression" &&
50
+ call.callee === parent &&
51
+ isPipeMethodCall(call);
52
+ if (isPipeMethod) {
53
+ return [...stepsOf(call.arguments, sourceCode), ...stepsAppliedTo(call, sourceCode)];
54
+ }
55
+ const isFirstArgument = parent?.type === "CallExpression" && parent.arguments[0] === effect;
56
+ if (!isFirstArgument) {
57
+ return [];
58
+ }
59
+ const isAppliedStep =
60
+ constantValue(parent.callee, sourceCode).type === "CallExpression" &&
61
+ parent.arguments.length === 1;
62
+ if (isAppliedStep) {
63
+ return [stepOf(parent.callee, sourceCode), ...stepsAppliedTo(parent, sourceCode)];
64
+ }
65
+ if (isPipeFunction(parent.callee, sourceCode)) {
66
+ return [
67
+ ...stepsOf(parent.arguments.slice(1), sourceCode),
68
+ ...stepsAppliedTo(parent, sourceCode),
69
+ ];
70
+ }
71
+ return [
72
+ {
73
+ operation: effectOperation(parent.callee, sourceCode),
74
+ callArguments: parent.arguments.slice(1),
75
+ isDataFirst: true,
76
+ },
77
+ ...stepsAppliedTo(parent, sourceCode),
78
+ ];
79
+ };
80
+
81
+ export const stepsAfter = (step: ESTree.Node, sourceCode: SourceCode) => {
82
+ const { parent } = step;
83
+ if (parent?.type !== "CallExpression") {
84
+ return [];
85
+ }
86
+ const position = Option.getOrUndefined(
87
+ Arrays.findFirstIndex(parent.arguments, (argument) => argument === step),
88
+ );
89
+ if (position === undefined) {
90
+ return [];
91
+ }
92
+ const isPipeStep =
93
+ isPipeMethodCall(parent) || (position > 0 && isPipeFunction(parent.callee, sourceCode));
94
+ return isPipeStep
95
+ ? [
96
+ ...stepsOf(parent.arguments.slice(position + 1), sourceCode),
97
+ ...stepsAppliedTo(parent, sourceCode),
98
+ ]
99
+ : [];
100
+ };