@shivaedev/quality 0.53.1 → 0.55.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 (165) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +14 -9
  3. package/dist/adapters/compileCache.config.d.ts +2 -0
  4. package/dist/adapters/compileCache.config.d.ts.map +1 -0
  5. package/dist/adapters/compileCache.config.js +3 -0
  6. package/dist/adapters/compileCache.config.js.map +1 -0
  7. package/dist/adapters/knip/entryPointFindings.d.ts.map +1 -1
  8. package/dist/adapters/knip/entryPointFindings.js +14 -8
  9. package/dist/adapters/knip/entryPointFindings.js.map +1 -1
  10. package/dist/adapters/manifestInventory.d.ts.map +1 -1
  11. package/dist/adapters/manifestInventory.js +3 -1
  12. package/dist/adapters/manifestInventory.js.map +1 -1
  13. package/dist/adapters/manifestReader.d.ts +2 -2
  14. package/dist/adapters/manifestReader.d.ts.map +1 -1
  15. package/dist/adapters/manifestReader.js +2 -1
  16. package/dist/adapters/manifestReader.js.map +1 -1
  17. package/dist/adapters/testProjects.d.ts.map +1 -1
  18. package/dist/adapters/testProjects.js +1 -0
  19. package/dist/adapters/testProjects.js.map +1 -1
  20. package/dist/biome/recognizeDiagnostics.d.ts.map +1 -1
  21. package/dist/biome/recognizeDiagnostics.js +4 -5
  22. package/dist/biome/recognizeDiagnostics.js.map +1 -1
  23. package/dist/biome/report.d.ts +2 -1
  24. package/dist/biome/report.d.ts.map +1 -1
  25. package/dist/biome/report.js +11 -5
  26. package/dist/biome/report.js.map +1 -1
  27. package/dist/cli/changedRanges.d.ts +2 -0
  28. package/dist/cli/changedRanges.d.ts.map +1 -0
  29. package/dist/cli/changedRanges.js +23 -0
  30. package/dist/cli/changedRanges.js.map +1 -0
  31. package/dist/cli/fix.d.ts.map +1 -1
  32. package/dist/cli/fix.js +12 -12
  33. package/dist/cli/fix.js.map +1 -1
  34. package/dist/cli/lint.d.ts.map +1 -1
  35. package/dist/cli/lint.js +3 -1
  36. package/dist/cli/lint.js.map +1 -1
  37. package/dist/config.d.ts +5 -5
  38. package/dist/config.d.ts.map +1 -1
  39. package/dist/config.js.map +1 -1
  40. package/dist/engine/runRules.d.ts.map +1 -1
  41. package/dist/engine/runRules.js +29 -6
  42. package/dist/engine/runRules.js.map +1 -1
  43. package/dist/engine/session.d.ts +3 -2
  44. package/dist/engine/session.d.ts.map +1 -1
  45. package/dist/engine/session.js +9 -6
  46. package/dist/engine/session.js.map +1 -1
  47. package/dist/exceptions/biomeFindings.d.ts +3 -0
  48. package/dist/exceptions/biomeFindings.d.ts.map +1 -1
  49. package/dist/exceptions/biomeFindings.js +21 -0
  50. package/dist/exceptions/biomeFindings.js.map +1 -1
  51. package/dist/hooks/preCommit.js +1 -1
  52. package/dist/hooks/preCommit.js.map +1 -1
  53. package/dist/imports/adminBindings.d.ts +8 -0
  54. package/dist/imports/adminBindings.d.ts.map +1 -0
  55. package/dist/imports/adminBindings.js +36 -0
  56. package/dist/imports/adminBindings.js.map +1 -0
  57. package/dist/imports/adminEvidence.d.ts +6 -0
  58. package/dist/imports/adminEvidence.d.ts.map +1 -0
  59. package/dist/imports/adminEvidence.js +46 -0
  60. package/dist/imports/adminEvidence.js.map +1 -0
  61. package/dist/imports/adminFindings.d.ts +4 -0
  62. package/dist/imports/adminFindings.d.ts.map +1 -0
  63. package/dist/imports/adminFindings.js +55 -0
  64. package/dist/imports/adminFindings.js.map +1 -0
  65. package/dist/imports/extract.d.ts +2 -1
  66. package/dist/imports/extract.d.ts.map +1 -1
  67. package/dist/imports/extract.js +11 -10
  68. package/dist/imports/extract.js.map +1 -1
  69. package/dist/imports/graph.d.ts +2 -1
  70. package/dist/imports/graph.d.ts.map +1 -1
  71. package/dist/imports/graph.js +4 -2
  72. package/dist/imports/graph.js.map +1 -1
  73. package/dist/imports/nodePlatformBarrels.d.ts +3 -0
  74. package/dist/imports/nodePlatformBarrels.d.ts.map +1 -0
  75. package/dist/imports/nodePlatformBarrels.js +46 -0
  76. package/dist/imports/nodePlatformBarrels.js.map +1 -0
  77. package/dist/imports/projects.d.ts +4 -1
  78. package/dist/imports/projects.d.ts.map +1 -1
  79. package/dist/imports/projects.js +42 -17
  80. package/dist/imports/projects.js.map +1 -1
  81. package/dist/imports/resolve.d.ts.map +1 -1
  82. package/dist/imports/resolve.js +5 -3
  83. package/dist/imports/resolve.js.map +1 -1
  84. package/dist/manifests/sorted.d.ts.map +1 -1
  85. package/dist/manifests/sorted.js +1 -1
  86. package/dist/manifests/sorted.js.map +1 -1
  87. package/dist/naming/ownExports.d.ts +1 -0
  88. package/dist/naming/ownExports.d.ts.map +1 -1
  89. package/dist/naming/ownExports.js +4 -1
  90. package/dist/naming/ownExports.js.map +1 -1
  91. package/dist/rules/builtIn.d.ts +2 -2
  92. package/dist/rules/builtIn.d.ts.map +1 -1
  93. package/dist/rules/builtIn.js +4 -0
  94. package/dist/rules/builtIn.js.map +1 -1
  95. package/dist/rules/files/namedAfterExport.d.ts.map +1 -1
  96. package/dist/rules/files/namedAfterExport.js +6 -2
  97. package/dist/rules/files/namedAfterExport.js.map +1 -1
  98. package/dist/rules/imports/adminPaths.d.ts +2 -0
  99. package/dist/rules/imports/adminPaths.d.ts.map +1 -0
  100. package/dist/rules/imports/adminPaths.js +11 -0
  101. package/dist/rules/imports/adminPaths.js.map +1 -0
  102. package/dist/rules/imports/resolvable.d.ts.map +1 -1
  103. package/dist/rules/imports/resolvable.js +9 -6
  104. package/dist/rules/imports/resolvable.js.map +1 -1
  105. package/dist/rules/imports/runtime.d.ts.map +1 -1
  106. package/dist/rules/imports/runtime.js +3 -2
  107. package/dist/rules/imports/runtime.js.map +1 -1
  108. package/dist/rules/stories/collectionOrigins.d.ts +1 -1
  109. package/dist/rules/stories/collectionOrigins.d.ts.map +1 -1
  110. package/dist/rules/stories/collectionOrigins.js.map +1 -1
  111. package/dist/rules/stories/globalRetries.d.ts +2 -0
  112. package/dist/rules/stories/globalRetries.d.ts.map +1 -0
  113. package/dist/rules/stories/globalRetries.js +45 -0
  114. package/dist/rules/stories/globalRetries.js.map +1 -0
  115. package/dist/rules/stories/httpStatus.d.ts.map +1 -1
  116. package/dist/rules/stories/httpStatus.js +11 -2
  117. package/dist/rules/stories/httpStatus.js.map +1 -1
  118. package/dist/rules/stories/importOrigin.d.ts +3 -1
  119. package/dist/rules/stories/importOrigin.d.ts.map +1 -1
  120. package/dist/rules/stories/importOrigin.js +15 -0
  121. package/dist/rules/stories/importOrigin.js.map +1 -1
  122. package/dist/rules/stories/origins.d.ts.map +1 -1
  123. package/dist/rules/stories/origins.js +14 -12
  124. package/dist/rules/stories/origins.js.map +1 -1
  125. package/dist/rules/stories/retryOption.d.ts +3 -0
  126. package/dist/rules/stories/retryOption.d.ts.map +1 -0
  127. package/dist/rules/stories/retryOption.js +37 -0
  128. package/dist/rules/stories/retryOption.js.map +1 -0
  129. package/package.json +4 -4
  130. package/src/adapters/compileCache.config.ts +3 -0
  131. package/src/adapters/knip/entryPointFindings.ts +15 -8
  132. package/src/adapters/manifestInventory.ts +3 -1
  133. package/src/adapters/manifestReader.ts +4 -3
  134. package/src/adapters/testProjects.ts +1 -0
  135. package/src/biome/recognizeDiagnostics.ts +6 -7
  136. package/src/biome/report.ts +11 -5
  137. package/src/cli/changedRanges.ts +24 -0
  138. package/src/cli/fix.ts +13 -14
  139. package/src/cli/lint.ts +3 -0
  140. package/src/config.ts +7 -5
  141. package/src/engine/runRules.ts +31 -11
  142. package/src/engine/session.ts +14 -13
  143. package/src/exceptions/biomeFindings.ts +29 -0
  144. package/src/hooks/preCommit.ts +1 -1
  145. package/src/imports/adminBindings.ts +45 -0
  146. package/src/imports/adminEvidence.ts +52 -0
  147. package/src/imports/adminFindings.ts +65 -0
  148. package/src/imports/extract.ts +12 -10
  149. package/src/imports/graph.ts +7 -4
  150. package/src/imports/nodePlatformBarrels.ts +51 -0
  151. package/src/imports/projects.ts +61 -27
  152. package/src/imports/resolve.ts +5 -3
  153. package/src/manifests/sorted.ts +3 -3
  154. package/src/naming/ownExports.ts +5 -1
  155. package/src/rules/builtIn.ts +4 -0
  156. package/src/rules/files/namedAfterExport.ts +6 -2
  157. package/src/rules/imports/adminPaths.ts +12 -0
  158. package/src/rules/imports/resolvable.ts +9 -6
  159. package/src/rules/imports/runtime.ts +3 -2
  160. package/src/rules/stories/collectionOrigins.ts +13 -1
  161. package/src/rules/stories/globalRetries.ts +50 -0
  162. package/src/rules/stories/httpStatus.ts +13 -2
  163. package/src/rules/stories/importOrigin.ts +17 -0
  164. package/src/rules/stories/origins.ts +14 -13
  165. package/src/rules/stories/retryOption.ts +41 -0
