@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
@@ -16,7 +16,7 @@ import {
16
16
  } from "./bans-each-permission-lifts.ts";
17
17
  import { isWithin } from "./match-file-names-and-path-prefixes.ts";
18
18
  import { MalformedGrant, PermissionGrantsRefused } from "./permission-grant-errors.ts";
19
- import { SCRIPTS_DIRECTORY, TEST_HOME } from "./test-home-directories.ts";
19
+ import { SCRIPTS_DIRECTORY, TEST_DIRECTORY, TEST_HOME } from "./test-home-directories.ts";
20
20
 
21
21
  export const DIRECTORY = "isAnUnlistedDirectory";
22
22
  export const GENERATED = "isGeneratedByATool";
@@ -26,11 +26,17 @@ export const TEST_TIMEOUTS_RULE = "no-test-timeouts";
26
26
  export const TYPE_PREDICATES_RULE = "no-type-predicates";
27
27
  export const STDIO_SERVICE_RULE = "no-stdio-service";
28
28
  export const FAILURES_AS_RESULTS_RULE = "no-failures-as-results";
29
- const UNNAMED_FALLBACKS_RULE = "no-unnamed-fallbacks";
29
+ export const UNNAMED_FALLBACKS_RULE = "no-unnamed-fallbacks";
30
+ export const FIXED_FALLBACKS = "fallsBackToFixedValues";
31
+ export const FIXED_FALLBACKS_RULE = "no-fixed-fallbacks";
32
+ export const FIXED_FALLBACKS_GRANTED = "granted";
30
33
  const SCHEDULES = "pollsWithADeadline";
31
34
  const TIMERS = "waitsOnTimers";
32
- const SLEEP_RULE = "no-sleep";
33
- const CLOCK_RULE = "no-clock-reads-and-sleeps";
35
+ export const SCHEDULES_RULE = "no-schedules";
36
+ export const SLEEP_RULE = "no-sleep";
37
+ export const CLOCK_RULE = "no-clock-reads-and-sleeps";
38
+ export const UNUSED_CODE_GRANTS_RULE = "no-unused-code-grants";
39
+ export const INSIDE_THE_TEST_HOME = "inside";
34
40
  const GLOB_CHARACTERS = /[*?[\]{}]/u;
35
41
  const ROUTE_PARAMETER_SEGMENT = /^\[\[?(?:\.\.\.)?[A-Za-z0-9_-]+\]\]?$/u;
36
42
 
@@ -50,6 +56,7 @@ export const PERMISSION_NAMES = [
50
56
  FILE_TYPE,
51
57
  TRUSTS_UNVERIFIED_TYPES,
52
58
  HANDLES_EVERY_FAILURE,
59
+ FIXED_FALLBACKS,
53
60
  GENERATED,
54
61
  ] as const;
55
62
 
@@ -93,7 +100,7 @@ const rulesGrantedBy = (permission: (typeof PERMISSION_NAMES)[number]) => {
93
100
  }
94
101
  if (permission === SCHEDULES) {
95
102
  return ruleSeverities({
96
- "sshkeda/no-schedules": ["error", { timedSchedules: "allowedWithDeadline" }],
103
+ [`sshkeda/${SCHEDULES_RULE}`]: ["error", { timedSchedules: "allowedWithDeadline" }],
97
104
  [`sshkeda/${TEST_TIMEOUTS_RULE}`]: "off",
98
105
  } as const);
99
106
  }
@@ -116,6 +123,11 @@ const rulesGrantedBy = (permission: (typeof PERMISSION_NAMES)[number]) => {
116
123
  [`sshkeda/${UNNAMED_FALLBACKS_RULE}`]: "off",
117
124
  } as const);
118
125
  }
