@sshkeda/check 1.1.0 → 2.1.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 (102) hide show
  1. package/README.md +7 -6
  2. package/docs/how-to-make-check-pass.md +4 -14
  3. package/package.json +4 -4
  4. package/src/internal/ban-abbreviated-words-in-declared-names.ts +0 -4
  5. package/src/internal/ban-checked-members-outside-calls.ts +8 -8
  6. package/src/internal/ban-comments.ts +0 -1
  7. package/src/internal/ban-comparing-or-switching-on-tag.ts +50 -10
  8. package/src/internal/ban-deadlines-inside-tests.ts +3 -4
  9. package/src/internal/ban-declared-values.ts +2 -5
  10. package/src/internal/ban-dropped-failures-detached-fibers-sleeps-and-untraced-functions.ts +0 -2
  11. package/src/internal/ban-failures-collected-as-results.ts +0 -4
  12. package/src/internal/ban-fallbacks-of-named-recoveries.ts +1 -29
  13. package/src/internal/ban-function-overloads.ts +0 -4
  14. package/src/internal/ban-global-error-in-failure-types.ts +10 -15
  15. package/src/internal/ban-instanceof-in-effect-recovery-callbacks.ts +17 -26
  16. package/src/internal/ban-let-and-effect-mutable-ref.ts +0 -8
  17. package/src/internal/ban-logic-in-index-files.ts +0 -3
  18. package/src/internal/ban-namespaces-used-without-a-member.ts +0 -3
  19. package/src/internal/ban-node-builtins-that-effect-replaces.ts +0 -3
  20. package/src/internal/ban-parsing-outside-data-without-a-schema.ts +0 -4
  21. package/src/internal/ban-re-exports.ts +54 -18
  22. package/src/internal/ban-reading-the-clock-and-sleeping-outside-effect.ts +88 -4
  23. package/src/internal/ban-recovering-file-system-exists.ts +300 -0
  24. package/src/internal/ban-retired-words-in-names.ts +1 -4
  25. package/src/internal/ban-retries-without-a-wait.ts +292 -0
  26. package/src/internal/ban-scanning-directories-with-bun-glob.ts +0 -3
  27. package/src/internal/ban-shebang-lines.ts +0 -4
  28. package/src/internal/ban-timer-globals-and-the-global-object.ts +0 -1
  29. package/src/internal/ban-timer-schedules-without-deadlines.ts +129 -45
  30. package/src/internal/ban-type-and-interface-declarations.ts +0 -4
  31. package/src/internal/ban-type-predicates.ts +0 -4
  32. package/src/internal/ban-unknown-in-function-signatures.ts +49 -13
  33. package/src/internal/ban-vague-error-class-names.ts +0 -4
  34. package/src/internal/ban-vague-file-names.ts +3 -7
  35. package/src/internal/ban-what-a-file-is-not-granted.ts +37 -14
  36. package/src/internal/ban-while-do-while-and-for-loops.ts +0 -4
  37. package/src/internal/ban-writing-captured-objects-inside-effect-callbacks.ts +210 -0
  38. package/src/internal/confine-service-declarations-to-granted-files.ts +0 -7
  39. package/src/internal/confine-the-stdio-service-to-terminal-output.ts +2 -16
  40. package/src/internal/define-the-lint-plugin-and-configs.ts +6 -0
  41. package/src/internal/keep-assertions-in-the-test-home-and-ban-test-runners.ts +0 -6
  42. package/src/internal/keep-effect-testing-helpers-in-test-files.ts +2 -14
  43. package/src/internal/require-a-named-const-for-compound-conditions.ts +0 -4
  44. package/src/internal/require-capital-snake-case-and-as-const-on-literal-constants.ts +0 -4
  45. package/src/internal/require-service-keys-to-end-with-their-class-name.ts +5 -2
  46. package/src/internal/resolve-what-an-expression-imports.ts +115 -28
  47. package/src/internal/visit-every-declared-name.ts +13 -0
  48. package/src/lib/tasks/internal/declare-the-check-task.ts +2 -0
  49. package/src/lib/tasks/internal/declare-the-checker-queries-task.ts +2 -1
  50. package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/index.ts +2 -1
  51. package/src/lib/tasks/lib/check-effect-diagnostics-with-effect-tsgo/internal/check-effect-diagnostics-with-effect-tsgo.ts +17 -0
  52. package/src/lib/tasks/lib/check-import-boundaries/internal/decide-what-each-home-may-import.ts +62 -0
  53. package/src/lib/tasks/lib/check-import-boundaries/internal/find-import-boundary-violations.ts +215 -187
  54. package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/find-layer-provides-outside-program-starts.ts +13 -16
  55. package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/layer-provide-errors.ts +2 -1
  56. package/src/lib/tasks/lib/confine-layer-provides-to-program-starts/internal/resolve-imported-package-apis.ts +3 -1
  57. package/src/lib/tasks/lib/detect-duplicate-functions/index.ts +10 -0
  58. package/src/lib/tasks/lib/detect-duplicate-functions/internal/duplicate-function-errors.ts +23 -0
  59. package/src/lib/tasks/lib/detect-duplicate-functions/internal/find-duplicate-functions.ts +150 -0
  60. package/src/lib/tasks/lib/detect-duplicate-functions/internal/list-named-functions.ts +416 -0
  61. package/src/lib/tasks/lib/detect-inferrable-annotations/internal/find-inferrable-annotations.ts +31 -12
  62. package/src/lib/tasks/lib/enforce-file-layout/index.ts +6 -1
  63. package/src/lib/tasks/lib/enforce-file-layout/internal/file-layout-errors.ts +11 -1
  64. package/src/lib/tasks/lib/enforce-file-layout/internal/find-export-path-mismatches.ts +39 -7
  65. package/src/lib/tasks/lib/enforce-file-layout/internal/find-file-layout-violations.ts +11 -4
  66. package/src/lib/tasks/lib/enforce-file-layout/internal/find-module-layout-violations.ts +6 -4
  67. package/src/lib/tasks/lib/enforce-file-types/index.ts +6 -1
  68. package/src/lib/tasks/lib/format-with-bun-fmt/internal/declare-the-formatting-task.ts +3 -2
  69. package/src/lib/tasks/lib/judge-index-re-exports/internal/find-index-re-export-violations.ts +27 -21
  70. package/src/lib/tasks/lib/lint-with-oxlint/index.ts +2 -1
  71. package/src/lib/tasks/lib/lint-with-oxlint/internal/check-lint-rules-with-oxlint.ts +11 -8
  72. package/src/lib/tasks/lib/lint-with-oxlint/internal/read-oxlint-json-report.ts +18 -2
  73. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/export-placement-errors.ts +12 -1
  74. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-export-placement-violations.ts +75 -21
  75. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-package-entry-sources.ts +146 -0
  76. package/src/lib/tasks/lib/place-exports-in-the-narrowest-directory/internal/find-the-importer-graph.ts +24 -190
  77. package/src/lib/tasks/lib/refuse-disable-directives/index.ts +2 -1
  78. package/src/lib/tasks/lib/refuse-disable-directives/internal/find-disable-directives.ts +9 -3
  79. package/src/lib/tasks/lib/refuse-error-mappings-that-end-streams/internal/find-error-mappings-to-done.ts +108 -9
  80. package/src/lib/tasks/lib/require-separate-service-layers/internal/find-service-layer-violations.ts +1 -5
  81. package/src/lib/tasks/lib/require-type-checking-every-linted-file/index.ts +2 -1
  82. package/src/lib/tasks/lib/require-type-checking-every-linted-file/internal/find-linted-files-not-type-checked.ts +2 -4
  83. package/src/lib/tasks/shared/check-each-nested-package.ts +13 -1
  84. package/src/lib/tasks/shared/classify-files-by-role.ts +12 -2
  85. package/src/lib/tasks/shared/count-the-line-of-an-offset.ts +20 -2
  86. package/src/lib/tasks/shared/create-the-module-resolver.ts +39 -23
  87. package/src/lib/tasks/shared/declare-lint-config-task.ts +2 -1
  88. package/src/lib/tasks/shared/declare-typescript-config-task.ts +30 -2
  89. package/src/lib/tasks/shared/find-unmet-typescript-config-requirements.ts +19 -6
  90. package/src/lib/tasks/shared/list-ignored-files-imported-by-source.ts +25 -16
  91. package/src/lib/tasks/shared/load-the-lint-config.ts +14 -12
  92. package/src/lib/tasks/shared/parse-config-files-that-import-from-check.ts +6 -7
  93. package/src/lib/tasks/shared/project-config-and-tool-errors.ts +46 -2
  94. package/src/lib/tasks/shared/provide-project-query-caches.ts +11 -0
  95. package/src/lib/tasks/shared/query-the-typescript-project.ts +108 -43
  96. package/src/lib/tasks/shared/resolve-absolute-paths.ts +4 -1
  97. package/src/lib/tasks/shared/resolve-module-requests.ts +131 -90
  98. package/src/lib/tasks/shared/run-tools-and-decode-their-reports.ts +15 -11
  99. package/src/shared/bans-each-permission-lifts.ts +4 -21
  100. package/src/shared/find-retired-words.ts +1 -1
  101. package/src/shared/lint-rule-messages-and-patterns.ts +7 -12
  102. package/src/shared/record-and-grant-permissions-by-path.ts +41 -65
