@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
package/dist/src/print.js CHANGED
@@ -1,84 +1,15 @@
1
- import { renderOrigin, } from "./config.js";
1
+ import { renderOrigin } from "./config.js";
2
2
  import { bytewise } from "./text/compare.js";
3
- /** One declaration entry as a document writes it: the members of its shape alone. */
4
- function declarationOf(entry) {
5
- switch (entry.shape) {
6
- case "symbol":
7
- return { symbol: entry.symbol };
8
- case "module":
9
- return { module: entry.module, name: entry.name };
10
- case "global":
11
- return { global: entry.global };
12
- }
13
- }
14
- /** One provider entry as a document writes it: the members of its shape alone. */
15
- function providerOf(entry) {
16
- const installed = { name: entry.name, languages: entry.languages, command: entry.command };
17
- if (entry.shape === "installed") {
18
- return installed;
19
- }
20
- return { ...installed, source: entry.source, version: entry.version, digest: entry.digest };
21
- }
22
3
  /**
23
- * The resolved configuration and its provenance as one JSON object, indented,
24
- * ending in a newline.
25
- *
26
- * The output is an instance of the closed key list, so reading it back as a
27
- * repository configuration resolves to the same configuration: the provenance
28
- * object is a declared key resolution ignores. Keys are written in the schema's
29
- * order and the severity and provenance objects in ascending key order, so one
30
- * configuration renders to one string whatever order a source named its settings
31
- * in.
4
+ * The resolved configuration and its provenance as one JSON object, indented, ending
5
+ * in a newline: the configuration in the order resolution gives it, then the provenance
6
+ * object in ascending key order. Read back as a repository configuration it resolves to
7
+ * the same configuration, because resolution checks the provenance object and then
8
+ * ignores it.
32
9
  */
33
10
  export function printConfig(config, provenance) {
34
- const document = {
35
- contract_version: config.contractVersion,
36
- target: { kind: config.targetKind },
37
- analysis: {
38
- languages: config.analysis.languages,
39
- min_confidence: config.analysis.minConfidence,
40
- generated_files: config.analysis.generatedFiles,
41
- consumer_tests: config.analysis.consumerTests,
42
- configurations: config.analysis.configurations.map((entry) => entry.shape === "project"
43
- ? { id: entry.id, project: entry.project }
44
- : { id: entry.id, os: entry.os, arch: entry.arch, tags: entry.tags }),
45
- matrix: { complete: config.analysis.matrixComplete },
46
- template_dirs: config.analysis.templateDirs,
47
- template_delimiters: {
48
- left: config.analysis.templateDelimiters.left,
49
- right: config.analysis.templateDelimiters.right,
50
- },
51
- },
52
- consumers: { complete: config.consumersComplete },
53
- roots: { patterns: config.rootPatterns },
54
- severity: Object.fromEntries([...config.severity].sort(([a], [b]) => bytewise(a, b))),
55
- exemptions: { disabled: config.exemptionsDisabled },
56
- reporters: {
57
- formats: config.reporters.formats,
58
- sort: config.reporters.sort,
59
- cascade: config.reporters.cascade,
60
- max_findings: config.reporters.maxFindings,
61
- fail_on: config.reporters.failOn,
62
- },
63
- providers: { analyzers: config.providers.analyzers.map(providerOf) },
64
- go: {},
65
- ts: {
66
- test_files: config.ts.testFiles,
67
- entry_files: config.ts.entryFiles,
68
- component_extensions: config.ts.componentExtensions,
69
- disabled_conventions: config.ts.disabledConventions,
70
- injection_registrations: config.ts.injectionRegistrations.map(declarationOf),
71
- lifecycle_contracts: config.ts.lifecycleContracts.map((entry) => ({
72
- components: entry.components.map(declarationOf),
73
- bases: entry.bases.map(declarationOf),
74
- members: entry.members,
75
- })),
76
- serializers: config.ts.serializers.map(declarationOf),
77
- roots_complete: config.ts.rootsComplete,
78
- },
79
- provenance: Object.fromEntries([...provenance]
80
- .sort(([a], [b]) => bytewise(a, b))
81
- .map(([path, origin]) => [path, renderOrigin(origin)])),
82
- };
83
- return `${JSON.stringify(document, undefined, 2)}\n`;
11
+ const origins = [...provenance]
12
+ .sort(([a], [b]) => bytewise(a, b))
13
+ .map(([path, origin]) => [path, renderOrigin(origin)]);
14
+ return `${JSON.stringify({ ...config, provenance: Object.fromEntries(origins) }, undefined, 2)}\n`;
84
15
  }
