@shivaedev/quality 0.54.0 → 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.
- package/CHANGELOG.md +25 -0
- package/README.md +6 -4
- package/dist/adapters/compileCache.config.d.ts +2 -0
- package/dist/adapters/compileCache.config.d.ts.map +1 -0
- package/dist/adapters/compileCache.config.js +3 -0
- package/dist/adapters/compileCache.config.js.map +1 -0
- package/dist/adapters/manifestInventory.d.ts.map +1 -1
- package/dist/adapters/manifestInventory.js +3 -1
- package/dist/adapters/manifestInventory.js.map +1 -1
- package/dist/adapters/manifestReader.d.ts +2 -2
- package/dist/adapters/manifestReader.d.ts.map +1 -1
- package/dist/adapters/manifestReader.js +2 -1
- package/dist/adapters/manifestReader.js.map +1 -1
- package/dist/adapters/testProjects.d.ts.map +1 -1
- package/dist/adapters/testProjects.js +1 -0
- package/dist/adapters/testProjects.js.map +1 -1
- package/dist/biome/report.d.ts +2 -1
- package/dist/biome/report.d.ts.map +1 -1
- package/dist/biome/report.js +11 -5
- package/dist/biome/report.js.map +1 -1
- package/dist/cli/lint.d.ts.map +1 -1
- package/dist/cli/lint.js +3 -1
- package/dist/cli/lint.js.map +1 -1
- package/dist/config.d.ts +5 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/engine/runRules.d.ts.map +1 -1
- package/dist/engine/runRules.js +29 -6
- package/dist/engine/runRules.js.map +1 -1
- package/dist/engine/session.d.ts +3 -2
- package/dist/engine/session.d.ts.map +1 -1
- package/dist/engine/session.js +9 -6
- package/dist/engine/session.js.map +1 -1
- package/dist/exceptions/biomeFindings.d.ts +3 -0
- package/dist/exceptions/biomeFindings.d.ts.map +1 -1
- package/dist/exceptions/biomeFindings.js +21 -0
- package/dist/exceptions/biomeFindings.js.map +1 -1
- package/dist/hooks/preCommit.js +1 -1
- package/dist/hooks/preCommit.js.map +1 -1
- package/dist/imports/extract.d.ts +2 -1
- package/dist/imports/extract.d.ts.map +1 -1
- package/dist/imports/extract.js +11 -10
- package/dist/imports/extract.js.map +1 -1
- package/dist/imports/graph.d.ts +2 -1
- package/dist/imports/graph.d.ts.map +1 -1
- package/dist/imports/graph.js +4 -2
- package/dist/imports/graph.js.map +1 -1
- package/dist/imports/projects.d.ts +4 -1
- package/dist/imports/projects.d.ts.map +1 -1
- package/dist/imports/projects.js +42 -17
- package/dist/imports/projects.js.map +1 -1
- package/dist/imports/resolve.d.ts.map +1 -1
- package/dist/imports/resolve.js +5 -3
- package/dist/imports/resolve.js.map +1 -1
- package/dist/manifests/sorted.d.ts.map +1 -1
- package/dist/manifests/sorted.js +1 -1
- package/dist/manifests/sorted.js.map +1 -1
- package/dist/rules/builtIn.d.ts +1 -1
- package/dist/rules/builtIn.d.ts.map +1 -1
- package/dist/rules/builtIn.js +2 -0
- package/dist/rules/builtIn.js.map +1 -1
- package/dist/rules/imports/resolvable.d.ts.map +1 -1
- package/dist/rules/imports/resolvable.js +9 -6
- package/dist/rules/imports/resolvable.js.map +1 -1
- package/dist/rules/stories/collectionOrigins.d.ts +1 -1
- package/dist/rules/stories/collectionOrigins.d.ts.map +1 -1
- package/dist/rules/stories/collectionOrigins.js.map +1 -1
- package/dist/rules/stories/globalRetries.d.ts +2 -0
- package/dist/rules/stories/globalRetries.d.ts.map +1 -0
- package/dist/rules/stories/globalRetries.js +45 -0
- package/dist/rules/stories/globalRetries.js.map +1 -0
- package/dist/rules/stories/importOrigin.d.ts +3 -1
- package/dist/rules/stories/importOrigin.d.ts.map +1 -1
- package/dist/rules/stories/importOrigin.js +15 -0
- package/dist/rules/stories/importOrigin.js.map +1 -1
- package/dist/rules/stories/origins.d.ts.map +1 -1
- package/dist/rules/stories/origins.js +14 -12
- package/dist/rules/stories/origins.js.map +1 -1
- package/dist/rules/stories/retryOption.d.ts +3 -0
- package/dist/rules/stories/retryOption.d.ts.map +1 -0
- package/dist/rules/stories/retryOption.js +37 -0
- package/dist/rules/stories/retryOption.js.map +1 -0
- package/package.json +4 -4
- package/src/adapters/compileCache.config.ts +3 -0
- package/src/adapters/manifestInventory.ts +3 -1
- package/src/adapters/manifestReader.ts +4 -3
- package/src/adapters/testProjects.ts +1 -0
- package/src/biome/report.ts +11 -5
- package/src/cli/lint.ts +3 -0
- package/src/config.ts +7 -5
- package/src/engine/runRules.ts +31 -11
- package/src/engine/session.ts +14 -13
- package/src/exceptions/biomeFindings.ts +29 -0
- package/src/hooks/preCommit.ts +1 -1
- package/src/imports/extract.ts +12 -10
- package/src/imports/graph.ts +7 -4
- package/src/imports/projects.ts +61 -27
- package/src/imports/resolve.ts +5 -3
- package/src/manifests/sorted.ts +3 -3
- package/src/rules/builtIn.ts +2 -0
- package/src/rules/imports/resolvable.ts +9 -6
- package/src/rules/stories/collectionOrigins.ts +13 -1
- package/src/rules/stories/globalRetries.ts +50 -0
- package/src/rules/stories/importOrigin.ts +17 -0
- package/src/rules/stories/origins.ts +14 -13
- package/src/rules/stories/retryOption.ts +41 -0
package/src/imports/extract.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
package/src/imports/graph.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { realpathSync } from "node:fs";
|
|
2
2
|
import { join, posix } from "node:path";
|
|
3
|
-
import
|
|
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
|
-
|
|
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> {
|
package/src/imports/projects.ts
CHANGED
|
@@ -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
|
|
43
|
-
|
|
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(
|
|
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
|
|
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 (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
}
|
package/src/imports/resolve.ts
CHANGED
|
@@ -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
|
|
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)
|
|
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
|
|
package/src/manifests/sorted.ts
CHANGED
|
@@ -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);
|
package/src/rules/builtIn.ts
CHANGED
|
@@ -26,6 +26,7 @@ import { jsxConditionals } from "#rules/react/jsxConditionals.ts";
|
|
|
26
26
|
import { authSql } from "#rules/stories/authSql.ts";
|
|
27
27
|
import { domainOutcomes } from "#rules/stories/domainOutcomes.ts";
|
|
28
28
|
import { storyEngine } from "#rules/stories/engine.ts";
|
|
29
|
+
import { globalRetries } from "#rules/stories/globalRetries.ts";
|
|
29
30
|
import { groupedOutcomes } from "#rules/stories/groupedOutcomes.ts";
|
|
30
31
|
import { httpStatus } from "#rules/stories/httpStatus.ts";
|
|
31
32
|
import { namedValues } from "#rules/stories/namedValues.ts";
|
|
@@ -99,6 +100,7 @@ export const builtInRules = [
|
|
|
99
100
|
testsColocated,
|
|
100
101
|
storySetup,
|
|
101
102
|
storySpecs,
|
|
103
|
+
globalRetries,
|
|
102
104
|
storyEngine,
|
|
103
105
|
queueSql,
|
|
104
106
|
authSql,
|
|
@@ -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
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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,6 +1,18 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
|
|
3
|
-
export type Origin =
|
|
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,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;
|
|
@@ -3,18 +3,10 @@ import ts from "typescript";
|
|
|
3
3
|
import type { ImportGraph } from "#imports/graph.ts";
|
|
4
4
|
import type { RuleInputs } from "#rule.ts";
|
|
5
5
|
import { iterationOrigin, type Origin } from "./collectionOrigins.ts";
|
|
6
|
-
import { importOrigin } from "./importOrigin.ts";
|
|
6
|
+
import { importFrom, importOrigin } from "./importOrigin.ts";
|
|
7
7
|
import { storyProgram } from "./program.ts";
|
|
8
8
|
import { returnValues } from "./returnValues.ts";
|
|
9
|
-
|
|
10
|
-
function importFrom(node: ts.Node): string | undefined {
|
|
11
|
-
for (let current: ts.Node | undefined = node; current !== undefined; current = current.parent) {
|
|
12
|
-
if (ts.isImportDeclaration(current) && ts.isStringLiteral(current.moduleSpecifier)) {
|
|
13
|
-
return current.moduleSpecifier.text;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
9
|
+
import { memberName } from "./syntax.ts";
|
|
18
10
|
|
|
19
11
|
export function storyOrigins(inputs: RuleInputs, graph: ImportGraph) {
|
|
20
12
|
const program = storyProgram(inputs, graph);
|
|
@@ -75,8 +67,8 @@ export function storyOrigins(inputs: RuleInputs, graph: ImportGraph) {
|
|
|
75
67
|
}
|
|
76
68
|
|
|
77
69
|
function member(receiver: Origin, name: string): Origin {
|
|
78
|
-
if (receiver === "kit" && name === "it") {
|
|
79
|
-
return "story";
|
|
70
|
+
if ((receiver === "effectKit" && name === "effectApp") || (receiver === "kit" && name === "it")) {
|
|
71
|
+
return receiver === "kit" ? "story" : "plain";
|
|
80
72
|
}
|
|
81
73
|
if (receiver === "story" || receiver === "plain" || receiver === "suite") {
|
|
82
74
|
return receiver;
|
|
@@ -112,7 +104,10 @@ export function storyOrigins(inputs: RuleInputs, graph: ImportGraph) {
|
|
|
112
104
|
const values = returnValues(checker.getResolvedSignature(node)?.declaration);
|
|
113
105
|
return values.length > 0 && values.every((value) => value !== undefined && visit(value) === "kit") ? "kit" : callee;
|
|
114
106
|
}
|
|
115
|
-
|
|
107
|
+
if (callee === "factory" || callee === "effectFactory") {
|
|
108
|
+
return callee === "factory" ? "kit" : "effectKit";
|
|
109
|
+
}
|
|
110
|
+
return callee;
|
|
116
111
|
}
|
|
117
112
|
|
|
118
113
|
function expression(node: ts.Node): Origin {
|
|
@@ -122,9 +117,15 @@ export function storyOrigins(inputs: RuleInputs, graph: ImportGraph) {
|
|
|
122
117
|
if (ts.isCallExpression(node)) {
|
|
123
118
|
return call(node);
|
|
124
119
|
}
|
|
120
|
+
if (ts.isTaggedTemplateExpression(node)) {
|
|
121
|
+
return visit(node.tag);
|
|
122
|
+
}
|
|
125
123
|
if (ts.isPropertyAccessExpression(node)) {
|
|
126
124
|
return member(visit(node.expression), node.name.text) ?? symbol(checker.getSymbolAtLocation(node.name));
|
|
127
125
|
}
|
|
126
|
+
if (ts.isElementAccessExpression(node)) {
|
|
127
|
+
return member(visit(node.expression), memberName(node) ?? "");
|
|
128
|
+
}
|
|
128
129
|
return ts.isIdentifier(node) ? identifier(node) : declaration(node);
|
|
129
130
|
}
|
|
130
131
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { unwrapped } from "./syntax.ts";
|
|
3
|
+
|
|
4
|
+
function retryKey(name: ts.PropertyName | undefined): boolean {
|
|
5
|
+
if (name === undefined) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
const key = ts.isComputedPropertyName(name) ? unwrapped(name.expression) : name;
|
|
9
|
+
return (ts.isIdentifier(key) && !ts.isComputedPropertyName(name) && key.text === "retry") || (ts.isStringLiteralLike(key) && key.text === "retry");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function initializers(node: ts.Expression, checker: ts.TypeChecker): readonly ts.Expression[] {
|
|
13
|
+
if (!(ts.isIdentifier(node) || ts.isPropertyAccessExpression(node))) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
const symbol = checker.getSymbolAtLocation(node);
|
|
17
|
+
const target = symbol !== undefined && symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
18
|
+
return (target?.declarations ?? []).flatMap((declaration) =>
|
|
19
|
+
(ts.isVariableDeclaration(declaration) || ts.isPropertyAssignment(declaration)) && declaration.initializer !== undefined
|
|
20
|
+
? [declaration.initializer]
|
|
21
|
+
: [],
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function retryOption(checker: ts.TypeChecker) {
|
|
26
|
+
function visit(expression: ts.Expression, seen: Set<ts.Node>): boolean {
|
|
27
|
+
const node = unwrapped(expression);
|
|
28
|
+
if (seen.has(node)) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
seen.add(node);
|
|
32
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
33
|
+
return node.properties.some((property) => retryKey(property.name) || (ts.isSpreadAssignment(property) && visit(property.expression, seen)));
|
|
34
|
+
}
|
|
35
|
+
if (ts.isConditionalExpression(node)) {
|
|
36
|
+
return visit(node.whenTrue, seen) || visit(node.whenFalse, seen);
|
|
37
|
+
}
|
|
38
|
+
return initializers(node, checker).some((value) => visit(value, seen));
|
|
39
|
+
}
|
|
40
|
+
return (expression: ts.Expression) => visit(expression, new Set());
|
|
41
|
+
}
|