@sshkeda/check 2.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sshkeda/check",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "homepage": "https://github.com/sshkeda/check#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/sshkeda/check/issues"
@@ -99,7 +99,7 @@ export class DirectoryOutsideModuleLayout extends Schema.TaggedError<DirectoryOu
99
99
  { location: Schema.String, module: Schema.String },
100
100
  ) {
101
101
  public override get message() {
102
- return `is a directory in the module ${this.module}/ other than ${INTERNAL_DIRECTORY_NAME}/, ${SHARED_DIRECTORY_NAME}/ or ${LIBRARY_DIRECTORY_NAME}/`;
102
+ return `is a directory in the module ${this.module}/ other than ${INTERNAL_DIRECTORY_NAME}/, ${SHARED_DIRECTORY_NAME}/ or ${LIBRARY_DIRECTORY_NAME}/. Move it to ${this.module}/${LIBRARY_DIRECTORY_NAME}/${fileNameOf(this.location)}/`;
103
103
  }
104
104
  }
105
105
 
@@ -35,6 +35,7 @@ import {
35
35
  TEST_DIRECTORY,
36
36
  } from "../../../../../shared/test-home-directories.ts";
37
37
  import {
38
+ MODULE_ROOT_DIRECTORIES,
38
39
  enclosingDirectoriesOf,
39
40
  isRootSupportFile,
40
41
  repeatsSourceNeverImportsScripts,
@@ -298,7 +299,8 @@ export const sourceViolations = (
298
299
  }
299
300
 
300
301
  const isSourceOutsideModuleImplementation =
301
- (isWithin(path, SOURCE_DIRECTORY) || isWithin(path, TEST_DIRECTORY)) &&
302
+ MODULE_ROOT_DIRECTORIES.has(path.split("/")[0] ?? "") &&
303
+ !isTopLevelScript(path) &&
302
304
  !isLibraryDirectoryOfAModule(directoryOf(path)) &&
303
305
  !isEntryFileName(fileNameOf(path)) &&
304
306
  !isDeclarationFile(path) &&
@@ -4,8 +4,11 @@ import {
4
4
  LAYOUT_DIRECTORY_NAMES,
5
5
  LIBRARY_DIRECTORY_NAME,
6
6
  } from "../../../../../shared/match-file-names-and-path-prefixes.ts";
7
- import { SOURCE_DIRECTORY, TEST_DIRECTORY } from "../../../../../shared/test-home-directories.ts";
8
- import { directoryOf, enclosingDirectoriesOf } from "../../../shared/classify-files-by-role.ts";
7
+ import {
8
+ directoryOf,
9
+ enclosingDirectoriesOf,
10
+ MODULE_ROOT_DIRECTORIES,
11
+ } from "../../../shared/classify-files-by-role.ts";
9
12
  import {
10
13
  DirectoryOutsideModuleLayout,
11
14
  FileInLibraryDirectory,
@@ -16,8 +19,7 @@ import {
16
19
  export const isModuleDirectory = (directory: string): boolean => {
17
20
  const parent = directoryOf(directory);
18
21
  return (
19
- directory === SOURCE_DIRECTORY ||
20
- directory === TEST_DIRECTORY ||
22
+ MODULE_ROOT_DIRECTORIES.has(directory) ||
21
23
  (fileNameOf(parent) === LIBRARY_DIRECTORY_NAME && isModuleDirectory(directoryOf(parent)))
22
24
  );
23
25
  };
@@ -3,7 +3,10 @@ import { parseSync } from "oxc-parser";
3
3
  import type { ImportNameKind } from "oxc-parser";
4
4
 
5
5
  import { FORMAT_CONFIG_FILE } from "../../../../../shared/config-file-names.ts";
6
+ import { isWithin } from "../../../../../shared/match-file-names-and-path-prefixes.ts";
7
+ import { SOURCE_DIRECTORY } from "../../../../../shared/test-home-directories.ts";
6
8
  import {
9
+ MODULE_ROOT_DIRECTORIES,
7
10
  isDeclarationFile,
8
11
  isTopLevelScript,
9
12
  isRootSupportFile,
@@ -253,15 +256,21 @@ export const findTheImporterGraph = (projectFile: string) =>
253
256
  ]);
254
257
  const importers = new Map<string, Set<string>>();
255
258
  for (const [importer, parsed] of files) {
256
- const isCountedImporter = reachable.has(importer) && !isUnderTestDirectory(importer);
259
+ const isCountedImporter = reachable.has(importer);
257
260
  for (const use of isCountedImporter ? parsed.uses : []) {
258
- if (use.file !== importer) {
261
+ const isCountedUse =
262
+ use.file !== importer &&
263
+ (!isUnderTestDirectory(importer) || !isWithin(use.file, SOURCE_DIRECTORY));
264
+ if (isCountedUse) {
259
265
  importers.set(use.file, (importers.get(use.file) ?? new Set()).add(importer));
260
266
  }
261
267
  }
262
268
  }
263
269
  const importersOf = (file: string) => [...(importers.get(file) ?? [])];
264
- const moduleDirectories = moduleDirectoriesAmong(paths);
270
+ const moduleDirectories = new Set([
271
+ ...MODULE_ROOT_DIRECTORIES,
272
+ ...moduleDirectoriesAmong(paths),
273
+ ]);
265
274
  return {
266
275
  paths,
267
276
  files,
@@ -63,8 +63,13 @@ export const isTestEntryFile = (path: string) =>
63
63
 
64
64
  export const isRootSupportFile = (path: string) => !path.includes("/") && toolFileIsPlaced(path);
65
65
 
66
- export const isSpecialContainer = (directory: string) =>
67
- directory === "" || directory === SCRIPTS_DIRECTORY;
66
+ export const isSpecialContainer = (directory: string) => directory === "";
67
+
68
+ export const MODULE_ROOT_DIRECTORIES: ReadonlySet<string> = new Set([
69
+ SOURCE_DIRECTORY,
70
+ TEST_DIRECTORY,
71
+ SCRIPTS_DIRECTORY,
72
+ ]);
68
73
 
69
74
  export const isStrictlyUnder = (directory: string, scope: string) =>
70
75
  directory !== scope && (scope === "" || directory.startsWith(`${scope}/`));