126
+ if (permission === FIXED_FALLBACKS) {
127
+ return ruleSeverities({
128
+ [`sshkeda/${FIXED_FALLBACKS_RULE}`]: ["error", { fixedFallbacks: FIXED_FALLBACKS_GRANTED }],
129
+ } as const);
130
+ }
119
131
  if (permission === TRUSTS_UNVERIFIED_TYPES) {
120
132
  return ruleSeverities({
121
133
  [permissionBanRuleId(permission)]: "off",
@@ -135,6 +147,16 @@ const rulesGrantedBy = (permission: (typeof PERMISSION_NAMES)[number]) => {
135
147
  } as const);
136
148
  };
137
149
 
150
+ export const CODE_GRANTS = [
151
+ HANDLES_EVERY_FAILURE,
152
+ TIMERS,
153
+ SCHEDULES,
154
+ SHORT_NAMES,
155
+ TRUSTS_UNVERIFIED_TYPES,
156
+ ] as const;
157
+
158
+ const isCodeGrant = Schema.is(Schema.Literals(CODE_GRANTS));
159
+
138
160
  const ABORT_ON_FAILURE = true;
139
161
 
140
162
  const pathRule = (isAllowed: (path: string) => boolean, violation: (path: string) => string) =>
@@ -278,12 +300,23 @@ const GRANTS_AGAINST_THEIR_PATHS = Schema.Record(Schema.String, Schema.Unknown).
278
300
 
279
301
  const STANDARD_SCHEMA_ISSUES = SchemaIssue.makeFormatterStandardSchemaV1();
280
302
 
303
+ const unusedCodeGrantsRule = (path: string, permissions: readonly string[]) => {
304
+ const codeGrants = permissions.filter((permission) => isCodeGrant(permission));
305
+ const place = isWithin(path, TEST_DIRECTORY) ? { testHome: INSIDE_THE_TEST_HOME } : {};
306
+ return codeGrants.length > 0
307
+ ? Object.entries({
308
+ [`sshkeda/${UNUSED_CODE_GRANTS_RULE}`]: ["error", { permissions: codeGrants, ...place }],
309
+ } as const)
310
+ : [];
311
+ };
312
+
281
313
  const grantOverride = (
282
314
  grant: Extract<ReturnType<typeof recordedGrantsOf>, { grants: unknown }>["grants"][number],
283
315
  ) => ({
284
316
  files: [`./${grant.path.replaceAll("[", String.raw`\[`).replaceAll("]", String.raw`\]`)}`],
285
317
  rules: {
286
318
  ...Object.fromEntries(grant.allow.flatMap((permission) => rulesGrantedBy(permission))),
319
+ ...Object.fromEntries(unusedCodeGrantsRule(grant.path, grant.allow)),
287
320
  ...Object.fromEntries(
288
321
  grant.services.length > 0
289
322
  ? Object.entries({
@@ -300,13 +333,33 @@ const TEST_HOME_OVERRIDE = {
300
333
  rules: {
301
334
  "sshkeda/no-testing-helpers": "off",
302
335
  "sshkeda/no-assertions": "off",
303
- "sshkeda/no-schedules": "off",
336
+ [`sshkeda/${SCHEDULES_RULE}`]: "off",
337
+ [`sshkeda/${FIXED_FALLBACKS_RULE}`]: "off",
304
338
  "sshkeda/no-instant-retries": "off",
305
339
  "sshkeda/no-shared-holders": "off",
306
340
  [`sshkeda/${TEST_TIMEOUTS_RULE}`]: "error",
307
341
  },
308
342
  } as const;
309
343
 
344
+ const TEST_HOME_SEVERITIES: ReadonlyMap<string, string> = new Map(
345
+ Object.entries(TEST_HOME_OVERRIDE.rules),
346
+ );
347
+
348
+ const isOnWithoutAGrant = (ruleId: string, isInTheTestHome: boolean) => {
349
+ const testHomeSeverity = TEST_HOME_SEVERITIES.get(ruleId);
350
+ return isInTheTestHome ? testHomeSeverity !== "off" : testHomeSeverity !== "error";
351
+ };
352
+
353
+ export const rulesACodeGrantChanges = (
354
+ permission: (typeof CODE_GRANTS)[number],
355
+ isInTheTestHome: boolean,
356
+ ) =>
357
+ rulesGrantedBy(permission).map(([ruleId, granted]) => ({
358
+ ruleId,
359
+ granted,
360
+ isOnWithoutTheGrant: isOnWithoutAGrant(ruleId, isInTheTestHome),
361
+ }));
362
+
310
363
  const SCRIPTS_OVERRIDE = {
311
364
  files: [`./${SCRIPTS_DIRECTORY}/*`],
312
365
  rules: { [permissionBanRuleId(SCRIPT)]: "off" },