@conformetry/languages 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +941 -0
- package/dist/src/index.d.ts +977 -0
- package/dist/src/index.js +1184 -0
- package/package.json +69 -0
|
@@ -0,0 +1,1184 @@
|
|
|
1
|
+
import { Injectable as e, Module as t } from "@nestjs/common";
|
|
2
|
+
import { ConfigurationModule as n, ConfigurationService as r } from "@conformetry/configuration";
|
|
3
|
+
import i from "node:fs";
|
|
4
|
+
import a from "node:path";
|
|
5
|
+
import { parse as o } from "jsonc-parser";
|
|
6
|
+
import { toString as s } from "mdast-util-to-string";
|
|
7
|
+
import { remark as c } from "remark";
|
|
8
|
+
import l from "remark-gfm";
|
|
9
|
+
import { spawnSync as ee } from "node:child_process";
|
|
10
|
+
import { fileURLToPath as te } from "node:url";
|
|
11
|
+
import { ScriptKind as u, ScriptTarget as ne, SyntaxKind as d, createSourceFile as re, forEachChild as ie, getLeadingCommentRanges as ae, isBigIntLiteral as f, isCallExpression as p, isDecorator as m, isExportDeclaration as oe, isExpressionStatement as se, isIdentifier as h, isImportDeclaration as ce, isNoSubstitutionTemplateLiteral as le, isNumericLiteral as g, isPrivateIdentifier as ue, isPropertyAccessExpression as de, isStringLiteral as _ } from "typescript";
|
|
12
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/differences/differences.constants.ts
|
|
13
|
+
var fe = [
|
|
14
|
+
"javascript",
|
|
15
|
+
"json",
|
|
16
|
+
"markdown",
|
|
17
|
+
"python",
|
|
18
|
+
"text",
|
|
19
|
+
"typescript"
|
|
20
|
+
], v = [
|
|
21
|
+
"code",
|
|
22
|
+
"comment",
|
|
23
|
+
"directory",
|
|
24
|
+
"file",
|
|
25
|
+
"instance"
|
|
26
|
+
];
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/decorateMetadata.js
|
|
29
|
+
function y(e, t) {
|
|
30
|
+
if (typeof Reflect == "object" && typeof Reflect.metadata == "function") return Reflect.metadata(e, t);
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/decorate.js
|
|
34
|
+
function b(e, t, n, r) {
|
|
35
|
+
var i = arguments.length, a = i < 3 ? t : r === null ? r = Object.getOwnPropertyDescriptor(t, n) : r, o;
|
|
36
|
+
if (typeof Reflect == "object" && typeof Reflect.decorate == "function") a = Reflect.decorate(e, t, n, r);
|
|
37
|
+
else for (var s = e.length - 1; s >= 0; s--) (o = e[s]) && (a = (i < 3 ? o(a) : i > 3 ? o(t, n, a) : o(t, n)) || a);
|
|
38
|
+
return i > 3 && a && Object.defineProperty(t, n, a), a;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/differences/differences.service.ts
|
|
42
|
+
var x = class {
|
|
43
|
+
constructor() {}
|
|
44
|
+
buildMissingDirectoryDifference(e) {
|
|
45
|
+
return {
|
|
46
|
+
differenceType: "directory",
|
|
47
|
+
fix: `Create the directory ${e.instanceDirectoryPath} to match the template at ${e.templateDirectoryPath}.`,
|
|
48
|
+
message: `Missing directory: ${e.instanceDirectoryPath}`
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
buildMissingFileDifference(e) {
|
|
52
|
+
return {
|
|
53
|
+
differenceType: "file",
|
|
54
|
+
fix: `Create the file using the generator, or manually from the template at ${e.templateFilePath}.`,
|
|
55
|
+
message: `Missing file: ${e.instanceFilePath}`
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
resolveDifferenceType(e) {
|
|
59
|
+
return v.find((t) => t === e) ?? "code";
|
|
60
|
+
}
|
|
61
|
+
resolveErrorLanguage(e) {
|
|
62
|
+
return fe.find((t) => t === e);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
x = b([e(), y("design:paramtypes", [])], x);
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/differences/differences.module.ts
|
|
68
|
+
var S = class {};
|
|
69
|
+
S = b([t({
|
|
70
|
+
controllers: [],
|
|
71
|
+
exports: [x],
|
|
72
|
+
imports: [],
|
|
73
|
+
providers: [x]
|
|
74
|
+
})], S);
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/files/files.service.ts
|
|
77
|
+
var C = class {
|
|
78
|
+
configurationService;
|
|
79
|
+
errorsService;
|
|
80
|
+
constructor(e, t) {
|
|
81
|
+
this.configurationService = e, this.errorsService = t;
|
|
82
|
+
}
|
|
83
|
+
buildMissingDifference(e) {
|
|
84
|
+
let t = a.dirname(e.instanceFilePath);
|
|
85
|
+
return i.existsSync(t) ? {
|
|
86
|
+
...this.errorsService.buildMissingFileDifference(e),
|
|
87
|
+
weight: 1
|
|
88
|
+
} : {
|
|
89
|
+
...this.errorsService.buildMissingDirectoryDifference({
|
|
90
|
+
instanceDirectoryPath: t,
|
|
91
|
+
templateDirectoryPath: a.dirname(e.templateFilePath)
|
|
92
|
+
}),
|
|
93
|
+
weight: e.expectedFileCount
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
countExpectedFiles(e) {
|
|
97
|
+
return e.expectedFiles.filter((t) => a.dirname(t.instanceFilePath) === e.parentDirectoryPath).length;
|
|
98
|
+
}
|
|
99
|
+
checkInstanceFiles(e) {
|
|
100
|
+
let t = this.configurationService.resolveInstanceFiles(e.instances), n = /* @__PURE__ */ new Set(), r = [];
|
|
101
|
+
for (let e of t) {
|
|
102
|
+
if (i.existsSync(e.instanceFilePath)) continue;
|
|
103
|
+
let o = a.dirname(e.instanceFilePath);
|
|
104
|
+
if (n.has(o)) continue;
|
|
105
|
+
let s = this.buildMissingDifference({
|
|
106
|
+
expectedFileCount: this.countExpectedFiles({
|
|
107
|
+
expectedFiles: t,
|
|
108
|
+
parentDirectoryPath: o
|
|
109
|
+
}),
|
|
110
|
+
...e
|
|
111
|
+
});
|
|
112
|
+
s.differenceType === "directory" && n.add(o), r.push({
|
|
113
|
+
differences: [s],
|
|
114
|
+
filename: a.basename(e.instanceFilePath),
|
|
115
|
+
instanceFilePath: e.instanceFilePath,
|
|
116
|
+
templateFilePath: e.templateFilePath,
|
|
117
|
+
totalWeight: s.weight
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
fileResults: r,
|
|
122
|
+
totalWeight: t.length
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
C = b([e(), y("design:paramtypes", [r === void 0 ? Object : r, x === void 0 ? Object : x])], C);
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/files/files.module.ts
|
|
129
|
+
var w = class {};
|
|
130
|
+
w = b([t({
|
|
131
|
+
controllers: [],
|
|
132
|
+
exports: [C],
|
|
133
|
+
imports: [n, S],
|
|
134
|
+
providers: [C]
|
|
135
|
+
})], w);
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/scoring/scoring.constants.ts
|
|
138
|
+
var T = 1, E = 1, pe = 1, D = class {
|
|
139
|
+
constructor() {}
|
|
140
|
+
calculateScore(e) {
|
|
141
|
+
if (e.totalWeight <= 0) return 1;
|
|
142
|
+
let t = (e.totalWeight - e.failedWeight) / e.totalWeight;
|
|
143
|
+
return Math.min(1, Math.max(0, t));
|
|
144
|
+
}
|
|
145
|
+
sumWeights(e) {
|
|
146
|
+
return e.reduce((e, t) => e + (t.weight ?? 1), 0);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
D = b([e(), y("design:paramtypes", [])], D);
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/json/json-comparison.service.ts
|
|
152
|
+
var O = class {
|
|
153
|
+
scoringService;
|
|
154
|
+
constructor(e) {
|
|
155
|
+
this.scoringService = e;
|
|
156
|
+
}
|
|
157
|
+
buildError(e) {
|
|
158
|
+
return {
|
|
159
|
+
...e.actual === void 0 ? {} : { actual: e.actual },
|
|
160
|
+
differenceType: "code",
|
|
161
|
+
...e.expected === void 0 ? {} : { expected: e.expected },
|
|
162
|
+
fix: e.fix,
|
|
163
|
+
instancePath: e.pathValue,
|
|
164
|
+
language: e.language,
|
|
165
|
+
message: e.message,
|
|
166
|
+
templatePath: e.pathValue,
|
|
167
|
+
weight: e.weight
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
combine(e) {
|
|
171
|
+
return e.reduce((e, t) => ({
|
|
172
|
+
differences: [...e.differences, ...t.differences],
|
|
173
|
+
totalWeight: e.totalWeight + t.totalWeight
|
|
174
|
+
}), {
|
|
175
|
+
differences: [],
|
|
176
|
+
totalWeight: 0
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
compareArrayItem(e) {
|
|
180
|
+
let t = this.formatPath(e.pathSegments), n = this.countNodes(e.templateItem);
|
|
181
|
+
return this.isJsonPrimitive(e.templateItem) ? e.instanceArray.includes(e.templateItem) ? {
|
|
182
|
+
differences: [],
|
|
183
|
+
totalWeight: n
|
|
184
|
+
} : {
|
|
185
|
+
differences: [this.buildError({
|
|
186
|
+
expected: JSON.stringify(e.templateItem),
|
|
187
|
+
fix: `Add ${JSON.stringify(e.templateItem)} to the array at "${t}".`,
|
|
188
|
+
language: e.language,
|
|
189
|
+
message: `Missing required array value ${JSON.stringify(e.templateItem)} at "${t}"`,
|
|
190
|
+
pathValue: t,
|
|
191
|
+
weight: n
|
|
192
|
+
})],
|
|
193
|
+
totalWeight: n
|
|
194
|
+
} : e.instanceArray.length === 0 ? {
|
|
195
|
+
differences: [this.buildError({
|
|
196
|
+
fix: `Add the required entry to the array at "${t}".`,
|
|
197
|
+
language: e.language,
|
|
198
|
+
message: `Missing required array structure at "${t}"`,
|
|
199
|
+
pathValue: t,
|
|
200
|
+
weight: n
|
|
201
|
+
})],
|
|
202
|
+
totalWeight: n
|
|
203
|
+
} : this.pickClosestMatch(e.instanceArray.map((t, n) => this.compare({
|
|
204
|
+
instanceValue: t,
|
|
205
|
+
language: e.language,
|
|
206
|
+
pathSegments: [...e.pathSegments, n],
|
|
207
|
+
templateValue: e.templateItem
|
|
208
|
+
})));
|
|
209
|
+
}
|
|
210
|
+
compareArrays(e) {
|
|
211
|
+
return this.combine(e.templateArray.map((t) => this.compareArrayItem({
|
|
212
|
+
...e,
|
|
213
|
+
templateItem: t
|
|
214
|
+
})));
|
|
215
|
+
}
|
|
216
|
+
compareObjects(e) {
|
|
217
|
+
return this.combine(Object.entries(e.templateObject).map(([t, n]) => {
|
|
218
|
+
let r = [...e.pathSegments, t], i = this.formatPath(r), a = e.instanceObject[t];
|
|
219
|
+
if (a === void 0) {
|
|
220
|
+
let t = this.countNodes(n);
|
|
221
|
+
return {
|
|
222
|
+
differences: [this.buildError({
|
|
223
|
+
expected: JSON.stringify(n),
|
|
224
|
+
fix: `Add the key "${i}" to the instance document.`,
|
|
225
|
+
language: e.language,
|
|
226
|
+
message: `Missing required key "${i}"`,
|
|
227
|
+
pathValue: i,
|
|
228
|
+
weight: t
|
|
229
|
+
})],
|
|
230
|
+
totalWeight: t
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
return this.compare({
|
|
234
|
+
instanceValue: a,
|
|
235
|
+
language: e.language,
|
|
236
|
+
pathSegments: r,
|
|
237
|
+
templateValue: n
|
|
238
|
+
});
|
|
239
|
+
}));
|
|
240
|
+
}
|
|
241
|
+
countContainer(e) {
|
|
242
|
+
return {
|
|
243
|
+
...e,
|
|
244
|
+
totalWeight: e.totalWeight + 1
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
countNodes(e) {
|
|
248
|
+
return Array.isArray(e) ? e.reduce((e, t) => e + this.countNodes(t), 1) : this.isJsonObject(e) ? Object.values(e).reduce((e, t) => e + this.countNodes(t), 1) : 1;
|
|
249
|
+
}
|
|
250
|
+
formatPath(e) {
|
|
251
|
+
return e.reduce((e, t) => typeof t == "number" ? `${e}[${String(t)}]` : e === "" ? t : `${e}.${t}`, "");
|
|
252
|
+
}
|
|
253
|
+
isJsonObject(e) {
|
|
254
|
+
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
255
|
+
}
|
|
256
|
+
isJsonPrimitive(e) {
|
|
257
|
+
return typeof e != "object" || !e;
|
|
258
|
+
}
|
|
259
|
+
pickClosestMatch(e) {
|
|
260
|
+
return e.reduce((e, t) => this.scoringService.sumWeights(t.differences) < this.scoringService.sumWeights(e.differences) ? t : e);
|
|
261
|
+
}
|
|
262
|
+
compare(e) {
|
|
263
|
+
let t = e.pathSegments ?? [];
|
|
264
|
+
if (Array.isArray(e.templateValue) && Array.isArray(e.instanceValue)) return this.countContainer(this.compareArrays({
|
|
265
|
+
instanceArray: e.instanceValue,
|
|
266
|
+
language: e.language,
|
|
267
|
+
pathSegments: t,
|
|
268
|
+
templateArray: e.templateValue
|
|
269
|
+
}));
|
|
270
|
+
if (this.isJsonObject(e.templateValue) && this.isJsonObject(e.instanceValue)) return this.countContainer(this.compareObjects({
|
|
271
|
+
instanceObject: e.instanceValue,
|
|
272
|
+
language: e.language,
|
|
273
|
+
pathSegments: t,
|
|
274
|
+
templateObject: e.templateValue
|
|
275
|
+
}));
|
|
276
|
+
let n = this.countNodes(e.templateValue);
|
|
277
|
+
if (e.templateValue === e.instanceValue) return {
|
|
278
|
+
differences: [],
|
|
279
|
+
totalWeight: n
|
|
280
|
+
};
|
|
281
|
+
let r = this.formatPath(t);
|
|
282
|
+
return {
|
|
283
|
+
differences: [this.buildError({
|
|
284
|
+
actual: JSON.stringify(e.instanceValue),
|
|
285
|
+
expected: JSON.stringify(e.templateValue),
|
|
286
|
+
fix: `Set "${r}" to ${JSON.stringify(e.templateValue)}.`,
|
|
287
|
+
language: e.language,
|
|
288
|
+
message: `Expected ${JSON.stringify(e.templateValue)} at "${r}" but found ${JSON.stringify(e.instanceValue)}`,
|
|
289
|
+
pathValue: r,
|
|
290
|
+
weight: n
|
|
291
|
+
})],
|
|
292
|
+
totalWeight: n
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
O = b([e(), y("design:paramtypes", [D === void 0 ? Object : D])], O);
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/scoring/scoring.module.ts
|
|
299
|
+
var k = class {};
|
|
300
|
+
k = b([t({
|
|
301
|
+
controllers: [],
|
|
302
|
+
exports: [D],
|
|
303
|
+
imports: [],
|
|
304
|
+
providers: [D]
|
|
305
|
+
})], k);
|
|
306
|
+
var me = {
|
|
307
|
+
description: "Checks JSON and JSONC structural conformance",
|
|
308
|
+
fileExtensions: [".json", ".jsonc"],
|
|
309
|
+
name: "json"
|
|
310
|
+
}, A = class {
|
|
311
|
+
jsonComparisonService;
|
|
312
|
+
constructor(e) {
|
|
313
|
+
this.jsonComparisonService = e;
|
|
314
|
+
}
|
|
315
|
+
descriptor = me;
|
|
316
|
+
validateDocument(e) {
|
|
317
|
+
return this.jsonComparisonService.compare({
|
|
318
|
+
instanceValue: o(e.instance),
|
|
319
|
+
language: "json",
|
|
320
|
+
templateValue: o(e.renderedTemplate)
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
A = b([e(), y("design:paramtypes", [O === void 0 ? Object : O])], A);
|
|
325
|
+
//#endregion
|
|
326
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/json/json.module.ts
|
|
327
|
+
var j = class {};
|
|
328
|
+
j = b([t({
|
|
329
|
+
controllers: [],
|
|
330
|
+
exports: [O, A],
|
|
331
|
+
imports: [k],
|
|
332
|
+
providers: [O, A]
|
|
333
|
+
})], j);
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/jupyter/jupyter-notebook.service.ts
|
|
336
|
+
var M = class {
|
|
337
|
+
constructor() {}
|
|
338
|
+
groupSourcesByKind(e) {
|
|
339
|
+
let t = /* @__PURE__ */ new Map();
|
|
340
|
+
for (let n of e) {
|
|
341
|
+
let e = this.readCellKind(n), r = t.get(e) ?? [];
|
|
342
|
+
r.push(this.readCellSource(n)), t.set(e, r);
|
|
343
|
+
}
|
|
344
|
+
return t;
|
|
345
|
+
}
|
|
346
|
+
readCellKind(e) {
|
|
347
|
+
return e.cell_type === "code" || e.cell_type === "markdown" ? e.cell_type : "raw";
|
|
348
|
+
}
|
|
349
|
+
readCellSource(e) {
|
|
350
|
+
if (typeof e.source == "string") return e.source;
|
|
351
|
+
let t = e.source;
|
|
352
|
+
return Array.isArray(t) ? t.filter((e) => typeof e == "string").join("") : "";
|
|
353
|
+
}
|
|
354
|
+
pairCells(e) {
|
|
355
|
+
let t = [], n = [], r = this.groupSourcesByKind(e.instanceNotebook.cells), i = /* @__PURE__ */ new Map();
|
|
356
|
+
for (let [a, o] of e.templateNotebook.cells.entries()) {
|
|
357
|
+
let e = this.readCellKind(o), s = i.get(e) ?? 0, c = r.get(e)?.[s], l = {
|
|
358
|
+
index: a,
|
|
359
|
+
instanceSource: c ?? "",
|
|
360
|
+
kind: e,
|
|
361
|
+
templateSource: this.readCellSource(o)
|
|
362
|
+
};
|
|
363
|
+
i.set(e, s + 1), c === void 0 ? t.push(l) : n.push(l);
|
|
364
|
+
}
|
|
365
|
+
return {
|
|
366
|
+
missingCells: t,
|
|
367
|
+
pairedCells: n
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
parseNotebook(e) {
|
|
371
|
+
let t = o(e);
|
|
372
|
+
if (typeof t != "object" || !t) return { cells: [] };
|
|
373
|
+
let n = t.cells;
|
|
374
|
+
return Array.isArray(n) ? { cells: n.filter((e) => typeof e == "object" && !!e) } : { cells: [] };
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
M = b([e(), y("design:paramtypes", [])], M);
|
|
378
|
+
var he = {
|
|
379
|
+
description: "Checks markdown structural conformance using mdast",
|
|
380
|
+
fileExtensions: [".md"],
|
|
381
|
+
name: "markdown"
|
|
382
|
+
}, N = /* @__PURE__ */ new Set([
|
|
383
|
+
"blockquote",
|
|
384
|
+
"document",
|
|
385
|
+
"list",
|
|
386
|
+
"listItem",
|
|
387
|
+
"root",
|
|
388
|
+
"table",
|
|
389
|
+
"tableCell",
|
|
390
|
+
"tableRow"
|
|
391
|
+
]), P = /* @__PURE__ */ new Set(["text"]), F = class {
|
|
392
|
+
constructor() {}
|
|
393
|
+
matchersByType = {
|
|
394
|
+
code: (e, t) => this.sameField(e.lang, t.lang) && this.sameField(e.value, t.value),
|
|
395
|
+
heading: (e, t) => e.depth === t.depth && this.readText(e) === this.readText(t),
|
|
396
|
+
html: (e, t) => this.sameField(e.value, t.value),
|
|
397
|
+
image: (e, t) => this.sameField(e.url, t.url) && this.sameField(e.alt, t.alt),
|
|
398
|
+
inlineCode: (e, t) => this.sameField(e.value, t.value),
|
|
399
|
+
link: (e, t) => this.sameField(e.url, t.url) && this.readText(e) === this.readText(t),
|
|
400
|
+
list: (e, t) => e.ordered === t.ordered,
|
|
401
|
+
table: (e, t) => this.readColumnCount(e) === this.readColumnCount(t),
|
|
402
|
+
tableRow: (e, t) => this.readChildren(e).length === this.readChildren(t).length,
|
|
403
|
+
text: (e, t) => this.sameField(e.value, t.value),
|
|
404
|
+
thematicBreak: () => !0
|
|
405
|
+
};
|
|
406
|
+
readColumnCount(e) {
|
|
407
|
+
let t = this.readChildren(e)[0];
|
|
408
|
+
return t === void 0 ? 0 : this.readChildren(t).length;
|
|
409
|
+
}
|
|
410
|
+
sameField(e, t) {
|
|
411
|
+
return (e ?? "") === (t ?? "");
|
|
412
|
+
}
|
|
413
|
+
countSubtree(e) {
|
|
414
|
+
return P.has(e.type) ? 0 : this.readChildren(e).reduce((e, t) => e + this.countSubtree(t), 1);
|
|
415
|
+
}
|
|
416
|
+
filterNodes(e) {
|
|
417
|
+
return e.filter((e) => typeof e == "object" && !!e && "type" in e);
|
|
418
|
+
}
|
|
419
|
+
matches(e) {
|
|
420
|
+
let { instanceNode: t, templateNode: n } = e;
|
|
421
|
+
if (n.type !== t.type) return !1;
|
|
422
|
+
let r = this.matchersByType[n.type];
|
|
423
|
+
return r === void 0 ? this.readText(n) === this.readText(t) : r(n, t);
|
|
424
|
+
}
|
|
425
|
+
readChildren(e) {
|
|
426
|
+
return e.children ?? [];
|
|
427
|
+
}
|
|
428
|
+
readText(e) {
|
|
429
|
+
return s(e);
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
F = b([e(), y("design:paramtypes", [])], F);
|
|
433
|
+
//#endregion
|
|
434
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/markdown/markdown-tree.service.ts
|
|
435
|
+
var I = class {
|
|
436
|
+
markdownNodesService;
|
|
437
|
+
scoringService;
|
|
438
|
+
constructor(e, t) {
|
|
439
|
+
this.markdownNodesService = e, this.scoringService = t;
|
|
440
|
+
}
|
|
441
|
+
buildError(e) {
|
|
442
|
+
let t = e.lastMatchedNode?.position?.end?.line;
|
|
443
|
+
return {
|
|
444
|
+
instanceLine: t === void 0 ? void 0 : t + 1,
|
|
445
|
+
nodeType: e.templateChild.type,
|
|
446
|
+
text: this.markdownNodesService.readText(e.templateChild),
|
|
447
|
+
weight: this.markdownNodesService.countSubtree(e.templateChild)
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
compareContainer(e) {
|
|
451
|
+
let t = this.findCandidates(e);
|
|
452
|
+
if (t.length === 0) {
|
|
453
|
+
let t = this.buildError(e);
|
|
454
|
+
return {
|
|
455
|
+
differences: [t],
|
|
456
|
+
lastMatchedNode: e.lastMatchedNode,
|
|
457
|
+
totalWeight: t.weight
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
let n = this.markdownNodesService.readChildren(e.templateChild);
|
|
461
|
+
return n.length === 0 ? {
|
|
462
|
+
differences: [],
|
|
463
|
+
lastMatchedNode: t.at(-1),
|
|
464
|
+
totalWeight: 1
|
|
465
|
+
} : t.map((e) => {
|
|
466
|
+
let t = this.compareChildren({
|
|
467
|
+
instanceChildren: this.markdownNodesService.readChildren(e),
|
|
468
|
+
templateChildren: n
|
|
469
|
+
});
|
|
470
|
+
return {
|
|
471
|
+
differences: t.differences,
|
|
472
|
+
lastMatchedNode: e,
|
|
473
|
+
totalWeight: t.totalWeight + 1
|
|
474
|
+
};
|
|
475
|
+
}).reduce((e, t) => this.scoringService.sumWeights(t.differences) < this.scoringService.sumWeights(e.differences) ? t : e);
|
|
476
|
+
}
|
|
477
|
+
compareLeaf(e) {
|
|
478
|
+
let t = this.findCandidates(e), n = this.markdownNodesService.countSubtree(e.templateChild);
|
|
479
|
+
return t.length === 0 ? {
|
|
480
|
+
differences: [this.buildError(e)],
|
|
481
|
+
lastMatchedNode: e.lastMatchedNode,
|
|
482
|
+
totalWeight: n
|
|
483
|
+
} : {
|
|
484
|
+
differences: [],
|
|
485
|
+
lastMatchedNode: t.at(-1),
|
|
486
|
+
totalWeight: n
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
findCandidates(e) {
|
|
490
|
+
return e.instanceChildren.filter((t) => this.markdownNodesService.matches({
|
|
491
|
+
instanceNode: t,
|
|
492
|
+
templateNode: e.templateChild
|
|
493
|
+
}));
|
|
494
|
+
}
|
|
495
|
+
compareChildren(e) {
|
|
496
|
+
let t = [], n, r = 0;
|
|
497
|
+
for (let i of e.templateChildren) {
|
|
498
|
+
if (P.has(i.type)) continue;
|
|
499
|
+
let a = N.has(i.type) ? this.compareContainer({
|
|
500
|
+
instanceChildren: e.instanceChildren,
|
|
501
|
+
lastMatchedNode: n,
|
|
502
|
+
templateChild: i
|
|
503
|
+
}) : this.compareLeaf({
|
|
504
|
+
instanceChildren: e.instanceChildren,
|
|
505
|
+
lastMatchedNode: n,
|
|
506
|
+
templateChild: i
|
|
507
|
+
});
|
|
508
|
+
t.push(...a.differences), n = a.lastMatchedNode, r += a.totalWeight;
|
|
509
|
+
}
|
|
510
|
+
return {
|
|
511
|
+
differences: t,
|
|
512
|
+
totalWeight: r
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
I = b([e(), y("design:paramtypes", [F === void 0 ? Object : F, D === void 0 ? Object : D])], I);
|
|
517
|
+
//#endregion
|
|
518
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/markdown/markdown.service.ts
|
|
519
|
+
var L = class {
|
|
520
|
+
markdownNodesService;
|
|
521
|
+
markdownTreeService;
|
|
522
|
+
constructor(e, t) {
|
|
523
|
+
this.markdownNodesService = e, this.markdownTreeService = t;
|
|
524
|
+
}
|
|
525
|
+
processor = c().use(l);
|
|
526
|
+
descriptor = he;
|
|
527
|
+
validateDocument(e) {
|
|
528
|
+
let t = this.processor.parse(e.renderedTemplate), n = this.processor.parse(e.instance), r = this.markdownTreeService.compareChildren({
|
|
529
|
+
instanceChildren: this.markdownNodesService.filterNodes(n.children),
|
|
530
|
+
templateChildren: this.markdownNodesService.filterNodes(t.children)
|
|
531
|
+
});
|
|
532
|
+
return {
|
|
533
|
+
differences: r.differences.map((e) => ({
|
|
534
|
+
differenceType: "code",
|
|
535
|
+
expected: e.text,
|
|
536
|
+
fix: `Add the ${e.nodeType} "${e.text}" to the instance file.`,
|
|
537
|
+
...e.instanceLine === void 0 ? {} : { instanceLine: e.instanceLine },
|
|
538
|
+
language: "markdown",
|
|
539
|
+
message: `Missing markdown ${e.nodeType}: "${e.text}"`,
|
|
540
|
+
weight: e.weight
|
|
541
|
+
})),
|
|
542
|
+
totalWeight: r.totalWeight
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
L = b([e(), y("design:paramtypes", [F === void 0 ? Object : F, I === void 0 ? Object : I])], L);
|
|
547
|
+
//#endregion
|
|
548
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/markdown/markdown.module.ts
|
|
549
|
+
var R = class {};
|
|
550
|
+
R = b([t({
|
|
551
|
+
controllers: [],
|
|
552
|
+
exports: [L],
|
|
553
|
+
imports: [k],
|
|
554
|
+
providers: [
|
|
555
|
+
F,
|
|
556
|
+
L,
|
|
557
|
+
I
|
|
558
|
+
]
|
|
559
|
+
})], R);
|
|
560
|
+
var ge = {
|
|
561
|
+
description: "Checks Python structure and comments against templates",
|
|
562
|
+
fileExtensions: [".py"],
|
|
563
|
+
name: "python"
|
|
564
|
+
}, z = "python3", _e = "python.bridge", ve = "Install Python 3 and ensure `python3` is on PATH; conformetry validates Python files through the interpreter's own ast module.", B = class {
|
|
565
|
+
errorsService;
|
|
566
|
+
scoringService;
|
|
567
|
+
constructor(e, t) {
|
|
568
|
+
this.errorsService = e, this.scoringService = t;
|
|
569
|
+
}
|
|
570
|
+
pythonRootPath = a.resolve(a.dirname(te(import.meta.url)), "..", "..");
|
|
571
|
+
buildBridgeError(e) {
|
|
572
|
+
return {
|
|
573
|
+
differences: [{
|
|
574
|
+
differenceType: "code",
|
|
575
|
+
fix: ve,
|
|
576
|
+
language: "python",
|
|
577
|
+
message: e
|
|
578
|
+
}],
|
|
579
|
+
totalWeight: 1
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
readLocations(e) {
|
|
583
|
+
let t = this.readNumber(e, "instance_column"), n = this.readNumber(e, "instance_line"), r = this.readNumber(e, "template_column"), i = this.readNumber(e, "template_line");
|
|
584
|
+
return {
|
|
585
|
+
...t === void 0 ? {} : { instanceColumn: t },
|
|
586
|
+
...n === void 0 ? {} : { instanceLine: n },
|
|
587
|
+
...r === void 0 ? {} : { templateColumn: r },
|
|
588
|
+
...i === void 0 ? {} : { templateLine: i }
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
readNumber(e, t) {
|
|
592
|
+
let n = e[t];
|
|
593
|
+
return typeof n == "number" ? n : void 0;
|
|
594
|
+
}
|
|
595
|
+
readString(e, t) {
|
|
596
|
+
let n = e[t];
|
|
597
|
+
return typeof n == "string" ? n : void 0;
|
|
598
|
+
}
|
|
599
|
+
readValues(e) {
|
|
600
|
+
let t = this.readString(e, "actual"), n = this.readString(e, "expected");
|
|
601
|
+
return {
|
|
602
|
+
...t === void 0 ? {} : { actual: t },
|
|
603
|
+
...n === void 0 ? {} : { expected: n }
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
toConformetryDifference(e) {
|
|
607
|
+
return {
|
|
608
|
+
...this.readValues(e),
|
|
609
|
+
...this.readLocations(e),
|
|
610
|
+
differenceType: this.errorsService.resolveDifferenceType(e.difference_type),
|
|
611
|
+
fix: this.readString(e, "fix") ?? "Fix the conformance issue.",
|
|
612
|
+
language: this.errorsService.resolveErrorLanguage(e.language) ?? "python",
|
|
613
|
+
message: this.readString(e, "message") ?? "Python conformance issue found.",
|
|
614
|
+
weight: this.readNumber(e, "weight") ?? 1
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
validatePythonSource(e) {
|
|
618
|
+
let t = ee(z, ["-m", _e], {
|
|
619
|
+
cwd: this.pythonRootPath,
|
|
620
|
+
encoding: "utf8",
|
|
621
|
+
env: {
|
|
622
|
+
...process.env,
|
|
623
|
+
PYTHONPATH: this.pythonRootPath
|
|
624
|
+
},
|
|
625
|
+
input: JSON.stringify(e)
|
|
626
|
+
});
|
|
627
|
+
if (t.error !== void 0) return this.buildBridgeError(`Could not run ${z}: ${t.error.message}`);
|
|
628
|
+
if (t.status !== 0) return this.buildBridgeError(`Python validator exited with status ${String(t.status)}: ${t.stderr || t.stdout}`);
|
|
629
|
+
try {
|
|
630
|
+
let e = JSON.parse(t.stdout), n = e.differences.map((e) => this.toConformetryDifference(e));
|
|
631
|
+
return {
|
|
632
|
+
differences: n,
|
|
633
|
+
totalWeight: typeof e.total_weight == "number" ? e.total_weight : this.scoringService.sumWeights(n)
|
|
634
|
+
};
|
|
635
|
+
} catch {
|
|
636
|
+
return this.buildBridgeError("Python validator returned output that could not be parsed.");
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
B = b([e(), y("design:paramtypes", [x === void 0 ? Object : x, D === void 0 ? Object : D])], B);
|
|
641
|
+
//#endregion
|
|
642
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/python/python.service.ts
|
|
643
|
+
var V = class {
|
|
644
|
+
pythonBridgeService;
|
|
645
|
+
constructor(e) {
|
|
646
|
+
this.pythonBridgeService = e;
|
|
647
|
+
}
|
|
648
|
+
descriptor = ge;
|
|
649
|
+
validateDocument(e) {
|
|
650
|
+
return this.pythonBridgeService.validatePythonSource({
|
|
651
|
+
filename: e.filename,
|
|
652
|
+
instance: e.instance,
|
|
653
|
+
template: e.renderedTemplate
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
V = b([e(), y("design:paramtypes", [B === void 0 ? Object : B])], V);
|
|
658
|
+
//#endregion
|
|
659
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/python/python.module.ts
|
|
660
|
+
var H = class {};
|
|
661
|
+
H = b([t({
|
|
662
|
+
controllers: [],
|
|
663
|
+
exports: [B, V],
|
|
664
|
+
imports: [S, k],
|
|
665
|
+
providers: [B, V]
|
|
666
|
+
})], H);
|
|
667
|
+
var ye = {
|
|
668
|
+
description: "Checks Jupyter notebook structure, markdown cells, and code cells",
|
|
669
|
+
fileExtensions: [".ipynb"],
|
|
670
|
+
name: "jupyter"
|
|
671
|
+
}, be = [
|
|
672
|
+
"metadata",
|
|
673
|
+
"nbformat",
|
|
674
|
+
"nbformat_minor"
|
|
675
|
+
], U = class {
|
|
676
|
+
jsonComparisonService;
|
|
677
|
+
jupyterNotebookService;
|
|
678
|
+
markdownService;
|
|
679
|
+
pythonBridgeService;
|
|
680
|
+
constructor(e, t, n, r) {
|
|
681
|
+
this.jsonComparisonService = e, this.jupyterNotebookService = t, this.markdownService = n, this.pythonBridgeService = r;
|
|
682
|
+
}
|
|
683
|
+
descriptor = ye;
|
|
684
|
+
attributeToCell(e) {
|
|
685
|
+
return e.differences.map((t) => ({
|
|
686
|
+
...t,
|
|
687
|
+
message: `Cell ${String(e.cell.index + 1)} (${e.cell.kind}): ${t.message}`
|
|
688
|
+
}));
|
|
689
|
+
}
|
|
690
|
+
readEnvelope(e) {
|
|
691
|
+
let t = o(e);
|
|
692
|
+
if (typeof t != "object" || !t || Array.isArray(t)) return {};
|
|
693
|
+
let n = {};
|
|
694
|
+
for (let e of be) {
|
|
695
|
+
let r = t[e];
|
|
696
|
+
r !== void 0 && (n[e] = r);
|
|
697
|
+
}
|
|
698
|
+
return n;
|
|
699
|
+
}
|
|
700
|
+
validateCell(e) {
|
|
701
|
+
let { cell: t } = e;
|
|
702
|
+
if (t.kind === "markdown") {
|
|
703
|
+
let n = this.markdownService.validateDocument({
|
|
704
|
+
...e.document,
|
|
705
|
+
instance: t.instanceSource,
|
|
706
|
+
renderedTemplate: t.templateSource
|
|
707
|
+
});
|
|
708
|
+
return {
|
|
709
|
+
differences: this.attributeToCell({
|
|
710
|
+
cell: t,
|
|
711
|
+
differences: n.differences
|
|
712
|
+
}),
|
|
713
|
+
totalWeight: n.totalWeight
|
|
714
|
+
};
|
|
715
|
+
}
|
|
716
|
+
if (t.kind === "code") {
|
|
717
|
+
let n = this.pythonBridgeService.validatePythonSource({
|
|
718
|
+
filename: `${e.document.filename}#cell-${String(t.index + 1)}.py`,
|
|
719
|
+
instance: t.instanceSource,
|
|
720
|
+
template: t.templateSource
|
|
721
|
+
});
|
|
722
|
+
return {
|
|
723
|
+
differences: this.attributeToCell({
|
|
724
|
+
cell: t,
|
|
725
|
+
differences: n.differences
|
|
726
|
+
}),
|
|
727
|
+
totalWeight: n.totalWeight
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
return {
|
|
731
|
+
differences: [],
|
|
732
|
+
totalWeight: 0
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
weighMissingCell(e) {
|
|
736
|
+
return this.validateCell({
|
|
737
|
+
cell: {
|
|
738
|
+
...e.cell,
|
|
739
|
+
instanceSource: ""
|
|
740
|
+
},
|
|
741
|
+
document: e.document
|
|
742
|
+
}).totalWeight;
|
|
743
|
+
}
|
|
744
|
+
validateDocument(e) {
|
|
745
|
+
let t = this.jupyterNotebookService.parseNotebook(e.renderedTemplate), n = this.jupyterNotebookService.parseNotebook(e.instance), { missingCells: r, pairedCells: i } = this.jupyterNotebookService.pairCells({
|
|
746
|
+
instanceNotebook: n,
|
|
747
|
+
templateNotebook: t
|
|
748
|
+
}), a = this.jsonComparisonService.compare({
|
|
749
|
+
instanceValue: this.readEnvelope(e.instance),
|
|
750
|
+
language: "json",
|
|
751
|
+
templateValue: this.readEnvelope(e.renderedTemplate)
|
|
752
|
+
}), o = r.map((t) => {
|
|
753
|
+
let n = this.weighMissingCell({
|
|
754
|
+
cell: t,
|
|
755
|
+
document: e
|
|
756
|
+
});
|
|
757
|
+
return {
|
|
758
|
+
error: {
|
|
759
|
+
differenceType: "code",
|
|
760
|
+
expected: t.templateSource,
|
|
761
|
+
fix: `Add a ${t.kind} cell matching the template's cell ${String(t.index + 1)}.`,
|
|
762
|
+
language: "python",
|
|
763
|
+
message: `Missing ${t.kind} cell ${String(t.index + 1)}`,
|
|
764
|
+
weight: n
|
|
765
|
+
},
|
|
766
|
+
weight: n
|
|
767
|
+
};
|
|
768
|
+
}), s = i.map((t) => this.validateCell({
|
|
769
|
+
cell: t,
|
|
770
|
+
document: e
|
|
771
|
+
}));
|
|
772
|
+
return {
|
|
773
|
+
differences: [
|
|
774
|
+
...a.differences,
|
|
775
|
+
...o.map((e) => e.error),
|
|
776
|
+
...s.flatMap((e) => e.differences)
|
|
777
|
+
],
|
|
778
|
+
totalWeight: [
|
|
779
|
+
a.totalWeight,
|
|
780
|
+
...o.map((e) => e.weight),
|
|
781
|
+
...s.map((e) => e.totalWeight)
|
|
782
|
+
].reduce((e, t) => e + t, 0)
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
U = b([e(), y("design:paramtypes", [
|
|
787
|
+
O === void 0 ? Object : O,
|
|
788
|
+
M === void 0 ? Object : M,
|
|
789
|
+
L === void 0 ? Object : L,
|
|
790
|
+
B === void 0 ? Object : B
|
|
791
|
+
])], U);
|
|
792
|
+
//#endregion
|
|
793
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/jupyter/jupyter.module.ts
|
|
794
|
+
var W = class {};
|
|
795
|
+
W = b([t({
|
|
796
|
+
controllers: [],
|
|
797
|
+
exports: [U],
|
|
798
|
+
imports: [
|
|
799
|
+
j,
|
|
800
|
+
R,
|
|
801
|
+
H
|
|
802
|
+
],
|
|
803
|
+
providers: [M, U]
|
|
804
|
+
})], W);
|
|
805
|
+
var xe = {
|
|
806
|
+
description: "Checks text files using duplicate-aware line conformance",
|
|
807
|
+
fileExtensions: [".txt"],
|
|
808
|
+
name: "text"
|
|
809
|
+
}, G = class {
|
|
810
|
+
constructor() {}
|
|
811
|
+
descriptor = xe;
|
|
812
|
+
countLines(e) {
|
|
813
|
+
let t = /* @__PURE__ */ new Map();
|
|
814
|
+
for (let n of e.split("\n")) t.set(n, (t.get(n) ?? 0) + 1);
|
|
815
|
+
return t;
|
|
816
|
+
}
|
|
817
|
+
findMissingLines(e) {
|
|
818
|
+
let t = this.countLines(e.instance), n = [];
|
|
819
|
+
for (let [r, i] of e.renderedTemplate.split("\n").entries()) {
|
|
820
|
+
let e = t.get(i) ?? 0;
|
|
821
|
+
e === 0 ? n.push({
|
|
822
|
+
line: i,
|
|
823
|
+
templateLine: r + 1
|
|
824
|
+
}) : t.set(i, e - 1);
|
|
825
|
+
}
|
|
826
|
+
return n;
|
|
827
|
+
}
|
|
828
|
+
validateDocument(e) {
|
|
829
|
+
return {
|
|
830
|
+
differences: this.findMissingLines(e).map((e) => ({
|
|
831
|
+
differenceType: "code",
|
|
832
|
+
expected: e.line,
|
|
833
|
+
fix: `Add the line \`${e.line}\` to the instance file.`,
|
|
834
|
+
language: "text",
|
|
835
|
+
message: `Missing line: ${e.line}`,
|
|
836
|
+
templateLine: e.templateLine
|
|
837
|
+
})),
|
|
838
|
+
totalWeight: e.renderedTemplate.split("\n").length
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
};
|
|
842
|
+
G = b([e(), y("design:paramtypes", [])], G);
|
|
843
|
+
//#endregion
|
|
844
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/text/text.module.ts
|
|
845
|
+
var K = class {};
|
|
846
|
+
K = b([t({
|
|
847
|
+
controllers: [],
|
|
848
|
+
exports: [G],
|
|
849
|
+
imports: [],
|
|
850
|
+
providers: [G]
|
|
851
|
+
})], K);
|
|
852
|
+
var Se = {
|
|
853
|
+
description: "Checks TypeScript AST structure and required comments",
|
|
854
|
+
fileExtensions: [".ts", ".tsx"],
|
|
855
|
+
name: "typescript"
|
|
856
|
+
}, Ce = /\bTODO\b/u, q = class {
|
|
857
|
+
constructor() {}
|
|
858
|
+
compareComments(e) {
|
|
859
|
+
let t = this.extractComments(e.instanceSourceFile), n = this.extractComments(e.templateSourceFile), r = [], i = 0;
|
|
860
|
+
for (let e of n) {
|
|
861
|
+
let n = Ce.test(e.text), a = t.slice(i).findIndex((t) => n || t.text === e.text);
|
|
862
|
+
if (a === -1) {
|
|
863
|
+
r.push(e);
|
|
864
|
+
continue;
|
|
865
|
+
}
|
|
866
|
+
i += a + 1;
|
|
867
|
+
}
|
|
868
|
+
return {
|
|
869
|
+
missingComments: r,
|
|
870
|
+
totalWeight: n.length
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
extractComments(e) {
|
|
874
|
+
let t = /* @__PURE__ */ new Map(), n = (r) => {
|
|
875
|
+
let i = r.getChildren(e);
|
|
876
|
+
if (i.length === 0) {
|
|
877
|
+
for (let n of ae(e.text, r.getFullStart()) ?? []) t.set(n.pos, {
|
|
878
|
+
position: n.pos,
|
|
879
|
+
text: e.text.slice(n.pos, n.end).trim()
|
|
880
|
+
});
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
for (let e of i) n(e);
|
|
884
|
+
};
|
|
885
|
+
return n(e), [...t.values()].toSorted((e, t) => e.position - t.position);
|
|
886
|
+
}
|
|
887
|
+
};
|
|
888
|
+
q = b([e(), y("design:paramtypes", [])], q);
|
|
889
|
+
//#endregion
|
|
890
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/typescript/typescript-nodes.service.ts
|
|
891
|
+
var J = class {
|
|
892
|
+
constructor() {}
|
|
893
|
+
buildDottedName(e) {
|
|
894
|
+
let t = [], n = e;
|
|
895
|
+
for (; de(n);) t.unshift(n.name.text), n = n.expression;
|
|
896
|
+
return h(n) ? (t.unshift(n.text), t.join(".")) : null;
|
|
897
|
+
}
|
|
898
|
+
isNode(e) {
|
|
899
|
+
return typeof e == "object" && !!e && "kind" in e && typeof e.kind == "number";
|
|
900
|
+
}
|
|
901
|
+
readDecoratorKey(e) {
|
|
902
|
+
return this.buildDottedName(p(e.expression) ? e.expression.expression : e.expression);
|
|
903
|
+
}
|
|
904
|
+
readExportKey(e) {
|
|
905
|
+
let { moduleSpecifier: t } = e;
|
|
906
|
+
return t === void 0 || !_(t) ? null : t.text;
|
|
907
|
+
}
|
|
908
|
+
readExpressionStatementKey(e) {
|
|
909
|
+
if (!p(e)) return null;
|
|
910
|
+
let t = this.buildDottedName(e.expression);
|
|
911
|
+
if (t === null) return null;
|
|
912
|
+
let n = e.arguments[0], r = n === void 0 ? void 0 : this.readLiteralKey(n);
|
|
913
|
+
return r === void 0 ? t : `${t}:${r}`;
|
|
914
|
+
}
|
|
915
|
+
readImportKey(e) {
|
|
916
|
+
return _(e.moduleSpecifier) ? e.moduleSpecifier.text : null;
|
|
917
|
+
}
|
|
918
|
+
readLiteralKey(e) {
|
|
919
|
+
if (h(e) || _(e) || g(e) || f(e) || le(e)) return e.text;
|
|
920
|
+
}
|
|
921
|
+
readNamedKey(e) {
|
|
922
|
+
if (!("name" in e)) return null;
|
|
923
|
+
let t = e.name;
|
|
924
|
+
return this.isNode(t) && (h(t) || ue(t) || _(t) || g(t)) ? t.text : null;
|
|
925
|
+
}
|
|
926
|
+
countSubtree(e) {
|
|
927
|
+
return this.readChildren(e).reduce((e, t) => e + this.countSubtree(t), 1);
|
|
928
|
+
}
|
|
929
|
+
readChildren(e) {
|
|
930
|
+
let t = [];
|
|
931
|
+
return ie(e, (e) => {
|
|
932
|
+
e.kind !== d.EndOfFileToken && t.push(e);
|
|
933
|
+
}), t;
|
|
934
|
+
}
|
|
935
|
+
readKey(e) {
|
|
936
|
+
if (ce(e)) return this.readImportKey(e);
|
|
937
|
+
if (oe(e)) return this.readExportKey(e);
|
|
938
|
+
if (m(e)) return this.readDecoratorKey(e);
|
|
939
|
+
if (se(e)) {
|
|
940
|
+
let t = this.readExpressionStatementKey(e.expression);
|
|
941
|
+
if (t !== null) return t;
|
|
942
|
+
}
|
|
943
|
+
return this.readLiteralKey(e) ?? this.readNamedKey(e);
|
|
944
|
+
}
|
|
945
|
+
readKindLabel(e) {
|
|
946
|
+
return d[e.kind];
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
J = b([e(), y("design:paramtypes", [])], J);
|
|
950
|
+
//#endregion
|
|
951
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/typescript/typescript-tree.service.ts
|
|
952
|
+
var Y = class {
|
|
953
|
+
scoringService;
|
|
954
|
+
typeScriptNodesService;
|
|
955
|
+
constructor(e, t) {
|
|
956
|
+
this.scoringService = e, this.typeScriptNodesService = t;
|
|
957
|
+
}
|
|
958
|
+
buildError(e) {
|
|
959
|
+
return {
|
|
960
|
+
instancePosition: e.instanceNode.getStart(),
|
|
961
|
+
kindLabel: this.typeScriptNodesService.readKindLabel(e.templateChild),
|
|
962
|
+
nodeKey: e.nodeKey ?? void 0,
|
|
963
|
+
templatePosition: e.templateChild.getStart(),
|
|
964
|
+
weight: this.typeScriptNodesService.countSubtree(e.templateChild)
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
compareBestCandidate(e) {
|
|
968
|
+
return e.candidates.map((t) => this.compareTree({
|
|
969
|
+
instanceNode: t,
|
|
970
|
+
templateNode: e.templateChild
|
|
971
|
+
})).reduce((e, t) => this.scoringService.sumWeights(t.differences) < this.scoringService.sumWeights(e.differences) ? t : e);
|
|
972
|
+
}
|
|
973
|
+
compareChild(e) {
|
|
974
|
+
let t = this.typeScriptNodesService.readKey(e.templateChild), n = t === null ? e.instanceChildren.filter((t) => t.kind === e.templateChild.kind) : e.instanceChildren.filter((e) => this.typeScriptNodesService.readKey(e) === t);
|
|
975
|
+
if (n.length === 0) {
|
|
976
|
+
let n = this.buildError({
|
|
977
|
+
instanceNode: e.instanceNode,
|
|
978
|
+
nodeKey: t,
|
|
979
|
+
templateChild: e.templateChild
|
|
980
|
+
});
|
|
981
|
+
return {
|
|
982
|
+
differences: [n],
|
|
983
|
+
totalWeight: n.weight
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
return this.compareBestCandidate({
|
|
987
|
+
candidates: n,
|
|
988
|
+
templateChild: e.templateChild
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
compareTree(e) {
|
|
992
|
+
let t = this.typeScriptNodesService.readChildren(e.instanceNode);
|
|
993
|
+
return this.typeScriptNodesService.readChildren(e.templateNode).map((n) => this.compareChild({
|
|
994
|
+
instanceChildren: t,
|
|
995
|
+
instanceNode: e.instanceNode,
|
|
996
|
+
templateChild: n
|
|
997
|
+
})).reduce((e, t) => ({
|
|
998
|
+
differences: [...e.differences, ...t.differences],
|
|
999
|
+
totalWeight: e.totalWeight + t.totalWeight
|
|
1000
|
+
}), {
|
|
1001
|
+
differences: [],
|
|
1002
|
+
totalWeight: 1
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
Y = b([e(), y("design:paramtypes", [D === void 0 ? Object : D, J === void 0 ? Object : J])], Y);
|
|
1007
|
+
//#endregion
|
|
1008
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/typescript/typescript.service.ts
|
|
1009
|
+
var X = class {
|
|
1010
|
+
typeScriptCommentsService;
|
|
1011
|
+
typeScriptTreeService;
|
|
1012
|
+
constructor(e, t) {
|
|
1013
|
+
this.typeScriptCommentsService = e, this.typeScriptTreeService = t;
|
|
1014
|
+
}
|
|
1015
|
+
descriptor = Se;
|
|
1016
|
+
parseSourceFile(e) {
|
|
1017
|
+
return re(e.filename, e.content, ne.Latest, !0, e.filename.endsWith(".tsx") ? u.TSX : u.TS);
|
|
1018
|
+
}
|
|
1019
|
+
readLocation(e) {
|
|
1020
|
+
if (e.position === void 0 || e.position < 0) return;
|
|
1021
|
+
let { character: t, line: n } = e.sourceFile.getLineAndCharacterOfPosition(e.position);
|
|
1022
|
+
return {
|
|
1023
|
+
column: t + 1,
|
|
1024
|
+
line: n + 1
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
validateComments(e) {
|
|
1028
|
+
let t = this.typeScriptCommentsService.compareComments(e);
|
|
1029
|
+
return {
|
|
1030
|
+
differences: t.missingComments.map((t) => {
|
|
1031
|
+
let n = this.readLocation({
|
|
1032
|
+
position: t.position,
|
|
1033
|
+
sourceFile: e.templateSourceFile
|
|
1034
|
+
});
|
|
1035
|
+
return {
|
|
1036
|
+
differenceType: "comment",
|
|
1037
|
+
expected: t.text,
|
|
1038
|
+
fix: `Add the comment ${t.text} to the instance file, in the order the template declares it.`,
|
|
1039
|
+
language: "typescript",
|
|
1040
|
+
message: `Missing comment ${t.text}`,
|
|
1041
|
+
...n === void 0 ? {} : {
|
|
1042
|
+
templateColumn: n.column,
|
|
1043
|
+
templateLine: n.line
|
|
1044
|
+
}
|
|
1045
|
+
};
|
|
1046
|
+
}),
|
|
1047
|
+
totalWeight: t.totalWeight
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
validateStructure(e) {
|
|
1051
|
+
let t = this.typeScriptTreeService.compareTree({
|
|
1052
|
+
instanceNode: e.instanceSourceFile,
|
|
1053
|
+
templateNode: e.templateSourceFile
|
|
1054
|
+
});
|
|
1055
|
+
return {
|
|
1056
|
+
differences: t.differences.map((t) => {
|
|
1057
|
+
let n = t.nodeKey === void 0 ? t.kindLabel : `${t.kindLabel} "${t.nodeKey}"`, r = this.readLocation({
|
|
1058
|
+
position: t.instancePosition,
|
|
1059
|
+
sourceFile: e.instanceSourceFile
|
|
1060
|
+
}), i = this.readLocation({
|
|
1061
|
+
position: t.templatePosition,
|
|
1062
|
+
sourceFile: e.templateSourceFile
|
|
1063
|
+
});
|
|
1064
|
+
return {
|
|
1065
|
+
differenceType: "code",
|
|
1066
|
+
fix: `Add the missing ${n} to the instance file. See the template for the expected structure.`,
|
|
1067
|
+
...r === void 0 ? {} : {
|
|
1068
|
+
instanceColumn: r.column,
|
|
1069
|
+
instanceLine: r.line
|
|
1070
|
+
},
|
|
1071
|
+
language: "typescript",
|
|
1072
|
+
message: `Missing ${n}`,
|
|
1073
|
+
...i === void 0 ? {} : {
|
|
1074
|
+
templateColumn: i.column,
|
|
1075
|
+
templateLine: i.line
|
|
1076
|
+
},
|
|
1077
|
+
weight: t.weight
|
|
1078
|
+
};
|
|
1079
|
+
}),
|
|
1080
|
+
totalWeight: t.totalWeight
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
validateDocument(e) {
|
|
1084
|
+
let t = {
|
|
1085
|
+
instanceSourceFile: this.parseSourceFile({
|
|
1086
|
+
content: e.instance,
|
|
1087
|
+
filename: e.filename
|
|
1088
|
+
}),
|
|
1089
|
+
templateSourceFile: this.parseSourceFile({
|
|
1090
|
+
content: e.renderedTemplate,
|
|
1091
|
+
filename: e.filename
|
|
1092
|
+
})
|
|
1093
|
+
}, n = this.validateStructure(t), r = this.validateComments(t);
|
|
1094
|
+
return {
|
|
1095
|
+
differences: [...n.differences, ...r.differences],
|
|
1096
|
+
totalWeight: n.totalWeight + r.totalWeight
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
X = b([e(), y("design:paramtypes", [q === void 0 ? Object : q, Y === void 0 ? Object : Y])], X);
|
|
1101
|
+
//#endregion
|
|
1102
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/typescript/typescript.module.ts
|
|
1103
|
+
var Z = class {};
|
|
1104
|
+
Z = b([t({
|
|
1105
|
+
controllers: [],
|
|
1106
|
+
exports: [X],
|
|
1107
|
+
imports: [k],
|
|
1108
|
+
providers: [
|
|
1109
|
+
q,
|
|
1110
|
+
J,
|
|
1111
|
+
Y,
|
|
1112
|
+
X
|
|
1113
|
+
]
|
|
1114
|
+
})], Z);
|
|
1115
|
+
//#endregion
|
|
1116
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/languages/languages.service.ts
|
|
1117
|
+
var Q = class {
|
|
1118
|
+
jsonService;
|
|
1119
|
+
jupyterService;
|
|
1120
|
+
markdownService;
|
|
1121
|
+
pythonService;
|
|
1122
|
+
textService;
|
|
1123
|
+
typescriptService;
|
|
1124
|
+
constructor(e, t, n, r, i, a) {
|
|
1125
|
+
this.jsonService = e, this.jupyterService = t, this.markdownService = n, this.pythonService = r, this.textService = i, this.typescriptService = a;
|
|
1126
|
+
}
|
|
1127
|
+
claimingLanguages() {
|
|
1128
|
+
return [
|
|
1129
|
+
this.jsonService,
|
|
1130
|
+
this.jupyterService,
|
|
1131
|
+
this.markdownService,
|
|
1132
|
+
this.pythonService,
|
|
1133
|
+
this.typescriptService
|
|
1134
|
+
];
|
|
1135
|
+
}
|
|
1136
|
+
widenFallback(e) {
|
|
1137
|
+
let t = this.textService;
|
|
1138
|
+
return {
|
|
1139
|
+
descriptor: {
|
|
1140
|
+
...t.descriptor,
|
|
1141
|
+
fileExtensions: [...t.descriptor.fileExtensions, ...e]
|
|
1142
|
+
},
|
|
1143
|
+
validateDocument: (e) => t.validateDocument(e)
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
resolveValidators(e) {
|
|
1147
|
+
let t = this.claimingLanguages().filter((t) => t.descriptor.fileExtensions.some((t) => e.extensions.includes(t))), n = new Set(t.flatMap((e) => [...e.descriptor.fileExtensions])), r = e.extensions.filter((e) => !n.has(e));
|
|
1148
|
+
return r.length === 0 ? t : [...t, this.widenFallback(r)];
|
|
1149
|
+
}
|
|
1150
|
+
};
|
|
1151
|
+
Q = b([e(), y("design:paramtypes", [
|
|
1152
|
+
A === void 0 ? Object : A,
|
|
1153
|
+
U === void 0 ? Object : U,
|
|
1154
|
+
L === void 0 ? Object : L,
|
|
1155
|
+
V === void 0 ? Object : V,
|
|
1156
|
+
G === void 0 ? Object : G,
|
|
1157
|
+
X === void 0 ? Object : X
|
|
1158
|
+
])], Q);
|
|
1159
|
+
//#endregion
|
|
1160
|
+
//#region packages/ic-suite/conformetry/conformetry-languages/src/modules/languages/languages.module.ts
|
|
1161
|
+
var $ = class {};
|
|
1162
|
+
$ = b([t({
|
|
1163
|
+
controllers: [],
|
|
1164
|
+
exports: [
|
|
1165
|
+
j,
|
|
1166
|
+
W,
|
|
1167
|
+
Q,
|
|
1168
|
+
R,
|
|
1169
|
+
H,
|
|
1170
|
+
K,
|
|
1171
|
+
Z
|
|
1172
|
+
],
|
|
1173
|
+
imports: [
|
|
1174
|
+
j,
|
|
1175
|
+
W,
|
|
1176
|
+
R,
|
|
1177
|
+
H,
|
|
1178
|
+
K,
|
|
1179
|
+
Z
|
|
1180
|
+
],
|
|
1181
|
+
providers: [Q]
|
|
1182
|
+
})], $);
|
|
1183
|
+
//#endregion
|
|
1184
|
+
export { T as DEFAULT_ERROR_WEIGHT, S as DifferencesModule, x as DifferencesService, E as EMPTY_TEMPLATE_SCORE, w as FilesModule, C as FilesService, O as JsonComparisonService, j as JsonModule, A as JsonService, W as JupyterModule, M as JupyterNotebookService, U as JupyterService, $ as LanguagesModule, Q as LanguagesService, R as MarkdownModule, F as MarkdownNodesService, L as MarkdownService, I as MarkdownTreeService, pe as PERFECT_SCORE, B as PythonBridgeService, H as PythonModule, V as PythonService, k as ScoringModule, D as ScoringService, K as TextModule, G as TextService, q as TypescriptCommentsService, Z as TypescriptModule, J as TypescriptNodesService, X as TypescriptService, Y as TypescriptTreeService };
|