@stateward/core 1.2.2 → 1.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.
- package/dist/analyses.d.ts +37 -0
- package/dist/analyses.js +57 -0
- package/dist/backend/program-record.d.ts +7 -0
- package/dist/backend/typescript6.d.ts +33 -32
- package/dist/backend/typescript6.js +1438 -139
- package/dist/baseline.d.ts +1 -1
- package/dist/baseline.js +14 -10
- package/dist/cache.d.ts +74 -4
- package/dist/cache.js +211 -37
- package/dist/checker.d.ts +6 -1
- package/dist/checker.js +10 -0
- package/dist/class-id.d.ts +34 -0
- package/dist/class-id.js +93 -0
- package/dist/code-text.d.ts +8 -0
- package/dist/code-text.js +66 -0
- package/dist/config-file.js +7 -5
- package/dist/config.d.ts +10 -2
- package/dist/config.js +490 -48
- package/dist/define.d.ts +8 -2
- package/dist/disk-cache.d.ts +2 -0
- package/dist/disk-cache.js +77 -11
- package/dist/engine.d.ts +33 -1
- package/dist/engine.js +344 -24
- package/dist/fact-lines.d.ts +31 -0
- package/dist/fact-lines.js +197 -0
- package/dist/facts-versions.d.ts +27 -0
- package/dist/facts-versions.js +99 -0
- package/dist/fixes.js +4 -1
- package/dist/ignores.d.ts +11 -0
- package/dist/ignores.js +74 -27
- package/dist/implementation.d.ts +0 -6
- package/dist/implementation.js +0 -17
- package/dist/index.d.ts +8 -9
- package/dist/index.js +10 -7
- package/dist/internal.d.ts +7 -4
- package/dist/internal.js +5 -3
- package/dist/lazy.d.ts +8 -1
- package/dist/lazy.js +27 -2
- package/dist/ledger.d.ts +2 -2
- package/dist/ledger.js +2 -2
- package/dist/off-by-default.d.ts +13 -0
- package/dist/off-by-default.js +15 -0
- package/dist/options.d.ts +21 -5
- package/dist/options.js +22 -7
- package/dist/package-facts.d.ts +211 -17
- package/dist/package-facts.js +520 -38
- package/dist/plan.d.ts +1 -1
- package/dist/plan.js +7 -2
- package/dist/release.d.ts +12 -21
- package/dist/release.js +26 -38
- package/dist/renamed.d.ts +22 -3
- package/dist/renamed.js +50 -16
- package/dist/rollout.js +7 -4
- package/dist/severity.d.ts +1 -1
- package/dist/severity.js +17 -3
- package/dist/test-runner.d.ts +18 -0
- package/dist/test-runner.js +483 -0
- package/dist/testing.d.ts +3 -3
- package/dist/testing.js +5 -5
- package/dist/timing.d.ts +8 -0
- package/dist/timing.js +35 -1
- package/dist/types.d.ts +692 -19
- package/dist/unread.d.ts +90 -0
- package/dist/unread.js +405 -0
- package/dist/vocabulary.d.ts +1 -1
- package/dist/vocabulary.js +1 -1
- package/package.json +4 -2
package/dist/class-id.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a class is named across packs: by the language, never by a library. A class of the project
|
|
3
|
+
* is its declaration's symbol id; a class of the platform (TypeScript's lib, a global in a
|
|
4
|
+
* declaration file) is `builtin:<Name>`; a package's class is `package:<name>#<Class>`, the same
|
|
5
|
+
* from its types, its source and the config. The errors pack's `errors/throws` names classes so,
|
|
6
|
+
* and a pack that reads it names the classes in its own code with `classIdOf`.
|
|
7
|
+
*/
|
|
8
|
+
import ts from "typescript";
|
|
9
|
+
const TS_LIB = /\/typescript\/lib\/lib\.[^/]*\.d\.ts$/;
|
|
10
|
+
/** The outermost of nested module declarations (`declare global { namespace X { … } }`). */
|
|
11
|
+
function outermostModule(module) {
|
|
12
|
+
const outer = ts.findAncestor(module.parent, ts.isModuleDeclaration);
|
|
13
|
+
return outer === undefined ? module : outermostModule(outer);
|
|
14
|
+
}
|
|
15
|
+
/** A declaration of the platform: TypeScript's lib, or a global in a declaration file. */
|
|
16
|
+
export function isPlatformDeclaration(node, file) {
|
|
17
|
+
if (TS_LIB.test(file))
|
|
18
|
+
return true;
|
|
19
|
+
const sourceFile = node.getSourceFile();
|
|
20
|
+
if (!sourceFile.isDeclarationFile)
|
|
21
|
+
return false;
|
|
22
|
+
const module = ts.findAncestor(node.parent, ts.isModuleDeclaration);
|
|
23
|
+
const enclosing = module === undefined ? undefined : outermostModule(module);
|
|
24
|
+
// `declare module "x"` is a package; `declare global` is the platform; a namespace is what
|
|
25
|
+
// its file is.
|
|
26
|
+
if (enclosing !== undefined && ts.isStringLiteral(enclosing.name))
|
|
27
|
+
return false;
|
|
28
|
+
if (enclosing?.name.text === "global")
|
|
29
|
+
return true;
|
|
30
|
+
return !ts.isExternalModule(sourceFile);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `axios`, `@tanstack/react-query`, `react` for `@types/react`, `@babel/core` for
|
|
34
|
+
* `@types/babel__core`: the package of a path inside a node_modules folder (either slash).
|
|
35
|
+
* Undefined for a path outside one.
|
|
36
|
+
*/
|
|
37
|
+
function packageNameIn(file) {
|
|
38
|
+
const normal = file.replaceAll("\\", "/");
|
|
39
|
+
const at = normal.lastIndexOf("/node_modules/");
|
|
40
|
+
if (at < 0)
|
|
41
|
+
return undefined;
|
|
42
|
+
const [first = "", second = ""] = normal.slice(at + "/node_modules/".length).split("/");
|
|
43
|
+
const scoped = first.startsWith("@");
|
|
44
|
+
if (first === "" || (scoped && second === ""))
|
|
45
|
+
return undefined;
|
|
46
|
+
if (first === "@types")
|
|
47
|
+
return second.includes("__") ? `@${second.replace("__", "/")}` : second;
|
|
48
|
+
return scoped ? `${first}/${second}` : first;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The package a file outside the project belongs to: by its node_modules folder, or, for a
|
|
52
|
+
* package linked from elsewhere (a workspace package, whose real path has no node_modules), by
|
|
53
|
+
* the name in its package.json.
|
|
54
|
+
*/
|
|
55
|
+
export function packageNameOf(types, file) {
|
|
56
|
+
return packageNameIn(file) ?? types.packageOf(file);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The package a declaration outside the project belongs to: the `declare module "x"` it sits in,
|
|
60
|
+
* by the name it is written with, else its file's package (`packageNameOf`); undefined when
|
|
61
|
+
* neither names one.
|
|
62
|
+
*/
|
|
63
|
+
export function declaredPackageOf(types, declaration) {
|
|
64
|
+
const module = ts.findAncestor(declaration.node.parent, ts.isModuleDeclaration);
|
|
65
|
+
const outer = module === undefined ? undefined : outermostModule(module);
|
|
66
|
+
return outer !== undefined && ts.isStringLiteral(outer.name)
|
|
67
|
+
? outer.name.text
|
|
68
|
+
: packageNameOf(types, declaration.file);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The id of the class a name refers to (`X` in `throw new X()`, `ns.X`, `@Catch(X)`):
|
|
72
|
+
* `builtin:<Name>` for a class of the platform, `package:<name>#<Class>` for a package's class,
|
|
73
|
+
* the symbol id (`SymbolRef.id`) for a class of the project. Undefined when the name resolves to
|
|
74
|
+
* nothing, or to a declaration outside the project whose package is not known.
|
|
75
|
+
*/
|
|
76
|
+
export function classIdOf(types, node) {
|
|
77
|
+
const name = ts.isPropertyAccessExpression(node)
|
|
78
|
+
? node.name
|
|
79
|
+
: ts.isQualifiedName(node)
|
|
80
|
+
? node.right
|
|
81
|
+
: node;
|
|
82
|
+
const symbol = types.symbolAt(name);
|
|
83
|
+
const declaration = symbol === undefined ? undefined : types.declarationOf(symbol);
|
|
84
|
+
if (symbol === undefined || declaration === undefined)
|
|
85
|
+
return undefined;
|
|
86
|
+
if (types.isOwnFile(declaration.file))
|
|
87
|
+
return symbol.id;
|
|
88
|
+
if (isPlatformDeclaration(declaration.node, declaration.file))
|
|
89
|
+
return `builtin:${symbol.name}`;
|
|
90
|
+
const owner = declaredPackageOf(types, declaration);
|
|
91
|
+
return owner === undefined ? undefined : `package:${owner}#${symbol.name}`;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=class-id.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `code` on one line, as it would be written on one: no white space next to a `.` or `?.`
|
|
3
|
+
* (`z.object`, not `z .object`); a line break after `(` or `[`, or before `)`, `]` or `,`, is
|
|
4
|
+
* removed, with a trailing comma before a closing bracket; any other run of white space, inside a
|
|
5
|
+
* token too, is one space.
|
|
6
|
+
*/
|
|
7
|
+
export declare function codeOnOneLine(code: string): string;
|
|
8
|
+
//# sourceMappingURL=code-text.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code shown on one line, in a message or a `coverage --facts` line. The code is read token by
|
|
3
|
+
* token with the TypeScript scanner, so the text of a string, a template or a comment is never
|
|
4
|
+
* joined to its neighbour: only the white space between tokens changes.
|
|
5
|
+
*/
|
|
6
|
+
import ts from "typescript";
|
|
7
|
+
const MEMBER_ACCESS = new Set([ts.SyntaxKind.DotToken, ts.SyntaxKind.QuestionDotToken]);
|
|
8
|
+
const OPENING = new Set([ts.SyntaxKind.OpenParenToken, ts.SyntaxKind.OpenBracketToken]);
|
|
9
|
+
const CLOSING = new Set([ts.SyntaxKind.CloseParenToken, ts.SyntaxKind.CloseBracketToken]);
|
|
10
|
+
/**
|
|
11
|
+
* `code` on one line, as it would be written on one: no white space next to a `.` or `?.`
|
|
12
|
+
* (`z.object`, not `z .object`); a line break after `(` or `[`, or before `)`, `]` or `,`, is
|
|
13
|
+
* removed, with a trailing comma before a closing bracket; any other run of white space, inside a
|
|
14
|
+
* token too, is one space.
|
|
15
|
+
*/
|
|
16
|
+
export function codeOnOneLine(code) {
|
|
17
|
+
const scanner = ts.createScanner(ts.ScriptTarget.Latest, false, ts.LanguageVariant.Standard, code);
|
|
18
|
+
const parts = [];
|
|
19
|
+
// The brace depth at which each open template substitution (`${`) started.
|
|
20
|
+
const substitutions = [];
|
|
21
|
+
let depth = 0;
|
|
22
|
+
let gap = "none";
|
|
23
|
+
let previous;
|
|
24
|
+
for (let kind = scanner.scan(); kind !== ts.SyntaxKind.EndOfFileToken; kind = scanner.scan()) {
|
|
25
|
+
if (kind === ts.SyntaxKind.NewLineTrivia) {
|
|
26
|
+
gap = "line";
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (kind === ts.SyntaxKind.WhitespaceTrivia) {
|
|
30
|
+
if (gap === "none")
|
|
31
|
+
gap = "space";
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (kind === ts.SyntaxKind.OpenBraceToken)
|
|
35
|
+
depth += 1;
|
|
36
|
+
else if (kind === ts.SyntaxKind.CloseBraceToken) {
|
|
37
|
+
if (substitutions.at(-1) === depth) {
|
|
38
|
+
kind = scanner.reScanTemplateToken(false);
|
|
39
|
+
if (kind === ts.SyntaxKind.TemplateTail)
|
|
40
|
+
substitutions.pop();
|
|
41
|
+
}
|
|
42
|
+
else
|
|
43
|
+
depth -= 1;
|
|
44
|
+
}
|
|
45
|
+
else if (kind === ts.SyntaxKind.TemplateHead)
|
|
46
|
+
substitutions.push(depth);
|
|
47
|
+
if (gap === "line" && previous === ts.SyntaxKind.CommaToken && CLOSING.has(kind))
|
|
48
|
+
parts.pop();
|
|
49
|
+
else if (previous !== undefined && gap !== "none" && !joined(previous, kind, gap)) {
|
|
50
|
+
parts.push(" ");
|
|
51
|
+
}
|
|
52
|
+
parts.push(scanner.getTokenText().replace(/\s+/g, " "));
|
|
53
|
+
previous = kind;
|
|
54
|
+
gap = "none";
|
|
55
|
+
}
|
|
56
|
+
return parts.join("").trim();
|
|
57
|
+
}
|
|
58
|
+
/** Whether the white space between two tokens is dropped. */
|
|
59
|
+
function joined(previous, next, gap) {
|
|
60
|
+
if (MEMBER_ACCESS.has(previous) || MEMBER_ACCESS.has(next))
|
|
61
|
+
return true;
|
|
62
|
+
if (gap !== "line")
|
|
63
|
+
return false;
|
|
64
|
+
return OPENING.has(previous) || CLOSING.has(next) || next === ts.SyntaxKind.CommaToken;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=code-text.js.map
|
package/dist/config-file.js
CHANGED
|
@@ -7,8 +7,8 @@ import { MessageChannel } from "node:worker_threads";
|
|
|
7
7
|
import { createJiti } from "jiti";
|
|
8
8
|
import { configLocalImports, foreignTypeScriptWarnings } from "./implementation.js";
|
|
9
9
|
import { parseConfig } from "./config.js";
|
|
10
|
-
import {
|
|
11
|
-
import { RuleDeclarationError, RuleLoadError, loadRules } from "./lazy.js";
|
|
10
|
+
import { keyLine, quotedIdLine } from "./renamed.js";
|
|
11
|
+
import { RuleDeclarationError, RuleLoadError, RuleReadsError, loadRules } from "./lazy.js";
|
|
12
12
|
import { CONFIG_FILE_NAMES, CONFIG_FILE_PATTERN } from "./vocabulary.js";
|
|
13
13
|
/** The path of the config file in `cwd`, if there is one. */
|
|
14
14
|
export function findConfigFile(cwd) {
|
|
@@ -217,8 +217,8 @@ export async function loadConfigFile(configFile) {
|
|
|
217
217
|
};
|
|
218
218
|
}
|
|
219
219
|
// The first line that names each old rule id, for the notice that says where to rename it.
|
|
220
|
-
const
|
|
221
|
-
const parsed = parseConfig(exported, path.dirname(configFile), path.basename(configFile), (id) =>
|
|
220
|
+
const text = readFileSync(configFile, "utf8");
|
|
221
|
+
const parsed = parseConfig(exported, path.dirname(configFile), path.basename(configFile), (id) => quotedIdLine(text, id), (name, entry) => keyLine(text, name, entry));
|
|
222
222
|
if (!parsed.ok)
|
|
223
223
|
return { ok: false, errors: parsed.errors.map((e) => `${configFile}: ${e}`) };
|
|
224
224
|
// The rules that are on are loaded now, so a check can run them; the rest never load.
|
|
@@ -226,7 +226,9 @@ export async function loadConfigFile(configFile) {
|
|
|
226
226
|
await loadRules(parsed.value);
|
|
227
227
|
}
|
|
228
228
|
catch (error) {
|
|
229
|
-
if (error instanceof RuleLoadError ||
|
|
229
|
+
if (error instanceof RuleLoadError ||
|
|
230
|
+
error instanceof RuleDeclarationError ||
|
|
231
|
+
error instanceof RuleReadsError) {
|
|
230
232
|
return { ok: false, errors: [`${configFile}: ${error.message}`] };
|
|
231
233
|
}
|
|
232
234
|
throw error;
|
package/dist/config.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Config, ExtendedConfig, ParseResult, Plugin, Preset, UserConfig } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* What stateward checks when the config does not say: import it to add to the lists instead of
|
|
4
|
-
* replacing them, for example `exclude: [...defaults.exclude, "src/generated/**"]`.
|
|
4
|
+
* replacing them, for example `exclude: [...defaults.exclude, "src/generated/**"]`. The packs the
|
|
5
|
+
* config loads add the test patterns of their library to `exclude` (`Plugin.defaultExclude`),
|
|
6
|
+
* unless the config's own list leaves out one of these.
|
|
5
7
|
*/
|
|
6
8
|
export declare const defaults: {
|
|
7
9
|
readonly include: readonly string[];
|
|
@@ -11,6 +13,10 @@ export declare const defaults: {
|
|
|
11
13
|
export declare function defineConfig<const P extends readonly Plugin[] = readonly [], const E extends readonly ExtendedConfig[] = readonly []>(config: UserConfig<P, E>): UserConfig<P, E>;
|
|
12
14
|
/** Whether `value` is the name of a preset. */
|
|
13
15
|
export declare function isPreset(value: unknown): value is Preset;
|
|
16
|
+
/** The test patterns the packs add to the default `exclude` (`Plugin.defaultExclude`), in order. */
|
|
17
|
+
export declare function packExcludes(plugins: readonly Plugin[]): readonly string[];
|
|
18
|
+
/** The key of a package's lines in `facts` that gives the range of versions they are for. */
|
|
19
|
+
export declare const VERSIONS_KEY = "@versions";
|
|
14
20
|
/** The least `maxMemory` (MB): below it Node cannot even load TypeScript. */
|
|
15
21
|
export declare const MIN_MAX_MEMORY = 512;
|
|
16
22
|
/** Whether `value` is a memory limit stateward accepts: a whole number of MB, at least 512. */
|
|
@@ -21,5 +27,7 @@ export declare function isMaxMemory(value: unknown): value is number;
|
|
|
21
27
|
*/
|
|
22
28
|
export declare function parseConfig(given: unknown, configDir: string, configName?: string,
|
|
23
29
|
/** The line the config file names an old rule id on, so the notice says where to rename it. */
|
|
24
|
-
lineOf?: (id: string) => number | undefined
|
|
30
|
+
lineOf?: (id: string) => number | undefined,
|
|
31
|
+
/** The line the config file names a package's function or class on under `facts`. */
|
|
32
|
+
factLineOf?: (name: string, entry: string) => number | undefined): ParseResult<Config>;
|
|
25
33
|
//# sourceMappingURL=config.d.ts.map
|