@cplieger/deadset-ts 8.0.0-dev.7 → 8.0.0-dev.9

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 (137) hide show
  1. package/dist/bin/node-host.js +21 -3
  2. package/dist/src/analysis.js +94 -299
  3. package/dist/src/config.js +6 -83
  4. package/dist/src/configuration-files.js +2 -9
  5. package/dist/src/configured-declarations.js +15 -20
  6. package/dist/src/consumers.js +3 -30
  7. package/dist/src/contract/config.generated.js +544 -0
  8. package/dist/src/contract/contract.generated.js +20 -10
  9. package/dist/src/contract/report.generated.js +3 -2
  10. package/dist/src/conventions.js +3 -8
  11. package/dist/src/edges.js +36 -112
  12. package/dist/src/exempt-classes.js +0 -2
  13. package/dist/src/exempt.js +1 -1
  14. package/dist/src/failure.js +36 -0
  15. package/dist/src/findings/completion.js +5 -4
  16. package/dist/src/findings/emitters.js +1 -1
  17. package/dist/src/findings/intra-function.js +1 -1
  18. package/dist/src/findings/non-code-artifacts.js +2 -2
  19. package/dist/src/findings/unused-declarations.js +1 -1
  20. package/dist/src/findings/visibility-narrowing.js +2 -2
  21. package/dist/src/findings-pass.js +1 -1
  22. package/dist/src/framework-lifecycle.js +7 -7
  23. package/dist/src/fs/document.js +52 -0
  24. package/dist/src/fs/manifest.js +7 -0
  25. package/dist/src/injection-container.js +1 -1
  26. package/dist/src/json-document.js +194 -67
  27. package/dist/src/kinds.js +0 -7
  28. package/dist/src/load/classify.js +236 -0
  29. package/dist/src/load/diagnostics.js +79 -0
  30. package/dist/src/load/discover.js +230 -0
  31. package/dist/src/{emit-map.js → load/emit-map.js} +1 -1
  32. package/dist/src/load/expected-module.js +136 -0
  33. package/dist/src/load/load.js +22 -0
  34. package/dist/src/load/module-lookup.js +37 -0
  35. package/dist/src/load/plan.js +155 -0
  36. package/dist/src/{test-globals.js → load/test-globals.js} +51 -56
  37. package/dist/src/load/test-joins.js +82 -0
  38. package/dist/src/{workspace-manifests.js → load/workspace-manifests.js} +3 -3
  39. package/dist/src/{workspace-programs.js → load/workspace-programs.js} +37 -40
  40. package/dist/src/{workspace-resolution.js → load/workspace-resolution.js} +21 -59
  41. package/dist/src/{workspace-run.js → load/workspace-run.js} +4 -3
  42. package/dist/src/{workspace.js → load/workspace.js} +21 -17
  43. package/dist/src/outside-tests.js +1 -1
  44. package/dist/src/print.js +10 -79
  45. package/dist/src/report-schema.js +3 -224
  46. package/dist/src/resolve.js +245 -715
  47. package/dist/src/run.js +59 -72
  48. package/dist/src/schema.js +320 -344
  49. package/dist/src/scope.js +37 -113
  50. package/dist/src/serialization-contract.js +1 -1
  51. package/dist/src/session.js +22 -28
  52. package/dist/src/source-files.js +1 -1
  53. package/dist/src/suppress-file.js +15 -17
  54. package/dist/src/suppress.js +3 -3
  55. package/dist/src/template-field.js +4 -4
  56. package/dist/src/type-errors.js +11 -216
  57. package/dist/src/usage.js +10 -0
  58. package/dist/src/verbs/analyze.js +100 -122
  59. package/dist/src/verbs/describe.js +5 -12
  60. package/dist/src/verbs/explain.js +3 -3
  61. package/dist/src/verbs/print-projects.js +2 -2
  62. package/dist/src/verbs/version.js +12 -2
  63. package/jsr.json +1 -1
  64. package/package.json +1 -1
  65. package/src/analysis.ts +95 -460
  66. package/src/config.ts +31 -298
  67. package/src/configuration-files.ts +8 -10
  68. package/src/configured-declarations.ts +18 -23
  69. package/src/consumers.ts +6 -57
  70. package/src/contract/config.generated.ts +798 -0
  71. package/src/contract/contract.generated.ts +20 -10
  72. package/src/contract/report.generated.ts +3 -2
  73. package/src/conventions.ts +6 -12
  74. package/src/edges.ts +39 -124
  75. package/src/exempt-classes.ts +0 -5
  76. package/src/exempt.ts +4 -4
  77. package/src/failure.ts +63 -0
  78. package/src/findings/completion.ts +5 -6
  79. package/src/findings/emitter.ts +2 -2
  80. package/src/findings/emitters.ts +1 -1
  81. package/src/findings/intra-function.ts +1 -1
  82. package/src/findings/non-code-artifacts.ts +4 -4
  83. package/src/findings/unused-declarations.ts +1 -1
  84. package/src/findings/visibility-narrowing.ts +2 -2
  85. package/src/findings-pass.ts +3 -3
  86. package/src/framework-lifecycle.ts +7 -7
  87. package/src/fs/document.ts +70 -0
  88. package/src/fs/manifest.ts +8 -0
  89. package/src/host.ts +12 -5
  90. package/src/injection-container.ts +1 -1
  91. package/src/json-document.ts +236 -76
  92. package/src/kinds.ts +0 -8
  93. package/src/load/classify.ts +352 -0
  94. package/src/load/diagnostics.ts +141 -0
  95. package/src/load/discover.ts +378 -0
  96. package/src/{emit-map.ts → load/emit-map.ts} +1 -1
  97. package/src/load/expected-module.ts +188 -0
  98. package/src/load/load.ts +61 -0
  99. package/src/load/module-lookup.ts +50 -0
  100. package/src/load/plan.ts +258 -0
  101. package/src/{test-globals.ts → load/test-globals.ts} +59 -65
  102. package/src/load/test-joins.ts +98 -0
  103. package/src/{workspace-manifests.ts → load/workspace-manifests.ts} +4 -4
  104. package/src/{workspace-programs.ts → load/workspace-programs.ts} +59 -53
  105. package/src/{workspace-resolution.ts → load/workspace-resolution.ts} +31 -78
  106. package/src/{workspace-run.ts → load/workspace-run.ts} +14 -11
  107. package/src/{workspace.ts → load/workspace.ts} +28 -21
  108. package/src/outside-tests.ts +1 -1
  109. package/src/partial.ts +1 -1
  110. package/src/print.ts +11 -92
  111. package/src/report-schema.ts +3 -299
  112. package/src/resolve.ts +281 -1105
  113. package/src/run.ts +68 -80
  114. package/src/schema.ts +391 -389
  115. package/src/scope.ts +45 -131
  116. package/src/serialization-contract.ts +1 -1
  117. package/src/session.ts +52 -53
  118. package/src/source-files.ts +1 -1
  119. package/src/suppress-file.ts +15 -20
  120. package/src/suppress.ts +3 -3
  121. package/src/template-field.ts +10 -7
  122. package/src/type-errors.ts +18 -288
  123. package/src/usage.ts +10 -0
  124. package/src/verbs/analyze.ts +139 -157
  125. package/src/verbs/describe.ts +4 -11
  126. package/src/verbs/explain.ts +3 -7
  127. package/src/verbs/print-projects.ts +2 -2
  128. package/src/verbs/verb.ts +2 -2
  129. package/src/verbs/version.ts +13 -2
  130. package/dist/src/base-url.js +0 -18
  131. package/dist/src/discover.js +0 -374
  132. package/dist/src/setup-failure.js +0 -19
  133. package/dist/src/test-joins.js +0 -101
  134. package/src/base-url.ts +0 -24
  135. package/src/discover.ts +0 -548
  136. package/src/setup-failure.ts +0 -37
  137. package/src/test-joins.ts +0 -118
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The one read of a document the target holds at its root, which a checkout under analysis
3
+ * controls: the repository configuration, the ignore file, the baseline and the edges
4
+ * document. The read stays inside the target root, takes a regular file alone, and holds no
5
+ * more of it than the Contract's document bound.
6
+ */
7
+
8
+ import { CONFIG_MAX_BYTES } from "../contract/config.generated.ts";
9
+ import type { Host } from "../host.ts";
10
+ import { failureExit } from "../failure.ts";
11
+ import { joinPath, relativePath } from "../paths.ts";
12
+ import { message } from "../product.ts";
13
+ import { utf8Bytes } from "../reporters/sha256.ts";
14
+ import { UsageError } from "../usage.ts";
15
+
16
+ function unreadable(label: string, reason: string): Error {
17
+ return failureExit(
18
+ "unreadable-document",
19
+ `${label}: ${reason}: make it a regular file inside the target root that the run can read, or remove it`,
20
+ );
21
+ }
22
+
23
+ /** Refuses a document past the Contract's bound with the usage code, naming it `label`. */
24
+ export function refuseOverBound(label: string, text: string): void {
25
+ if (utf8Bytes(text).length > CONFIG_MAX_BYTES) {
26
+ throw new UsageError(`${label}: holds more than ${String(CONFIG_MAX_BYTES)} bytes`);
27
+ }
28
+ }
29
+
30
+ /**
31
+ * The text of the document `name` at the absolute `targetRoot`, undefined where nothing is
32
+ * there. One whose name resolves outside the target root or to anything but a regular file,
33
+ * or whose read fails, is refused by `refuse` naming it `label`, nothing read from it. A
34
+ * document past the bound is read one byte past it and refused as {@link refuseOverBound} does.
35
+ */
36
+ export function readTargetDocument(
37
+ host: Host,
38
+ targetRoot: string,
39
+ name: string,
40
+ label = name,
41
+ refuse: (label: string, reason: string) => Error = unreadable,
42
+ ): string | undefined {
43
+ const attempt = <T>(read: () => T): T => {
44
+ try {
45
+ return read();
46
+ } catch (error: unknown) {
47
+ throw refuse(label, message(error));
48
+ }
49
+ };
50
+ const path = joinPath(targetRoot, name);
51
+ const kind = attempt(() => host.kindOf(path));
52
+ if (kind === "absent") {
53
+ return undefined;
54
+ }
55
+ const real = attempt(() => host.realPath(path));
56
+ if (
57
+ relativePath(
58
+ attempt(() => host.realPath(targetRoot)),
59
+ real,
60
+ ) === undefined
61
+ ) {
62
+ throw refuse(label, `resolves to ${real}, outside the target root`);
63
+ }
64
+ if (kind !== "file") {
65
+ throw refuse(label, "is not a regular file");
66
+ }
67
+ const text = attempt(() => host.readFile(real, CONFIG_MAX_BYTES + 1));
68
+ refuseOverBound(label, text);
69
+ return text;
70
+ }
@@ -8,6 +8,14 @@ export const MANIFEST = "package.json";
8
8
  /** The directory a package manager installs packages into, whose files are no project's own. */
