@cplieger/deadset-ts 8.0.0-dev.6 → 8.0.0-dev.8
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/bin/mapper-connection.js +2 -1
- package/dist/bin/node-host.js +24 -5
- package/dist/src/analysis.js +37 -56
- package/dist/src/automatic-types.js +10 -29
- package/dist/src/build-scripts.js +17 -29
- package/dist/src/component-layer.js +4 -2
- package/dist/src/components.js +2 -3
- package/dist/src/config.js +6 -82
- package/dist/src/configuration-files.js +27 -168
- package/dist/src/configured-declarations.js +15 -20
- package/dist/src/consumers.js +2 -2
- package/dist/src/contract/config.generated.js +544 -0
- package/dist/src/contract/contract.generated.js +13 -0
- package/dist/src/contract/report.generated.js +3 -2
- package/dist/src/conventions.js +20 -60
- package/dist/src/dependencies.js +25 -43
- package/dist/src/discover.js +14 -40
- package/dist/src/edges.js +38 -122
- package/dist/src/element-access.js +4 -6
- package/dist/src/entry-point-gaps.js +2 -8
- package/dist/src/entry-points.js +3 -10
- package/dist/src/enum-group.js +3 -10
- package/dist/src/erased-stores.js +4 -6
- package/dist/src/exempt-classes.js +0 -4
- package/dist/src/exempt.js +6 -22
- package/dist/src/file-facts.js +2 -25
- package/dist/src/findings/completion.js +5 -4
- package/dist/src/findings/emitters.js +1 -1
- package/dist/src/findings/intra-function.js +1 -1
- package/dist/src/findings/non-code-artifacts.js +2 -2
- package/dist/src/findings/reads-and-writes.js +2 -1
- package/dist/src/findings/self-check.js +3 -2
- package/dist/src/findings/unused-declarations.js +1 -1
- package/dist/src/findings/visibility-narrowing.js +2 -2
- package/dist/src/findings-pass.js +7 -12
- package/dist/src/framework-lifecycle.js +7 -7
- package/dist/src/fs/document.js +59 -0
- package/dist/src/fs/manifest.js +43 -0
- package/dist/src/fs/tree.js +88 -0
- package/dist/src/git-ignore.js +34 -25
- package/dist/src/html-entries.js +6 -33
- package/dist/src/in-operands.js +2 -1
- package/dist/src/injection-container.js +1 -1
- package/dist/src/intra-function-parts.js +10 -13
- package/dist/src/inventory.js +2 -21
- package/dist/src/json-document.js +198 -67
- package/dist/src/keyof-comparisons.js +4 -6
- package/dist/src/kinds.js +0 -7
- package/dist/src/manifest.js +5 -43
- package/dist/src/mdx-entries.js +3 -26
- package/dist/src/partial.js +2 -1
- package/dist/src/paths.js +26 -15
- package/dist/src/position.js +2 -1
- package/dist/src/print.js +11 -79
- package/dist/src/product.js +13 -0
- package/dist/src/references.js +14 -27
- package/dist/src/report-schema.js +3 -225
- package/dist/src/report.js +22 -31
- package/dist/src/reporters/sarif.js +4 -2
- package/dist/src/reporters/template.js +4 -19
- package/dist/src/resolve.js +245 -724
- package/dist/src/roots.js +7 -17
- package/dist/src/run.js +55 -61
- package/dist/src/schema.js +320 -343
- package/dist/src/scope.js +34 -103
- package/dist/src/serialization-contract.js +5 -9
- package/dist/src/session.js +2 -1
- package/dist/src/suppress-file.js +21 -25
- package/dist/src/suppress.js +3 -3
- package/dist/src/symbol-keys.js +3 -5
- package/dist/src/template-field.js +9 -19
- package/dist/src/test-globals.js +6 -28
- package/dist/src/test-joins.js +6 -6
- package/dist/src/text/compare.js +26 -0
- package/dist/src/text/glob.js +194 -0
- package/dist/src/text/shell.js +159 -0
- package/dist/src/{yaml-document.js → text/yaml.js} +38 -0
- package/dist/src/type-errors.js +14 -38
- package/dist/src/unseen-loads.js +2 -9
- package/dist/src/unwrap.js +23 -0
- package/dist/src/usage.js +10 -0
- package/dist/src/verbs/analyze.js +25 -26
- package/dist/src/verbs/describe.js +4 -4
- package/dist/src/verbs/explain.js +8 -6
- package/dist/src/verbs/print-projects.js +4 -3
- package/dist/src/verbs/print-retained.js +2 -1
- package/dist/src/verbs/print-roots.js +2 -1
- package/dist/src/verbs/version.js +2 -1
- package/dist/src/workflow-steps.js +9 -46
- package/dist/src/workspace-manifests.js +2 -2
- package/dist/src/workspace-programs.js +5 -3
- package/dist/src/workspace-resolution.js +13 -17
- package/dist/src/workspace.js +28 -116
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/analysis.ts +55 -76
- package/src/automatic-types.ts +11 -29
- package/src/build-scripts.ts +17 -38
- package/src/component-layer.ts +4 -2
- package/src/components.ts +2 -4
- package/src/config.ts +31 -296
- package/src/configuration-files.ts +27 -170
- package/src/configured-declarations.ts +18 -23
- package/src/consumers.ts +4 -4
- package/src/contract/config.generated.ts +798 -0
- package/src/contract/contract.generated.ts +25 -0
- package/src/contract/report.generated.ts +3 -2
- package/src/conventions.ts +26 -74
- package/src/dependencies.ts +32 -50
- package/src/discover.ts +15 -40
- package/src/edges.ts +41 -140
- package/src/element-access.ts +4 -7
- package/src/entry-point-gaps.ts +3 -9
- package/src/entry-points.ts +2 -13
- package/src/enum-group.ts +2 -11
- package/src/erased-stores.ts +3 -7
- package/src/exempt-classes.ts +0 -5
- package/src/exempt.ts +8 -30
- package/src/file-facts.ts +6 -24
- package/src/findings/completion.ts +5 -6
- package/src/findings/emitter.ts +2 -2
- package/src/findings/emitters.ts +1 -1
- package/src/findings/intra-function.ts +1 -1
- package/src/findings/non-code-artifacts.ts +4 -4
- package/src/findings/reads-and-writes.ts +2 -1
- package/src/findings/self-check.ts +3 -2
- package/src/findings/unused-declarations.ts +1 -1
- package/src/findings/visibility-narrowing.ts +2 -2
- package/src/findings-pass.ts +9 -15
- package/src/framework-lifecycle.ts +7 -7
- package/src/fs/document.ts +74 -0
- package/src/fs/manifest.ts +52 -0
- package/src/fs/tree.ts +110 -0
- package/src/git-ignore.ts +38 -25
- package/src/host.ts +12 -5
- package/src/html-entries.ts +6 -33
- package/src/in-operands.ts +2 -1
- package/src/injection-container.ts +1 -1
- package/src/intra-function-parts.ts +10 -14
- package/src/inventory.ts +2 -20
- package/src/json-document.ts +241 -76
- package/src/keyof-comparisons.ts +3 -7
- package/src/kinds.ts +0 -8
- package/src/manifest.ts +5 -46
- package/src/mdx-entries.ts +3 -26
- package/src/partial.ts +2 -1
- package/src/paths.ts +27 -15
- package/src/position.ts +2 -1
- package/src/print.ts +12 -92
- package/src/product.ts +18 -0
- package/src/references.ts +14 -29
- package/src/report-schema.ts +3 -301
- package/src/report.ts +24 -34
- package/src/reporters/sarif.ts +4 -4
- package/src/reporters/template.ts +4 -20
- package/src/resolve.ts +283 -1114
- package/src/roots.ts +7 -20
- package/src/run.ts +57 -75
- package/src/schema.ts +391 -388
- package/src/scope.ts +40 -126
- package/src/serialization-contract.ts +5 -10
- package/src/session.ts +2 -1
- package/src/suppress-file.ts +21 -29
- package/src/suppress.ts +3 -3
- package/src/symbol-keys.ts +2 -5
- package/src/template-field.ts +15 -25
- package/src/test-globals.ts +9 -27
- package/src/test-joins.ts +6 -8
- package/src/text/compare.ts +27 -0
- package/src/text/glob.ts +210 -0
- package/src/text/shell.ts +161 -0
- package/src/{yaml-document.ts → text/yaml.ts} +46 -0
- package/src/type-errors.ts +25 -36
- package/src/unseen-loads.ts +1 -12
- package/src/unwrap.ts +34 -0
- package/src/usage.ts +10 -0
- package/src/verbs/analyze.ts +32 -42
- package/src/verbs/describe.ts +4 -4
- package/src/verbs/explain.ts +8 -10
- package/src/verbs/print-projects.ts +4 -3
- package/src/verbs/print-retained.ts +2 -1
- package/src/verbs/print-roots.ts +2 -1
- package/src/verbs/verb.ts +2 -2
- package/src/verbs/version.ts +2 -1
- package/src/workflow-steps.ts +9 -44
- package/src/workspace-manifests.ts +2 -2
- package/src/workspace-programs.ts +5 -3
- package/src/workspace-resolution.ts +21 -17
- package/src/workspace.ts +35 -121
- package/dist/src/glob.js +0 -65
- package/dist/src/pnpm-workspace.js +0 -120
- package/src/glob.ts +0 -67
- package/src/pnpm-workspace.ts +0 -135
package/src/resolve.ts
CHANGED
|
@@ -1,1201 +1,370 @@
|
|
|
1
|
+
import { SETTINGS, type SettingRow } from "./contract/config.generated.ts";
|
|
2
|
+
import { FAMILY_KEY_LENGTH } from "./contract/contract.generated.ts";
|
|
1
3
|
import {
|
|
2
|
-
|
|
3
|
-
LANGUAGES,
|
|
4
|
-
CONFIDENCES,
|
|
5
|
-
FORMATS,
|
|
6
|
-
type Confidence,
|
|
7
|
-
type Format,
|
|
8
|
-
type Language,
|
|
9
|
-
type Severity,
|
|
10
|
-
FAMILY_KEY_LENGTH,
|
|
11
|
-
} from "./contract/contract.generated.ts";
|
|
12
|
-
import {
|
|
13
|
-
ConfigError,
|
|
14
|
-
defaultConfig,
|
|
15
|
-
type BuildConfiguration,
|
|
16
|
-
type Cascade,
|
|
17
|
-
type Config,
|
|
18
|
-
type ConsumerTests,
|
|
19
|
-
type DeclarationEntry,
|
|
20
|
-
type GeneratedFiles,
|
|
4
|
+
type Document,
|
|
21
5
|
type Inputs,
|
|
22
|
-
type LifecycleContract,
|
|
23
6
|
type Origin,
|
|
7
|
+
type PartialConfig,
|
|
24
8
|
type Provenance,
|
|
25
|
-
type
|
|
26
|
-
type Sort,
|
|
9
|
+
type ResolvedConfig,
|
|
27
10
|
type Source,
|
|
28
|
-
type TargetKind,
|
|
29
|
-
type TargetKindSetting,
|
|
30
|
-
type TemplateDelimiters,
|
|
31
11
|
} from "./config.ts";
|
|
32
12
|
import { CONVENTION_ROWS } from "./convention-rows.ts";
|
|
33
|
-
import {
|
|
13
|
+
import { refuseOverBound } from "./fs/document.ts";
|
|
34
14
|
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
/** The members only an acquirable provider entry carries. */
|
|
55
|
-
const ACQUIRABLE_MEMBERS = ["source", "version", "digest"] as const;
|
|
56
|
-
|
|
57
|
-
/** The members only a platform build configuration carries. */
|
|
58
|
-
const PLATFORM_MEMBERS = ["os", "arch", "tags"] as const;
|
|
59
|
-
|
|
60
|
-
/** The member only a project build configuration carries. */
|
|
61
|
-
const PROJECT_MEMBER = "project";
|
|
15
|
+
dotted,
|
|
16
|
+
isRecord,
|
|
17
|
+
locatedFault,
|
|
18
|
+
type Place,
|
|
19
|
+
placeIn,
|
|
20
|
+
pointerOf,
|
|
21
|
+
readStrict,
|
|
22
|
+
StrictJSONError,
|
|
23
|
+
} from "./json-document.ts";
|
|
24
|
+
import { FIXED_SEVERITY_CODES } from "./kinds.ts";
|
|
25
|
+
import { LANGUAGE } from "./product.ts";
|
|
26
|
+
import { firstRefusal, type SchemaRefusal } from "./schema.ts";
|
|
27
|
+
import { bytewise } from "./text/compare.ts";
|
|
28
|
+
import { UsageError } from "./usage.ts";
|
|
29
|
+
|
|
30
|
+
const ROWS: ReadonlyMap<string, SettingRow> = new Map(SETTINGS.map((row) => [row.key, row]));
|
|
31
|
+
|
|
32
|
+
/** The schema of a section or a keyed section's value, so the validator words its refusal. */
|
|
33
|
+
const OBJECT = { type: "object" };
|
|
62
34
|
|
|
63
35
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
36
|
+
* The settings whose entries name rows of this analyzer's own data, which the
|
|
37
|
+
* Contract's schema cannot list: a disabled convention names a convention row.
|
|
66
38
|
*/
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
* A project path: segments joined by a solidus, so the path is relative, below
|
|
71
|
-
* the root it is read against, and spelled one way on every machine.
|
|
72
|
-
*/
|
|
73
|
-
const PROJECT_PATH = new RegExp(`^${PROJECT_SEGMENT}(?:/${PROJECT_SEGMENT})*$`, "u");
|
|
74
|
-
|
|
75
|
-
const TARGET_KINDS: readonly TargetKind[] = ["application", "library"];
|
|
76
|
-
const GENERATED_FILES: readonly GeneratedFiles[] = ["exclude", "include"];
|
|
77
|
-
const CONSUMER_TESTS: readonly ConsumerTests[] = ["test", "production"];
|
|
78
|
-
const SORTS: readonly Sort[] = ["position", "size"];
|
|
79
|
-
const CASCADES: readonly Cascade[] = ["roots", "full"];
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* One configuration document, read as the settings it supplies. Every member is
|
|
83
|
-
* possibly undefined, so a key the document omits is distinguishable from one it
|
|
84
|
-
* sets to a value equal to the default, which is what makes resolution per
|
|
85
|
-
* setting rather than per document.
|
|
86
|
-
*/
|
|
87
|
-
interface Doc {
|
|
88
|
-
readonly contractVersion: string | undefined;
|
|
89
|
-
readonly targetKind: TargetKindSetting | undefined;
|
|
90
|
-
readonly languages: readonly Language[] | undefined;
|
|
91
|
-
readonly minConfidence: Confidence | undefined;
|
|
92
|
-
readonly generatedFiles: GeneratedFiles | undefined;
|
|
93
|
-
readonly consumerTests: ConsumerTests | undefined;
|
|
94
|
-
readonly configurations: readonly BuildConfiguration[] | undefined;
|
|
95
|
-
readonly matrixComplete: boolean | undefined;
|
|
96
|
-
readonly templateDirs: readonly string[] | undefined;
|
|
97
|
-
readonly templateDelimiters: TemplateDelimiters | undefined;
|
|
98
|
-
readonly consumersComplete: boolean | undefined;
|
|
99
|
-
readonly rootPatterns: readonly string[] | undefined;
|
|
100
|
-
readonly severity: ReadonlyMap<string, Severity> | undefined;
|
|
101
|
-
readonly exemptionsDisabled: readonly string[] | undefined;
|
|
102
|
-
readonly formats: readonly Format[] | undefined;
|
|
103
|
-
readonly sort: Sort | undefined;
|
|
104
|
-
readonly cascade: Cascade | undefined;
|
|
105
|
-
readonly maxFindings: number | undefined;
|
|
106
|
-
readonly failOn: Severity | undefined;
|
|
107
|
-
readonly providers: readonly Provider[] | undefined;
|
|
108
|
-
readonly testFiles: readonly string[] | undefined;
|
|
109
|
-
readonly entryFiles: readonly string[] | undefined;
|
|
110
|
-
readonly componentExtensions: readonly string[] | undefined;
|
|
111
|
-
readonly disabledConventions: readonly string[] | undefined;
|
|
112
|
-
readonly injectionRegistrations: readonly DeclarationEntry[] | undefined;
|
|
113
|
-
readonly lifecycleContracts: readonly LifecycleContract[] | undefined;
|
|
114
|
-
readonly serializers: readonly DeclarationEntry[] | undefined;
|
|
115
|
-
readonly rootsComplete: boolean | undefined;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/** One document the resolution reads, with the origin its settings carry. */
|
|
119
|
-
interface DocSource {
|
|
120
|
-
readonly doc: Doc;
|
|
121
|
-
readonly kind: Source;
|
|
122
|
-
readonly label: string;
|
|
123
|
-
readonly flagLabels: ReadonlyMap<string, string>;
|
|
124
|
-
}
|
|
39
|
+
const OWN_VOCABULARIES: ReadonlyMap<string, ReadonlySet<string>> = new Map([
|
|
40
|
+
["ts.disabled_conventions", new Set(CONVENTION_ROWS.map((row) => row.name))],
|
|
41
|
+
]);
|
|
125
42
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
* because one invocation carries many.
|
|
129
|
-
*/
|
|
130
|
-
function originOf(source: DocSource, path: string): Origin {
|
|
131
|
-
if (source.kind === "flag") {
|
|
132
|
-
return { source: "flag", label: source.flagLabels.get(path) ?? "" };
|
|
133
|
-
}
|
|
134
|
-
return { source: source.kind, label: source.label };
|
|
43
|
+
function malformed(label: string, path: string, detail: string): UsageError {
|
|
44
|
+
return new UsageError(path === "" ? `${label}: ${detail}` : `${label}: ${path}: ${detail}`);
|
|
135
45
|
}
|
|
136
46
|
|
|
137
|
-
|
|
138
|
-
|
|
47
|
+
/** A key the closed key list does not declare, with the reason where there is more to say. */
|
|
48
|
+
function unimplemented(label: string, path: string, reason = ""): UsageError {
|
|
49
|
+
const why = reason === "" ? "" : `: ${reason}`;
|
|
50
|
+
return new UsageError(`${label}: key ${JSON.stringify(path)} is not implemented${why}`);
|
|
139
51
|
}
|
|
140
52
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
53
|
+
/** Why a well-formed severity key the vocabulary does not hold names no setting. */
|
|
54
|
+
function severityKeyRefused(key: string): string {
|
|
55
|
+
const fixed = FIXED_SEVERITY_CODES.filter(
|
|
56
|
+
(code) => code === key || (key.length === FAMILY_KEY_LENGTH && code.startsWith(key)),
|
|
57
|
+
).sort(bytewise);
|
|
58
|
+
if (fixed.length > 0) {
|
|
59
|
+
const named =
|
|
60
|
+
fixed.length < 2
|
|
61
|
+
? fixed.join("")
|
|
62
|
+
: `${fixed.slice(0, -1).join(", ")} and ${String(fixed.at(-1))}`;
|
|
63
|
+
return `the Contract fixes the severity of ${named}, which this key names`;
|
|
144
64
|
}
|
|
145
|
-
return
|
|
65
|
+
return key.length === FAMILY_KEY_LENGTH
|
|
66
|
+
? `no issue kind carries a code of the family ${key}`
|
|
67
|
+
: `no issue kind carries the code ${key}`;
|
|
146
68
|
}
|
|
147
69
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
label: string,
|
|
153
|
-
): Record<string, unknown> | undefined {
|
|
154
|
-
const value = member(parent, name);
|
|
155
|
-
if (value === undefined) {
|
|
156
|
-
return undefined;
|
|
70
|
+
/** A value with every object's members in ascending order, so it prints one way. */
|
|
71
|
+
function canonical(value: unknown): unknown {
|
|
72
|
+
if (Array.isArray(value)) {
|
|
73
|
+
return value.map(canonical);
|
|
157
74
|
}
|
|
158
75
|
if (!isRecord(value)) {
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
return value;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function spell(values: readonly string[]): string {
|
|
165
|
-
return values.map((value) => JSON.stringify(value)).join(", ");
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function readEnum<T extends string>(
|
|
169
|
-
parent: Record<string, unknown> | undefined,
|
|
170
|
-
name: string,
|
|
171
|
-
path: string,
|
|
172
|
-
label: string,
|
|
173
|
-
allowed: readonly T[],
|
|
174
|
-
): T | undefined {
|
|
175
|
-
const value = member(parent, name);
|
|
176
|
-
if (value === undefined) {
|
|
177
|
-
return undefined;
|
|
178
|
-
}
|
|
179
|
-
if (typeof value !== "string") {
|
|
180
|
-
throw malformed(label, path, "is not a string");
|
|
181
|
-
}
|
|
182
|
-
if (!(allowed as readonly string[]).includes(value)) {
|
|
183
|
-
throw malformed(label, path, `${JSON.stringify(value)} is not one of ${spell(allowed)}`);
|
|
184
|
-
}
|
|
185
|
-
return value as T;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function readString(
|
|
189
|
-
parent: Record<string, unknown> | undefined,
|
|
190
|
-
name: string,
|
|
191
|
-
path: string,
|
|
192
|
-
label: string,
|
|
193
|
-
): string | undefined {
|
|
194
|
-
const value = member(parent, name);
|
|
195
|
-
if (value === undefined) {
|
|
196
|
-
return undefined;
|
|
76
|
+
return value;
|
|
197
77
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
78
|
+
return Object.fromEntries(
|
|
79
|
+
Object.keys(value)
|
|
80
|
+
.sort(bytewise)
|
|
81
|
+
.map((name) => [name, canonical(value[name])]),
|
|
82
|
+
);
|
|
202
83
|
}
|
|
203
84
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
label: string,
|
|
209
|
-
): boolean | undefined {
|
|
210
|
-
const value = member(parent, name);
|
|
211
|
-
if (value === undefined) {
|
|
212
|
-
return undefined;
|
|
213
|
-
}
|
|
214
|
-
if (typeof value !== "boolean") {
|
|
215
|
-
throw malformed(label, path, "is not a boolean");
|
|
216
|
-
}
|
|
217
|
-
return value;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function readCount(
|
|
221
|
-
parent: Record<string, unknown> | undefined,
|
|
222
|
-
name: string,
|
|
223
|
-
path: string,
|
|
224
|
-
label: string,
|
|
225
|
-
): number | undefined {
|
|
226
|
-
const value = member(parent, name);
|
|
227
|
-
if (value === undefined) {
|
|
228
|
-
return undefined;
|
|
229
|
-
}
|
|
230
|
-
if (typeof value !== "number" || !Number.isInteger(value)) {
|
|
231
|
-
throw malformed(label, path, "is not an integer");
|
|
232
|
-
}
|
|
233
|
-
if (value < 0) {
|
|
234
|
-
throw malformed(label, path, `${String(value)} is below the minimum of 0`);
|
|
235
|
-
}
|
|
236
|
-
return value;
|
|
85
|
+
/** What one checked source supplies: each setting's value and each keyed section's members. */
|
|
86
|
+
interface Supplied {
|
|
87
|
+
readonly values: Map<string, unknown>;
|
|
88
|
+
readonly keyed: Map<string, Readonly<Record<string, unknown>>>;
|
|
237
89
|
}
|
|
238
90
|
|
|
239
91
|
/**
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
92
|
+
* The walk of one source over the closed key list. The members of an object are checked
|
|
93
|
+
* in ascending order and a key is checked whole before the next. A key this analyzer's
|
|
94
|
+
* language does not read is accepted unread, and of a key written per language, every
|
|
95
|
+
* other language's member.
|
|
243
96
|
*/
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if (typeof entry !== "string") {
|
|
270
|
-
throw malformed(label, at, "is not a string");
|
|
271
|
-
}
|
|
272
|
-
if (entry === "") {
|
|
273
|
-
throw malformed(label, at, "is empty");
|
|
274
|
-
}
|
|
275
|
-
if (seen.has(entry)) {
|
|
276
|
-
throw malformed(label, at, `names ${JSON.stringify(entry)} again`);
|
|
277
|
-
}
|
|
278
|
-
if (allowed !== undefined && !(allowed as readonly string[]).includes(entry)) {
|
|
279
|
-
throw malformed(label, at, `${JSON.stringify(entry)} is not one of ${spell(allowed)}`);
|
|
97
|
+
class Walk {
|
|
98
|
+
private readonly label: string;
|
|
99
|
+
private readonly fractions: ReadonlyMap<string, string>;
|
|
100
|
+
private readonly into: Supplied;
|
|
101
|
+
|
|
102
|
+
constructor(label: string, fractions: ReadonlyMap<string, string>, into: Supplied) {
|
|
103
|
+
this.label = label;
|
|
104
|
+
this.fractions = fractions;
|
|
105
|
+
this.into = into;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
section(at: string, members: Readonly<Record<string, unknown>>): void {
|
|
109
|
+
for (const name of Object.keys(members).sort(bytewise)) {
|
|
110
|
+
const key = at === "" ? name : `${at}.${name}`;
|
|
111
|
+
const row = ROWS.get(key);
|
|
112
|
+
if (name.includes(".")) {
|
|
113
|
+
const reason = row === undefined ? "" : "it is one setting, written as nested objects";
|
|
114
|
+
throw unimplemented(this.label, key, reason);
|
|
115
|
+
}
|
|
116
|
+
if (row === undefined) {
|
|
117
|
+
throw unimplemented(this.label, key);
|
|
118
|
+
}
|
|
119
|
+
if (row.read) {
|
|
120
|
+
this.key(row, members[name]);
|
|
121
|
+
}
|
|
280
122
|
}
|
|
281
|
-
seen.add(entry);
|
|
282
123
|
}
|
|
283
|
-
return value as readonly T[];
|
|
284
|
-
}
|
|
285
124
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
return undefined;
|
|
300
|
-
}
|
|
301
|
-
if (typeof value === "string") {
|
|
302
|
-
if (!(TARGET_KINDS as readonly string[]).includes(value)) {
|
|
303
|
-
throw malformed(
|
|
304
|
-
label,
|
|
305
|
-
"target.kind",
|
|
306
|
-
`${JSON.stringify(value)} is not one of ${spell(TARGET_KINDS)}, nor ${perLanguage}`,
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
return value as TargetKind;
|
|
310
|
-
}
|
|
311
|
-
if (!isRecord(value)) {
|
|
312
|
-
throw malformed(
|
|
313
|
-
label,
|
|
314
|
-
"target.kind",
|
|
315
|
-
`${JSON.stringify(value)} is neither one of ${spell(TARGET_KINDS)} nor ${perLanguage}`,
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
const missing = LANGUAGES.find((language) => !Object.hasOwn(value, language));
|
|
319
|
-
if (missing !== undefined) {
|
|
320
|
-
throw malformed(label, `target.kind.${missing}`, `is not set, and ${perLanguage} names each`);
|
|
321
|
-
}
|
|
322
|
-
for (const language of LANGUAGES) {
|
|
323
|
-
const kind = value[language];
|
|
324
|
-
if (typeof kind !== "string" || !(TARGET_KINDS as readonly string[]).includes(kind)) {
|
|
325
|
-
throw malformed(
|
|
326
|
-
label,
|
|
327
|
-
`target.kind.${language}`,
|
|
328
|
-
`${JSON.stringify(kind)} is not one of ${spell(TARGET_KINDS)}`,
|
|
329
|
-
);
|
|
125
|
+
private key(row: SettingRow, value: unknown): void {
|
|
126
|
+
if (row.role === "section") {
|
|
127
|
+
this.refuse(row.key.split("."), value, firstRefusal(OBJECT, value));
|
|
128
|
+
this.section(row.key, value as Record<string, unknown>);
|
|
129
|
+
} else if (row.role === "setting") {
|
|
130
|
+
const read = row.perLanguage === undefined ? value : this.narrowed(row, value);
|
|
131
|
+
this.setting(row, read);
|
|
132
|
+
this.into.values.set(row.key, canonical(read));
|
|
133
|
+
} else {
|
|
134
|
+
const members = this.keyed(row, value);
|
|
135
|
+
if (row.role === "keyed") {
|
|
136
|
+
this.into.keyed.set(row.key, members);
|
|
137
|
+
}
|
|
330
138
|
}
|
|
331
139
|
}
|
|
332
|
-
return { go: value["go"] as TargetKind, ts: value["ts"] as TargetKind };
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
/** A component file's extension: a full stop followed by letters and digits. */
|
|
336
|
-
const COMPONENT_EXTENSION = /^\.[A-Za-z0-9]+$/u;
|
|
337
|
-
|
|
338
|
-
function readComponentExtensions(
|
|
339
|
-
ts: Record<string, unknown> | undefined,
|
|
340
|
-
label: string,
|
|
341
|
-
): readonly string[] | undefined {
|
|
342
|
-
const extensions = readStrings(ts, "component_extensions", "ts.component_extensions", label, 0);
|
|
343
|
-
const wrong = extensions?.findIndex((one) => !COMPONENT_EXTENSION.test(one)) ?? -1;
|
|
344
|
-
if (extensions !== undefined && wrong !== -1) {
|
|
345
|
-
throw malformed(
|
|
346
|
-
label,
|
|
347
|
-
`ts.component_extensions[${String(wrong)}]`,
|
|
348
|
-
`${JSON.stringify(extensions[wrong])} is not a full stop followed by letters and digits`,
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
return extensions;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/** The names of the convention rows this analyzer's table carries. */
|
|
355
|
-
const CONVENTION_NAMES: ReadonlySet<string> = new Set(CONVENTION_ROWS.map((row) => row.name));
|
|
356
|
-
|
|
357
|
-
function readDisabledConventions(
|
|
358
|
-
ts: Record<string, unknown> | undefined,
|
|
359
|
-
label: string,
|
|
360
|
-
): readonly string[] | undefined {
|
|
361
|
-
const names = readStrings(ts, "disabled_conventions", "ts.disabled_conventions", label, 0);
|
|
362
|
-
const unknown = names?.findIndex((one) => !CONVENTION_NAMES.has(one)) ?? -1;
|
|
363
|
-
if (names !== undefined && unknown !== -1) {
|
|
364
|
-
throw malformed(
|
|
365
|
-
label,
|
|
366
|
-
`ts.disabled_conventions[${String(unknown)}]`,
|
|
367
|
-
`${JSON.stringify(names[unknown])} names no convention row this analyzer carries`,
|
|
368
|
-
);
|
|
369
|
-
}
|
|
370
|
-
return names;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
function requireMember(value: string | undefined, path: string, label: string): string {
|
|
374
|
-
if (value === undefined || value === "") {
|
|
375
|
-
throw malformed(label, path, "is required and names nothing");
|
|
376
|
-
}
|
|
377
|
-
return value;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/** One build configuration entry as a platform: an identifier, an operating system and an architecture. */
|
|
381
|
-
function readPlatform(
|
|
382
|
-
entry: Record<string, unknown>,
|
|
383
|
-
at: string,
|
|
384
|
-
label: string,
|
|
385
|
-
): BuildConfiguration {
|
|
386
|
-
return {
|
|
387
|
-
shape: "platform",
|
|
388
|
-
id: requireMember(readString(entry, "id", `${at}.id`, label), `${at}.id`, label),
|
|
389
|
-
os: requireMember(readString(entry, "os", `${at}.os`, label), `${at}.os`, label),
|
|
390
|
-
arch: requireMember(readString(entry, "arch", `${at}.arch`, label), `${at}.arch`, label),
|
|
391
|
-
tags: readStrings(entry, "tags", `${at}.tags`, label, 0) ?? [],
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
140
|
|
|
395
|
-
/**
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
const project = requireMember(readString(entry, PROJECT_MEMBER, path, label), path, label);
|
|
404
|
-
if (!PROJECT_PATH.test(project)) {
|
|
405
|
-
throw malformed(
|
|
406
|
-
label,
|
|
407
|
-
path,
|
|
408
|
-
`${JSON.stringify(project)} is not a path below the target root: segments joined by /, ` +
|
|
409
|
-
"none empty, . or .., and no control character",
|
|
410
|
-
);
|
|
411
|
-
}
|
|
412
|
-
return { shape: "project", id, project };
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* One build configuration entry, read as the one shape its members name: a member
|
|
417
|
-
* only a platform carries makes it a platform, the member only a project carries
|
|
418
|
-
* makes it a project, and an entry naming members of both, or of neither, is
|
|
419
|
-
* refused at the entry, because the two shapes are exclusive.
|
|
420
|
-
*/
|
|
421
|
-
function readConfiguration(entry: unknown, at: string, label: string): BuildConfiguration {
|
|
422
|
-
if (!isRecord(entry)) {
|
|
423
|
-
throw malformed(label, at, "is not an object");
|
|
424
|
-
}
|
|
425
|
-
const platform = PLATFORM_MEMBERS.filter((name) => Object.hasOwn(entry, name));
|
|
426
|
-
const project = Object.hasOwn(entry, PROJECT_MEMBER);
|
|
427
|
-
if (platform.length > 0 && project) {
|
|
428
|
-
throw malformed(
|
|
429
|
-
label,
|
|
430
|
-
at,
|
|
431
|
-
`carries ${spell(platform)} of a platform and ${JSON.stringify(PROJECT_MEMBER)} of a ` +
|
|
432
|
-
"project, and an entry is one shape or the other",
|
|
433
|
-
);
|
|
434
|
-
}
|
|
435
|
-
if (project) {
|
|
436
|
-
return readProject(entry, at, label);
|
|
437
|
-
}
|
|
438
|
-
if (platform.length === 0) {
|
|
439
|
-
throw malformed(
|
|
440
|
-
label,
|
|
441
|
-
at,
|
|
442
|
-
`names neither a platform's "os" and "arch" nor a project's ${JSON.stringify(PROJECT_MEMBER)}`,
|
|
141
|
+
/** A per-language value as this language reads it: of the object form, its own member alone. */
|
|
142
|
+
private narrowed(row: SettingRow, value: unknown): unknown {
|
|
143
|
+
if (!isRecord(value)) {
|
|
144
|
+
return value;
|
|
145
|
+
}
|
|
146
|
+
const others: readonly string[] = row.perLanguage ?? [];
|
|
147
|
+
return Object.fromEntries(
|
|
148
|
+
Object.entries(value).filter(([name]) => name === LANGUAGE || !others.includes(name)),
|
|
443
149
|
);
|
|
444
150
|
}
|
|
445
|
-
return readPlatform(entry, at, label);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/** The build matrix, one entry in one shape at a time. */
|
|
449
|
-
function readConfigurations(
|
|
450
|
-
analysis: Record<string, unknown> | undefined,
|
|
451
|
-
label: string,
|
|
452
|
-
): readonly BuildConfiguration[] | undefined {
|
|
453
|
-
const value = member(analysis, "configurations");
|
|
454
|
-
if (value === undefined) {
|
|
455
|
-
return undefined;
|
|
456
|
-
}
|
|
457
|
-
if (!Array.isArray(value)) {
|
|
458
|
-
throw malformed(label, "analysis.configurations", "is not an array");
|
|
459
|
-
}
|
|
460
|
-
return (value as unknown[]).map((entry, index) =>
|
|
461
|
-
readConfiguration(entry, `analysis.configurations[${String(index)}]`, label),
|
|
462
|
-
);
|
|
463
|
-
}
|
|
464
151
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
label: string,
|
|
474
|
-
): TemplateDelimiters | undefined {
|
|
475
|
-
const at = "analysis.template_delimiters";
|
|
476
|
-
const pair = section(analysis, "template_delimiters", at, label);
|
|
477
|
-
if (pair === undefined) {
|
|
478
|
-
return undefined;
|
|
479
|
-
}
|
|
480
|
-
return {
|
|
481
|
-
left: requireMember(readString(pair, "left", `${at}.left`, label), `${at}.left`, label),
|
|
482
|
-
right: requireMember(readString(pair, "right", `${at}.right`, label), `${at}.right`, label),
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* A severity key that names no setting: it names no live kind, or the Contract
|
|
488
|
-
* fixes the severity of the kind or kinds it names.
|
|
489
|
-
*/
|
|
490
|
-
function unimplementedSeverityKey(label: string, path: string, reason: string): ConfigError {
|
|
491
|
-
return new ConfigError(
|
|
492
|
-
"unimplemented-key",
|
|
493
|
-
path,
|
|
494
|
-
`${label}: key ${JSON.stringify(path)} is not implemented: ${reason}`,
|
|
495
|
-
);
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
/**
|
|
499
|
-
* Every code whose severity the Contract fixes that one severity key names, in
|
|
500
|
-
* ascending code order: the code itself, or every code of the family its
|
|
501
|
-
* two-digit prefix names. A family key covers every such code, so a refusal names
|
|
502
|
-
* them all rather than the first one found.
|
|
503
|
-
*/
|
|
504
|
-
function fixedByContract(code: string): string[] {
|
|
505
|
-
return FIXED_SEVERITY_CODES.filter(
|
|
506
|
-
(candidate) =>
|
|
507
|
-
code === candidate || (code.length === FAMILY_KEY_LENGTH && candidate.startsWith(code)),
|
|
508
|
-
).sort();
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
/** The codes a refusal names: one on its own, and several with the last joined by and. */
|
|
512
|
-
function spellCodes(codes: readonly string[]): string {
|
|
513
|
-
if (codes.length < 2) {
|
|
514
|
-
return codes.join("");
|
|
515
|
-
}
|
|
516
|
-
return `${codes.slice(0, -1).join(", ")} and ${String(codes[codes.length - 1])}`;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
/** Whether one severity key names a live kind: the code itself, or a family holding one. */
|
|
520
|
-
function namesLiveKind(code: string): boolean {
|
|
521
|
-
return LIVE_CODES.some(
|
|
522
|
-
(candidate) =>
|
|
523
|
-
code === candidate || (code.length === FAMILY_KEY_LENGTH && candidate.startsWith(code)),
|
|
524
|
-
);
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* The severity object, one code at a time.
|
|
529
|
-
*
|
|
530
|
-
* A key is one issue-kind code or one two-digit family prefix. A key naming no
|
|
531
|
-
* live kind, and a key naming a kind whose severity the Contract fixes or a family
|
|
532
|
-
* prefix whose range holds one, is an unimplemented key rather than a setting.
|
|
533
|
-
*
|
|
534
|
-
* Whether a key names a kind this analyzer reports is not decided here: a live
|
|
535
|
-
* kind of another language is a setting the analyzer of that language reads.
|
|
536
|
-
*/
|
|
537
|
-
function readSeverity(
|
|
538
|
-
document: Record<string, unknown> | undefined,
|
|
539
|
-
label: string,
|
|
540
|
-
): ReadonlyMap<string, Severity> | undefined {
|
|
541
|
-
const object = section(document, SEVERITY_SECTION, SEVERITY_SECTION, label);
|
|
542
|
-
if (object === undefined) {
|
|
543
|
-
return undefined;
|
|
544
|
-
}
|
|
545
|
-
const severity = new Map<string, Severity>();
|
|
546
|
-
for (const code of Object.keys(object).sort()) {
|
|
547
|
-
const path = `${SEVERITY_SECTION}.${code}`;
|
|
548
|
-
if (!SEVERITY_KEY.test(code)) {
|
|
549
|
-
throw unimplementedSeverityKey(
|
|
550
|
-
label,
|
|
551
|
-
path,
|
|
552
|
-
"a severity key is one issue-kind code or one two-digit family prefix",
|
|
553
|
-
);
|
|
554
|
-
}
|
|
555
|
-
if (!namesLiveKind(code)) {
|
|
556
|
-
throw unimplementedSeverityKey(
|
|
557
|
-
label,
|
|
558
|
-
path,
|
|
559
|
-
code.length === FAMILY_KEY_LENGTH
|
|
560
|
-
? "the family this prefix names holds no live issue kind"
|
|
561
|
-
: "the code names no live issue kind",
|
|
562
|
-
);
|
|
563
|
-
}
|
|
564
|
-
const fixed = fixedByContract(code);
|
|
565
|
-
if (fixed.length > 0) {
|
|
566
|
-
throw unimplementedSeverityKey(
|
|
567
|
-
label,
|
|
568
|
-
path,
|
|
569
|
-
`the Contract fixes the severity of ${spellCodes(fixed)}, which this key names`,
|
|
152
|
+
private setting(row: SettingRow, value: unknown): void {
|
|
153
|
+
this.refuse(row.key.split("."), value, firstRefusal(row.value ?? {}, value));
|
|
154
|
+
const text = this.fractions.get(pointerOf(row.key.split(".")));
|
|
155
|
+
if (typeof value === "number" && text !== undefined) {
|
|
156
|
+
throw malformed(
|
|
157
|
+
this.label,
|
|
158
|
+
row.key,
|
|
159
|
+
`holds ${text}, want an integer written as an optional minus sign and digits alone`,
|
|
570
160
|
);
|
|
571
161
|
}
|
|
572
|
-
const
|
|
573
|
-
if (
|
|
574
|
-
|
|
162
|
+
const own = OWN_VOCABULARIES.get(row.key);
|
|
163
|
+
if (own !== undefined) {
|
|
164
|
+
const names = value as readonly string[];
|
|
165
|
+
const unknown = names.findIndex((name) => !own.has(name));
|
|
166
|
+
if (unknown !== -1) {
|
|
167
|
+
throw malformed(
|
|
168
|
+
this.label,
|
|
169
|
+
`${row.key}[${String(unknown)}]`,
|
|
170
|
+
`${JSON.stringify(names[unknown])} names no row this analyzer carries`,
|
|
171
|
+
);
|
|
172
|
+
}
|
|
575
173
|
}
|
|
576
174
|
}
|
|
577
|
-
return severity;
|
|
578
|
-
}
|
|
579
175
|
|
|
580
|
-
/**
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
`${JSON.stringify(entry)} is not an exemption class name`,
|
|
596
|
-
);
|
|
176
|
+
/** A keyed or an ignored section: an object whose member names its key pattern admits. */
|
|
177
|
+
private keyed(row: SettingRow, value: unknown): Readonly<Record<string, unknown>> {
|
|
178
|
+
this.refuse(row.key.split("."), value, firstRefusal(OBJECT, value));
|
|
179
|
+
const members = value as Readonly<Record<string, unknown>>;
|
|
180
|
+
const shape = new RegExp(row.keyPattern ?? "", "u");
|
|
181
|
+
for (const name of Object.keys(members).sort(bytewise)) {
|
|
182
|
+
const at = `${row.key}.${name}`;
|
|
183
|
+
if (!shape.test(name)) {
|
|
184
|
+
throw unimplemented(this.label, at, `the name does not match ${String(row.keyPattern)}`);
|
|
185
|
+
}
|
|
186
|
+
if (row.values !== undefined && !row.values.includes(name)) {
|
|
187
|
+
throw unimplemented(this.label, at, severityKeyRefused(name));
|
|
188
|
+
}
|
|
189
|
+
const member = members[name];
|
|
190
|
+
this.refuse([...row.key.split("."), name], member, firstRefusal(row.value ?? {}, member));
|
|
597
191
|
}
|
|
192
|
+
return members;
|
|
598
193
|
}
|
|
599
|
-
return disabled;
|
|
600
|
-
}
|
|
601
194
|
|
|
602
|
-
/**
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
const SYMBOL_PREFIX = "ts://";
|
|
607
|
-
|
|
608
|
-
/**
|
|
609
|
-
* A bare specifier: neither relative nor absolute, and not one the package's own
|
|
610
|
-
* imports field maps, each of which names a file of the analyzed program.
|
|
611
|
-
*/
|
|
612
|
-
const BARE_SPECIFIER = /^[^./#]/u;
|
|
613
|
-
|
|
614
|
-
/**
|
|
615
|
-
* One declaration entry, read as the one shape its members name. An entry carrying
|
|
616
|
-
* members of two shapes, or of none, is refused at the entry, as is a module named
|
|
617
|
-
* without the declaration's path or a path without its module.
|
|
618
|
-
*/
|
|
619
|
-
function readDeclaration(entry: unknown, at: string, label: string): DeclarationEntry {
|
|
620
|
-
if (!isRecord(entry)) {
|
|
621
|
-
throw malformed(label, at, "is not an object");
|
|
622
|
-
}
|
|
623
|
-
const named = SHAPE_MEMBERS.filter((name) => Object.hasOwn(entry, name));
|
|
624
|
-
if (named.length === 1 && named[0] === "symbol") {
|
|
625
|
-
const symbol = requireMember(
|
|
626
|
-
readString(entry, "symbol", `${at}.symbol`, label),
|
|
627
|
-
`${at}.symbol`,
|
|
628
|
-
label,
|
|
629
|
-
);
|
|
630
|
-
if (!symbol.startsWith(SYMBOL_PREFIX)) {
|
|
631
|
-
throw malformed(label, `${at}.symbol`, `${JSON.stringify(symbol)} is not a ts:// reference`);
|
|
195
|
+
/** Throws the refusal the schema makes of `value`, at `at`, naming the place inside it. */
|
|
196
|
+
private refuse(at: Place, value: unknown, refused: SchemaRefusal | undefined): void {
|
|
197
|
+
if (refused === undefined) {
|
|
198
|
+
return;
|
|
632
199
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
global: requireMember(readString(entry, "global", path, label), path, label),
|
|
640
|
-
};
|
|
641
|
-
}
|
|
642
|
-
if (named.length === 2 && named.includes("module") && named.includes("name")) {
|
|
643
|
-
const module = requireMember(
|
|
644
|
-
readString(entry, "module", `${at}.module`, label),
|
|
645
|
-
`${at}.module`,
|
|
646
|
-
label,
|
|
647
|
-
);
|
|
648
|
-
if (!BARE_SPECIFIER.test(module)) {
|
|
649
|
-
throw malformed(
|
|
650
|
-
label,
|
|
651
|
-
`${at}.module`,
|
|
652
|
-
`${JSON.stringify(module)} is not a bare specifier: a file of the analyzed program is named by its symbol`,
|
|
653
|
-
);
|
|
200
|
+
const place = dotted([...at, ...placeIn(value, refused.pointer, refused.member)]);
|
|
201
|
+
switch (refused.keyword) {
|
|
202
|
+
case "additionalProperties":
|
|
203
|
+
throw unimplemented(this.label, place);
|
|
204
|
+
case "required":
|
|
205
|
+
throw malformed(this.label, place, "is required and absent");
|
|
654
206
|
}
|
|
655
|
-
|
|
656
|
-
return {
|
|
657
|
-
shape: "module",
|
|
658
|
-
module,
|
|
659
|
-
name: requireMember(readString(entry, "name", path, label), path, label),
|
|
660
|
-
};
|
|
207
|
+
throw malformed(this.label, place, refused.reason);
|
|
661
208
|
}
|
|
662
|
-
throw malformed(
|
|
663
|
-
label,
|
|
664
|
-
at,
|
|
665
|
-
named.length === 0
|
|
666
|
-
? 'names no declaration: an entry carries "symbol", "module" with "name", or "global"'
|
|
667
|
-
: `carries ${spell(named)}, which is not one of "symbol", "module" with "name", or "global"`,
|
|
668
|
-
);
|
|
669
209
|
}
|
|
670
210
|
|
|
671
|
-
/** One
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
label: string,
|
|
677
|
-
): readonly DeclarationEntry[] | undefined {
|
|
678
|
-
const value = member(parent, name);
|
|
679
|
-
if (value === undefined) {
|
|
680
|
-
return undefined;
|
|
681
|
-
}
|
|
682
|
-
if (!Array.isArray(value)) {
|
|
683
|
-
throw malformed(label, path, "is not an array");
|
|
684
|
-
}
|
|
685
|
-
return (value as unknown[]).map((entry, index) =>
|
|
686
|
-
readDeclaration(entry, `${path}[${String(index)}]`, label),
|
|
687
|
-
);
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
/**
|
|
691
|
-
* One lifecycle contract. The member names are required, and the entry names at least
|
|
692
|
-
* one component declaration or one base class, because a contract naming neither
|
|
693
|
-
* makes no class a component and so retains nothing.
|
|
694
|
-
*/
|
|
695
|
-
function readLifecycleContract(entry: unknown, at: string, label: string): LifecycleContract {
|
|
696
|
-
if (!isRecord(entry)) {
|
|
697
|
-
throw malformed(label, at, "is not an object");
|
|
698
|
-
}
|
|
699
|
-
const components = readDeclarations(entry, "components", `${at}.components`, label) ?? [];
|
|
700
|
-
const bases = readDeclarations(entry, "bases", `${at}.bases`, label) ?? [];
|
|
701
|
-
const members = readStrings(entry, "members", `${at}.members`, label, 1);
|
|
702
|
-
if (members === undefined) {
|
|
703
|
-
throw malformed(label, `${at}.members`, "is required and names nothing");
|
|
704
|
-
}
|
|
705
|
-
if (components.length === 0 && bases.length === 0) {
|
|
706
|
-
throw malformed(
|
|
707
|
-
label,
|
|
708
|
-
at,
|
|
709
|
-
'names no declaration in "components" and no class in "bases", so it makes no class a component',
|
|
710
|
-
);
|
|
711
|
-
}
|
|
712
|
-
return { components, bases, members };
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
/** The lifecycle contracts, one per framework the project declares. */
|
|
716
|
-
function readLifecycleContracts(
|
|
717
|
-
ts: Record<string, unknown> | undefined,
|
|
718
|
-
label: string,
|
|
719
|
-
): readonly LifecycleContract[] | undefined {
|
|
720
|
-
const path = "ts.lifecycle_contracts";
|
|
721
|
-
const value = member(ts, "lifecycle_contracts");
|
|
722
|
-
if (value === undefined) {
|
|
723
|
-
return undefined;
|
|
724
|
-
}
|
|
725
|
-
if (!Array.isArray(value)) {
|
|
726
|
-
throw malformed(label, path, "is not an array");
|
|
727
|
-
}
|
|
728
|
-
return (value as unknown[]).map((entry, index) =>
|
|
729
|
-
readLifecycleContract(entry, `${path}[${String(index)}]`, label),
|
|
730
|
-
);
|
|
211
|
+
/** One source a resolution reads, with what it supplies. */
|
|
212
|
+
interface Held {
|
|
213
|
+
readonly source: Source;
|
|
214
|
+
readonly label: string;
|
|
215
|
+
readonly supplied: Supplied;
|
|
731
216
|
}
|
|
732
217
|
|
|
733
|
-
|
|
734
|
-
function readMatching(
|
|
735
|
-
entry: Record<string, unknown>,
|
|
736
|
-
name: string,
|
|
737
|
-
at: string,
|
|
738
|
-
label: string,
|
|
739
|
-
pattern: RegExp,
|
|
740
|
-
): string {
|
|
741
|
-
const path = `${at}.${name}`;
|
|
742
|
-
const value = requireMember(readString(entry, name, path, label), path, label);
|
|
743
|
-
if (!pattern.test(value)) {
|
|
744
|
-
throw malformed(label, path, `${JSON.stringify(value)} does not match ${pattern.source}`);
|
|
745
|
-
}
|
|
746
|
-
return value;
|
|
747
|
-
}
|
|
218
|
+
const supplies = (): Supplied => ({ values: new Map(), keyed: new Map() });
|
|
748
219
|
|
|
749
|
-
/**
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
throw malformed(label,
|
|
220
|
+
/** Reads and checks one configuration document. */
|
|
221
|
+
function documentSource(source: Source, document: Document): Held {
|
|
222
|
+
const { text, label } = document;
|
|
223
|
+
refuseOverBound(label, text);
|
|
224
|
+
let read;
|
|
225
|
+
try {
|
|
226
|
+
read = readStrict(text);
|
|
227
|
+
} catch (error: unknown) {
|
|
228
|
+
if (!(error instanceof StrictJSONError)) {
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
throw malformed(label, dotted(error.place), locatedFault(text, error));
|
|
761
232
|
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
readString(entry, "command", commandPath, label),
|
|
765
|
-
commandPath,
|
|
766
|
-
label,
|
|
767
|
-
);
|
|
768
|
-
if (!ACQUIRABLE_MEMBERS.some((member) => Object.hasOwn(entry, member))) {
|
|
769
|
-
return { shape: "installed", name, languages, command };
|
|
233
|
+
if (!isRecord(read.value)) {
|
|
234
|
+
throw malformed(label, "", "is not one JSON object");
|
|
770
235
|
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
languages,
|
|
775
|
-
command,
|
|
776
|
-
source: readMatching(entry, "source", at, label, PROVIDER_SOURCE),
|
|
777
|
-
version: readMatching(entry, "version", at, label, PROVIDER_VERSION),
|
|
778
|
-
digest: readMatching(entry, "digest", at, label, PROVIDER_DIGEST),
|
|
779
|
-
};
|
|
236
|
+
const supplied = supplies();
|
|
237
|
+
new Walk(label, read.fractions, supplied).section("", read.value);
|
|
238
|
+
return { source, label, supplied };
|
|
780
239
|
}
|
|
781
240
|
|
|
782
|
-
/**
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
const path = "providers.analyzers";
|
|
791
|
-
const value = member(providers, "analyzers");
|
|
792
|
-
if (value === undefined) {
|
|
793
|
-
return undefined;
|
|
794
|
-
}
|
|
795
|
-
if (!Array.isArray(value)) {
|
|
796
|
-
throw malformed(label, path, "is not an array");
|
|
797
|
-
}
|
|
798
|
-
const read = (value as unknown[]).map((entry, index) =>
|
|
799
|
-
readProvider(entry, `${path}[${String(index)}]`, label),
|
|
800
|
-
);
|
|
801
|
-
const first = new Map<string, number>();
|
|
802
|
-
read.forEach((entry, index) => {
|
|
803
|
-
const earlier = first.get(entry.name);
|
|
804
|
-
if (earlier !== undefined) {
|
|
805
|
-
throw malformed(
|
|
806
|
-
label,
|
|
807
|
-
`${path}[${String(index)}].name`,
|
|
808
|
-
`${JSON.stringify(entry.name)} is already the name of ${path}[${String(earlier)}], ` +
|
|
809
|
-
"and every entry's name keys the files a run writes for it",
|
|
810
|
-
);
|
|
241
|
+
/** The command line as a source: each flag checked as the one-setting document it supplies. */
|
|
242
|
+
function flagSource(flags: ReadonlyMap<string, string>): Held {
|
|
243
|
+
const supplied = supplies();
|
|
244
|
+
for (const key of [...flags.keys()].sort(bytewise)) {
|
|
245
|
+
const row = ROWS.get(key);
|
|
246
|
+
const text = flags.get(key) ?? "";
|
|
247
|
+
if (row?.option === undefined) {
|
|
248
|
+
throw unimplemented("the command line", key, "no flag supplies it");
|
|
811
249
|
}
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
* express: a value of the wrong type, a value outside a closed set, an array that
|
|
821
|
-
* repeats an entry or holds too few, and a count below its minimum.
|
|
822
|
-
*/
|
|
823
|
-
function readDoc(value: unknown, label: string): Doc {
|
|
824
|
-
if (!isRecord(value)) {
|
|
825
|
-
throw malformed(label, "", "is not one JSON object");
|
|
826
|
-
}
|
|
827
|
-
const analysis = section(value, "analysis", "analysis", label);
|
|
828
|
-
const matrix = section(analysis, "matrix", "analysis.matrix", label);
|
|
829
|
-
const target = section(value, "target", "target", label);
|
|
830
|
-
const consumers = section(value, "consumers", "consumers", label);
|
|
831
|
-
const roots = section(value, "roots", "roots", label);
|
|
832
|
-
const reporters = section(value, "reporters", "reporters", label);
|
|
833
|
-
const providers = section(value, "providers", "providers", label);
|
|
834
|
-
const ts = section(value, "ts", "ts", label);
|
|
835
|
-
section(value, "go", "go", label);
|
|
836
|
-
section(value, "provenance", "provenance", label);
|
|
837
|
-
|
|
838
|
-
const contractVersion = readString(value, "contract_version", "contract_version", label);
|
|
839
|
-
if (contractVersion !== undefined && !CONTRACT_VERSION_PATTERN.test(contractVersion)) {
|
|
840
|
-
throw malformed(
|
|
841
|
-
label,
|
|
842
|
-
"contract_version",
|
|
843
|
-
`${JSON.stringify(contractVersion)} is not a semantic version`,
|
|
250
|
+
const integer = row.value?.["type"] === "integer" && /^-?[0-9]+$/u.test(text);
|
|
251
|
+
let document: unknown = integer ? Number(text) : text;
|
|
252
|
+
for (const name of key.split(".").reverse()) {
|
|
253
|
+
document = { [name]: document };
|
|
254
|
+
}
|
|
255
|
+
new Walk(`--${row.option}`, new Map(), supplied).section(
|
|
256
|
+
"",
|
|
257
|
+
document as Record<string, unknown>,
|
|
844
258
|
);
|
|
845
259
|
}
|
|
846
|
-
|
|
847
|
-
return {
|
|
848
|
-
contractVersion,
|
|
849
|
-
targetKind: readTargetKind(target, label),
|
|
850
|
-
languages: readStrings(analysis, "languages", "analysis.languages", label, 0, LANGUAGES),
|
|
851
|
-
minConfidence: readEnum(
|
|
852
|
-
analysis,
|
|
853
|
-
"min_confidence",
|
|
854
|
-
"analysis.min_confidence",
|
|
855
|
-
label,
|
|
856
|
-
CONFIDENCES,
|
|
857
|
-
),
|
|
858
|
-
generatedFiles: readEnum(
|
|
859
|
-
analysis,
|
|
860
|
-
"generated_files",
|
|
861
|
-
"analysis.generated_files",
|
|
862
|
-
label,
|
|
863
|
-
GENERATED_FILES,
|
|
864
|
-
),
|
|
865
|
-
consumerTests: readEnum(
|
|
866
|
-
analysis,
|
|
867
|
-
"consumer_tests",
|
|
868
|
-
"analysis.consumer_tests",
|
|
869
|
-
label,
|
|
870
|
-
CONSUMER_TESTS,
|
|
871
|
-
),
|
|
872
|
-
configurations: readConfigurations(analysis, label),
|
|
873
|
-
matrixComplete: readBoolean(matrix, "complete", "analysis.matrix.complete", label),
|
|
874
|
-
templateDirs: readStrings(analysis, "template_dirs", "analysis.template_dirs", label, 0),
|
|
875
|
-
templateDelimiters: readDelimiters(analysis, label),
|
|
876
|
-
consumersComplete: readBoolean(consumers, "complete", "consumers.complete", label),
|
|
877
|
-
rootPatterns: readStrings(roots, "patterns", "roots.patterns", label, 0),
|
|
878
|
-
severity: readSeverity(value, label),
|
|
879
|
-
exemptionsDisabled: readExemptions(value, label),
|
|
880
|
-
formats: readStrings(reporters, "formats", "reporters.formats", label, 1, FORMATS),
|
|
881
|
-
sort: readEnum(reporters, "sort", "reporters.sort", label, SORTS),
|
|
882
|
-
cascade: readEnum(reporters, "cascade", "reporters.cascade", label, CASCADES),
|
|
883
|
-
maxFindings: readCount(reporters, "max_findings", "reporters.max_findings", label),
|
|
884
|
-
failOn: readEnum(reporters, "fail_on", "reporters.fail_on", label, SEVERITIES),
|
|
885
|
-
providers: readProviders(providers, label),
|
|
886
|
-
testFiles: readStrings(ts, "test_files", "ts.test_files", label, 1),
|
|
887
|
-
entryFiles: readStrings(ts, "entry_files", "ts.entry_files", label, 0),
|
|
888
|
-
componentExtensions: readComponentExtensions(ts, label),
|
|
889
|
-
disabledConventions: readDisabledConventions(ts, label),
|
|
890
|
-
injectionRegistrations: readDeclarations(
|
|
891
|
-
ts,
|
|
892
|
-
"injection_registrations",
|
|
893
|
-
"ts.injection_registrations",
|
|
894
|
-
label,
|
|
895
|
-
),
|
|
896
|
-
lifecycleContracts: readLifecycleContracts(ts, label),
|
|
897
|
-
serializers: readDeclarations(ts, "serializers", "ts.serializers", label),
|
|
898
|
-
rootsComplete: readBoolean(ts, "roots_complete", "ts.roots_complete", label),
|
|
899
|
-
};
|
|
260
|
+
return { source: "flag", label: "", supplied };
|
|
900
261
|
}
|
|
901
262
|
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
try {
|
|
906
|
-
value = JSON.parse(text);
|
|
907
|
-
} catch (error: unknown) {
|
|
908
|
-
throw malformed(label, "", error instanceof Error ? error.message : String(error));
|
|
909
|
-
}
|
|
910
|
-
checkDocument(text, node, label);
|
|
911
|
-
return value;
|
|
263
|
+
function originOf(held: Held, key: string): Origin {
|
|
264
|
+
const label = held.source === "flag" ? `--${String(ROWS.get(key)?.option)}` : held.label;
|
|
265
|
+
return { source: held.source, label };
|
|
912
266
|
}
|
|
913
267
|
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
return label === undefined || label === "" ? named : label;
|
|
268
|
+
function searched(named: string, document: Document | undefined): string {
|
|
269
|
+
return `${named} (${document === undefined ? "not present" : document.label})`;
|
|
917
270
|
}
|
|
918
271
|
|
|
919
|
-
/**
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
const flagLabels = inputs.flagLabels ?? new Map<string, string>();
|
|
926
|
-
if (inputs.flags !== undefined) {
|
|
927
|
-
const flat = parseDocument(inputs.flags, { kind: "map" }, FLAGS_LABEL);
|
|
928
|
-
if (!isRecord(flat)) {
|
|
929
|
-
throw malformed(FLAGS_LABEL, "", "is not one JSON object");
|
|
930
|
-
}
|
|
931
|
-
sources.push({
|
|
932
|
-
doc: readDoc(nestFlags(flat, FLAGS_LABEL), FLAGS_LABEL),
|
|
933
|
-
kind: "flag",
|
|
934
|
-
label: "",
|
|
935
|
-
flagLabels,
|
|
936
|
-
});
|
|
272
|
+
/** Sets the value at one dotted key of the resolved tree, whose sections the table lists first. */
|
|
273
|
+
function setAt(tree: Record<string, unknown>, key: string, value: unknown): void {
|
|
274
|
+
const names = key.split(".");
|
|
275
|
+
let into = tree;
|
|
276
|
+
for (const name of names.slice(0, -1)) {
|
|
277
|
+
into = into[name] as Record<string, unknown>;
|
|
937
278
|
}
|
|
938
|
-
|
|
939
|
-
{
|
|
940
|
-
kind: "repository",
|
|
941
|
-
named: "the repository configuration",
|
|
942
|
-
...(inputs.repository === undefined ? {} : { text: inputs.repository }),
|
|
943
|
-
...(inputs.repositoryLabel === undefined ? {} : { label: inputs.repositoryLabel }),
|
|
944
|
-
},
|
|
945
|
-
{
|
|
946
|
-
kind: "central",
|
|
947
|
-
named: "the central configuration",
|
|
948
|
-
...(inputs.central === undefined ? {} : { text: inputs.central }),
|
|
949
|
-
...(inputs.centralLabel === undefined ? {} : { label: inputs.centralLabel }),
|
|
950
|
-
},
|
|
951
|
-
];
|
|
952
|
-
for (const entry of held) {
|
|
953
|
-
if (entry.text === undefined) {
|
|
954
|
-
continue;
|
|
955
|
-
}
|
|
956
|
-
const label = labelOr(entry.label, entry.named);
|
|
957
|
-
sources.push({
|
|
958
|
-
doc: readDoc(parseDocument(entry.text, SCHEMA_ROOT, label), label),
|
|
959
|
-
kind: entry.kind,
|
|
960
|
-
label: entry.label ?? "",
|
|
961
|
-
flagLabels,
|
|
962
|
-
});
|
|
963
|
-
}
|
|
964
|
-
return sources;
|
|
279
|
+
into[names.at(-1) ?? key] = value;
|
|
965
280
|
}
|
|
966
281
|
|
|
967
282
|
/**
|
|
968
|
-
*
|
|
969
|
-
*
|
|
283
|
+
* Every setting this analyzer reads, each from the highest-ranked source carrying it,
|
|
284
|
+
* else its default, in the closed key list's order. A setting with no default no
|
|
285
|
+
* source supplies is refused where its row is required and `enforce` holds, and left
|
|
286
|
+
* unset otherwise. A keyed section's members overlay its default's, member by member.
|
|
970
287
|
*/
|
|
971
|
-
function settle
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
sources:
|
|
976
|
-
|
|
977
|
-
)
|
|
978
|
-
for (const source of sources) {
|
|
979
|
-
const value = read(source.doc);
|
|
980
|
-
if (value !== undefined) {
|
|
981
|
-
provenance.set(path, originOf(source, path));
|
|
982
|
-
return value;
|
|
983
|
-
}
|
|
288
|
+
function settle(
|
|
289
|
+
inputs: Inputs,
|
|
290
|
+
enforce: boolean,
|
|
291
|
+
): { config: PartialConfig; provenance: Provenance } {
|
|
292
|
+
const sources: Held[] = [];
|
|
293
|
+
if (inputs.flags !== undefined && inputs.flags.size > 0) {
|
|
294
|
+
sources.push(flagSource(inputs.flags));
|
|
984
295
|
}
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
}
|
|
988
|
-
|
|
989
|
-
/**
|
|
990
|
-
* The severity object, resolved one code at a time so a code only the central
|
|
991
|
-
* configuration names keeps its central value. An object that resolves empty
|
|
992
|
-
* carries one entry for the object itself.
|
|
993
|
-
*/
|
|
994
|
-
function settleSeverity(
|
|
995
|
-
provenance: Map<string, Origin>,
|
|
996
|
-
sources: readonly DocSource[],
|
|
997
|
-
): ReadonlyMap<string, Severity> {
|
|
998
|
-
const codes = new Set<string>();
|
|
999
|
-
for (const source of sources) {
|
|
1000
|
-
for (const code of source.doc.severity?.keys() ?? []) {
|
|
1001
|
-
codes.add(code);
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
const severity = new Map<string, Severity>();
|
|
1005
|
-
for (const code of [...codes].sort()) {
|
|
1006
|
-
const path = `${SEVERITY_SECTION}.${code}`;
|
|
1007
|
-
for (const source of sources) {
|
|
1008
|
-
const value = source.doc.severity?.get(code);
|
|
1009
|
-
if (value === undefined) {
|
|
1010
|
-
continue;
|
|
1011
|
-
}
|
|
1012
|
-
severity.set(code, value);
|
|
1013
|
-
provenance.set(path, originOf(source, path));
|
|
1014
|
-
break;
|
|
1015
|
-
}
|
|
296
|
+
if (inputs.repository !== undefined) {
|
|
297
|
+
sources.push(documentSource("repository", inputs.repository));
|
|
1016
298
|
}
|
|
1017
|
-
if (
|
|
1018
|
-
|
|
299
|
+
if (inputs.central !== undefined) {
|
|
300
|
+
sources.push(documentSource("central", inputs.central));
|
|
1019
301
|
}
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
302
|
+
const tree: Record<string, unknown> = {};
|
|
303
|
+
const provenance = new Map<string, Origin>();
|
|
304
|
+
for (const row of SETTINGS) {
|
|
305
|
+
if (!row.read || row.role === "ignored") {
|
|
306
|
+
continue;
|
|
1025
307
|
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
)
|
|
308
|
+
if (row.role === "section") {
|
|
309
|
+
setAt(tree, row.key, {});
|
|
310
|
+
} else if (row.role === "keyed") {
|
|
311
|
+
const members: Record<string, unknown> = isRecord(row.default) ? { ...row.default } : {};
|
|
312
|
+
provenance.set(row.key, { source: "default", label: "" });
|
|
313
|
+
for (const name of Object.keys(members)) {
|
|
314
|
+
provenance.set(`${row.key}.${name}`, { source: "default", label: "" });
|
|
315
|
+
}
|
|
316
|
+
for (const held of sources.toReversed()) {
|
|
317
|
+
const named = held.supplied.keyed.get(row.key);
|
|
318
|
+
if (named === undefined) {
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
provenance.set(row.key, originOf(held, row.key));
|
|
322
|
+
for (const [name, value] of Object.entries(named)) {
|
|
323
|
+
members[name] = value;
|
|
324
|
+
provenance.set(`${row.key}.${name}`, originOf(held, row.key));
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (Object.keys(members).length > 0) {
|
|
328
|
+
provenance.delete(row.key);
|
|
329
|
+
}
|
|
330
|
+
setAt(tree, row.key, canonical(members));
|
|
331
|
+
} else {
|
|
332
|
+
const held = sources.find((one) => one.supplied.values.has(row.key));
|
|
333
|
+
if (held !== undefined) {
|
|
334
|
+
setAt(tree, row.key, held.supplied.values.get(row.key));
|
|
335
|
+
provenance.set(row.key, originOf(held, row.key));
|
|
336
|
+
} else if (row.default !== undefined) {
|
|
337
|
+
setAt(tree, row.key, canonical(row.default));
|
|
338
|
+
provenance.set(row.key, { source: "default", label: "" });
|
|
339
|
+
} else if (enforce && row.required === true) {
|
|
340
|
+
throw new UsageError(
|
|
341
|
+
`${row.key} is not set, it has no default and is never inferred: searched ` +
|
|
342
|
+
`${searched("the repository configuration", inputs.repository)} and ` +
|
|
343
|
+
searched("the central configuration", inputs.central),
|
|
344
|
+
);
|
|
345
|
+
}
|
|
1055
346
|
}
|
|
1056
347
|
}
|
|
348
|
+
// gen-config.ts marks a member optional exactly where this loop may leave it unset.
|
|
349
|
+
return { config: tree as unknown as PartialConfig, provenance };
|
|
1057
350
|
}
|
|
1058
351
|
|
|
1059
352
|
/**
|
|
1060
|
-
* Applies
|
|
353
|
+
* Applies the command-line flags over the repository configuration over the central
|
|
1061
354
|
* configuration over the default each key declares, and returns the resolved
|
|
1062
|
-
* configuration with the origin of every setting
|
|
1063
|
-
*
|
|
1064
|
-
*
|
|
1065
|
-
* list does not declare, a document that names one key twice, and a resolved
|
|
1066
|
-
* configuration no source supplied a target kind for. Every one of them maps to
|
|
1067
|
-
* the usage exit code.
|
|
1068
|
-
*/
|
|
1069
|
-
export function resolve(inputs: Inputs): { config: Config; provenance: Provenance } {
|
|
1070
|
-
const { config, provenance } = settleAll(inputs);
|
|
1071
|
-
if (config.targetKind === "") {
|
|
1072
|
-
throw new ConfigError(
|
|
1073
|
-
"missing-target-kind",
|
|
1074
|
-
"target.kind",
|
|
1075
|
-
"target.kind is not set, it has no default and is never inferred: searched " +
|
|
1076
|
-
`${describeSource("the repository configuration", inputs.repository, inputs.repositoryLabel)} and ` +
|
|
1077
|
-
describeSource("the central configuration", inputs.central, inputs.centralLabel),
|
|
1078
|
-
);
|
|
1079
|
-
}
|
|
1080
|
-
checkLabels(provenance);
|
|
1081
|
-
return { config, provenance };
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
/**
|
|
1085
|
-
* The configuration the documents resolve to, every document read and refused as
|
|
1086
|
-
* {@link resolve} refuses it, with no target kind required of them: which projects a
|
|
1087
|
-
* run analyzes does not depend on the kind, so a question about the projects asks
|
|
1088
|
-
* none. The kind is empty where no document names one.
|
|
355
|
+
* configuration with the origin of every setting: its keys in the closed key list's
|
|
356
|
+
* order, every object's members inside a value ascending. Every refusal is a
|
|
357
|
+
* {@link UsageError}.
|
|
1089
358
|
*/
|
|
1090
|
-
export function
|
|
1091
|
-
|
|
359
|
+
export function resolve(inputs: Inputs): { config: ResolvedConfig; provenance: Provenance } {
|
|
360
|
+
const { config, provenance } = settle(inputs, true);
|
|
361
|
+
return { config: config as ResolvedConfig, provenance };
|
|
1092
362
|
}
|
|
1093
363
|
|
|
1094
364
|
/**
|
|
1095
|
-
*
|
|
1096
|
-
*
|
|
365
|
+
* The configuration the sources resolve to, refused as {@link resolve} refuses it but
|
|
366
|
+
* with no target kind required: which projects a run analyzes asks none.
|
|
1097
367
|
*/
|
|
1098
|
-
function
|
|
1099
|
-
|
|
1100
|
-
const defaults = defaultConfig();
|
|
1101
|
-
const provenance = new Map<string, Origin>();
|
|
1102
|
-
const at = <T>(path: string, fallback: T, read: (doc: Doc) => T | undefined): T =>
|
|
1103
|
-
settle(fallback, path, provenance, sources, read);
|
|
1104
|
-
|
|
1105
|
-
const config: Config = {
|
|
1106
|
-
contractVersion: at("contract_version", defaults.contractVersion, (doc) => doc.contractVersion),
|
|
1107
|
-
targetKind: at<TargetKindSetting | "">("target.kind", "", (doc) => doc.targetKind),
|
|
1108
|
-
analysis: {
|
|
1109
|
-
languages: at("analysis.languages", defaults.analysis.languages, (doc) => doc.languages),
|
|
1110
|
-
minConfidence: at(
|
|
1111
|
-
"analysis.min_confidence",
|
|
1112
|
-
defaults.analysis.minConfidence,
|
|
1113
|
-
(doc) => doc.minConfidence,
|
|
1114
|
-
),
|
|
1115
|
-
generatedFiles: at(
|
|
1116
|
-
"analysis.generated_files",
|
|
1117
|
-
defaults.analysis.generatedFiles,
|
|
1118
|
-
(doc) => doc.generatedFiles,
|
|
1119
|
-
),
|
|
1120
|
-
consumerTests: at(
|
|
1121
|
-
"analysis.consumer_tests",
|
|
1122
|
-
defaults.analysis.consumerTests,
|
|
1123
|
-
(doc) => doc.consumerTests,
|
|
1124
|
-
),
|
|
1125
|
-
configurations: at(
|
|
1126
|
-
"analysis.configurations",
|
|
1127
|
-
defaults.analysis.configurations,
|
|
1128
|
-
(doc) => doc.configurations,
|
|
1129
|
-
),
|
|
1130
|
-
matrixComplete: at(
|
|
1131
|
-
"analysis.matrix.complete",
|
|
1132
|
-
defaults.analysis.matrixComplete,
|
|
1133
|
-
(doc) => doc.matrixComplete,
|
|
1134
|
-
),
|
|
1135
|
-
templateDirs: at(
|
|
1136
|
-
"analysis.template_dirs",
|
|
1137
|
-
defaults.analysis.templateDirs,
|
|
1138
|
-
(doc) => doc.templateDirs,
|
|
1139
|
-
),
|
|
1140
|
-
templateDelimiters: at(
|
|
1141
|
-
"analysis.template_delimiters",
|
|
1142
|
-
defaults.analysis.templateDelimiters,
|
|
1143
|
-
(doc) => doc.templateDelimiters,
|
|
1144
|
-
),
|
|
1145
|
-
},
|
|
1146
|
-
consumersComplete: at(
|
|
1147
|
-
"consumers.complete",
|
|
1148
|
-
defaults.consumersComplete,
|
|
1149
|
-
(doc) => doc.consumersComplete,
|
|
1150
|
-
),
|
|
1151
|
-
rootPatterns: at("roots.patterns", defaults.rootPatterns, (doc) => doc.rootPatterns),
|
|
1152
|
-
severity: settleSeverity(provenance, sources),
|
|
1153
|
-
exemptionsDisabled: at(
|
|
1154
|
-
"exemptions.disabled",
|
|
1155
|
-
defaults.exemptionsDisabled,
|
|
1156
|
-
(doc) => doc.exemptionsDisabled,
|
|
1157
|
-
),
|
|
1158
|
-
reporters: {
|
|
1159
|
-
formats: at("reporters.formats", defaults.reporters.formats, (doc) => doc.formats),
|
|
1160
|
-
sort: at("reporters.sort", defaults.reporters.sort, (doc) => doc.sort),
|
|
1161
|
-
cascade: at("reporters.cascade", defaults.reporters.cascade, (doc) => doc.cascade),
|
|
1162
|
-
maxFindings: at(
|
|
1163
|
-
"reporters.max_findings",
|
|
1164
|
-
defaults.reporters.maxFindings,
|
|
1165
|
-
(doc) => doc.maxFindings,
|
|
1166
|
-
),
|
|
1167
|
-
failOn: at("reporters.fail_on", defaults.reporters.failOn, (doc) => doc.failOn),
|
|
1168
|
-
},
|
|
1169
|
-
providers: {
|
|
1170
|
-
analyzers: at("providers.analyzers", defaults.providers.analyzers, (doc) => doc.providers),
|
|
1171
|
-
},
|
|
1172
|
-
ts: {
|
|
1173
|
-
testFiles: at("ts.test_files", defaults.ts.testFiles, (doc) => doc.testFiles),
|
|
1174
|
-
entryFiles: at("ts.entry_files", defaults.ts.entryFiles, (doc) => doc.entryFiles),
|
|
1175
|
-
componentExtensions: at(
|
|
1176
|
-
"ts.component_extensions",
|
|
1177
|
-
defaults.ts.componentExtensions,
|
|
1178
|
-
(doc) => doc.componentExtensions,
|
|
1179
|
-
),
|
|
1180
|
-
disabledConventions: at(
|
|
1181
|
-
"ts.disabled_conventions",
|
|
1182
|
-
defaults.ts.disabledConventions,
|
|
1183
|
-
(doc) => doc.disabledConventions,
|
|
1184
|
-
),
|
|
1185
|
-
injectionRegistrations: at(
|
|
1186
|
-
"ts.injection_registrations",
|
|
1187
|
-
defaults.ts.injectionRegistrations,
|
|
1188
|
-
(doc) => doc.injectionRegistrations,
|
|
1189
|
-
),
|
|
1190
|
-
lifecycleContracts: at(
|
|
1191
|
-
"ts.lifecycle_contracts",
|
|
1192
|
-
defaults.ts.lifecycleContracts,
|
|
1193
|
-
(doc) => doc.lifecycleContracts,
|
|
1194
|
-
),
|
|
1195
|
-
serializers: at("ts.serializers", defaults.ts.serializers, (doc) => doc.serializers),
|
|
1196
|
-
rootsComplete: at("ts.roots_complete", defaults.ts.rootsComplete, (doc) => doc.rootsComplete),
|
|
1197
|
-
},
|
|
1198
|
-
};
|
|
1199
|
-
|
|
1200
|
-
return { config, provenance };
|
|
368
|
+
export function resolvePartial(inputs: Inputs): PartialConfig {
|
|
369
|
+
return settle(inputs, false).config;
|
|
1201
370
|
}
|