@@ -1,231 +1,10 @@
1
1
  /**
2
2
  * Holds a report to `contract/report.schema.json` and `contract/finding.schema.json`
3
3
  * before it is written, reading the schemas the generator copies from the Contract, so
4
- * this analyzer never writes a document a reader refuses. It evaluates the keywords the
5
- * Contract's schemas use; the schemas' patterns are written to match alike in RE2 and in
6
- * ECMAScript.
4
+ * this analyzer never writes a document a reader refuses.
7
5
  */
8
6
  import { REPORT_SCHEMAS } from "./contract/report.generated.js";
9
- import { bytewise } from "./text/compare.js";
10
- import { isRecord } from "./json-document.js";
11
- /**
12
- * Every keyword the validator evaluates or knows to carry no assertion. A schema naming
13
- * another fails every check rather than passing values the keyword would refuse.
14
- */
15
- const KEYWORDS = new Set([
16
- ...["$schema", "$id", "$comment", "$defs", "title", "description", "default", "examples"],
17
- ...["$ref", "type", "enum", "const", "pattern", "minLength", "minimum", "maximum"],
18
- ...["properties", "additionalProperties", "required", "minProperties"],
19
- ...["items", "minItems", "maxItems", "uniqueItems"],
20
- ...["allOf", "anyOf", "oneOf", "not", "if", "then", "else"],
21
- ]);
22
- const patterns = new Map();
23
- function pattern(source) {
24
- let held = patterns.get(source);
25
- if (held === undefined) {
26
- held = new RegExp(source, "u");
27
- patterns.set(source, held);
28
- }
29
- return held;
30
- }
31
- function typeOf(value) {
32
- if (value === null) {
33
- return "null";
34
- }
35
- if (Array.isArray(value)) {
36
- return "array";
37
- }
38
- if (typeof value === "number") {
39
- return Number.isInteger(value) ? "integer" : "number";
40
- }
41
- return typeof value;
42
- }
43
- function hasType(value, name) {
44
- const held = typeOf(value);
45
- return held === name || (name === "number" && held === "integer");
46
- }
47
- /** One value's encoding with object members sorted, so two equal values encode alike. */
48
- function canonical(value) {
49
- if (Array.isArray(value)) {
50
- return `[${value.map(canonical).join(",")}]`;
51
- }
52
- if (isRecord(value)) {
53
- return `{${Object.keys(value)
54
- .sort(bytewise)
55
- .map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`)
56
- .join(",")}}`;
57
- }
58
- return JSON.stringify(value);
59
- }
60
- /** A string's length in code points, which JSON Schema's minLength counts. */
61
- function codePoints(value) {
62
- let counted = 0;
63
- for (const _point of value) {
64
- counted += 1;
65
- }
66
- return counted;
67
- }
68
- const escape = (name) => name.replaceAll("~", "~0").replaceAll("/", "~1");
69
- /** A schema evaluated in the document it is read from, so a relative `$ref` resolves there. */
70
- class Checker {
71
- documents;
72
- constructor(documents) {
73
- this.documents = documents;
74
- }
75
- resolve(doc, ref) {
76
- const [file = "", pointer = ""] = ref.split("#");
77
- const target = file === "" ? doc : file;
78
- let schema = this.documents[target];
79
- for (const token of pointer.split("/").filter((one) => one !== "")) {
80
- schema = isRecord(schema)
81
- ? schema[token.replaceAll("~1", "/").replaceAll("~0", "~")]
82
- : undefined;
83
- }
84
- if (!isRecord(schema)) {
85
- throw new Error(`report schema: ${ref} names no schema`);
86
- }
87
- return [target, schema];
88
- }
89
- matches(doc, schema, value, at) {
90
- const found = [];
91
- this.check(doc, schema, value, at, found);
92
- return found.length === 0;
93
- }
94
- check(doc, schema, value, at, found) {
95
- for (const keyword of Object.keys(schema)) {
96
- if (!KEYWORDS.has(keyword) && !keyword.startsWith("x-")) {
97
- throw new Error(`report schema: the keyword ${keyword} is not one this validator evaluates`);
98
- }
99
- }
100
- const refuse = (keyword, reason, pointer = at) => {
101
- found.push({ pointer, keyword, reason });
102
- };
103
- if (typeof schema["$ref"] === "string") {
104
- const [target, referenced] = this.resolve(doc, schema["$ref"]);
105
- this.check(target, referenced, value, at, found);
106
- }
107
- const types = schema["type"];
108
- const named = types === undefined ? [] : Array.isArray(types) ? types : [types];
109
- if (named.length > 0 && !named.some((one) => hasType(value, String(one)))) {
110
- refuse("type", `the value is ${typeOf(value)}, want ${named.join(", ")}`);
111
- return;
112
- }
113
- this.checkValue(schema, value, refuse);
114
- if (Array.isArray(value)) {
115
- this.checkArray(doc, schema, value, at, found, refuse);
116
- }
117
- else if (isRecord(value)) {
118
- this.checkObject(doc, schema, value, at, found, refuse);
119
- }
120
- this.checkApplicators(doc, schema, value, at, found, refuse);
121
- }
122
- checkValue(schema, value, refuse) {
123
- const values = schema["enum"];
124
- if (Array.isArray(values) && !values.some((one) => canonical(one) === canonical(value))) {
125
- refuse("enum", `${canonical(value)} is not one of the values the schema lists`);
126
- }
127
- if (schema["const"] !== undefined && canonical(schema["const"]) !== canonical(value)) {
128
- refuse("const", `${canonical(value)} is not ${canonical(schema["const"])}`);
129
- }
130
- if (typeof value === "string") {
131
- if (typeof schema["pattern"] === "string" && !pattern(schema["pattern"]).test(value)) {
132
- refuse("pattern", `${JSON.stringify(value)} does not match ${schema["pattern"]}`);
133
- }
134
- if (typeof schema["minLength"] === "number" && codePoints(value) < schema["minLength"]) {
135
- refuse("minLength", `${JSON.stringify(value)} is shorter than ${String(schema["minLength"])} characters`);
136
- }
137
- }
138
- if (typeof value === "number") {
139
- if (typeof schema["minimum"] === "number" && value < schema["minimum"]) {
140
- refuse("minimum", `${String(value)} is below ${String(schema["minimum"])}`);
141
- }
142
- if (typeof schema["maximum"] === "number" && value > schema["maximum"]) {
143
- refuse("maximum", `${String(value)} is above ${String(schema["maximum"])}`);
144
- }
145
- }
146
- }
147
- checkObject(doc, schema, value, at, found, refuse) {
148
- const properties = isRecord(schema["properties"]) ? schema["properties"] : {};
149
- const additional = schema["additionalProperties"];
150
- for (const name of Object.keys(value).sort(bytewise)) {
151
- const member = `${at}/${escape(name)}`;
152
- const declared = properties[name];
153
- if (isRecord(declared)) {
154
- this.check(doc, declared, value[name], member, found);
155
- }
156
- else if (additional === false) {
157
- refuse("additionalProperties", `the member ${JSON.stringify(name)} is not one the schema declares`);
158
- }
159
- else if (isRecord(additional)) {
160
- this.check(doc, additional, value[name], member, found);
161
- }
162
- }
163
- for (const name of Array.isArray(schema["required"]) ? schema["required"] : []) {
164
- if (!Object.hasOwn(value, name)) {
165
- refuse("required", `the member ${JSON.stringify(name)} is absent`);
166
- }
167
- }
168
- const fewest = schema["minProperties"];
169
- if (typeof fewest === "number" && Object.keys(value).length < fewest) {
170
- refuse("minProperties", `the object holds ${String(Object.keys(value).length)} members, fewer than ${String(fewest)}`);
171
- }
172
- }
173
- checkArray(doc, schema, value, at, found, refuse) {
174
- const items = schema["items"];
175
- if (isRecord(items)) {
176
- value.forEach((item, i) => {
177
- this.check(doc, items, item, `${at}/${String(i)}`, found);
178
- });
179
- }
180
- if (typeof schema["minItems"] === "number" && value.length < schema["minItems"]) {
181
- refuse("minItems", `the array holds ${String(value.length)} items, fewer than ${String(schema["minItems"])}`);
182
- }
183
- if (typeof schema["maxItems"] === "number" && value.length > schema["maxItems"]) {
184
- refuse("maxItems", `the array holds ${String(value.length)} items, more than ${String(schema["maxItems"])}`);
185
- }
186
- if (schema["uniqueItems"] === true && new Set(value.map(canonical)).size !== value.length) {
187
- refuse("uniqueItems", "the array lists one value twice");
188
- }
189
- }
190
- checkApplicators(doc, schema, value, at, found, refuse) {
191
- const list = (keyword) => Array.isArray(schema[keyword]) ? schema[keyword] : [];
192
- for (const each of list("allOf")) {
193
- this.check(doc, each, value, at, found);
194
- }
195
- const matching = (keyword) => list(keyword).filter((each) => this.matches(doc, each, value, at)).length;
196
- if (schema["anyOf"] !== undefined && matching("anyOf") === 0) {
197
- refuse("anyOf", "the value matches none of the alternatives");
198
- }
199
- if (schema["oneOf"] !== undefined && matching("oneOf") !== 1) {
200
- refuse("oneOf", `the value matches ${String(matching("oneOf"))} of the alternatives, want exactly one`);
201
- }
202
- if (isRecord(schema["not"]) && this.matches(doc, schema["not"], value, at)) {
203
- refuse("not", "the value matches a schema it must not match");
204
- }
205
- if (isRecord(schema["if"])) {
206
- const branch = this.matches(doc, schema["if"], value, at) ? schema["then"] : schema["else"];
207
- if (isRecord(branch)) {
208
- this.check(doc, branch, value, at, found);
209
- }
210
- }
211
- }
212
- }
213
- /**
214
- * A validator over one set of schema documents, each named as a `$ref` names it, rooted
215
- * at one of them: what it refuses in a value, none for an instance.
216
- */
217
- export function schemaRefusals(documents, root) {
218
- const checker = new Checker(documents);
219
- const top = documents[root];
220
- if (top === undefined) {
221
- throw new Error(`the schema set holds no document ${root}`);
222
- }
223
- return (value) => {
224
- const found = [];
225
- checker.check(root, top, value, "", found);
226
- return found;
227
- };
228
- }
7
+ import { schemaRefusals } from "./schema.js";
229
8
  const reportSchema = schemaRefusals(REPORT_SCHEMAS, "report.schema.json");
230
9
  /**
231
10
  * What the report schema refuses in one report document, none for an instance, and, as
@@ -242,7 +21,7 @@ function listingRefusals(report) {
242
21
  return [];
243
22
  }
244
23
  const refuse = (pointer, reason) => [
245
- { pointer, keyword: "components", reason },
24
+ { pointer, keyword: "components", reason, member: "" },
246
25
  ];
247
26
  const listed = new Set();
248
27
  for (const [i, entry] of report.components.entries()) {