9
9
  export const INSTALLED_PACKAGES = "node_modules";
10
10
 
11
+ /** The manifest members a package declares the packages it depends on under. */
12
+ export const DEPENDENCY_SECTIONS = [
13
+ "dependencies",
14
+ "devDependencies",
15
+ "peerDependencies",
16
+ "optionalDependencies",
17
+ ] as const;
18
+
11
19
  /** Whether one path passes through an installed-packages directory. */
12
20
  export function inInstalledPackages(path: string): boolean {
13
21
  return path.split("/").includes(INSTALLED_PACKAGES);
package/src/host.ts CHANGED
@@ -1,5 +1,5 @@
1
- /** What one path names. */
2
- export type PathKind = "file" | "directory" | "absent";
1
+ /** What one path names: `"other"` is anything else there, a named pipe, a device or a socket. */
2
+ export type PathKind = "file" | "directory" | "other" | "absent";
3
3
 
4
4
  /** One entry of a directory. */
5
5
  export interface DirectoryEntry {
@@ -17,11 +17,18 @@ export interface DirectoryEntry {
17
17
  export interface Host {
18
18
  /** The directory a relative path resolves against. */
19
19
  workingDirectory(): string;
20
- /** The text of one file, or a throw naming why it cannot be read. */
21
- readFile(path: string): string;
20
+ /**
21
+ * The text of one file, or a throw naming why it cannot be read. Given `limit`, the
22
+ * text of no more than the file's first `limit` bytes, so a caller bounding a document
23
+ * asks for one byte past its bound and never holds a larger file whole.
24
+ */
25
+ readFile(path: string, limit?: number): string;
22
26
  /** The entries of one directory, or a throw naming why it cannot be read. */
23
27
  readDirectory(path: string): readonly DirectoryEntry[];
24
- /** What one path names, `"absent"` where nothing is there. */
28
+ /**
29
+ * What one path names once every symbolic link along it is followed, `"absent"` where
30
+ * nothing is there, or a throw naming why it cannot be known, as for a link loop.
31
+ */
25
32
  kindOf(path: string): PathKind;
26
33
  /**
27
34
  * The path one path names once every symbolic link along it is followed, or a throw
@@ -53,7 +53,7 @@ function isInjected(node: Node): boolean {
53
53
  /** The classes of the target a call whose callee an entry names passes, with that call's entry. */
54
54
  function registrations<Brand>(input: DetectorInput<Brand>): readonly Registration[] {
55
55
  const { project, held } = input;
56
- const resolved = resolveEntries(project, held, input.ts.injectionRegistrations);
56
+ const resolved = resolveEntries(project, held, input.ts.injection_registrations);
57
57
  if (!resolved.some(namesADeclaration)) {
58
58
  return [];
59
59
  }
@@ -1,122 +1,276 @@
1
+ import type { Position } from "./position.ts";
2
+
3
+ /** A place inside a document: each member name a string, each array index a number. */
4
+ export type Place = readonly (string | number)[];
5
+
1
6
  /**
2
- * A read of a strict JSON document beside its parse: what a parse into a value cannot
3
- * report, the offset of each record of one array and a member written twice.
7
+ * A text that is not one strict JSON document: a syntax error, data after the value, a
8
+ * member one object writes twice, or nesting past {@link MAX_DEPTH}. `place` is the
9
+ * value the fault is in, followed by the member written twice.
4
10
  */
11
+ export class StrictJSONError extends Error {
12
+ readonly offset: number;
13
+ readonly place: Place;
5
14
 
6
- import type { Position } from "./position.ts";
15
+ constructor(reason: string, offset: number, place: Place) {
16
+ super(reason);
17
+ this.name = "StrictJSONError";
18
+ this.offset = offset;
19
+ this.place = place;
20
+ }
21
+ }
7
22
 
8
- /** The token walk over a document `JSON.parse` accepted, so every token is well formed. */
9
- class Walk {
10
- readonly starts: number[] = [];
11
- /** The member written twice, where one is, as the offset of its name. */
12
- twice: { readonly name: string; readonly offset: number } | undefined;
13
- private readonly text: string;
14
- private readonly array: string;
23
+ /** One strict JSON document, read whole. */
24
+ interface StrictDocument {
25
+ readonly value: unknown;
26
+ /**
27
+ * The text of every number written with a fraction or an exponent, by its JSON
28
+ * Pointer: a value reads `100.0` as the integer 100, so only the text tells them apart.
29
+ */
30
+ readonly fractions: ReadonlyMap<string, string>;
31
+ /**
32
+ * The offset of each value inside the top-level member a read names, by its index or
33
+ * its member name, in document order.
34
+ */
35
+ readonly starts: ReadonlyMap<string | number, number>;
36
+ }
37
+
38
+ /**
39
+ * How deep values may nest. A document this analyzer reads nests a few levels, and a
40
+ * bound turns a document built to exhaust the stack into a refusal.
41
+ */
42
+ const MAX_DEPTH = 1000;
43
+
44
+ const SPACE = /[ \t\n\r]*/uy;
45
+ const STRING =
46
+ /"(?:[ !#$%&'()*+,\-./0-9:;<=>?@A-Z[\]-\u{10FFFF}]|\\(?:["\\/bfnrt]|u[0-9A-Fa-f]{4}))*"/uy;
47
+ const NUMBER = /-?(?:0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?/uy;
48
+ const LITERALS: ReadonlyMap<string, unknown> = new Map<string, unknown>([
49
+ ["true", true],
50
+ ["false", false],
51
+ ["null", null],
52
+ ]);
53
+
54
+ /** One member name spelled as a JSON Pointer token. */
55
+ const escaped = (name: string): string => name.replaceAll("~", "~0").replaceAll("/", "~1");
56
+
57
+ /** The member names and indexes a JSON Pointer holds, unescaped. */
58
+ export function pointerSegments(pointer: string): string[] {
59
+ return pointer === ""
60
+ ? []
61
+ : pointer
62
+ .slice(1)
63
+ .split("/")
64
+ .map((token) => token.replaceAll("~1", "/").replaceAll("~0", "~"));
65
+ }
66
+
67
+ /** The JSON Pointer of a place written as segments. */
68
+ export function pointerOf(segments: readonly string[]): string {
69
+ return segments.map((segment) => `/${escaped(segment)}`).join("");
70
+ }
71
+
72
+ /**
73
+ * The place a JSON Pointer names inside `value`, followed by `member` where it is not
74
+ * empty: a pointer's text does not say whether a segment of digits is an index, so the
75
+ * value it points into does.
76
+ */
77
+ export function placeIn(value: unknown, pointer: string, member = ""): (string | number)[] {
78
+ const place: (string | number)[] = [];
79
+ let held = value;
80
+ for (const segment of pointerSegments(pointer)) {
81
+ if (Array.isArray(held)) {
82
+ place.push(Number(segment));
83
+ held = held[Number(segment)];
84
+ } else {
85
+ place.push(segment);
86
+ held = isRecord(held) ? held[segment] : undefined;
87
+ }
88
+ }
89
+ return member === "" ? place : [...place, member];
90
+ }
91
+
92
+ /**
93
+ * A place as a refusal names it: member names joined by full stops and an index in
94
+ * square brackets, as `ts.serializers[0].returns`.
95
+ */
96
+ export function dotted(place: Place): string {
97
+ let path = "";
98
+ for (const segment of place) {
99
+ path +=
100
+ typeof segment === "number" ? `[${String(segment)}]` : path === "" ? segment : `.${segment}`;
101
+ }
102
+ return path;
103
+ }
104
+
105
+ class Reader {
15
106
  private at = 0;
107
+ private readonly path: (string | number)[] = [];
108
+ readonly fractions = new Map<string, string>();
109
+ readonly starts = new Map<string | number, number>();
110
+ private readonly text: string;
111
+ private readonly records: string | undefined;
16
112
 
17
- constructor(text: string, array: string) {
113
+ constructor(text: string, records: string | undefined) {
18
114
  this.text = text;
19
- this.array = array;
115
+ this.records = records;
20
116
  }
21
117
 
22
- run(): void {
23
- this.value("document");
118
+ read(): unknown {
119
+ const value = this.value(0);
120
+ this.match(SPACE);
121
+ if (this.at < this.text.length) {
122
+ this.fail("data follows the document's value");
123
+ }
124
+ return value;
24
125
  }
25
126
 
26
- private skip(): void {
27
- while (/[ \t\r\n]/u.test(this.text[this.at] ?? "")) {
28
- this.at += 1;
29
- }
127
+ private fail(reason: string, offset = this.at, member = ""): never {
128
+ throw new StrictJSONError(
129
+ reason,
130
+ offset,
131
+ member === "" ? [...this.path] : [...this.path, member],
132
+ );
30
133
  }
31
134
 
32
- private string(): string {
33
- const start = this.at;
34
- this.at += 1;
35
- while (this.text[this.at] !== '"') {
36
- this.at += this.text[this.at] === "\\" ? 2 : 1;
135
+ private match(pattern: RegExp): string | undefined {
136
+ pattern.lastIndex = this.at;
137
+ const found = pattern.exec(this.text)?.[0];
138
+ this.at = found === undefined ? this.at : pattern.lastIndex;
139
+ return found;
140
+ }
141
+
142
+ private expect(char: string, what: string): void {
143
+ this.match(SPACE);
144
+ if (this.text[this.at] !== char) {
145
+ this.fail(`${what} is expected`);
37
146
  }
38
147
  this.at += 1;
39
- return JSON.parse(this.text.slice(start, this.at)) as string;
40
148
  }
41
149
 
42
- private value(role: "document" | "array" | "record" | "other"): void {
43
- this.skip();
44
- if (role === "record") {
45
- this.starts.push(this.at);
150
+ private value(depth: number): unknown {
151
+ this.match(SPACE);
152
+ if (depth > MAX_DEPTH) {
153
+ this.fail(`values nest deeper than ${String(MAX_DEPTH)} levels`);
46
154
  }
47
155
  const char = this.text[this.at];
48
156
  if (char === "{") {
49
- this.object(role);
50
- } else if (char === "[") {
51
- this.list(role === "array" ? "record" : "other");
52
- } else if (char === '"') {
53
- this.string();
54
- } else {
55
- while (this.at < this.text.length && !/[,\]} \t\r\n]/u.test(this.text[this.at] ?? "")) {
56
- this.at += 1;
157
+ return this.object(depth);
158
+ }
159
+ if (char === "[") {
160
+ return this.array(depth);
161
+ }
162
+ const string = this.match(STRING);
163
+ if (string !== undefined) {
164
+ return JSON.parse(string) as string;
165
+ }
166
+ NUMBER.lastIndex = this.at;
167
+ const number = NUMBER.exec(this.text);
168
+ if (number !== null) {
169
+ this.at = NUMBER.lastIndex;
170
+ if (number[1] !== undefined || number[2] !== undefined) {
171
+ this.fractions.set(pointerOf(this.path.map(String)), number[0]);
172
+ }
173
+ return Number(number[0]);
174
+ }
175
+ for (const [literal, held] of LITERALS) {
176
+ if (this.text.startsWith(literal, this.at)) {
177
+ this.at += literal.length;
178
+ return held;
57
179
  }
58
180
  }
181
+ return this.fail(
182
+ char === undefined ? "the document ends where a value is expected" : "a value is expected",
183
+ );
59
184
  }
60
185
 
61
- private object(role: string): void {
62
- const seen = new Set<string>();
186
+ private object(depth: number): Record<string, unknown> {
187
+ const held: Record<string, unknown> = {};
63
188
  this.at += 1;
189
+ this.match(SPACE);
190
+ if (this.text[this.at] === "}") {
191
+ this.at += 1;
192
+ return held;
193
+ }
64
194
  for (;;) {
65
- this.skip();
66
- if (this.text[this.at] === "}") {
67
- this.at += 1;
68
- return;
195
+ this.match(SPACE);
196
+ const offset = this.at;
197
+ const spelled = this.match(STRING);
198
+ if (spelled === undefined) {
199
+ return this.fail("a member name is expected");
69
200
  }
70
- if (this.text[this.at] === ",") {
71
- this.at += 1;
72
- this.skip();
201
+ const name = JSON.parse(spelled) as string;
202
+ if (Object.hasOwn(held, name)) {
203
+ this.fail(
204
+ `the member ${JSON.stringify(name)} is written twice, so neither value is chosen`,
205
+ offset,
206
+ name,
207
+ );
73
208
  }
74
- const offset = this.at;
75
- const name = this.string();
76
- if (seen.has(name) && this.twice === undefined) {
77
- this.twice = { name, offset };
209
+ this.expect(":", "a colon after the member name");
210
+ if (depth === 1 && this.path[0] === this.records) {
211
+ this.match(SPACE);
212
+ this.starts.set(name, this.at);
78
213
  }
79
- seen.add(name);
80
- this.skip();
214
+ this.path.push(name);
215
+ Object.defineProperty(held, name, {
216
+ value: this.value(depth + 1),
217
+ enumerable: true,
218
+ writable: true,
219
+ configurable: true,
220
+ });
221
+ this.path.pop();
222
+ this.match(SPACE);
223
+ const next = this.text[this.at];
81
224
  this.at += 1;
82
- this.value(role === "document" && name === this.array ? "array" : "other");
225
+ if (next === "}") {
226
+ return held;
227
+ }
228
+ if (next !== ",") {
229
+ this.at -= 1;
230
+ this.fail("a comma or a closing brace is expected");
231
+ }
83
232
  }
84
233
  }
85
234
 
86
- private list(element: "record" | "other"): void {
235
+ private array(depth: number): unknown[] {
236
+ const held: unknown[] = [];
237
+ const records = depth === 1 && this.path[0] === this.records;
87
238
  this.at += 1;
239
+ this.match(SPACE);
240
+ if (this.text[this.at] === "]") {
241
+ this.at += 1;
242
+ return held;
243
+ }
88
244
  for (;;) {
89
- this.skip();
90
- if (this.text[this.at] === "]") {
91
- this.at += 1;
92
- return;
245
+ this.match(SPACE);
246
+ if (records) {
247
+ this.starts.set(held.length, this.at);
248
+ }
249
+ this.path.push(held.length);
250
+ held.push(this.value(depth + 1));
251
+ this.path.pop();
252
+ this.match(SPACE);
253
+ const next = this.text[this.at];
254
+ this.at += 1;
255
+ if (next === "]") {
256
+ return held;
93
257
  }
94
- if (this.text[this.at] === ",") {
95
- this.at += 1;
258
+ if (next !== ",") {
259
+ this.at -= 1;
260
+ this.fail("a comma or a closing bracket is expected");
96
261
  }
97
- this.value(element);
98
262
  }
99
263
  }
100
264
  }
101
265
 
102
- /** What a walk of one document found. */
103
- interface DocumentWalk {
104
- /** The offset of each element of the document's array member, in order: an object's `{`. */
105
- readonly starts: readonly number[];
106
- /** The first member one object writes twice, at any depth, as the offset of its name. */
107
- readonly twice: { readonly name: string; readonly offset: number } | undefined;
108
- }
109
-
110
266
  /**
111
- * Walks a document `JSON.parse` accepted, whose top-level member `array` holds the
112
- * records. A member one object writes twice reads as though it were written once, its
113
- * later value silently replacing the earlier one, so a document holding one is one a
114
- * reader names rather than reads.
267
+ * Reads `text` as one strict JSON document, or throws a {@link StrictJSONError}.
268
+ * `records` names the top-level member whose values' offsets the read keeps.
115
269
  */
116
- export function walkDocument(text: string, array: string): DocumentWalk {
117
- const walk = new Walk(text, array);
118
- walk.run();
119
- return { starts: walk.starts, twice: walk.twice };
270
+ export function readStrict(text: string, records?: string): StrictDocument {
271
+ const reader = new Reader(text, records);
272
+ const value = reader.read();
273
+ return { value, fractions: reader.fractions, starts: reader.starts };
120
274
  }
121
275
 
122
276
  /**
@@ -129,6 +283,12 @@ export function positionAt(text: string, file: string, offset: number): Position
129
283
  return { path: file, line: before.split("\n").length, column: offset - lineStart + 1 };
130
284
  }
131
285
 
286
+ /** A strict read's fault with the line and column it is at, as a refusal states it. */
287
+ export function locatedFault(text: string, error: StrictJSONError): string {
288
+ const { line, column } = positionAt(text, "", error.offset);
289
+ return `line ${String(line)}, column ${String(column)}: ${error.message}`;
290
+ }
291
+
132
292
  /** Whether a decoded JSON value is an object: not `null` and not an array. */
133
293
  export function isRecord(value: unknown): value is Record<string, unknown> {
134
294
  return typeof value === "object" && value !== null && !Array.isArray(value);
package/src/kinds.ts CHANGED
@@ -5,14 +5,6 @@ export const KINDS: ReadonlyMap<string, KindRow> = new Map(
5
5
  KIND_ROWS.map((one): [string, KindRow] => [one.code, one]),
6
6
  );
7
7
 
8
- /**
9
- * The code of every live issue kind, in ascending order. A severity key names one of
10
- * them or a family prefix whose range holds one; a key naming a retired code, an
11
- * unassigned code or a range holding no live kind is an unimplemented key, so every
12
- * severity a configuration sets is one some analyzer reports under.
13
- */
14
- export const LIVE_CODES: readonly string[] = KIND_ROWS.map((one) => one.code);
15
-
16
8
  /** The issue-kind codes whose severity the Contract fixes, in ascending order. */
17
9
  export const FIXED_SEVERITY_CODES: readonly string[] = KIND_ROWS.filter((one) => one.fixed).map(
18
10
  (one) => one.code,