@stateward/core 1.2.2 → 1.3.1
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/fingerprints.d.ts +3 -1
- package/dist/backend/fingerprints.js +198 -9
- package/dist/backend/program-record.d.ts +7 -0
- package/dist/backend/program-size.d.ts +32 -0
- package/dist/backend/program-size.js +166 -0
- package/dist/backend/typescript6.d.ts +62 -32
- package/dist/backend/typescript6.js +1615 -164
- package/dist/baseline.d.ts +1 -1
- package/dist/baseline.js +14 -10
- package/dist/cache.d.ts +92 -4
- package/dist/cache.js +257 -68
- package/dist/checker.d.ts +28 -3
- package/dist/checker.js +42 -8
- 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 +34 -2
- package/dist/disk-cache.js +82 -15
- package/dist/engine.d.ts +64 -3
- package/dist/engine.js +474 -59
- 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 +9 -9
- package/dist/index.js +12 -7
- package/dist/internal.d.ts +13 -6
- package/dist/internal.js +7 -3
- package/dist/journal.d.ts +40 -0
- package/dist/journal.js +197 -0
- 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/memory-plan.d.ts +121 -0
- package/dist/memory-plan.js +174 -0
- 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 +17 -7
- package/dist/timing.js +60 -38
- package/dist/types.d.ts +704 -20
- 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
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How much memory a check needs, estimated from its input before anything is built (the text of
|
|
3
|
+
* each program and of its own files), never from the live heap: the same input gives the same
|
|
4
|
+
* plan on every machine and run (SW5).
|
|
5
|
+
*
|
|
6
|
+
* The estimate, in MB, while a project is checked:
|
|
7
|
+
*
|
|
8
|
+
* BASE
|
|
9
|
+
* + PARSED_BASE + PARSED_BYTES_PER_CODE_CHAR × its program's code (its text without comments
|
|
10
|
+
* and white space) + PARSED_BYTES_PER_FILE × its files (syntax trees, binder; not sliced)
|
|
11
|
+
* + RESULT_BYTES_PER_OWN_CHAR × every project's own text (findings and summaries kept to the end)
|
|
12
|
+
* + CHECKER_BASE + the least of
|
|
13
|
+
* CHECKER_BYTES_PER_OWN_CHAR × the own text one type checker checks (a small slice), and
|
|
14
|
+
* WIDE_CHECKER_MB + WIDE_CHECKER_BYTES_PER_OWN_CHAR × that text (a large one)
|
|
15
|
+
*
|
|
16
|
+
* plus, when the programs are kept (fixes are tried), the other projects' programs and checkers.
|
|
17
|
+
* It must stay within USABLE_SHARE of the budget: V8 collects at length, then fails, when the live
|
|
18
|
+
* heap nears its limit.
|
|
19
|
+
*
|
|
20
|
+
* Measured on 2026-12-02 (all eight packs, `recommended`, results cache on), the live heap read
|
|
21
|
+
* after a forced collection every 1 to 3 s by a rule that samples it, with a new checker every
|
|
22
|
+
* 139 to 555 files (the smaller app) and every 676 to 10,822 files (the larger):
|
|
23
|
+
*
|
|
24
|
+
* - a React app of 21,016 files, 95.2 M characters (the walk counts 96.9 M), 10,822 own files of
|
|
25
|
+
* 35.4 M: 2,303 MB once parsed and bound (23.3 bytes a character over the 47 MB at start);
|
|
26
|
+
* about 407 MB of results after 10,141 files (12.1 bytes an own character); one checker for
|
|
27
|
+
* all files 1,060 MB (30 bytes an own character); slices of 676 files 200 to 490 MB, the
|
|
28
|
+
* densest near 110 bytes an own character;
|
|
29
|
+
* - a React app of 1,549 files, 18.9 M characters, 555 own files of 6.6 M: 466 MB parsed and bound
|
|
30
|
+
* (22.2 bytes a character); 68 MB of results after 438 files (13 bytes an own character); one
|
|
31
|
+
* checker 268 MB (40 bytes), slices of 139 files about 130 MB (79 bytes).
|
|
32
|
+
*
|
|
33
|
+
* Parsing and binding, measured on 2026-12-03 apart from the check (a program built as stateward
|
|
34
|
+
* builds it, its checker created, the heap read after a forced collection), on seven projects:
|
|
35
|
+
* the two apps above (2,216 and 406 MB), a server of 25,785 files whose 295 M characters are
|
|
36
|
+
* mostly the documentation comments of a library's declaration files (105 M of code: 3,620 MB),
|
|
37
|
+
* two libraries of 4,226 and 2,889 files (604 and 269 MB), 40,000 own files of two lines each
|
|
38
|
+
* (359 MB) and a small example (126 MB). 35 bytes a character of code, 3.5 KB a file and 100 MB
|
|
39
|
+
* fit all seven within 12% but the smallest (37% over); per character of text they range from
|
|
40
|
+
* 6.5 to 70 bytes. On the server, a budget of 5,120 MB in 9 slices was measured at 4,794 MB of
|
|
41
|
+
* live heap; this estimate puts that plan at 5,133.
|
|
42
|
+
*
|
|
43
|
+
* The checker's cost per character varies fourfold between slices of one project, so the
|
|
44
|
+
* constant is near the densest measured; the others are rounded up. One checker for all files
|
|
45
|
+
* costs less per character (they share their types): 30 bytes for all 10,822 files, 40 for all
|
|
46
|
+
* 555. So a second line bounds it, above both: 400 MB + 40 bytes an own character (1,816 MB
|
|
47
|
+
* against the 1,060 measured; 652 against 268). A slice keeps the first line (`checkerMb`).
|
|
48
|
+
*/
|
|
49
|
+
export const MEMORY_MODEL = {
|
|
50
|
+
/** Node, TypeScript and stateward's code, before any project (MB). */
|
|
51
|
+
baseMb: 50,
|
|
52
|
+
/** Syntax trees, binder, module resolution: what any program costs (MB). */
|
|
53
|
+
parsedBaseMb: 100,
|
|
54
|
+
/** The same, per character of the program's code (its text without comments and white space). */
|
|
55
|
+
parsedBytesPerCodeChar: 35,
|
|
56
|
+
/** The same, per file of the program. */
|
|
57
|
+
parsedBytesPerFile: 3584,
|
|
58
|
+
/** What the run keeps to its end (findings, summaries, the results cache): per own character. */
|
|
59
|
+
resultBytesPerOwnChar: 13,
|
|
60
|
+
/** What any type checker computes first (MB), paid again by each new one. */
|
|
61
|
+
checkerBaseMb: 40,
|
|
62
|
+
/** What a type checker adds per character of the own files it checks, in a small slice. */
|
|
63
|
+
checkerBytesPerOwnChar: 112,
|
|
64
|
+
/** A large checker's cost (MB), before its share per character (`wideCheckerBytesPerOwnChar`). */
|
|
65
|
+
wideCheckerMb: 400,
|
|
66
|
+
/** What a type checker adds per character of the own files it checks, in a large slice. */
|
|
67
|
+
wideCheckerBytesPerOwnChar: 40,
|
|
68
|
+
/** The share of the budget the estimate may fill. */
|
|
69
|
+
usableShare: 0.9,
|
|
70
|
+
/** The fewest files a type checker is started for; a budget that allows fewer is too small. */
|
|
71
|
+
minFilesPerChecker: 200,
|
|
72
|
+
};
|
|
73
|
+
const MB = 1024 * 1024;
|
|
74
|
+
function parsedMb(size) {
|
|
75
|
+
return (MEMORY_MODEL.parsedBaseMb +
|
|
76
|
+
(MEMORY_MODEL.parsedBytesPerCodeChar * size.codeChars +
|
|
77
|
+
MEMORY_MODEL.parsedBytesPerFile * size.files) /
|
|
78
|
+
MB);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* A checker of `files` of the project's own files, at their average length. One checker for all of
|
|
82
|
+
* them is bounded by the large line too; a slice is not: the types a project makes are not spread
|
|
83
|
+
* evenly over its files, and one slice of three was measured making 475,000 of the 590,000 types
|
|
84
|
+
* one checker makes for all files (`--max-memory 4096` on the larger app above: a higher peak
|
|
85
|
+
* than one checker's).
|
|
86
|
+
*/
|
|
87
|
+
function checkerMb(size, files) {
|
|
88
|
+
const chars = size.ownFiles === 0 ? 0 : (size.ownChars * files) / size.ownFiles;
|
|
89
|
+
const small = (MEMORY_MODEL.checkerBytesPerOwnChar * chars) / MB;
|
|
90
|
+
if (files < size.ownFiles)
|
|
91
|
+
return MEMORY_MODEL.checkerBaseMb + small;
|
|
92
|
+
const large = MEMORY_MODEL.wideCheckerMb + (MEMORY_MODEL.wideCheckerBytesPerOwnChar * chars) / MB;
|
|
93
|
+
return MEMORY_MODEL.checkerBaseMb + Math.min(small, large);
|
|
94
|
+
}
|
|
95
|
+
/** The most own files one checker of a slice can take within `roomMb` (after its base). */
|
|
96
|
+
function filesWithin(size, roomMb) {
|
|
97
|
+
if (size.ownChars === 0)
|
|
98
|
+
return size.ownFiles;
|
|
99
|
+
const charsPerFile = size.ownChars / size.ownFiles;
|
|
100
|
+
return Math.floor((roomMb * MB) / (MEMORY_MODEL.checkerBytesPerOwnChar * charsPerFile));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The plan for a check of `projects` (in the order the file phase reaches them) within `budgetMb`:
|
|
104
|
+
* how many own files of each project share one type checker. `keepsPrograms`: the programs stay
|
|
105
|
+
* built to the end (fixes are tried), so every program counts at once; otherwise one at a time.
|
|
106
|
+
*/
|
|
107
|
+
export function planMemory(budgetMb, projects, keepsPrograms) {
|
|
108
|
+
const usable = budgetMb * MEMORY_MODEL.usableShare;
|
|
109
|
+
const results = (MEMORY_MODEL.resultBytesPerOwnChar *
|
|
110
|
+
projects.reduce((sum, project) => sum + project.size.ownChars, 0)) /
|
|
111
|
+
MB;
|
|
112
|
+
const planned = [];
|
|
113
|
+
/** The programs and checkers of the projects before this one, when they are kept. */
|
|
114
|
+
let kept = 0;
|
|
115
|
+
let worst;
|
|
116
|
+
for (const [at, { tsconfig, size }] of projects.entries()) {
|
|
117
|
+
const later = keepsPrograms
|
|
118
|
+
? projects.slice(at + 1).reduce((sum, project) => sum + parsedMb(project.size), 0)
|
|
119
|
+
: 0;
|
|
120
|
+
const fixed = MEMORY_MODEL.baseMb + results + kept + later + parsedMb(size);
|
|
121
|
+
const least = Math.min(size.ownFiles, MEMORY_MODEL.minFilesPerChecker);
|
|
122
|
+
// One checker for all files, priced by the large line too, can cost less than the smallest
|
|
123
|
+
// slice (a few hundred long files): the floor is the lesser.
|
|
124
|
+
const whole = fixed + checkerMb(size, size.ownFiles);
|
|
125
|
+
const floor = Math.min(whole, fixed + checkerMb(size, least));
|
|
126
|
+
if (floor > usable) {
|
|
127
|
+
const neededMb = Math.ceil(floor / MEMORY_MODEL.usableShare / 256) * 256;
|
|
128
|
+
if (worst === undefined || neededMb > worst.neededMb)
|
|
129
|
+
worst = { neededMb, tsconfig, size };
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
// One checker for all files when it fits; else the most files a slice can take, at least
|
|
133
|
+
// `least`, which fits as checked above.
|
|
134
|
+
const room = usable - fixed - MEMORY_MODEL.checkerBaseMb;
|
|
135
|
+
const slices = whole <= usable
|
|
136
|
+
? 1
|
|
137
|
+
: Math.max(1, Math.ceil(size.ownFiles / Math.max(least, filesWithin(size, room))));
|
|
138
|
+
const filesPerChecker = Math.ceil(size.ownFiles / slices);
|
|
139
|
+
planned.push({ tsconfig, files: size.ownFiles, slices, filesPerChecker });
|
|
140
|
+
if (keepsPrograms)
|
|
141
|
+
kept += parsedMb(size) + checkerMb(size, filesPerChecker);
|
|
142
|
+
}
|
|
143
|
+
if (worst !== undefined)
|
|
144
|
+
return { kind: "below-floor", budgetMb, ...worst };
|
|
145
|
+
return { kind: "fits", budgetMb, projects: planned };
|
|
146
|
+
}
|
|
147
|
+
function count(n) {
|
|
148
|
+
return n.toLocaleString("en-US");
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* The plan as stateward prints it once, before the check: "memory budget 3,072 MB: 4 slices of
|
|
152
|
+
* about 900 files". Undefined when every project keeps one type checker (nothing to say).
|
|
153
|
+
* `shown` names a project's tsconfig as the reader would type it.
|
|
154
|
+
*/
|
|
155
|
+
export function describePlan(plan, shown) {
|
|
156
|
+
const sliced = plan.projects.filter((project) => project.slices > 1);
|
|
157
|
+
if (sliced.length === 0)
|
|
158
|
+
return undefined;
|
|
159
|
+
const slicesOf = (project) => `${count(project.slices)} slices of about ${count(project.filesPerChecker)} files`;
|
|
160
|
+
const parts = plan.projects.length === 1
|
|
161
|
+
? sliced.map(slicesOf)
|
|
162
|
+
: sliced.map((project) => `\`${shown(project.tsconfig)}\` in ${slicesOf(project)}`);
|
|
163
|
+
return `memory budget ${count(plan.budgetMb)} MB: ${parts.join(", ")}`;
|
|
164
|
+
}
|
|
165
|
+
/** The budget is below what parsing and binding the project needs: the check does not start. */
|
|
166
|
+
export class MemoryBudgetError extends Error {
|
|
167
|
+
hint;
|
|
168
|
+
constructor(plan, shown) {
|
|
169
|
+
super(`memory budget ${count(plan.budgetMb)} MB is below the ${count(plan.neededMb)} MB \`${shown}\` needs: ${count(plan.size.files)} files to parse and bind, ${count(Math.round(plan.size.chars / 1e6))} million characters`);
|
|
170
|
+
this.name = "MemoryBudgetError";
|
|
171
|
+
this.hint = `set \`--max-memory ${String(plan.neededMb)}\` or \`maxMemory: ${String(plan.neededMb)}\` in the config, or more`;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=memory-plan.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A rule a release made off by default because too few of its findings were right on real
|
|
3
|
+
* projects (`RuleInfo.offByDefault`). Its page and the config notice give the same figure, from
|
|
4
|
+
* here.
|
|
5
|
+
*/
|
|
6
|
+
import type { OffByDefault } from "./types.js";
|
|
7
|
+
/** The share of its findings a rule needs right on real projects to be on by default. */
|
|
8
|
+
export declare const ON_BY_DEFAULT_SHARE = 86;
|
|
9
|
+
/** The sentence of the rule's page that says why it is off by default. */
|
|
10
|
+
export declare function offByDefaultText(off: OffByDefault): string;
|
|
11
|
+
/** The notice for a config that turns the rule on in `rules`. */
|
|
12
|
+
export declare function offByDefaultNotice(ruleId: string, off: OffByDefault): string;
|
|
13
|
+
//# sourceMappingURL=off-by-default.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** The share of its findings a rule needs right on real projects to be on by default. */
|
|
2
|
+
export const ON_BY_DEFAULT_SHARE = 86;
|
|
3
|
+
/** The share of the findings checked that were right, in whole percent. */
|
|
4
|
+
function rightShare(off) {
|
|
5
|
+
return Math.round((off.right / off.checked) * 100);
|
|
6
|
+
}
|
|
7
|
+
/** The sentence of the rule's page that says why it is off by default. */
|
|
8
|
+
export function offByDefaultText(off) {
|
|
9
|
+
return `It is off by default because ${String(rightShare(off))}% of its findings on real projects were right (${String(off.right)} of ${String(off.checked)} checked), under the ${String(ON_BY_DEFAULT_SHARE)}% a rule needs to be on by default.`;
|
|
10
|
+
}
|
|
11
|
+
/** The notice for a config that turns the rule on in `rules`. */
|
|
12
|
+
export function offByDefaultNotice(ruleId, off) {
|
|
13
|
+
return `\`${ruleId}\` is off by default since ${off.since} (right ${String(rightShare(off))}% of the time on real projects); your config turns it on`;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=off-by-default.js.map
|
package/dist/options.d.ts
CHANGED
|
@@ -6,7 +6,13 @@ type SpecsOf<R extends PluginRule> = NonNullable<R["meta"]["options"]>;
|
|
|
6
6
|
* (the union of `oneOf` for a string option). A rule that declares none takes no names at all; a
|
|
7
7
|
* rule typed as the wide `Rule` takes any name, because nothing says which exist.
|
|
8
8
|
*/
|
|
9
|
-
export type ConfigOptionsOf<R extends PluginRule> = SpecsOf<R> extends NoOptions ? NoOptions : Partial<OptionsOf<SpecsOf<R
|
|
9
|
+
export type ConfigOptionsOf<R extends PluginRule> = SpecsOf<R> extends NoOptions ? NoOptions : Partial<OptionsOf<UserSpecs<SpecsOf<R>>>>;
|
|
10
|
+
/** The specs a config may set: all but those only stateward sets (`internal`). */
|
|
11
|
+
type UserSpecs<S extends OptionSpecs> = {
|
|
12
|
+
[K in keyof S as S[K] extends {
|
|
13
|
+
internal: true;
|
|
14
|
+
} ? never : K]: S[K];
|
|
15
|
+
};
|
|
10
16
|
/** The rule of `P` (a plugin, or a union of plugins) whose id is `Id`. */
|
|
11
17
|
type RuleById<P extends Plugin, Id extends string> = P extends Plugin ? Id extends `${P["name"]}/${infer Key}` ? Key extends keyof P["rules"] ? P["rules"][Key] extends infer R extends PluginRule ? R : never : never : never : never;
|
|
12
18
|
/** The `rules` of a config for plugin type `P`: its rule ids as keys, each with its own options. */
|
|
@@ -31,10 +37,16 @@ declare function optionString(input: {
|
|
|
31
37
|
description: string;
|
|
32
38
|
}): StringOption;
|
|
33
39
|
export declare const option: {
|
|
34
|
-
|
|
40
|
+
/**
|
|
41
|
+
* With `convention: true`, `conventions: true` in the config turns it on; with `internal: true`,
|
|
42
|
+
* only stateward sets it (`BooleanOption`).
|
|
43
|
+
*/
|
|
44
|
+
boolean<const I extends {
|
|
35
45
|
default: boolean;
|
|
36
46
|
description: string;
|
|
37
|
-
|
|
47
|
+
convention?: true;
|
|
48
|
+
internal?: true;
|
|
49
|
+
}>(input: I): BooleanOption & Pick<I, "internal">;
|
|
38
50
|
number(input: {
|
|
39
51
|
default: number;
|
|
40
52
|
description: string;
|
|
@@ -79,11 +91,15 @@ export declare function expectation(spec: OptionSpec): string;
|
|
|
79
91
|
/** Why `value` is not a valid value of `spec`, as "must be …, got …"; undefined when it is. */
|
|
80
92
|
export declare function optionProblem(spec: OptionSpec, value: unknown): string | undefined;
|
|
81
93
|
/** The default of every option: what a rule receives when the config sets nothing. */
|
|
82
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Every option at its default; with `conventions` (the config's `conventions: true`), an option
|
|
96
|
+
* marked `convention` is true.
|
|
97
|
+
*/
|
|
98
|
+
export declare function defaultOptions(specs: OptionSpecs | undefined, conventions?: boolean): Options;
|
|
83
99
|
/**
|
|
84
100
|
* The options of rule `ruleId` from what the config gave (`given`, untrusted): defaults filled
|
|
85
101
|
* in, and one error per unknown name or value that does not fit, each naming rule and option.
|
|
86
102
|
*/
|
|
87
|
-
export declare function parseRuleOptions(ruleId: string, specs: OptionSpecs | undefined, given: unknown, errors: string[]): Options;
|
|
103
|
+
export declare function parseRuleOptions(ruleId: string, specs: OptionSpecs | undefined, given: unknown, errors: string[], conventions?: boolean): Options;
|
|
88
104
|
export {};
|
|
89
105
|
//# sourceMappingURL=options.d.ts.map
|
package/dist/options.js
CHANGED
|
@@ -3,6 +3,10 @@ function optionString(input) {
|
|
|
3
3
|
return { kind: "string", ...input };
|
|
4
4
|
}
|
|
5
5
|
export const option = {
|
|
6
|
+
/**
|
|
7
|
+
* With `convention: true`, `conventions: true` in the config turns it on; with `internal: true`,
|
|
8
|
+
* only stateward sets it (`BooleanOption`).
|
|
9
|
+
*/
|
|
6
10
|
boolean(input) {
|
|
7
11
|
return { kind: "boolean", ...input };
|
|
8
12
|
},
|
|
@@ -136,6 +140,10 @@ function accepts(spec, value) {
|
|
|
136
140
|
}
|
|
137
141
|
}
|
|
138
142
|
}
|
|
143
|
+
/** Whether only stateward sets the option (`BooleanOption.internal`). */
|
|
144
|
+
function isInternal(spec) {
|
|
145
|
+
return spec?.kind === "boolean" && spec.internal === true;
|
|
146
|
+
}
|
|
139
147
|
/** Why `value` is not a valid value of `spec`, as "must be …, got …"; undefined when it is. */
|
|
140
148
|
export function optionProblem(spec, value) {
|
|
141
149
|
return accepts(spec, value)
|
|
@@ -143,25 +151,32 @@ export function optionProblem(spec, value) {
|
|
|
143
151
|
: `must be ${expectation(spec)}, got ${describeGiven(value)}`;
|
|
144
152
|
}
|
|
145
153
|
/** The default of every option: what a rule receives when the config sets nothing. */
|
|
146
|
-
|
|
147
|
-
|
|
154
|
+
/**
|
|
155
|
+
* Every option at its default; with `conventions` (the config's `conventions: true`), an option
|
|
156
|
+
* marked `convention` is true.
|
|
157
|
+
*/
|
|
158
|
+
export function defaultOptions(specs, conventions = false) {
|
|
159
|
+
return Object.fromEntries(Object.entries(specs ?? {}).map(([name, spec]) => [
|
|
160
|
+
name,
|
|
161
|
+
conventions && spec.kind === "boolean" && spec.convention === true ? true : spec.default,
|
|
162
|
+
]));
|
|
148
163
|
}
|
|
149
164
|
/**
|
|
150
165
|
* The options of rule `ruleId` from what the config gave (`given`, untrusted): defaults filled
|
|
151
166
|
* in, and one error per unknown name or value that does not fit, each naming rule and option.
|
|
152
167
|
*/
|
|
153
|
-
export function parseRuleOptions(ruleId, specs, given, errors) {
|
|
168
|
+
export function parseRuleOptions(ruleId, specs, given, errors, conventions = false) {
|
|
154
169
|
const declared = specs ?? {};
|
|
155
170
|
const where = `rules["${ruleId}"]`;
|
|
156
171
|
if (typeof given !== "object" || given === null || Array.isArray(given)) {
|
|
157
172
|
errors.push(`${where}: options must be an object of option names to values, got ${describeGiven(given)}`);
|
|
158
|
-
return defaultOptions(specs);
|
|
173
|
+
return defaultOptions(specs, conventions);
|
|
159
174
|
}
|
|
160
|
-
const names = Object.keys(declared);
|
|
161
|
-
const values = { ...defaultOptions(specs) };
|
|
175
|
+
const names = Object.keys(declared).filter((name) => !isInternal(declared[name]));
|
|
176
|
+
const values = { ...defaultOptions(specs, conventions) };
|
|
162
177
|
for (const [name, value] of Object.entries(given)) {
|
|
163
178
|
const spec = declared[name];
|
|
164
|
-
if (spec === undefined) {
|
|
179
|
+
if (spec === undefined || isInternal(spec)) {
|
|
165
180
|
errors.push(names.length === 0
|
|
166
181
|
? `${where} takes no options, got "${name}"`
|
|
167
182
|
: `${where} has no option "${name}"; its options: ${names.join(", ")}`);
|
package/dist/package-facts.d.ts
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `facts` line for a package function or property: the config's first, then the facts the
|
|
3
|
-
* loaded plugins ship. Core reads the lines and knows no library; each line names a declaration
|
|
4
|
-
* by its path in the package's types (`Observable.subscribe`) or by its own name (`onSnapshot`).
|
|
5
|
-
*/
|
|
6
1
|
import ts from "typescript";
|
|
7
|
-
import type {
|
|
2
|
+
import type { Unread } from "./unread.js";
|
|
3
|
+
import type { FactKey, FactModule, FactNeed, FactSide, FactTarget, FileContext, FunctionFacts, PackageFactsConfig, TypeQueries, UnnamedFact, WithheldFacts } from "./types.js";
|
|
4
|
+
/** What a lookup asks of the program: how a key resolves. */
|
|
5
|
+
type FactTypes = Pick<TypeQueries, "factTarget" | "isOrExtends">;
|
|
8
6
|
/** What a lookup reads: the program's types, both sets of facts, and the file the code is in. */
|
|
9
|
-
export type FactContext = Pick<FileContext, "types" | "facts" | "shippedFacts" | "sourceFile">;
|
|
7
|
+
export type FactContext = Pick<FileContext, "types" | "facts" | "shippedFacts" | "withheldFacts" | "sourceFile">;
|
|
8
|
+
/**
|
|
9
|
+
* Which facts a lookup is after (`neverRejects`, `returns`): a line left out for the project's
|
|
10
|
+
* version makes the lookup "not checked" only when it states one. Undefined: any line.
|
|
11
|
+
*/
|
|
12
|
+
export type FactWanted = keyof FunctionFacts;
|
|
13
|
+
/**
|
|
14
|
+
* Reports, once per node, a lookup that found a facts line left out for the version the project
|
|
15
|
+
* runs (`Unread` from `packageFactOf` and the lookups built on it): "not checked: <what>: <reason>",
|
|
16
|
+
* with the line's hint. A rule then reads the call as it would with no line.
|
|
17
|
+
*/
|
|
18
|
+
export declare function reportWithheld(ctx: Pick<FileContext, "unknown">, found: Unread, node: ts.Node, what: string): void;
|
|
10
19
|
/** The facts line a declaration has, the package it is listed under, and which set it is from. */
|
|
11
20
|
export type PackageFact = {
|
|
21
|
+
readonly kind: "fact";
|
|
12
22
|
readonly package: string;
|
|
13
23
|
readonly fact: FunctionFacts;
|
|
14
24
|
readonly source: "config" | "shipped";
|
|
@@ -17,20 +27,145 @@ export type PackageFact = {
|
|
|
17
27
|
export declare function pathOf(node: ts.Node): string[];
|
|
18
28
|
/** The name the call is made through: `onSnapshot` of `onSnapshot(…)`, `subscribe` of `a.subscribe(…)`. */
|
|
19
29
|
export declare function calleeName(call: ts.CallExpression | ts.NewExpression): ts.Identifier | undefined;
|
|
20
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* `declared` with the value `name` is read on (`store` in `store.find`) as its receiver; as it is
|
|
32
|
+
* for a bare name.
|
|
33
|
+
*/
|
|
34
|
+
export declare function withReceiverOf<T extends Declared>(declared: T, name: ts.Identifier): T;
|
|
35
|
+
/**
|
|
36
|
+
* The module a file imports a name from: `"firebase/firestore"` for `onSnapshot`, also through
|
|
37
|
+
* `import name = require("…")`.
|
|
38
|
+
*/
|
|
21
39
|
export declare function importedFrom(sourceFile: ts.SourceFile, name: string): string | undefined;
|
|
22
40
|
/** The leftmost name of a callee: `db` of `db.users.watch`. */
|
|
23
41
|
export declare function rootName(expression: ts.Expression): string | undefined;
|
|
42
|
+
/** The name of the package a module path is in: `@acme/kit` of `@acme/kit/lib/x`. */
|
|
43
|
+
export declare function packageOfModule(module: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* The class a written `facts` line leaves for the developer to name (`throws: ["ErrorClass"]`): the
|
|
46
|
+
* config warns of it until it is replaced.
|
|
47
|
+
*/
|
|
48
|
+
export declare const PLACEHOLDER_CLASS = "ErrorClass";
|
|
49
|
+
/**
|
|
50
|
+
* The kinds a `facts` line states for calls that need `sides`, once each, `throws` first. Kinds are
|
|
51
|
+
* strict: `throws` states a synchronous throw, `rejects` a promise's rejection, so a line for a
|
|
52
|
+
* class whose methods need both carries both.
|
|
53
|
+
*/
|
|
54
|
+
export declare function neededSides(sides: readonly FactSide[]): FactSide[];
|
|
55
|
+
/** A key's name that stands for every name one step below: `"*"`, `"Repository.*"`. */
|
|
56
|
+
export declare const WILDCARD = "*";
|
|
57
|
+
/**
|
|
58
|
+
* What a `facts` key names, by how it is written: one function or property (`"Repository.find"`),
|
|
59
|
+
* every method and property of a class (`"Repository.*"`, `owner` is `"Repository"`), or every
|
|
60
|
+
* function and method the module exports (`"*"`).
|
|
61
|
+
*/
|
|
62
|
+
export type FactGrain = {
|
|
63
|
+
readonly kind: "function";
|
|
64
|
+
} | {
|
|
65
|
+
readonly kind: "class";
|
|
66
|
+
readonly owner: string;
|
|
67
|
+
} | {
|
|
68
|
+
readonly kind: "package";
|
|
69
|
+
};
|
|
70
|
+
export declare function factGrainOf(name: string): FactGrain;
|
|
71
|
+
/**
|
|
72
|
+
* A package's declaration a lookup is for, with `receiver`, the value it is called or read on
|
|
73
|
+
* (`store` in `store.find()`), when there is one: a class line states a method the class inherits
|
|
74
|
+
* only through a receiver of the class.
|
|
75
|
+
*/
|
|
76
|
+
export type Declared = {
|
|
77
|
+
readonly node: ts.Node;
|
|
78
|
+
readonly receiver?: ts.Node;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* The line of `facts` whose key resolves to `declaration` (`TypeQueries.factTarget`): its module,
|
|
82
|
+
* its name and the line. The most specific grain wins (`factGrainOf`): a function's line, then a
|
|
83
|
+
* class's (`"Repository.*"`), then a package's (`"*"`); the line chosen replaces the coarser ones
|
|
84
|
+
* whole. Among keys of one grain, the first the table lists. A class line states a method the
|
|
85
|
+
* class inherits only through `receiver`, the value it is called on, when that is of the class.
|
|
86
|
+
*/
|
|
87
|
+
export declare function factLineOf(types: FactTypes, facts: PackageFactsConfig, declaration: ts.Node, receiver?: ts.Node): {
|
|
88
|
+
package: string;
|
|
89
|
+
name: string;
|
|
90
|
+
fact: FunctionFacts;
|
|
91
|
+
} | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* The facts line for a package's declaration from the config's `facts`. `Unread` when the
|
|
94
|
+
* config's line is left out for the version the project runs (`"@versions"`) and states `wanted`;
|
|
95
|
+
* undefined when no line names it.
|
|
96
|
+
*/
|
|
97
|
+
export declare function declarationFactOf(ctx: Pick<FileContext, "types" | "facts" | "withheldFacts">, declared: Declared, wanted?: FactWanted): PackageFact | Unread | undefined;
|
|
24
98
|
/**
|
|
25
|
-
* The facts
|
|
26
|
-
* `
|
|
27
|
-
* the
|
|
28
|
-
* declaration of the project, or one no line names.
|
|
99
|
+
* The facts left out for a file's project version (`FileContext.withheldFacts`) that would name a
|
|
100
|
+
* declaration, as `factLineOf` finds a line, from `source` when given and stating `wanted` when
|
|
101
|
+
* given: the call it names is then "not checked" with their reason. Undefined when none would.
|
|
29
102
|
*/
|
|
30
|
-
export declare function
|
|
103
|
+
export declare function withheldFactOf(withheld: readonly WithheldFacts[], types: FactTypes, declared: Declared, source?: WithheldFacts["source"], wanted?: FactWanted): WithheldFacts | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* The facts line for `declared`, a declaration in a package's types: the config's line when one
|
|
106
|
+
* resolves to it, else a shipped one. Undefined for a declaration of the project, or one no line
|
|
107
|
+
* names.
|
|
108
|
+
*/
|
|
109
|
+
export declare function packageFactOf(declared: Declared & {
|
|
31
110
|
readonly file: string;
|
|
111
|
+
}, ctx: FactContext, wanted?: FactWanted): PackageFact | Unread | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* Why no `facts` key can name a call (`FactKey` `unnamed`): by the module the call is imported
|
|
114
|
+
* from, when it is; else by the modules of its package.
|
|
115
|
+
*/
|
|
116
|
+
export declare function unnamedReason(found: Extract<FactModule, {
|
|
117
|
+
kind: "unnamed";
|
|
118
|
+
}>): string;
|
|
119
|
+
/** Why a key found for a call is not given: read back, it names another declaration. */
|
|
120
|
+
export declare const UNRESOLVED_REASON = "the key that names it resolves to another declaration";
|
|
121
|
+
/**
|
|
122
|
+
* The `facts` key for `declared`, a function, property or class outside the project, as
|
|
123
|
+
* `reference` (the callee of a call, a class named in a decorator) reaches it: the module the
|
|
124
|
+
* project imports it from, as written, followed out of the project's own re-exports; for a global,
|
|
125
|
+
* a module that exports it (`TypeQueries.factModuleOf`). The name is the one that resolves to it
|
|
126
|
+
* in that module (`TypeQueries.factNameOf`), and the version the one `"@versions"` is checked
|
|
127
|
+
* against: the installed version of the package that owns the module, left out for the
|
|
128
|
+
* platform's modules and when it is not known. `unnamed` when no module names it. Every hint,
|
|
129
|
+
* `Finding.needs`, quick fix and `coverage --facts` takes its key from here.
|
|
130
|
+
*
|
|
131
|
+
* Each key is read back with `TypeQueries.factTarget` before it is given: one that does not resolve
|
|
132
|
+
* to `declared` would be a line that does nothing, so the call is `unnamed` instead.
|
|
133
|
+
*/
|
|
134
|
+
export declare function factKeyOf(types: Pick<TypeQueries, "factModuleOf" | "factTarget">, declared: {
|
|
32
135
|
readonly node: ts.Node;
|
|
33
|
-
},
|
|
136
|
+
}, reference: ts.Node): FactKey;
|
|
137
|
+
/**
|
|
138
|
+
* What a `facts` line states of the function `reference` calls: `rejects` when the call's value is
|
|
139
|
+
* a promise (a thenable, by its type), `throws` otherwise and for a constructor (`new X()`). A
|
|
140
|
+
* function referenced without a call is read by what its declaration returns.
|
|
141
|
+
*/
|
|
142
|
+
export declare function factSideOf(types: Pick<TypeQueries, "isPromiseLike" | "returnsPromiseLike">, declared: {
|
|
143
|
+
readonly node: ts.Node;
|
|
144
|
+
}, reference: ts.Node): FactSide;
|
|
145
|
+
/**
|
|
146
|
+
* The `facts` line a call that no line states needs (`Finding.needs`): its key (`factKeyOf`) and
|
|
147
|
+
* the side the function called states (`factSideOf`); `unnamed` when no key can name it.
|
|
148
|
+
*/
|
|
149
|
+
export declare function factNeedOf(types: Pick<TypeQueries, "factModuleOf" | "factTarget" | "isPromiseLike" | "returnsPromiseLike">, declared: {
|
|
150
|
+
readonly node: ts.Node;
|
|
151
|
+
}, reference: ts.Node): {
|
|
152
|
+
kind: "named";
|
|
153
|
+
need: FactNeed;
|
|
154
|
+
} | {
|
|
155
|
+
kind: "unnamed";
|
|
156
|
+
unnamed: UnnamedFact;
|
|
157
|
+
};
|
|
158
|
+
/** A key as the config writes it: as an identifier where it is one, else quoted. */
|
|
159
|
+
export declare function factKeyText(key: string): string;
|
|
160
|
+
/**
|
|
161
|
+
* The config's `facts` line for a key, with `value` as the line's value (`{ throws: [] }`), as
|
|
162
|
+
* a hint shows it: `facts: { "kit": { "@versions": "2.4.0", load: { throws: [] } } }`.
|
|
163
|
+
*/
|
|
164
|
+
export declare function factLineText(key: {
|
|
165
|
+
readonly module: string;
|
|
166
|
+
readonly name: string;
|
|
167
|
+
readonly version?: string;
|
|
168
|
+
}, value: string): string;
|
|
34
169
|
/**
|
|
35
170
|
* The package function a name of the project stands for: `listen` in `const listen = onSnapshot`,
|
|
36
171
|
* `const listen = db.onSnapshot` or `const { onSnapshot: listen } = firestore`. Only a name or a
|
|
@@ -38,15 +173,74 @@ export declare function packageFactOf(declared: {
|
|
|
38
173
|
* returned, not the function.
|
|
39
174
|
*/
|
|
40
175
|
export declare function packageFunctionOf(name: ts.Identifier, ctx: FactContext): {
|
|
41
|
-
declared: {
|
|
176
|
+
declared: Declared & {
|
|
42
177
|
file: string;
|
|
43
|
-
node: ts.Node;
|
|
44
178
|
};
|
|
45
179
|
through: ts.Expression | undefined;
|
|
46
180
|
} | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* The facts line for what a call calls (`useEffect(…)`, `db.watch(…)`): the package function
|
|
183
|
+
* itself, or the one a name of the project stands for (`const watch = db.watch`). The config's
|
|
184
|
+
* line first, then the ones the packs ship; undefined for the project's own functions and for one
|
|
185
|
+
* no line names.
|
|
186
|
+
*/
|
|
187
|
+
export declare function callFactOf(call: ts.CallExpression | ts.NewExpression, ctx: FactContext, wanted?: FactWanted): PackageFact | Unread | undefined;
|
|
47
188
|
/**
|
|
48
189
|
* The facts line that says an awaited promise never rejects (`neverRejects: true`), when one
|
|
49
190
|
* does: an `await` of it is then not a way out of the function. Undefined otherwise.
|
|
50
191
|
*/
|
|
51
|
-
export declare function neverRejectsFactOf(expression: ts.Expression, ctx: FactContext): PackageFact | undefined;
|
|
192
|
+
export declare function neverRejectsFactOf(expression: ts.Expression, ctx: FactContext): PackageFact | Unread | undefined;
|
|
193
|
+
/**
|
|
194
|
+
* The facts line that says a value comes from outside the program (`external: true`), when one
|
|
195
|
+
* does: the result of a call of the package function (`redis.get(key)`), or a read of the
|
|
196
|
+
* package property (`response.data`). Undefined otherwise.
|
|
197
|
+
*/
|
|
198
|
+
export declare function externalFactOf(expression: ts.Expression, ctx: FactContext): PackageFact | Unread | undefined;
|
|
199
|
+
/** What one key of the config's `facts` resolves to in one program (`checkFactKeys`). */
|
|
200
|
+
export type FactKeyCheck = {
|
|
201
|
+
readonly module: string;
|
|
202
|
+
readonly name: string;
|
|
203
|
+
readonly kind: FactTarget["kind"];
|
|
204
|
+
/** With `no-name`: the closest name the module has, when one is near. */
|
|
205
|
+
readonly near?: string;
|
|
206
|
+
/**
|
|
207
|
+
* With `found`: the kinds that can apply to the functions the key names
|
|
208
|
+
* (`factSidesOfDeclaration`), each once; empty when it names none, such as a property or a type.
|
|
209
|
+
*/
|
|
210
|
+
readonly fits?: readonly FactSide[];
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* The kinds of a `facts` line that can apply to a declaration: `throws` for any function, method
|
|
214
|
+
* or class (a function can throw before it returns, whatever its type says), and `rejects` too
|
|
215
|
+
* unless every return its declaration states cannot be a promise (`mayReturnPromise`: a type
|
|
216
|
+
* parameter, `any` or `unknown` can be one). Empty for anything else, whose kind the declaration
|
|
217
|
+
* does not say. The kinds a hint, a quick fix or `coverage --facts` suggest for a call
|
|
218
|
+
* (`factSideOf`) are always among them, so no line stateward suggests is warned of.
|
|
219
|
+
*/
|
|
220
|
+
export declare function factSidesOfDeclaration(types: Pick<TypeQueries, "mayReturnPromise">, node: ts.Node): readonly FactSide[];
|
|
221
|
+
/** Each key of the config's `facts` resolved in one program, in the order the config lists them. */
|
|
222
|
+
export declare function checkFactKeys(facts: PackageFactsConfig, types: Pick<TypeQueries, "factTarget" | "factNames" | "mayReturnPromise">): FactKeyCheck[];
|
|
223
|
+
/** A digest of the keys of `facts`: what `checkFactKeys` depends on. */
|
|
224
|
+
export declare function factKeysDigest(facts: PackageFactsConfig): string;
|
|
225
|
+
/** `checkFactKeys`'s result as `JSON.stringify` wrote it; undefined for anything else. */
|
|
226
|
+
export declare function readFactKeyChecks(text: string): FactKeyCheck[] | undefined;
|
|
227
|
+
/** The config's facts lines checked against the program's types (`unmatchedFacts`). */
|
|
228
|
+
export type FactsMatch = {
|
|
229
|
+
/**
|
|
230
|
+
* A line whose name resolves to nothing in its module, with the closest name when one is near;
|
|
231
|
+
* and a line whose `throws` or `rejects` fits none of the functions it names, with the kind that
|
|
232
|
+
* does.
|
|
233
|
+
*/
|
|
234
|
+
readonly unmatched: readonly string[];
|
|
235
|
+
/** A line whose module no project's types load (not installed, or not imported). */
|
|
236
|
+
readonly notChecked: readonly string[];
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* Each line of the config's `facts`, as the projects resolve it (`checkFactKeys`, one list per
|
|
240
|
+
* project): a line one project resolves is matched; else a warning for a name its module does
|
|
241
|
+
* not have, with the closest name it has ("`ioredis` has no function `Redis.hget`; did you mean
|
|
242
|
+
* `RedisCommander.hget`?"), and "not checked" for a module no project's types load.
|
|
243
|
+
*/
|
|
244
|
+
export declare function unmatchedFacts(projects: readonly (readonly FactKeyCheck[])[], facts?: PackageFactsConfig): FactsMatch;
|
|
245
|
+
export {};
|
|
52
246
|
//# sourceMappingURL=package-facts.d.ts.map
|