@@ -10,8 +10,6 @@ export const isDirective = (commentText: string) =>
10
10
 
11
11
  export const EFFECT_OPERATION_RULES = {
12
12
  "no-dropped-failures": {
13
- description:
14
- "Handle Effect, Layer, Stream and Channel failures instead of dying, and read an Option or Result without throwing.",
15
13
  operations: {
16
14
  Effect: ["orDie", "orDieWith"],
17
15
  Layer: ["orDie"],
@@ -19,25 +17,25 @@ export const EFFECT_OPERATION_RULES = {
19
17
  Channel: ["orDie"],
20
18
  Option: ["getOrThrow", "getOrThrowWith"],
21
19
  Result: ["getOrThrow", "getOrThrowWith"],
20
+ UndefinedOr: ["getOrThrow", "getOrThrowWith"],
22
21
  },
23
22
  },
24
23
  "no-detached-fibers": {
25
- description: "Fork fibers into a scope instead of detaching them.",
26
24
  operations: { Effect: ["forkDetach"] },
27
25
  },
28
26
  "no-sleep": {
29
- description: "Wait on signals instead of sleeping.",
30
- operations: { Effect: ["sleep", "delay"] },
27
+ operations: {
28
+ Effect: ["sleep", "delay"],
29
+ Stream: ["tick", "debounce", "throttle", "throttleEffect"],
30
+ },
31
31
  },
32
32
  "no-untraced-functions": {
33
- description: "Trace Effect functions.",
34
- operations: { Effect: ["fnUntraced"] },
33
+ operations: { Effect: ["fnUntraced", "fnUntracedEager"] },
35
34
  },
36
35
  } as const satisfies Readonly<
37
36
  Record<
38
37
  string,
39
38
  {
40
- readonly description: string;
41
39
  readonly operations: Readonly<Record<string, readonly string[]>>;
42
40
  }
43
41
  >
@@ -61,10 +59,7 @@ export const SCHEDULE_MESSAGES = {
61
59
  polling: "{{usage}} polls on a timer",
62
60
  deadline: "{{usage}} polls without a deadline",
63
61
  retrying: "{{usage}} retries on a timer",
64
- retryingEvenWhenGranted:
65
- "{{usage}} retries on a timer, which no file may do, even with a deadline",
66
- scheduleEvenWhenGranted:
67
- "{{usage}} is a timed schedule no file may use; repeat with Schedule.spaced under a deadline in a file allowed pollsWithADeadline",
62
+ scheduleEvenWhenGranted: "{{usage}} is a timed schedule no file may use",
68
63
  } as const;
69
64
 
70
65
  export const BUN_TEST = "bun:test";
@@ -6,10 +6,12 @@ import {
6
6
  GRANTABLE_BAN_NAMES,
7
7
  HANDLES_EVERY_FAILURE,
8
8
  PERMISSION_BANS,
9
+ READS_CONFIG,
9
10
  RULES_EACH_PERMISSION_LIFTS,
10
11
  SCRIPT,
11
12
  SHORT_NAMES,
12
13
  TRUSTS_UNVERIFIED_TYPES,
14
+ UNUSED_GRANT_REPORTED,
13
15
  WRITES_TO_THE_TERMINAL,
14
16
  } from "./bans-each-permission-lifts.ts";
15
17
  import { isWithin } from "./match-file-names-and-path-prefixes.ts";
@@ -26,6 +28,9 @@ export const STDIO_SERVICE_RULE = "no-stdio-service";
26
28
  export const FAILURES_AS_RESULTS_RULE = "no-failures-as-results";
27
29
  const UNNAMED_FALLBACKS_RULE = "no-unnamed-fallbacks";
28
30
  const SCHEDULES = "pollsWithADeadline";
31
+ const TIMERS = "waitsOnTimers";
32
+ const SLEEP_RULE = "no-sleep";
33
+ const CLOCK_RULE = "no-clock-reads-and-sleeps";
29
34
  const GLOB_CHARACTERS = /[*?[\]{}]/u;
30
35
  const ROUTE_PARAMETER_SEGMENT = /^\[\[?(?:\.\.\.)?[A-Za-z0-9_-]+\]\]?$/u;
31
36
 
@@ -35,30 +40,14 @@ const isGlobPath = (path: string) =>
35
40
  .some((segment) => !ROUTE_PARAMETER_SEGMENT.test(segment) && GLOB_CHARACTERS.test(segment));
36
41
  const MARKDOWN_EXTENSIONS = [".md", ".markdown"] as const;
37
42
 
38
- const UNREASONED_PERMISSION_NAMES = [
43
+ export const PERMISSION_NAMES = [
39
44
  ...GRANTABLE_BAN_NAMES,
40
45
  SHORT_NAMES,
41
46
  SCHEDULES,
47
+ TIMERS,
42
48
  DIRECTORY,
43
49
  PATCH,
44
50
  FILE_TYPE,
45
- ] satisfies readonly (
46
- | (typeof GRANTABLE_BAN_NAMES)[number]
47
- | typeof DIRECTORY
48
- | typeof FILE_TYPE
49
- | typeof PATCH
50
- | typeof SCHEDULES
51
- | typeof SHORT_NAMES
52
- )[];
53
-
54
- const REASONED_PERMISSION_NAMES: ReadonlySet<string> = new Set([
55
- TRUSTS_UNVERIFIED_TYPES,
56
- HANDLES_EVERY_FAILURE,
57
- GENERATED,
58
- ]);
59
-
60
- export const PERMISSION_NAMES = [
61
- ...UNREASONED_PERMISSION_NAMES,
62
51
  TRUSTS_UNVERIFIED_TYPES,
63
52
  HANDLES_EVERY_FAILURE,
64
53
  GENERATED,
@@ -77,9 +66,19 @@ export const permissionBanRuleId = (permission: keyof typeof PERMISSION_BANS) =>
77
66
 
78
67
  const GRANTED = ["error", { bans: BANS_NO_GRANT_LIFTS }] as const;
79
68
 
69
+ const GRANTED_UNLESS_UNUSED = [
70
+ "error",
71
+ { bans: BANS_NO_GRANT_LIFTS, unusedGrant: UNUSED_GRANT_REPORTED },
72
+ ] as const;
73
+
80
74
  const permissionBanSeverityOnceGranted = (permission: keyof typeof PERMISSION_BANS) =>
81
75
  bansNoGrantLifts(permission).length > 0 ? GRANTED : "off";
82
76
 
77
+ const severityOnceGranted = (permission: keyof typeof PERMISSION_BANS) =>
78
+ permission === READS_CONFIG
79
+ ? permissionBanSeverityOnceGranted(permission)
80
+ : GRANTED_UNLESS_UNUSED;
81
+
83
82
  const ruleSeverities = (
84
83
  severities: Readonly<
85
84
  Record<string, readonly ["error", Readonly<Record<string, string>>] | "off">
@@ -98,6 +97,12 @@ const rulesGrantedBy = (permission: (typeof PERMISSION_NAMES)[number]) => {
98
97
  [`sshkeda/${TEST_TIMEOUTS_RULE}`]: "off",
99
98
  } as const);
100
99
  }
100
+ if (permission === TIMERS) {
101
+ return ruleSeverities({
102
+ [`sshkeda/${SLEEP_RULE}`]: "off",
103
+ [`sshkeda/${CLOCK_RULE}`]: ["error", { clockServiceSleeps: "allowed" }],
104
+ } as const);
105
+ }
101
106
  if (permission === WRITES_TO_THE_TERMINAL) {
102
107
  return ruleSeverities({
103
108
  [permissionBanRuleId(permission)]: GRANTED,
@@ -126,7 +131,7 @@ const rulesGrantedBy = (permission: (typeof PERMISSION_NAMES)[number]) => {
126
131
  return ruleSeverities({});
127
132
  }
128
133
  return ruleSeverities({
129
- [permissionBanRuleId(permission)]: permissionBanSeverityOnceGranted(permission),
134
+ [permissionBanRuleId(permission)]: severityOnceGranted(permission),
130
135
  } as const);
131
136
  };
132
137
 
@@ -176,45 +181,19 @@ const GRANT_PATH = Schema.String.check(
176
181
  ),
177
182
  );
178
183
 
179
- const PERMISSION = Schema.String.check(
180
- Schema.makeFilter((name: string) => {
181
- const retirement = RETIRED_PERMISSIONS.get(name);
182
- return retirement === undefined || `${name} is retired: ${retirement}`;
183
- }),
184
- Schema.makeFilter(
185
- (name: string) => !REASONED_PERMISSION_NAMES.has(name) || `grants ${name} without a reason`,
186
- ),
187
- ).pipe(Schema.decodeTo(Schema.Literals(UNREASONED_PERMISSION_NAMES)));
188
-
189
- const REASON = Schema.String.check(
190
- Schema.makeFilter((reason: string) => reason.trim() !== "" || "is blank"),
191
- );
192
-
193
- const REASONED_PERMISSIONS = Schema.Struct({
194
- [TRUSTS_UNVERIFIED_TYPES]: Schema.optionalKey(REASON),
195
- [HANDLES_EVERY_FAILURE]: Schema.optionalKey(REASON),
196
- [GENERATED]: Schema.optionalKey(REASON),
197
- })
198
- .annotate({ messageUnexpectedKey: "is not a permission that takes a reason" })
199
- .check(Schema.makeFilter((reasons) => Object.keys(reasons).length > 0 || "grants nothing"));
200
-
201
- const permissionNamesOf = (allow: readonly (typeof ALLOWED.Type)[number][]) =>
202
- allow.flatMap((entry) =>
203
- typeof entry === "string"
204
- ? [entry]
205
- : [
206
- ...(entry.trustsUnverifiedTypes === undefined
207
- ? []
208
- : ([TRUSTS_UNVERIFIED_TYPES] as const)),
209
- ...(entry.handlesEveryFailure === undefined ? [] : ([HANDLES_EVERY_FAILURE] as const)),
210
- ...(entry.isGeneratedByATool === undefined ? [] : ([GENERATED] as const)),
211
- ],
212
- );
184
+ const PERMISSION = Schema.String.annotate({ message: "is not a permission name" })
185
+ .check(
186
+ Schema.makeFilter((name: string) => {
187
+ const retirement = RETIRED_PERMISSIONS.get(name);
188
+ return retirement === undefined || `${name} is retired: ${retirement}`;
189
+ }),
190
+ )
191
+ .pipe(Schema.decodeTo(Schema.Literals(PERMISSION_NAMES)));
213
192
 
214
193
  const nonEmptyList = <Entry extends Schema.Top>(entry: Entry) =>
215
194
  Schema.Array(entry).check(Schema.isNonEmpty({ message: "is empty" }));
216
195
 
217
- const ALLOWED = nonEmptyList(Schema.Union([PERMISSION, REASONED_PERMISSIONS]));
196
+ const ALLOWED = nonEmptyList(PERMISSION);
218
197
 
219
198
  const GRANT_FIELDS = {
220
199
  allow: Schema.optionalKey(ALLOWED),
@@ -237,14 +216,7 @@ const isString = Schema.is(Schema.String);
237
216
  const repeatedItems = (path: string, grant: typeof UNDECODED_GRANT.Type) =>
238
217
  Object.keys(GRANT_FIELDS).flatMap((key) => {
239
218
  const list = grant[key];
240
- const names = isList(list)
241
- ? list.flatMap((item) => {
242
- if (isString(item)) {
243
- return [item];
244
- }
245
- return isUndecodedGrant(item) ? Object.keys(item) : [];
246
- })
247
- : [];
219
+ const names = isList(list) ? list.filter((item) => isString(item)) : [];
248
220
  const repeated = names.filter((name, index) => names.indexOf(name) !== index);
249
221
  return Arrays.dedupe(repeated).map((name) => ({
250
222
  path: [path, key],
@@ -253,9 +225,11 @@ const repeatedItems = (path: string, grant: typeof UNDECODED_GRANT.Type) =>
253
225
  });
254
226
 
255
227
  const grantMismatches = (path: string, grant: typeof GRANT.Type): readonly Schema.FilterIssue[] => {
256
- const allowed = permissionNamesOf(grant.allow ?? []);
228
+ const allowed = grant.allow ?? [];
257
229
  const grantsOnlyFileType =
258
- allowed.every((permission) => permission === FILE_TYPE) && Object.keys(grant).length === 1;
230
+ allowed.length > 0 &&
231
+ allowed.every((permission) => permission === FILE_TYPE) &&
232
+ Object.keys(grant).length === 1;
259
233
  const grantsGenerated = allowed.includes(GENERATED);
260
234
  const grantsGeneratedWithOtherPermissions =
261
235
  grantsGenerated && (allowed.length !== 1 || Object.keys(grant).length !== 1);
@@ -327,6 +301,8 @@ const TEST_HOME_OVERRIDE = {
327
301
  "sshkeda/no-testing-helpers": "off",
328
302
  "sshkeda/no-assertions": "off",
329
303
  "sshkeda/no-schedules": "off",
304
+ "sshkeda/no-instant-retries": "off",
305
+ "sshkeda/no-shared-holders": "off",
330
306
  [`sshkeda/${TEST_TIMEOUTS_RULE}`]: "error",
331
307
  },
332
308
  } as const;
@@ -379,7 +355,7 @@ export const recordedGrantsOf = (permissionsByPath: unknown) => {
379
355
  }
380
356
  const grants = Object.entries(decoded.success).map(([path, grant]) => ({
381
357
  path,
382
- allow: permissionNamesOf(grant.allow ?? []),
358
+ allow: grant.allow ?? [],
383
359
  services: grant.services ?? [],
384
360
  cannotImport: grant.cannotImport ?? [],
385
361
  }));