@@ -5,6 +5,7 @@ export type ImportKind = "import" | "path-reference" | "resolve" | "type-referen
5
5
  export interface ImportRequest {
6
6
  readonly kind: ImportKind;
7
7
  readonly line: number;
8
+ readonly mode?: ts.ResolutionMode;
8
9
  readonly specifier: string;
9
10
  readonly type: boolean;
10
11
  }
@@ -80,27 +81,28 @@ function nested(node: ts.Node): Found | undefined {
80
81
  return undefined;
81
82
  }
82
83
 
83
- function requestOf(source: ts.SourceFile, at: ts.Node, found: Found | undefined): readonly ImportRequest[] {
84
+ function requestOf(source: ts.SourceFile, at: ts.Node, found: Found | undefined, options?: ts.CompilerOptions): readonly ImportRequest[] {
84
85
  if (found?.node === undefined || !ts.isStringLiteralLike(found.node)) {
85
86
  return [];
86
87
  }
87
- return [{ kind: found.kind, line: lineAt(source, at.getStart(source)), specifier: found.node.text, type: found.type }];
88
+ const mode = options === undefined ? {} : { mode: ts.getModeForUsageLocation(source, found.node, options) };
89
+ return [{ ...mode, kind: found.kind, line: lineAt(source, at.getStart(source)), specifier: found.node.text, type: found.type }];
88
90
  }
89
91
 
90
- function nestedRequests(source: ts.SourceFile): readonly ImportRequest[] {
92
+ function nestedRequests(source: ts.SourceFile, options?: ts.CompilerOptions): readonly ImportRequest[] {
91
93
  if (!MAY_CALL.test(source.text)) {
92
94
  return [];
93
95
  }
94
96
  const requests: ImportRequest[] = [];
95
97
  function visit(node: ts.Node): void {
96
- requests.push(...requestOf(source, node, nested(node)));
98
+ requests.push(...requestOf(source, node, nested(node), options));
97
99
  ts.forEachChild(node, visit);
98
100
  }
99
101
  visit(source);
100
102
  return requests;
101
103
  }
102
104
 
103
- function jsDocRequests(source: ts.SourceFile): readonly ImportRequest[] {
105
+ function jsDocRequests(source: ts.SourceFile, options?: ts.CompilerOptions): readonly ImportRequest[] {
104
106
  if (!source.text.includes(JSDOC_IMPORT)) {
105
107
  return [];
106
108
  }
@@ -108,7 +110,7 @@ function jsDocRequests(source: ts.SourceFile): readonly ImportRequest[] {
108
110
  .flatMap((node) => ts.getJSDocCommentsAndTags(node))
109
111
  .flatMap((doc) => (ts.isJSDoc(doc) ? (doc.tags ?? []) : [doc]))
110
112
  .filter(ts.isJSDocImportTag);
111
- return tags.flatMap((tag) => requestOf(source, tag, { kind: "import", node: tag.moduleSpecifier, type: true }));
113
+ return tags.flatMap((tag) => requestOf(source, tag, { kind: "import", node: tag.moduleSpecifier, type: true }, options));
112
114
  }
113
115
 
114
116
  function referenceRequests(source: ts.SourceFile): readonly ImportRequest[] {
@@ -118,12 +120,12 @@ function referenceRequests(source: ts.SourceFile): readonly ImportRequest[] {
118
120
  return [...source.typeReferenceDirectives.map(requestFor("type-reference")), ...source.referencedFiles.map(requestFor("path-reference"))];
119
121
  }
120
122
 
121
- export function importsOf(source: ts.SourceFile, declarationFile: boolean): readonly ImportRequest[] {
123
+ export function importsOf(source: ts.SourceFile, declarationFile: boolean, options?: ts.CompilerOptions): readonly ImportRequest[] {
122
124
  const all = [
123
125
  ...referenceRequests(source),
124
- ...source.statements.flatMap((statement) => requestOf(source, statement, declared(statement))),
125
- ...jsDocRequests(source),
126
- ...nestedRequests(source),
126
+ ...source.statements.flatMap((statement) => requestOf(source, statement, declared(statement), options)),
127
+ ...jsDocRequests(source, options),
128
+ ...nestedRequests(source, options),
127
129
  ];
128
130
  return declarationFile ? all.map((request) => ({ ...request, type: true })) : all;
129
131
  }
@@ -1,6 +1,7 @@
1
1
  import { realpathSync } from "node:fs";
2
2
  import { join, posix } from "node:path";
3
- import type { RuleInputs, SourceFile } from "#rule.ts";
3
+ import ts from "typescript";
4
+ import type { Findings, RuleInputs, SourceFile } from "#rule.ts";
4
5
  import { parse } from "#rules/parse.ts";
5
6
  import { ambientModules } from "./ambient.ts";
6
7
  import { type ImportKind, type ImportRequest, importsOf } from "./extract.ts";
@@ -20,6 +21,7 @@ export interface ImportEdge {
20
21
  export type UnresolvedImport = Omit<ImportEdge, "to"> & { readonly missing: string | undefined };
21
22
 
22
23
  export interface ImportGraph {
24
+ readonly configFindings: Findings;
23
25
  readonly edges: readonly ImportEdge[];
24
26
  readonly modules: readonly string[];
25
27
  readonly packages: readonly WorkspacePackage[];
@@ -42,7 +44,7 @@ function missingTarget(root: string, from: string, request: ImportRequest, proje
42
44
  return target === undefined || target.startsWith("../") ? undefined : target;
43
45
  }
44
46
 
45
- function walk(inputs: RuleInputs, root: string): Pick<ImportGraph, "edges" | "modules" | "unresolved"> {
47
+ function walk(inputs: RuleInputs, root: string): Pick<ImportGraph, "configFindings" | "edges" | "modules" | "unresolved"> {
46
48
  const projectOf = projectsFor(root);
47
49
  const parsed = inputs.sources.flatMap((file) => {
48
50
  const syntax = parse(file);
@@ -53,7 +55,8 @@ function walk(inputs: RuleInputs, root: string): Pick<ImportGraph, "edges" | "mo
53
55
  const unresolved: UnresolvedImport[] = [];
54
56
  for (const { file, path, syntax } of parsed) {
55
57
  const project = projectOf(path);
56
- for (const request of importsOf(syntax, isDeclarationFile(file.path))) {
58
+ syntax.impliedNodeFormat = ts.getImpliedNodeFormatForFile(path, undefined, ts.sys, project.options);
59
+ for (const request of importsOf(syntax, isDeclarationFile(file.path), project.options)) {
57
60
  const to = resolveImport(root, ambient, request, path, project);
58
61
  if (to === undefined) {
59
62
  const missing = missingTarget(root, file.path, request, project);
@@ -64,7 +67,7 @@ function walk(inputs: RuleInputs, root: string): Pick<ImportGraph, "edges" | "mo
64
67
  }
65
68
  }
66
69
  }
67
- return { edges, modules: parsed.map(({ file }) => file.path), unresolved };
70
+ return { configFindings: projectOf.findings, edges, modules: parsed.map(({ file }) => file.path), unresolved };
68
71
  }
69
72
 
70
73
  async function build(inputs: RuleInputs): Promise<ImportGraph> {
@@ -0,0 +1,51 @@
1
+ import ts from "typescript";
2
+ import { isTestCode } from "#naming/testName.ts";
3
+ import type { Finding, SourceFile } from "#rule.ts";
4
+ import { parse } from "#rules/parse.ts";
5
+ import { specifierSites } from "./specifiers.ts";
6
+
7
+ const BARREL = "@effect/platform-node";
8
+
9
+ function subpaths(source: ts.SourceFile, start: number): readonly string[] | undefined {
10
+ const statement = source.statements.find((node) => node.pos <= start && node.end > start);
11
+ const bindings = statement !== undefined && ts.isImportDeclaration(statement) ? statement.importClause?.namedBindings : undefined;
12
+ if (bindings !== undefined && ts.isNamedImports(bindings)) {
13
+ const values = bindings.elements.filter((element) => !element.isTypeOnly);
14
+ return values.length === 0 && bindings.elements.length > 0
15
+ ? undefined
16
+ : values.map((element) => `${BARREL}/${(element.propertyName ?? element.name).text}`);
17
+ }
18
+ if (
19
+ statement !== undefined
20
+ && ts.isExportDeclaration(statement)
21
+ && statement.exportClause !== undefined
22
+ && ts.isNamedExports(statement.exportClause)
23
+ && statement.exportClause.elements.every((element) => element.isTypeOnly)
24
+ ) {
25
+ return undefined;
26
+ }
27
+ return [];
28
+ }
29
+
30
+ export function nodePlatformBarrels(file: SourceFile): readonly Finding[] {
31
+ const source = isTestCode(file.path) ? undefined : parse(file);
32
+ if (source === undefined || source.isDeclarationFile) {
33
+ return [];
34
+ }
35
+ return specifierSites(source)
36
+ .filter((site) => site.specifier === BARREL && !site.type)
37
+ .flatMap((site) => {
38
+ const paths = subpaths(source, site.start);
39
+ if (paths === undefined) {
40
+ return [];
41
+ }
42
+ return [
43
+ {
44
+ file: file.path,
45
+ line: site.line,
46
+ message: `The ${BARREL} barrel loads optional integrations such as redis. Import module subpaths instead: ${paths.length > 0 ? paths.map((path) => `\`import * as ${path.slice(path.lastIndexOf("/") + 1)} from "${path}"\``).join("; ") : `\`import * as NodeServices from "${BARREL}/NodeServices"\` (choose the module you use)`}.`,
47
+ subject: BARREL,
48
+ },
49
+ ];
50
+ });
51
+ }
@@ -1,5 +1,6 @@
1
1
  import { dirname, join, relative } from "node:path";
2
2
  import ts from "typescript";
3
+ import type { Finding, Findings } from "#rule.ts";
3
4
 
4
5
  export interface Project {
5
6
  readonly cache: ts.ModuleResolutionCache;
@@ -18,29 +19,23 @@ interface ParsedProject {
18
19
 
19
20
  const CONFIG = "tsconfig.json";
20
21
 
21
- const SOURCE_CONDITION = "source";
22
-
23
- const quietHost: ts.ParseConfigFileHost = { ...ts.sys, onUnRecoverableConfigFileDiagnostic: () => undefined };
24
-
25
22
  function resolutionOptions(options: ts.CompilerOptions, declarations: boolean): ts.CompilerOptions {
26
23
  return {
27
24
  ...options,
28
- allowArbitraryExtensions: declarations,
29
- allowImportingTsExtensions: true,
30
- allowJs: true,
31
- customConditions: [...new Set([SOURCE_CONDITION, ...(options.customConditions ?? [])])],
32
- module: ts.ModuleKind.ESNext,
33
- moduleResolution: ts.ModuleResolutionKind.Bundler,
34
25
  noDtsResolution: !declarations,
35
- resolveJsonModule: true,
36
- resolvePackageJsonExports: true,
37
- resolvePackageJsonImports: true,
38
26
  };
39
27
  }
40
28
 
41
29
  function projectOf(root: string, parsed: ParsedProject | undefined): Project {
42
- const runtime = resolutionOptions(parsed?.options ?? {}, false);
43
- const types = resolutionOptions(parsed?.options ?? {}, true);
30
+ const options = parsed?.options ?? {
31
+ allowJs: true,
32
+ customConditions: ["source"],
33
+ module: ts.ModuleKind.ESNext,
34
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
35
+ resolveJsonModule: true,
36
+ };
37
+ const runtime = resolutionOptions(options, false);
38
+ const types = resolutionOptions(options, true);
44
39
  return {
45
40
  cache: ts.createModuleResolutionCache(root, (file) => file, runtime),
46
41
  files: parsed?.files ?? new Set(),
@@ -50,8 +45,28 @@ function projectOf(root: string, parsed: ParsedProject | undefined): Project {
50
45
  };
51
46
  }
52
47
 
53
- function parse(path: string): ParsedProject {
54
- const parsed = ts.getParsedCommandLineOfConfigFile(path, {}, quietHost);
48
+ function parse(path: string, report: (diagnostic: ts.Diagnostic, config: string) => void): ParsedProject {
49
+ const parsed = ts.getParsedCommandLineOfConfigFile(
50
+ path,
51
+ {},
52
+ {
53
+ ...ts.sys,
54
+ onUnRecoverableConfigFileDiagnostic: (diagnostic) => report(diagnostic, path),
55
+ readFile: (file) => {
56
+ const contents = ts.sys.readFile(file);
57
+ if (contents !== undefined) {
58
+ const diagnostic = ts.parseConfigFileTextToJson(file, contents).error;
59
+ if (diagnostic !== undefined) {
60
+ report(diagnostic, file);
61
+ }
62
+ }
63
+ return contents;
64
+ },
65
+ },
66
+ );
67
+ for (const diagnostic of parsed?.errors ?? []) {
68
+ report(diagnostic, path);
69
+ }
55
70
  return {
56
71
  files: new Set(parsed?.fileNames ?? []),
57
72
  key: path,
@@ -83,8 +98,24 @@ function memo<TValue>(compute: (key: string) => TValue): (key: string) => TValue
83
98
  }
84
99
 
85
100
  // A file resolves with the options of the project that includes it: the nearest tsconfig.json, or a project it references.
86
- export function projectsFor(root: string): (file: string) => Project {
87
- const parsedAt = memo(parse);
101
+ export function projectsFor(root: string): ((file: string) => Project) & { readonly findings: Findings } {
102
+ const findings: Finding[] = [];
103
+ const reported = new Set<string>();
104
+ const parsedAt = memo((path) =>
105
+ parse(path, (diagnostic, config) => {
106
+ const file = relative(root, diagnostic.file?.fileName ?? config).replaceAll("\\", "/");
107
+ const line =
108
+ diagnostic.file !== undefined && diagnostic.start !== undefined
109
+ ? diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start).line + 1
110
+ : undefined;
111
+ const message = `TS${diagnostic.code}: ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")} Repair the tsconfig before trusting import findings.`;
112
+ const key = `${file}:${line}:${message}`;
113
+ if (!reported.has(key)) {
114
+ reported.add(key);
115
+ findings.push({ file, line, message, subject: `TS${diagnostic.code}` });
116
+ }
117
+ }),
118
+ );
88
119
  function withReferences(path: string, seen: Set<string>): readonly ParsedProject[] {
89
120
  if (seen.has(path)) {
90
121
  return [];
@@ -95,12 +126,15 @@ export function projectsFor(root: string): (file: string) => Project {
95
126
  }
96
127
  const familyAt = memo((config) => withReferences(config, new Set()));
97
128
  const projects = new Map<string, Project>();
98
- return (file) => {
99
- const config = nearestConfig(root, file);
100
- const owner = config === undefined ? undefined : (familyAt(config).find((candidate) => candidate.files.has(file)) ?? parsedAt(config));
101
- const key = owner?.key ?? "";
102
- const project = projects.get(key) ?? projectOf(root, owner);
103
- projects.set(key, project);
104
- return project;
105
- };
129
+ return Object.assign(
130
+ (file: string) => {
131
+ const config = nearestConfig(root, file);
132
+ const owner = config === undefined ? undefined : (familyAt(config).find((candidate) => candidate.files.has(file)) ?? parsedAt(config));
133
+ const key = owner?.key ?? "";
134
+ const project = projects.get(key) ?? projectOf(root, owner);
135
+ projects.set(key, project);
136
+ return project;
137
+ },
138
+ { findings },
139
+ );
106
140
  }
@@ -60,8 +60,9 @@ function located(request: ImportRequest, from: string, project: Project): string
60
60
  return ts.sys.fileExists(path) ? path : undefined;
61
61
  }
62
62
  return (
63
- ts.resolveModuleName(specifier, from, project.options, ts.sys, project.cache).resolvedModule?.resolvedFileName
64
- ?? ts.resolveModuleName(specifier, from, project.typesOptions, assetHost, project.typesCache).resolvedModule?.resolvedFileName
63
+ ts.resolveModuleName(specifier, from, project.options, ts.sys, project.cache, undefined, request.mode).resolvedModule?.resolvedFileName
64
+ ?? ts.resolveModuleName(specifier, from, project.typesOptions, assetHost, project.typesCache, undefined, request.mode).resolvedModule
65
+ ?.resolvedFileName
65
66
  );
66
67
  }
67
68
 
@@ -74,7 +75,8 @@ export function presumedTarget(root: string, request: ImportRequest, from: strin
74
75
  if (request.kind !== "import" || !request.specifier.startsWith(PACKAGE_IMPORT)) {
75
76
  return undefined;
76
77
  }
77
- const path = ts.resolveModuleName(request.specifier.replace(QUERY, ""), from, project.options, presumingHost).resolvedModule?.resolvedFileName;
78
+ const path = ts.resolveModuleName(request.specifier.replace(QUERY, ""), from, project.options, presumingHost, undefined, undefined, request.mode)
79
+ .resolvedModule?.resolvedFileName;
78
80
  return path === undefined ? undefined : posix(relative(root, path));
79
81
  }
80
82
 
@@ -1,5 +1,5 @@
1
1
  import { basename, join, relative } from "node:path";
2
- import { Effect, FileSystem } from "effect";
2
+ import { Effect, FileSystem, type Scope } from "effect";
3
3
  import { sortPackageJson } from "sort-package-json";
4
4
  import { ManifestFailure, manifestEntry } from "#adapters/manifestInventory.ts";
5
5
  import { manifestReader } from "#adapters/manifestReader.ts";
@@ -27,7 +27,7 @@ export function sortingOf(text: string): Sorting {
27
27
 
28
28
  export const sortManifests = Effect.fn("Manifests.sortManifests")(function* (
29
29
  root: string,
30
- ): Effect.fn.Return<number, FilesystemFailure | ManifestFailure | SetupFailure, RuleServices> {
30
+ ): Effect.fn.Return<number, FilesystemFailure | ManifestFailure | SetupFailure, RuleServices | Scope.Scope> {
31
31
  const fs = yield* FileSystem.FileSystem;
32
32
  const manifests = yield* manifestsIn(root);
33
33
  const readText = yield* manifestReader(root);
@@ -57,4 +57,4 @@ export const sortManifests = Effect.fn("Manifests.sortManifests")(function* (
57
57
  ),
58
58
  );
59
59
  return written.filter(Boolean).length;
60
- });
60
+ }, Effect.scoped);
@@ -61,8 +61,12 @@ function declared(statement: ts.Statement): readonly OwnExport[] {
61
61
  return named !== undefined && ts.isIdentifier(named) ? [{ constant: false, kind: "value", name: named.text }] : [];
62
62
  }
63
63
 
64
+ export function ownDeclarations(source: ts.SourceFile): readonly OwnExport[] {
65
+ return source.statements.flatMap(declared);
66
+ }
67
+
64
68
  function locals(source: ts.SourceFile): ReadonlyMap<string, OwnExport> {
65
- const all = source.statements.flatMap(declared);
69
+ const all = ownDeclarations(source);
66
70
  return new Map(all.map((local) => [local.name, local]));
67
71
  }
68
72
 
@@ -14,6 +14,7 @@ import { distinctCase } from "#rules/files/distinctCase.ts";
14
14
  import { folderNames } from "#rules/files/folderNames.ts";
15
15
  import { namedAfterExport } from "#rules/files/namedAfterExport.ts";
16
16
  import { otherNames } from "#rules/files/otherNames.ts";
17
+ import { adminPaths } from "#rules/imports/adminPaths.ts";
17
18
  import { importsAliased } from "#rules/imports/aliased.ts";
18
19
  import { importCycles } from "#rules/imports/cycles.ts";
19
20
  import { importFences } from "#rules/imports/fences.ts";
@@ -25,6 +26,7 @@ import { jsxConditionals } from "#rules/react/jsxConditionals.ts";
25
26
  import { authSql } from "#rules/stories/authSql.ts";
26
27
  import { domainOutcomes } from "#rules/stories/domainOutcomes.ts";
27
28
  import { storyEngine } from "#rules/stories/engine.ts";
29
+ import { globalRetries } from "#rules/stories/globalRetries.ts";
28
30
  import { groupedOutcomes } from "#rules/stories/groupedOutcomes.ts";
29
31
  import { httpStatus } from "#rules/stories/httpStatus.ts";
30
32
  import { namedValues } from "#rules/stories/namedValues.ts";
@@ -83,6 +85,7 @@ export const builtInRules = [
83
85
  importsResolvable,
84
86
  importsManifest,
85
87
  importsAliased,
88
+ adminPaths,
86
89
  noTestCode,
87
90
  manifestsValid,
88
91
  manifestsSorted,
@@ -97,6 +100,7 @@ export const builtInRules = [
97
100
  testsColocated,
98
101
  storySetup,
99
102
  storySpecs,
103
+ globalRetries,
100
104
  storyEngine,
101
105
  queueSql,
102
106
  authSql,
@@ -6,7 +6,7 @@ import { exportFits } from "#naming/exportFits.ts";
6
6
  import { mainExport } from "#naming/mainExport.ts";
7
7
  import { isMigrationFile } from "#naming/migrationFile.ts";
8
8
  import { moduleRoot } from "#naming/moduleRoot.ts";
9
- import { ownExports } from "#naming/ownExports.ts";
9
+ import { ownDeclarations, ownExports } from "#naming/ownExports.ts";
10
10
  import { type PackageLayout, packageLayout } from "#naming/packageLayout.ts";
11
11
  import { CAMEL, KEBAB, sameWord, wordsOf } from "#naming/words.ts";
12
12
  import { defineRule, type Finding, type SourceFile } from "#rule.ts";
@@ -48,6 +48,10 @@ function repeated(stem: string, folders: readonly string[]): string | undefined
48
48
  function nameFinding(file: SourceFile, stem: string, folders: readonly string[]): string | undefined {
49
49
  const source = parse(file);
50
50
  const exports = source === undefined ? [] : ownExports(source);
51
+ const constants = source === undefined ? [] : ownDeclarations(source).filter((entry) => entry.constant);
52
+ if (constants.some((entry) => exportFits(entry.name, stem, folders))) {
53
+ return undefined;
54
+ }
51
55
  const [only] = exports;
52
56
  if (only === undefined) {
53
57
  return CAMEL.test(stem)
@@ -93,7 +97,7 @@ export const namedAfterExport = defineRule({
93
97
  .flatMap((file) => findingsOf(file, layout));
94
98
  },
95
99
  description:
96
- "A file is named after its main export, including a single constant, with its folders as the prefix; module client/admin and server/admin files may repeat names from above the admin folder. A file of several exports is a camelCase topic file, and a script is kebab-case. Rename the file or the export; nothing renames them for you.",
100
+ "A file is named after its main export or a module-level constant, including a private constant, with its folders as the prefix; module client/admin and server/admin files may repeat names from above the admin folder. A file of several exports is a camelCase topic file, and a script is kebab-case. Rename the file or the export; nothing renames them for you.",
97
101
  id: "files/named-after-export",
98
102
  options: Schema.toStandardSchemaV1(NamedAfterExportOptions, { parseOptions: { errors: "all", onExcessProperty: "error" } }),
99
103
  validate: validateGlobs,
@@ -0,0 +1,12 @@
1
+ import { Effect } from "effect";
2
+ import { adminFindings } from "#imports/adminFindings.ts";
3
+ import { importGraph } from "#imports/graph.ts";
4
+ import { defineRule } from "#rule.ts";
5
+
6
+ export const adminPaths = defineRule({
7
+ check: (inputs) => Effect.promise(() => importGraph(inputs)).pipe(Effect.map((graph) => adminFindings(graph, inputs.sources))),
8
+ description:
9
+ "Admin-only source files live under an admin/ segment; member code cannot reach admin/ implementations. Registration and module composition may import admin registrations and declarations. Move the file to the folder named by the finding.",
10
+ id: "imports/admin-paths",
11
+ registrable: false,
12
+ });
@@ -11,12 +11,15 @@ export const importsResolvable = defineRule({
11
11
  check: Effect.fn("Imports.check")(function* ({ options, ...inputs }) {
12
12
  const graph = yield* Effect.promise(() => importGraph(inputs));
13
13
  const unresolved = yield* withoutGenerated(inputs, graph, options.generated);
14
- return unresolved.map((request) => ({
15
- file: request.from,
16
- line: request.line,
17
- message: `Cannot resolve "${request.specifier}". Fix the path, install or declare the package, or declare the module in a .d.ts file among the sources.`,
18
- subject: request.specifier,
19
- }));
14
+ return [
15
+ ...graph.configFindings,
16
+ ...unresolved.map((request) => ({
17
+ file: request.from,
18
+ line: request.line,
19
+ message: `Cannot resolve "${request.specifier}". Fix the path, install or declare the package, or declare the module in a .d.ts file among the sources.`,
20
+ subject: request.specifier,
21
+ })),
22
+ ];
20
23
  }),
21
24
  description: "Every import resolves to a file, a package or a declared module, so no edge of the import graph goes unchecked.",
22
25
  id: "imports/resolvable",
@@ -1,5 +1,6 @@
1
1
  import { Effect } from "effect";
2
2
  import { type ImportGraph, importGraph } from "#imports/graph.ts";
3
+ import { nodePlatformBarrels } from "#imports/nodePlatformBarrels.ts";
3
4
  import { builtinName } from "#imports/packageName.ts";
4
5
  import { type Runtime, runtimeDeclarationProblems, runtimeOf } from "#imports/runtime.ts";
5
6
  import { isTestCode } from "#naming/testName.ts";
@@ -39,7 +40,7 @@ export const importsRuntime = defineRule({
39
40
  Effect.gen(function* () {
40
41
  const graph = yield* Effect.promise(() => importGraph(inputs));
41
42
  const runtime = yield* runtimeOf(inputs, graph.packages);
42
- const imports = runtimeFindings(graph, runtime);
43
+ const imports = [...runtimeFindings(graph, runtime), ...inputs.sources.flatMap(nodePlatformBarrels)];
43
44
  const declarations = (yield* runtimeDeclarationProblems(inputs, graph.packages)).map(({ directory, message }) => ({
44
45
  file: directory === "." ? "package.json" : `${directory}/package.json`,
45
46
  line: 1,
@@ -54,6 +55,6 @@ export const importsRuntime = defineRule({
54
55
  return [...imports, ...declarations, ...shared.flatMap(browserGlobals)];
55
56
  }),
56
57
  description:
57
- "Runtime folders define client, server and shared code. A manifest's quality.runtime declares a single-runtime package whole; executable packages without runtime folders and package-root tooling are server code.",
58
+ "Runtime folders define client, server and shared code. A manifest's quality.runtime declares a single-runtime package whole; executable packages without runtime folders and package-root tooling are server code. Production imports use @effect/platform-node module subpaths so its barrel does not load optional integrations.",
58
59
  id: "imports/runtime",
59
60
  });
@@ -1,6 +1,18 @@
1
1
  import ts from "typescript";
2
2
 
3
- export type Origin = "factory" | "kit" | "story" | "plain" | "suite" | "vitest" | "stories" | "function" | readonly Origin[] | undefined;
3
+ export type Origin =
4
+ | "factory"
5
+ | "kit"
6
+ | "story"
7
+ | "plain"
8
+ | "suite"
9
+ | "vitest"
10
+ | "stories"
11
+ | "effectFactory"
12
+ | "effectKit"
13
+ | "function"
14
+ | readonly Origin[]
15
+ | undefined;
4
16
 
5
17
  export function commonOrigin(values: readonly Origin[]): Origin {
6
18
  const first = values[0];
@@ -0,0 +1,50 @@
1
+ import { Effect } from "effect";
2
+ import ts from "typescript";
3
+ import { importGraph } from "#imports/graph.ts";
4
+ import { defineRule } from "#rule.ts";
5
+ import type { Origin } from "./collectionOrigins.ts";
6
+ import { storyOrigins } from "./origins.ts";
7
+ import { retryOption } from "./retryOption.ts";
8
+ import { memberName, nodesWhere } from "./syntax.ts";
9
+
10
+ const BUILDERS = new Set(["each", "for", "extend", "runIf", "skipIf", "layer"]);
11
+ const MESSAGE =
12
+ "Declares a test or suite retry. Remove the retry option: retries are global only and recorded by vitest-rerun, so flakes stay visible.";
13
+
14
+ function optionsOf(call: ts.CallExpression, origin: Origin): readonly ts.Expression[] {
15
+ if (origin === "story") {
16
+ return call.arguments.slice(3, 4);
17
+ }
18
+ return origin === "plain" || origin === "suite" ? call.arguments.slice(1, 3) : [];
19
+ }
20
+
21
+ export const globalRetries = defineRule({
22
+ check: (inputs) =>
23
+ Effect.gen(function* () {
24
+ const graph = yield* Effect.promise(() => importGraph(inputs));
25
+ const origins = storyOrigins(inputs, graph);
26
+ const retry = retryOption(origins.checker);
27
+ return inputs.sources.flatMap((file) => {
28
+ const source = origins.source(file.path);
29
+ if (source === undefined) {
30
+ return [];
31
+ }
32
+ const findings = nodesWhere(source, (node) => {
33
+ if (!ts.isCallExpression(node) || BUILDERS.has(memberName(node.expression) ?? "")) {
34
+ return false;
35
+ }
36
+ if (!node.arguments.slice(1, 4).some((argument) => retry(argument))) {
37
+ return false;
38
+ }
39
+ return optionsOf(node, origins.origin(node.expression)).some((argument) => retry(argument));
40
+ });
41
+ return findings.map((node) => ({
42
+ file: file.path,
43
+ line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1,
44
+ message: MESSAGE,
45
+ }));
46
+ });
47
+ }),
48
+ description: "Test, suite and story retries are global only and recorded by vitest-rerun; registrations declare no retry option.",
49
+ id: "tests/global-retries",
50
+ });
@@ -1,5 +1,6 @@
1
1
  import { matchesGlob } from "node:path";
2
2
  import { Schema } from "effect";
3
+ import * as HttpStatus from "effect/http/HttpStatus";
3
4
  import ts from "typescript";
4
5
  import { GlobDeclarations, globPatterns, validateGlobs } from "#config/globs.ts";
5
6
  import { defineRule } from "#rule.ts";
@@ -25,8 +26,18 @@ const COMPARISONS = new Set([
25
26
  ]);
26
27
 
27
28
  function isErrorStatus(node: ts.Expression): boolean {
28
- const number = numericValue(node);
29
- return number !== undefined && number >= 400 && number <= 599;
29
+ const value = unwrapped(node);
30
+ const literal =
31
+ ts.isCallExpression(value)
32
+ && ts.isPropertyAccessExpression(value.expression)
33
+ && ts.isIdentifier(value.expression.expression)
34
+ && value.expression.expression.text === "HttpStatus"
35
+ && value.expression.name.text === "fromLiteral"
36
+ ? value.arguments[0]
37
+ : undefined;
38
+ const number: unknown =
39
+ literal !== undefined && ts.isStringLiteralLike(literal) ? Reflect.apply(HttpStatus.fromLiteral, undefined, [literal.text]) : numericValue(value);
40
+ return typeof number === "number" && number >= 400 && number <= 599;
30
41
  }
31
42
 
32
43
  function statusBranch(node: ts.Node): boolean {
@@ -1,3 +1,14 @@
1
+ import ts from "typescript";
2
+
3
+ export function importFrom(node: ts.Node): string | undefined {
4
+ for (let current: ts.Node | undefined = node; current !== undefined; current = current.parent) {
5
+ if (ts.isImportDeclaration(current) && ts.isStringLiteral(current.moduleSpecifier)) {
6
+ return current.moduleSpecifier.text;
7
+ }
8
+ }
9
+ return undefined;
10
+ }
11
+
1
12
  function moduleOrigin(from: string | undefined) {
2
13
  if (from === "vitest" || from === "@effect/vitest") {
3
14
  return "vitest";
@@ -6,6 +17,12 @@ function moduleOrigin(from: string | undefined) {
6
17
  }
7
18
 
8
19
  export function importOrigin(from: string | undefined, name?: string) {
20
+ if (from === "@shivaedev/test/makeEffectIt.ts" && name === "makeEffectIt") {
21
+ return "effectFactory";
22
+ }
23
+ if (from === "@shivaedev/test/it.ts" && name === "it") {
24
+ return "plain";
25
+ }
9
26
  const namespace = moduleOrigin(from);
10
27
  if (name === undefined) {
11
28
  return namespace;