@sshkeda/check 4.1.0 → 4.3.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.
@@ -19,7 +19,7 @@ export default lintConfig({
19
19
  - `usesAbbreviations`: Allows abbreviations in variable, function, type and other declared names.
20
20
  - `pollsWithADeadline`: Allows `Effect.repeat` and `Effect.retry` with `Schedule.spaced` or `Schedule.exponential`, under a deadline. `Schedule.exponential` may be wrapped in or piped through `Schedule.jittered`.
21
21
  - `waitsOnTimers`: Allows `Effect.sleep`, `Effect.delay`, `Clock.sleep` and the Stream operations that wait on a timer, such as `Stream.tick`.
22
- - `hasAnUnlistedFileType`: Allows a file type Check doesn't list, such as Markdown.
22
+ - `hasAnUnlistedFileType`: Allows a file type Check doesn't list, such as Markdown outside `docs/`. Markdown in `docs/` and the root `README.md` pass as they are.
23
23
  - `isAnUnlistedDirectory`: Allows a directory Check doesn't list, such as `.github`. Check doesn't apply its directory-shape rules inside it, but files there still need their own `hasAnUnlistedFileType` grant.
24
24
  - `patchesADependency`: Allows a patch file from `bun patch`.
25
25
  - `trustsUnverifiedTypes`: Allows trusting a value's type without checking it, through `Schema.declare`.
@@ -10,7 +10,11 @@ Check may not catch every violation of these principles. Review your code agains
10
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.
11
11
  - Design for the current requirement as if you were starting fresh. Delete code the new design doesn't need.
12
12
  - Handle a forked effect's failure before the fork, or keep the fiber and join it.
13
+ - Wrap a Promise in `Effect.tryPromise` and `yield*` it instead of using `await`.
14
+ - Read a fact from where a tool states it, such as an error's fields, a command's exit code or its JSON output. Text written for people changes between releases, and code that searches it breaks quietly when it does.
13
15
  - Return a fixed value only for the one failure you expect, such as a file that isn't there. Let every other failure fail.
16
+ - Write a job that moves through stages as an explicit state machine, with one tagged case per stage in one union, so the job is always in exactly one stage.
17
+ - Give each status its own struct holding the fields that status always has, and join them in a union.
14
18
  - Grant `isGeneratedByATool` only to a file a tool generates.
15
19
 
16
20
  ## Make the code explain itself
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sshkeda/check",
3
- "version": "4.1.0",
3
+ "version": "4.3.0",
4
4
  "homepage": "https://github.com/sshkeda/check#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/sshkeda/check/issues"
@@ -5,10 +5,24 @@ import {
5
5
  NODE_BUILTIN_RULES,
6
6
  nodeBuiltinNameOf,
7
7
  } from "../shared/lint-rule-messages-and-patterns.ts";
8
- import { importsOnlyTypes, staticKeyName } from "./resolve-what-an-expression-imports.ts";
8
+ import {
9
+ importsOnlyTypes,
10
+ moduleExportName,
11
+ staticKeyName,
12
+ } from "./resolve-what-an-expression-imports.ts";
9
13
 
10
14
  export const nodeBuiltinRule = (ruleName: keyof typeof NODE_BUILTIN_RULES) => {
11
15
  const bannedModules: ReadonlySet<string> = new Set(NODE_BUILTIN_RULES[ruleName].modules);
16
+ const allowedImports: ReadonlySet<string> = new Set(NODE_BUILTIN_RULES[ruleName].allowedImports);
17
+ const isErasedOrAllowed = (specifier: ESTree.ImportSpecifier) => {
18
+ const isErased = specifier.importKind === "type";
19
+ return isErased || allowedImports.has(moduleExportName(specifier.imported));
20
+ };
21
+ const importsOnlyAllowedNames = (node: ESTree.ImportDeclaration) =>
22
+ node.specifiers.length > 0 &&
23
+ node.specifiers.every(
24
+ (specifier) => specifier.type === "ImportSpecifier" && isErasedOrAllowed(specifier),
25
+ );
12
26
  return defineRule({
13
27
  meta: {
14
28
  type: "problem",
@@ -23,7 +37,9 @@ export const nodeBuiltinRule = (ruleName: keyof typeof NODE_BUILTIN_RULES) => {
23
37
 
24
38
  return {
25
39
  ImportDeclaration(node) {
26
- if (!importsOnlyTypes(node, context.sourceCode)) {
40
+ const isAllowed =
41
+ importsOnlyTypes(node, context.sourceCode) || importsOnlyAllowedNames(node);
42
+ if (!isAllowed) {
27
43
  check(node.source, node.source.value);
28
44
  }
29
45
  },
@@ -235,6 +235,7 @@ const baseConfig = {
235
235
  "eslint/no-else-return": "error",
236
236
  "eslint/no-empty": "error",
237
237
  "eslint/no-empty-function": ["error", { allow: ["privateConstructors"] }],
238
+ "eslint/no-extend-native": "error",
238
239
  "eslint/no-implicit-coercion": "error",
239
240
  "eslint/no-lone-blocks": "error",
240
241
  "eslint/no-lonely-if": "error",
@@ -275,6 +276,7 @@ const baseConfig = {
275
276
  "typescript/no-empty-object-type": "error",
276
277
  "typescript/no-explicit-any": "error",
277
278
  "typescript/no-extraneous-class": "error",
279
+ "typescript/no-floating-promises": ["error", { ignoreVoid: false, checkThenables: true }],
278
280
  "typescript/no-import-type-side-effects": "error",
279
281
  "typescript/no-inferrable-types": "error",
280
282
  "typescript/no-misused-promises": "error",
@@ -1,19 +1,31 @@
1
- import { Effect, Path } from "effect";
2
- import type { Node, SourceFile } from "typescript/unstable/ast";
1
+ import { Effect, Path, Schema } from "effect";
2
+ import { SyntaxKind } from "typescript/unstable/ast";
3
+ import type { ImportDeclaration, Node, SourceFile } from "typescript/unstable/ast";
3
4
  import {
4
5
  isBindingElement,
5
6
  isComputedPropertyName,
6
7
  isElementAccessExpression,
8
+ isExpressionWithTypeArguments,
7
9
  isIdentifier,
10
+ isImportDeclaration,
11
+ isNamedImports,
12
+ isNamespaceImport,
8
13
  isNoSubstitutionTemplateLiteral,
9
14
  isNumericLiteral,
10
15
  isObjectBindingPattern,
11
16
  isPropertyAccessExpression,
12
17
  isStringLiteral,
18
+ isTypeAliasDeclaration,
19
+ isTypeNode,
13
20
  } from "typescript/unstable/ast/is";
14
21
  import { isStringLiteralType, isTypeParameter, isUnionType } from "typescript/unstable/async";
15
22
  import type { Checker, Type } from "typescript/unstable/async";
16
23
 
24
+ import {
25
+ moduleSpecifiersOfGlobalObject,
26
+ READS_CONFIG,
27
+ WRITES_TO_THE_TERMINAL,
28
+ } from "../../../../../shared/bans-each-permission-lifts.ts";
17
29
  import { loadedLintConfigIn } from "../../../shared/load-the-lint-config.ts";
18
30
  import {
19
31
  CONCURRENT_TYPESCRIPT_REQUESTS,
@@ -24,18 +36,36 @@ import {
24
36
  } from "../../../shared/query-the-typescript-project.ts";
25
37
  import type { openTypeScriptProjects } from "../../../shared/query-the-typescript-project.ts";
26
38
  import {
39
+ GrantNothingUses,
27
40
  StdioArgumentsReadWithoutGrant,
28
41
  StdioTerminalWriteWithoutGrant,
42
+ STDIO_PERMISSION,
29
43
  StdioUsesRefused,
30
44
  } from "./stdio-use-errors.ts";
31
45
 
32
46
  const STDIO_TYPE_ID = "~effect/Stdio";
33
47
 
34
- const PERMISSION_OF_STDIO_MEMBER = new Map<string, "readsConfig" | "writesToTheTerminal">([
35
- ["args", "readsConfig"],
36
- ["stdout", "writesToTheTerminal"],
37
- ["stderr", "writesToTheTerminal"],
48
+ const PERMISSION_OF_STDIO_MEMBER = new Map<string, typeof STDIO_PERMISSION.Type>([
49
+ ["args", READS_CONFIG],
50
+ ["stdout", WRITES_TO_THE_TERMINAL],
51
+ ["stderr", WRITES_TO_THE_TERMINAL],
52
+ ]);
53
+
54
+ const PROCESS = "process";
55
+ const PROCESS_MEMBERS_THAT_READ_CONFIG = new Set(["env", "argv"]);
56
+ const EFFECT = "effect";
57
+ const PERMISSION_OF_MODULE = new Map<string, typeof STDIO_PERMISSION.Type>([
58
+ ["effect/Config", READS_CONFIG],
59
+ ...moduleSpecifiersOfGlobalObject(PROCESS).map((specifier) => [specifier, READS_CONFIG] as const),
60
+ ["effect/Stdio", WRITES_TO_THE_TERMINAL],
61
+ ]);
62
+ const PERMISSION_OF_NAME = new Map<string, typeof STDIO_PERMISSION.Type>([
63
+ ["Config", READS_CONFIG],
64
+ ["Stdio", WRITES_TO_THE_TERMINAL],
38
65
  ]);
66
+ const EVERY_STDIO_PERMISSION = [READS_CONFIG, WRITES_TO_THE_TERMINAL] as const;
67
+
68
+ const isStdioPermission = Schema.is(STDIO_PERMISSION);
39
69
 
40
70
  const literalKeyText = (key: Node) => {
41
71
  const isNamedOrLiteralKey =
@@ -97,6 +127,155 @@ const possibleStdioReadsIn = (sourceFile: SourceFile) => {
97
127
  return reads;
98
128
  };
99
129
 
130
+ const processMemberRead = (reference: Node) => {
131
+ const parent = parentOf(reference);
132
+ const isMemberRead =
133
+ parent !== undefined && isPropertyAccessExpression(parent) && parent.expression === reference;
134
+ if (isMemberRead) {
135
+ return parent.name.text;
136
+ }
137
+ const isElementRead =
138
+ parent !== undefined && isElementAccessExpression(parent) && parent.expression === reference;
139
+ if (!isElementRead) {
140
+ return;
141
+ }
142
+ const key = parent.argumentExpression;
143
+ return isIdentifier(key) ? undefined : literalKeyText(key);
144
+ };
145
+
146
+ const readsConfigThroughProcess = (processReference: Node) => {
147
+ const parent = parentOf(processReference);
148
+ const isGlobalMember =
149
+ parent !== undefined && isPropertyAccessExpression(parent) && parent.name === processReference;
150
+ const member = processMemberRead(isGlobalMember ? parent : processReference);
151
+ return member === undefined || PROCESS_MEMBERS_THAT_READ_CONFIG.has(member);
152
+ };
153
+
154
+ const namespacePermissions = (moduleName: string) => {
155
+ if (moduleName === EFFECT) {
156
+ return EVERY_STDIO_PERMISSION;
157
+ }
158
+ const permission = PERMISSION_OF_MODULE.get(moduleName);
159
+ return permission === undefined ? [] : [permission];
160
+ };
161
+
162
+ const importedBindings = (declaration: ImportDeclaration) => {
163
+ const { importClause, moduleSpecifier } = declaration;
164
+ const isNamedModuleImport = importClause !== undefined && isStringLiteral(moduleSpecifier);
165
+ if (!isNamedModuleImport) {
166
+ return [];
167
+ }
168
+ const moduleName = moduleSpecifier.text;
169
+ const isTypeOnlyClause = importClause.phaseModifier === SyntaxKind.TypeKeyword;
170
+ const modulePermission = PERMISSION_OF_MODULE.get(moduleName);
171
+ const bindings = importClause.namedBindings;
172
+ const isNamespace = bindings !== undefined && isNamespaceImport(bindings);
173
+ if (isNamespace) {
174
+ return namespacePermissions(moduleName).map((permission) => ({
175
+ local: bindings.name.text,
176
+ permission,
177
+ isTypeOnly: isTypeOnlyClause,
178
+ }));
179
+ }
180
+ const isNamed = bindings !== undefined && isNamedImports(bindings);
181
+ const named = (isNamed ? bindings.elements : []).flatMap((specifier) => {
182
+ const imported = literalKeyText(specifier.propertyName ?? specifier.name) ?? "";
183
+ const permission = moduleName === EFFECT ? PERMISSION_OF_NAME.get(imported) : modulePermission;
184
+ const isTypeOnly = isTypeOnlyClause || specifier.isTypeOnly;
185
+ return permission === undefined ? [] : [{ local: specifier.name.text, permission, isTypeOnly }];
186
+ });
187
+ const defaultName = importClause.name;
188
+ const hasPermittingDefault = defaultName !== undefined && modulePermission !== undefined;
189
+ const defaultBinding = hasPermittingDefault
190
+ ? [{ local: defaultName.text, permission: modulePermission, isTypeOnly: isTypeOnlyClause }]
191
+ : [];
192
+ return [...named, ...defaultBinding];
193
+ };
194
+
195
+ const sideEffectImportPermission = (declaration: ImportDeclaration) => {
196
+ const specifier = declaration.moduleSpecifier;
197
+ const isSideEffectImport = declaration.importClause === undefined && isStringLiteral(specifier);
198
+ return isSideEffectImport ? PERMISSION_OF_MODULE.get(specifier.text) : undefined;
199
+ };
200
+
201
+ const permissionOfReference = (
202
+ reference: Node,
203
+ permissionOfLocal: ReadonlyMap<string, typeof STDIO_PERMISSION.Type>,
204
+ ) => {
205
+ if (!isIdentifier(reference)) {
206
+ return;
207
+ }
208
+ if (reference.text !== PROCESS) {
209
+ return permissionOfLocal.get(reference.text);
210
+ }
211
+ return readsConfigThroughProcess(reference) ? READS_CONFIG : undefined;
212
+ };
213
+
214
+ const importDeclarationsIn = (sourceFile: SourceFile) => {
215
+ const declarations: ImportDeclaration[] = [];
216
+ const visit = (node: Node): void => {
217
+ if (isImportDeclaration(node)) {
218
+ declarations.push(node);
219
+ return;
220
+ }
221
+ node.forEachChild(visit);
222
+ };
223
+ sourceFile.forEachChild(visit);
224
+ return declarations;
225
+ };
226
+
227
+ const visitComputedKeysIn = (node: Node, visit: (expression: Node) => void): void => {
228
+ if (isComputedPropertyName(node)) {
229
+ visit(node.expression);
230
+ return;
231
+ }
232
+ node.forEachChild((child) => {
233
+ visitComputedKeysIn(child, visit);
234
+ });
235
+ };
236
+
237
+ const permissionsUsedOutsideStdioReadsIn = (sourceFile: SourceFile) => {
238
+ const used = new Set<typeof STDIO_PERMISSION.Type>();
239
+ const permissionOfLocal = new Map(PERMISSION_OF_NAME);
240
+ for (const declaration of importDeclarationsIn(sourceFile)) {
241
+ const sideEffectPermission = sideEffectImportPermission(declaration);
242
+ if (sideEffectPermission !== undefined) {
243
+ used.add(sideEffectPermission);
244
+ }
245
+ for (const binding of importedBindings(declaration)) {
246
+ if (binding.isTypeOnly) {
247
+ permissionOfLocal.set(binding.local, binding.permission);
248
+ } else {
249
+ used.add(binding.permission);
250
+ }
251
+ }
252
+ }
253
+ const visit = (node: Node): void => {
254
+ if (isImportDeclaration(node)) {
255
+ return;
256
+ }
257
+ if (isExpressionWithTypeArguments(node)) {
258
+ visit(node.expression);
259
+ for (const typeArgument of node.typeArguments ?? []) {
260
+ visitComputedKeysIn(typeArgument, visit);
261
+ }
262
+ return;
263
+ }
264
+ const isErasedType = isTypeNode(node) || isTypeAliasDeclaration(node);
265
+ if (isErasedType) {
266
+ visitComputedKeysIn(node, visit);
267
+ return;
268
+ }
269
+ const permission = permissionOfReference(node, permissionOfLocal);
270
+ if (permission !== undefined) {
271
+ used.add(permission);
272
+ }
273
+ node.forEachChild(visit);
274
+ };
275
+ sourceFile.forEachChild(visit);
276
+ return used;
277
+ };
278
+
100
279
  const unionMembersOf = (type: Type) =>
101
280
  isUnionType(type)
102
281
  ? typeScriptRequest("read the members of a union", () => type.getTypes())
@@ -180,17 +359,39 @@ export const findUngrantedStdioUses = <OpeningError, OpeningRequirement>(
180
359
  Effect.gen(function* () {
181
360
  const path = yield* Path.Path;
182
361
  const grants = yield* loadedLintConfigIn(path.dirname(projectFile));
362
+ const stdioGrants = grants.flatMap((grant) =>
363
+ grant.allow.filter(isStdioPermission).map((permission) => ({ path: grant.path, permission })),
364
+ );
183
365
  const isGranted = (displayName: string, member: string) => {
184
366
  const permission = PERMISSION_OF_STDIO_MEMBER.get(member);
185
- return grants.some(
186
- (grant) =>
187
- grant.path === displayName &&
188
- permission !== undefined &&
189
- grant.allow.some((allowed) => allowed === permission),
367
+ return stdioGrants.some(
368
+ (grant) => grant.path === displayName && grant.permission === permission,
190
369
  );
191
370
  };
371
+ const usedPermissions = new Map<string, Set<typeof STDIO_PERMISSION.Type>>();
372
+ const recordUse = (
373
+ displayName: string,
374
+ permission: typeof STDIO_PERMISSION.Type | undefined,
375
+ ) => {
376
+ if (permission === undefined) {
377
+ return;
378
+ }
379
+ const used = usedPermissions.get(displayName) ?? new Set<typeof STDIO_PERMISSION.Type>();
380
+ used.add(permission);
381
+ usedPermissions.set(displayName, used);
382
+ };
383
+ const checkedFiles = new Set<string>();
192
384
  const violations: StdioUsesRefused["violations"][number][] = [];
193
385
  for (const { checker, sourceFiles } of yield* openedProjects) {
386
+ for (const { sourceFile, displayName } of sourceFiles) {
387
+ checkedFiles.add(displayName);
388
+ const isGrantedFile = stdioGrants.some((grant) => grant.path === displayName);
389
+ if (isGrantedFile) {
390
+ for (const permission of permissionsUsedOutsideStdioReadsIn(sourceFile)) {
391
+ recordUse(displayName, permission);
392
+ }
393
+ }
394
+ }
194
395
  const reads = sourceFiles.flatMap(({ sourceFile, displayName }) =>
195
396
  possibleStdioReadsIn(sourceFile).map((read) => {
196
397
  const location = nodePosition(sourceFile, read.receiver);
@@ -204,15 +405,32 @@ export const findUngrantedStdioUses = <OpeningError, OpeningRequirement>(
204
405
  const found = yield* Effect.forEach(
205
406
  reads,
206
407
  ({ read, displayName, location }) =>
207
- Effect.map(stdioMembersRead(checker, read), (members) =>
208
- members
209
- .filter((member) => !isGranted(displayName, member))
210
- .map((member) => violationOf(member, location)),
211
- ),
408
+ Effect.map(stdioMembersRead(checker, read), (members) => ({
409
+ displayName,
410
+ location,
411
+ members,
412
+ })),
212
413
  { concurrency: CONCURRENT_TYPESCRIPT_REQUESTS },
213
414
  );
214
- violations.push(...found.flat());
415
+ for (const { displayName, location, members } of found) {
416
+ for (const member of members) {
417
+ recordUse(displayName, PERMISSION_OF_STDIO_MEMBER.get(member));
418
+ if (!isGranted(displayName, member)) {
419
+ violations.push(violationOf(member, location));
420
+ }
421
+ }
422
+ }
215
423
  }
424
+ const unusedGrants = stdioGrants.filter(
425
+ ({ path: grantedPath, permission }) =>
426
+ checkedFiles.has(grantedPath) && usedPermissions.get(grantedPath)?.has(permission) !== true,
427
+ );
428
+ violations.push(
429
+ ...unusedGrants.map(
430
+ ({ path: grantedPath, permission }) =>
431
+ new GrantNothingUses({ location: grantedPath, permission }),
432
+ ),
433
+ );
216
434
  if (violations.length > 0) {
217
435
  return yield* new StdioUsesRefused({ violations });
218
436
  }
@@ -1,5 +1,10 @@
1
1
  import { Schema } from "effect";
2
2
 
3
+ import {
4
+ READS_CONFIG,
5
+ unusedGrantMessage,
6
+ WRITES_TO_THE_TERMINAL,
7
+ } from "../../../../../shared/bans-each-permission-lifts.ts";
3
8
  import { listedViolations } from "../../../../../shared/format-reported-failures.ts";
4
9
 
5
10
  export class StdioArgumentsReadWithoutGrant extends Schema.TaggedError<StdioArgumentsReadWithoutGrant>()(
@@ -20,9 +25,24 @@ export class StdioTerminalWriteWithoutGrant extends Schema.TaggedError<StdioTerm
20
25
  }
21
26
  }
22
27
 
28
+ export const STDIO_PERMISSION = Schema.Literals([READS_CONFIG, WRITES_TO_THE_TERMINAL]);
29
+
30
+ export class GrantNothingUses extends Schema.TaggedError<GrantNothingUses>()("GrantNothingUses", {
31
+ location: Schema.String,
32
+ permission: STDIO_PERMISSION,
33
+ }) {
34
+ public override get message() {
35
+ return unusedGrantMessage(this.permission);
36
+ }
37
+ }
38
+
23
39
  export class StdioUsesRefused extends Schema.TaggedError<StdioUsesRefused>()("StdioUsesRefused", {
24
40
  violations: Schema.Array(
25
- Schema.Union([StdioArgumentsReadWithoutGrant, StdioTerminalWriteWithoutGrant]),
41
+ Schema.Union([
42
+ StdioArgumentsReadWithoutGrant,
43
+ StdioTerminalWriteWithoutGrant,
44
+ GrantNothingUses,
45
+ ]),
26
46
  ),
27
47
  }) {
28
48
  public override get message() {
@@ -464,6 +464,10 @@ export const manifestViolations = (
464
464
 
465
465
  const ROOT_README = "README.md";
466
466
 
467
+ const isMarkdownInDocs = (path: string) => isMarkdown(path) && isWithin(path, DOCS_DIRECTORY);
468
+
469
+ const needsNoDocumentGrant = (path: string) => path === ROOT_README || isMarkdownInDocs(path);
470
+
467
471
  export const permissionGrantViolations = (
468
472
  paths: readonly string[],
469
473
  grants: Effect.Success<ReturnType<typeof loadedLintConfigIn>>,
@@ -500,7 +504,7 @@ export const permissionGrantViolations = (
500
504
  for (const path of paths) {
501
505
  const isUngrantedDocument =
502
506
  isMarkdown(path) &&
503
- path !== ROOT_README &&
507
+ !needsNoDocumentGrant(path) &&
504
508
  !generated.has(path) &&
505
509
  !isGranted(path, FILE_TYPE);
506
510
  if (isUngrantedDocument) {
@@ -538,8 +542,9 @@ export const permissionGrantViolations = (
538
542
  if (isDirectoryGrantedPermissions) {
539
543
  violations.push(new DirectoryGrantedPermissions({ path: grant.path }));
540
544
  }
541
- const grantsFileTypeToRootReadme =
542
- grant.path === ROOT_README && grant.allow.includes(FILE_TYPE);
545
+ const grantsFileTypeToExistingFile =
546
+ repositoryFiles.has(grant.path) && grant.allow.includes(FILE_TYPE);
547
+ const grantsFileTypeToRootReadme = grantsFileTypeToExistingFile && grant.path === ROOT_README;
543
548
  if (grantsFileTypeToRootReadme) {
544
549
  violations.push(
545
550
  new RedundantGrant({
@@ -549,6 +554,17 @@ export const permissionGrantViolations = (
549
554
  }),
550
555
  );
551
556
  }
557
+ const grantsFileTypeToMarkdownInDocs =
558
+ grantsFileTypeToExistingFile && isMarkdownInDocs(grant.path);
559
+ if (grantsFileTypeToMarkdownInDocs) {
560
+ violations.push(
561
+ new RedundantGrant({
562
+ path: grant.path,
563
+ permission: FILE_TYPE,
564
+ reason: `Markdown in ${DOCS_DIRECTORY}/ needs no grant`,
565
+ }),
566
+ );
567
+ }
552
568
  for (const target of grant.cannotImport.filter((candidate) => !exists(candidate))) {
553
569
  violations.push(new CannotImportTargetMissing({ path: grant.path, target }));
554
570
  }
@@ -47,13 +47,18 @@ export const GLOBAL_RULES = {
47
47
  } as const satisfies Readonly<Record<string, { readonly globals: readonly string[] }>>;
48
48
 
49
49
  export const NODE_BUILTIN_RULES = {
50
- "no-node-path": { modules: ["path", "path/posix", "path/win32"] },
51
- "no-node-crypto": { modules: ["crypto"] },
52
- "no-node-os": { modules: ["os"] },
53
- "no-node-http": { modules: ["http", "https"] },
54
- "no-node-stream": { modules: ["stream"] },
55
- "no-node-timers": { modules: ["timers", "timers/promises", "perf_hooks"] },
56
- } as const satisfies Readonly<Record<string, { readonly modules: readonly string[] }>>;
50
+ "no-node-path": { modules: ["path", "path/posix", "path/win32"], allowedImports: [] },
51
+ "no-node-crypto": { modules: ["crypto"], allowedImports: [] },
52
+ "no-node-os": { modules: ["os"], allowedImports: ["constants"] },
53
+ "no-node-http": { modules: ["http", "https"], allowedImports: [] },
54
+ "no-node-stream": { modules: ["stream"], allowedImports: [] },
55
+ "no-node-timers": { modules: ["timers", "timers/promises", "perf_hooks"], allowedImports: [] },
56
+ } as const satisfies Readonly<
57
+ Record<
58
+ string,
59
+ { readonly modules: readonly string[]; readonly allowedImports: readonly string[] }
60
+ >
61
+ >;
57
62
 
58
63
  export const SCHEDULE_MESSAGES = {
59
64
  polling: "{{usage}} polls on a timer",