@geonosis/oxlint-plugin-biological-architecture 0.1.2 → 0.2.0
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/README.md +39 -61
- package/corpus/.oxlintrc.json +33 -0
- package/corpus/layers/core/bad-reaches-up.ts +3 -0
- package/corpus/layers/core/thing.ts +1 -0
- package/corpus/layers/feature/bad-relative.ts +3 -0
- package/corpus/layers/feature/good-downward.ts +3 -0
- package/corpus/layers/feature/good-same-layer.ts +3 -0
- package/corpus/layers/feature/good-type-only.ts +3 -0
- package/corpus/layers/feature/sibling.ts +1 -0
- package/corpus/layers/shell/boot.ts +3 -0
- package/corpus/manifest.json +1 -0
- package/dist/{chunk-74VWOEPL.js → chunk-HXBZSOIU.js} +3 -1
- package/dist/discover-atoms.d.ts +39 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +159 -24
- package/dist/presets.d.ts +36 -0
- package/dist/presets.js +1 -1
- package/package.json +5 -8
- package/bin/geonosis-lint-parity.mjs +0 -4
- package/dist/chunk-2VSZAP5M.js +0 -240
- package/dist/chunk-BFFWNFJM.js +0 -6
- package/dist/chunk-BGX2XYEL.js +0 -153
- package/dist/chunk-FGUOGKA5.js +0 -228
- package/dist/chunk-FJ3J7B5J.js +0 -155
- package/dist/chunk-KZ5XEK6F.js +0 -83
- package/dist/chunk-NZVMV3Y5.js +0 -339
- package/dist/chunk-RNY5NDH5.js +0 -155
- package/dist/chunk-SUTNA6YD.js +0 -268
- package/dist/chunk-UM6UIUH3.js +0 -250
- package/dist/chunk-YIAUS4GG.js +0 -298
- package/dist/parity-cli.js +0 -84
- package/dist/parity.js +0 -32
package/dist/chunk-NZVMV3Y5.js
DELETED
|
@@ -1,339 +0,0 @@
|
|
|
1
|
-
// src/parity.ts
|
|
2
|
-
import { spawnSync } from "child_process";
|
|
3
|
-
import { cpSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
4
|
-
import { tmpdir } from "os";
|
|
5
|
-
import { join } from "path";
|
|
6
|
-
var ANSI = /\[[0-9;]*m/g;
|
|
7
|
-
var SUMMARY_COUNT = /^(\d+) problems?$/m;
|
|
8
|
-
var RULE_IN_LINE = /\[(?:Error|Warning)\/([^\]]+)\]$/;
|
|
9
|
-
var UNIX_FINDING = /^\S[^\n]*:\d+:\d+: .*\[(?:Error|Warning)\/[^\]\n]+\]$/;
|
|
10
|
-
var FINDING_PLACE = /^(\S[^\n]*?:\d+:\d+): .*\[(?:Error|Warning)\/([^\]\n]+)\]$/;
|
|
11
|
-
var ParityError = class extends Error {
|
|
12
|
-
constructor(message) {
|
|
13
|
-
super(message);
|
|
14
|
-
this.name = "ParityError";
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var normaliseFindings = (output, cwd) => output.replaceAll(ANSI, "").split("\n").map((line) => line.trim().replace(`${cwd}/`, "").replace(/^\.\//, "")).filter((line) => UNIX_FINDING.test(line)).toSorted();
|
|
18
|
-
var readRun = ({ code, output }, cwd, side) => {
|
|
19
|
-
const findings = normaliseFindings(output, cwd);
|
|
20
|
-
const summary = SUMMARY_COUNT.exec(output);
|
|
21
|
-
const refuse = (why) => {
|
|
22
|
-
throw new ParityError(`config ${side}: ${why}
|
|
23
|
-
${output.trim()}`);
|
|
24
|
-
};
|
|
25
|
-
if (summary?.[1] !== void 0 && Number(summary[1]) !== findings.length) {
|
|
26
|
-
return refuse(`oxlint says ${summary[1]} problems, ${findings.length} lines parsed as findings`);
|
|
27
|
-
}
|
|
28
|
-
if (findings.length === 0 && code !== 0) {
|
|
29
|
-
return refuse(`oxlint exited ${code} without reporting a single finding`);
|
|
30
|
-
}
|
|
31
|
-
return findings;
|
|
32
|
-
};
|
|
33
|
-
var UNATTRIBUTED = "(unattributed)";
|
|
34
|
-
var ruleOf = (line) => RULE_IN_LINE.exec(line)?.[1] ?? UNATTRIBUTED;
|
|
35
|
-
var asFile = (lines) => lines.length === 0 ? "" : `${lines.join("\n")}
|
|
36
|
-
`;
|
|
37
|
-
var changedLines = (changes) => changes.flatMap((one) => [`- A: ${one.a}`, `+ B: ${one.b}`]);
|
|
38
|
-
var countByRule = (lines) => {
|
|
39
|
-
const counts = /* @__PURE__ */ new Map();
|
|
40
|
-
for (const line of lines) counts.set(ruleOf(line), (counts.get(ruleOf(line)) ?? 0) + 1);
|
|
41
|
-
return counts;
|
|
42
|
-
};
|
|
43
|
-
var missingFrom = (lines, other) => {
|
|
44
|
-
const remaining = /* @__PURE__ */ new Map();
|
|
45
|
-
for (const line of other) remaining.set(line, (remaining.get(line) ?? 0) + 1);
|
|
46
|
-
return lines.filter((line) => {
|
|
47
|
-
const left = remaining.get(line) ?? 0;
|
|
48
|
-
if (left === 0) return true;
|
|
49
|
-
remaining.set(line, left - 1);
|
|
50
|
-
return false;
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
var identityOf = (line) => {
|
|
54
|
-
const found = FINDING_PLACE.exec(line);
|
|
55
|
-
return found === null ? line : `${found[1]} [${found[2]}]`;
|
|
56
|
-
};
|
|
57
|
-
var byIdentity = (lines) => {
|
|
58
|
-
const grouped = /* @__PURE__ */ new Map();
|
|
59
|
-
for (const line of lines) {
|
|
60
|
-
const identity = identityOf(line);
|
|
61
|
-
grouped.set(identity, [...grouped.get(identity) ?? [], line]);
|
|
62
|
-
}
|
|
63
|
-
return grouped;
|
|
64
|
-
};
|
|
65
|
-
var compareFindings = ({ a, b }) => {
|
|
66
|
-
const inA = countByRule(a);
|
|
67
|
-
const inB = countByRule(b);
|
|
68
|
-
const groupedA = byIdentity(a);
|
|
69
|
-
const groupedB = byIdentity(b);
|
|
70
|
-
const onlyInA = [];
|
|
71
|
-
const onlyInB = [];
|
|
72
|
-
const messageChanged = [];
|
|
73
|
-
for (const identity of [.../* @__PURE__ */ new Set([...groupedA.keys(), ...groupedB.keys()])].toSorted()) {
|
|
74
|
-
const here = groupedA.get(identity) ?? [];
|
|
75
|
-
const there = groupedB.get(identity) ?? [];
|
|
76
|
-
const leftA = missingFrom(here, there);
|
|
77
|
-
const leftB = missingFrom(there, here);
|
|
78
|
-
for (const [index, line] of leftA.entries()) {
|
|
79
|
-
const other = leftB[index];
|
|
80
|
-
if (other === void 0) onlyInA.push(line);
|
|
81
|
-
else messageChanged.push({ a: line, b: other });
|
|
82
|
-
}
|
|
83
|
-
onlyInB.push(...leftB.slice(leftA.length));
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
a,
|
|
87
|
-
b,
|
|
88
|
-
lost: onlyInA.length > 0,
|
|
89
|
-
messageChanged,
|
|
90
|
-
onlyInA,
|
|
91
|
-
onlyInB,
|
|
92
|
-
tally: [.../* @__PURE__ */ new Set([...inA.keys(), ...inB.keys()])].toSorted().map((rule) => ({
|
|
93
|
-
a: inA.get(rule) ?? 0,
|
|
94
|
-
b: inB.get(rule) ?? 0,
|
|
95
|
-
rule
|
|
96
|
-
}))
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
var formatSummary = (parity) => {
|
|
100
|
-
const rows = parity.tally.map(
|
|
101
|
-
(one) => `| \`${one.rule}\` | ${one.a} | ${one.b} | ${one.b - one.a >= 0 ? "+" : ""}${one.b - one.a} |`
|
|
102
|
-
);
|
|
103
|
-
const lost = parity.onlyInA.length === 0 ? "None. Every finding A reported, B reported too.\n" : `${parity.onlyInA.map((line) => `- \`${line}\``).join("\n")}
|
|
104
|
-
`;
|
|
105
|
-
const gained = parity.onlyInB.length === 0 ? "None.\n" : `${parity.onlyInB.map((line) => `- \`${line}\``).join("\n")}
|
|
106
|
-
`;
|
|
107
|
-
const changed = parity.messageChanged.length === 0 ? "None. Every finding both runs made is worded and graded the same.\n" : `${changedLines(parity.messageChanged).map((line) => `- \`${line}\``).join("\n")}
|
|
108
|
-
`;
|
|
109
|
-
return [
|
|
110
|
-
"# findings parity",
|
|
111
|
-
"",
|
|
112
|
-
`- findings A: **${parity.a.length}**`,
|
|
113
|
-
`- findings B: **${parity.b.length}**`,
|
|
114
|
-
`- only in A (lost): **${parity.onlyInA.length}**`,
|
|
115
|
-
`- only in B (gained): **${parity.onlyInB.length}**`,
|
|
116
|
-
`- same finding, changed message or severity: **${parity.messageChanged.length}**`,
|
|
117
|
-
"",
|
|
118
|
-
`**${parity.lost ? "FAIL" : "PASS"}** \u2014 ${parity.lost ? "B lost findings A reported. A rule that fired under A and fires nowhere under B stops the adoption." : "B reported everything A did."}`,
|
|
119
|
-
"",
|
|
120
|
-
"## per rule",
|
|
121
|
-
"",
|
|
122
|
-
"| rule | A | B | delta |",
|
|
123
|
-
"|---|---:|---:|---:|",
|
|
124
|
-
...rows,
|
|
125
|
-
"",
|
|
126
|
-
"## only in A (lost)",
|
|
127
|
-
"",
|
|
128
|
-
lost,
|
|
129
|
-
"## only in B (gained)",
|
|
130
|
-
"",
|
|
131
|
-
gained,
|
|
132
|
-
"## changed (same place, same rule, different message or severity)",
|
|
133
|
-
"",
|
|
134
|
-
"Reported, never counted against B: a reworded message is the same finding, and a rule graded",
|
|
135
|
-
"differently is a fact about the config. Neither reaches the exit code.",
|
|
136
|
-
"",
|
|
137
|
-
changed
|
|
138
|
-
].join("\n");
|
|
139
|
-
};
|
|
140
|
-
var rulesNamedBy = (config) => {
|
|
141
|
-
const parsed = JSON.parse(readFileSync(config, "utf8"));
|
|
142
|
-
return Object.keys(parsed.rules ?? {});
|
|
143
|
-
};
|
|
144
|
-
var ruleIdOf = (line) => {
|
|
145
|
-
const token = RULE_IN_LINE.exec(line)?.[1];
|
|
146
|
-
if (token === void 0) return UNATTRIBUTED;
|
|
147
|
-
const at = token.indexOf("(");
|
|
148
|
-
return at === -1 ? token : `${token.slice(0, at)}/${token.slice(at + 1, -1)}`;
|
|
149
|
-
};
|
|
150
|
-
var MANIFEST_FILE = "manifest.json";
|
|
151
|
-
var manifestOf = (plugin) => ({
|
|
152
|
-
plugin: plugin.meta.name,
|
|
153
|
-
rules: Object.keys(plugin.rules).map((rule) => `${plugin.meta.name}/${rule}`).toSorted()
|
|
154
|
-
});
|
|
155
|
-
var readManifest = (corpus) => {
|
|
156
|
-
const path = join(corpus, MANIFEST_FILE);
|
|
157
|
-
let parsed;
|
|
158
|
-
try {
|
|
159
|
-
parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
160
|
-
} catch (error) {
|
|
161
|
-
throw new ParityError(`could not read ${path}: ${error.message}`);
|
|
162
|
-
}
|
|
163
|
-
const manifest = parsed;
|
|
164
|
-
if (typeof manifest.plugin !== "string" || !Array.isArray(manifest.rules)) {
|
|
165
|
-
throw new ParityError(`${path} names no plugin and no rules \u2014 it cannot scope a reach run`);
|
|
166
|
-
}
|
|
167
|
-
return { plugin: manifest.plugin, rules: manifest.rules };
|
|
168
|
-
};
|
|
169
|
-
var corpusOf = ({
|
|
170
|
-
configA,
|
|
171
|
-
configB,
|
|
172
|
-
corpus,
|
|
173
|
-
oxlint
|
|
174
|
-
}) => {
|
|
175
|
-
const manifest = readManifest(corpus);
|
|
176
|
-
const exercised = new Set(manifest.rules);
|
|
177
|
-
const root = mkdtempSync(join(tmpdir(), "geonosis-corpus-"));
|
|
178
|
-
const here = join(root, "corpus");
|
|
179
|
-
const firedIn = (config, side) => new Set(
|
|
180
|
-
readRun(
|
|
181
|
-
lint({
|
|
182
|
-
config,
|
|
183
|
-
cwd: root,
|
|
184
|
-
extra: ["--no-ignore", "--disable-nested-config"],
|
|
185
|
-
oxlint,
|
|
186
|
-
paths: [here]
|
|
187
|
-
}),
|
|
188
|
-
root,
|
|
189
|
-
side
|
|
190
|
-
).map(ruleIdOf)
|
|
191
|
-
);
|
|
192
|
-
let inA = /* @__PURE__ */ new Set();
|
|
193
|
-
let inB = /* @__PURE__ */ new Set();
|
|
194
|
-
try {
|
|
195
|
-
cpSync(corpus, here, { recursive: true });
|
|
196
|
-
inA = firedIn(configA, "A");
|
|
197
|
-
inB = firedIn(configB, "B");
|
|
198
|
-
} finally {
|
|
199
|
-
rmSync(root, { force: true, recursive: true });
|
|
200
|
-
}
|
|
201
|
-
const configured = [.../* @__PURE__ */ new Set([...rulesNamedBy(configA), ...rulesNamedBy(configB)])].toSorted();
|
|
202
|
-
const reach = configured.filter((rule) => exercised.has(rule)).map((rule) => ({ firedInA: inA.has(rule), firedInB: inB.has(rule), rule }));
|
|
203
|
-
return {
|
|
204
|
-
neither: reach.filter((one) => !one.firedInA && !one.firedInB).map((one) => one.rule),
|
|
205
|
-
outside: configured.filter((rule) => !exercised.has(rule)),
|
|
206
|
-
plugin: manifest.plugin,
|
|
207
|
-
reach
|
|
208
|
-
};
|
|
209
|
-
};
|
|
210
|
-
var formatCorpus = (report) => {
|
|
211
|
-
const rows = report.reach.map(
|
|
212
|
-
(one) => `| \`${one.rule}\` | ${one.firedInA ? "yes" : "NO"} | ${one.firedInB ? "yes" : "NO"} |`
|
|
213
|
-
);
|
|
214
|
-
const outside = report.outside.length === 0 ? "None \u2014 this corpus speaks for every rule the configs enable.\n" : `${report.outside.map((rule) => `- \`${rule}\``).join("\n")}
|
|
215
|
-
`;
|
|
216
|
-
return [
|
|
217
|
-
"# corpus reach",
|
|
218
|
-
"",
|
|
219
|
-
`- rules in scope of this corpus: **${report.reach.length}**`,
|
|
220
|
-
`- fired under neither config: **${report.neither.length}**`,
|
|
221
|
-
`- outside this corpus: **${report.outside.length}**`,
|
|
222
|
-
"",
|
|
223
|
-
report.neither.length === 0 ? "**PASS** \u2014 every in-scope rule has at least one corpus file that fires it." : `**FAIL** \u2014 these rules fire nowhere in the corpus, so nothing shows they reach anything:
|
|
224
|
-
${report.neither.map((rule) => `- \`${rule}\``).join("\n")}`,
|
|
225
|
-
"",
|
|
226
|
-
"## per rule",
|
|
227
|
-
"",
|
|
228
|
-
"| rule | fired under A | fired under B |",
|
|
229
|
-
"|---|---|---|",
|
|
230
|
-
...rows,
|
|
231
|
-
"",
|
|
232
|
-
"## outside this corpus",
|
|
233
|
-
"",
|
|
234
|
-
`Configured rules this corpus never claimed to exercise. It speaks for \`${report.plugin}\` only,`,
|
|
235
|
-
"so it is no evidence either way about these and passes no verdict on them.",
|
|
236
|
-
"",
|
|
237
|
-
outside
|
|
238
|
-
].join("\n");
|
|
239
|
-
};
|
|
240
|
-
var FLAGS = { "--a": "configA", "--b": "configB", "--out": "out", "--oxlint": "oxlint" };
|
|
241
|
-
var CORPUS_FLAG = "--corpus";
|
|
242
|
-
var parseParityArgs = (argv) => {
|
|
243
|
-
const at = argv.indexOf("--");
|
|
244
|
-
const flags = at === -1 ? argv : argv.slice(0, at);
|
|
245
|
-
const paths = at === -1 ? [] : argv.slice(at + 1);
|
|
246
|
-
const read = {};
|
|
247
|
-
let corpus = false;
|
|
248
|
-
let corpusDir;
|
|
249
|
-
for (let index = 0; index < flags.length; index += 1) {
|
|
250
|
-
const flag = flags[index];
|
|
251
|
-
const value = flags[index + 1];
|
|
252
|
-
if (flag === CORPUS_FLAG) {
|
|
253
|
-
corpus = true;
|
|
254
|
-
if (value !== void 0 && !value.startsWith("--")) {
|
|
255
|
-
corpusDir = value;
|
|
256
|
-
index += 1;
|
|
257
|
-
}
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
const name = FLAGS[flag];
|
|
261
|
-
if (name === void 0) throw new Error(`geonosis-lint-parity: unknown argument "${flag}"`);
|
|
262
|
-
if (value === void 0 || value.startsWith("--")) {
|
|
263
|
-
throw new Error(`geonosis-lint-parity: ${flag} needs a value`);
|
|
264
|
-
}
|
|
265
|
-
read[name] = value;
|
|
266
|
-
index += 1;
|
|
267
|
-
}
|
|
268
|
-
if (read.configA === void 0 || read.configB === void 0) {
|
|
269
|
-
throw new Error(
|
|
270
|
-
"geonosis-lint-parity: both --a and --b are required \u2014 one config compares to nothing"
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
return {
|
|
274
|
-
configA: read.configA,
|
|
275
|
-
configB: read.configB,
|
|
276
|
-
corpus,
|
|
277
|
-
...corpusDir === void 0 ? {} : { corpusDir },
|
|
278
|
-
...read.out === void 0 ? {} : { out: read.out },
|
|
279
|
-
...read.oxlint === void 0 ? {} : { oxlint: read.oxlint },
|
|
280
|
-
paths: paths.length === 0 ? ["."] : paths
|
|
281
|
-
};
|
|
282
|
-
};
|
|
283
|
-
var lint = ({
|
|
284
|
-
config,
|
|
285
|
-
cwd,
|
|
286
|
-
extra = [],
|
|
287
|
-
oxlint,
|
|
288
|
-
paths
|
|
289
|
-
}) => {
|
|
290
|
-
const run = spawnSync(oxlint, ["--format=unix", ...extra, "--config", config, ...paths], {
|
|
291
|
-
cwd,
|
|
292
|
-
encoding: "utf8",
|
|
293
|
-
env: { ...process.env, NO_COLOR: "1" },
|
|
294
|
-
maxBuffer: 64 * 1024 * 1024
|
|
295
|
-
});
|
|
296
|
-
if (run.error !== void 0)
|
|
297
|
-
throw new ParityError(`could not run ${oxlint}: ${run.error.message}`);
|
|
298
|
-
return { code: run.status ?? -1, output: `${run.stdout ?? ""}${run.stderr ?? ""}` };
|
|
299
|
-
};
|
|
300
|
-
var parityOf = ({
|
|
301
|
-
configA,
|
|
302
|
-
configB,
|
|
303
|
-
cwd,
|
|
304
|
-
out,
|
|
305
|
-
oxlint,
|
|
306
|
-
paths
|
|
307
|
-
}) => {
|
|
308
|
-
const parity = compareFindings({
|
|
309
|
-
a: readRun(lint({ config: configA, cwd, oxlint, paths }), cwd, "A"),
|
|
310
|
-
b: readRun(lint({ config: configB, cwd, oxlint, paths }), cwd, "B")
|
|
311
|
-
});
|
|
312
|
-
if (out !== void 0) {
|
|
313
|
-
mkdirSync(out, { recursive: true });
|
|
314
|
-
writeFileSync(join(out, "a.txt"), asFile(parity.a));
|
|
315
|
-
writeFileSync(join(out, "b.txt"), asFile(parity.b));
|
|
316
|
-
writeFileSync(join(out, "only-in-a.txt"), asFile(parity.onlyInA));
|
|
317
|
-
writeFileSync(join(out, "only-in-b.txt"), asFile(parity.onlyInB));
|
|
318
|
-
writeFileSync(join(out, "changed.txt"), asFile(changedLines(parity.messageChanged)));
|
|
319
|
-
writeFileSync(join(out, "SUMMARY.md"), formatSummary(parity));
|
|
320
|
-
}
|
|
321
|
-
return parity;
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
export {
|
|
325
|
-
ParityError,
|
|
326
|
-
normaliseFindings,
|
|
327
|
-
readRun,
|
|
328
|
-
compareFindings,
|
|
329
|
-
formatSummary,
|
|
330
|
-
rulesNamedBy,
|
|
331
|
-
ruleIdOf,
|
|
332
|
-
MANIFEST_FILE,
|
|
333
|
-
manifestOf,
|
|
334
|
-
readManifest,
|
|
335
|
-
corpusOf,
|
|
336
|
-
formatCorpus,
|
|
337
|
-
parseParityArgs,
|
|
338
|
-
parityOf
|
|
339
|
-
};
|
package/dist/chunk-RNY5NDH5.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
// src/parity.ts
|
|
2
|
-
import { execFileSync } from "child_process";
|
|
3
|
-
import { mkdirSync, writeFileSync } from "fs";
|
|
4
|
-
import { join } from "path";
|
|
5
|
-
var ANSI = /\[[0-9;]*m/g;
|
|
6
|
-
var SUMMARY_LINE = /^\d+ problems?$/;
|
|
7
|
-
var RULE_IN_LINE = /\[(?:Error|Warning)\/([^\]]+)\]$/;
|
|
8
|
-
var normaliseFindings = (output, cwd) => output.replaceAll(ANSI, "").split("\n").map((line) => line.trim()).filter((line) => line !== "" && !SUMMARY_LINE.test(line)).map((line) => line.replace(`${cwd}/`, "").replace(/^\.\//, "")).toSorted();
|
|
9
|
-
var ruleOf = (line) => RULE_IN_LINE.exec(line)?.[1] ?? "(unattributed)";
|
|
10
|
-
var countByRule = (lines) => {
|
|
11
|
-
const counts = /* @__PURE__ */ new Map();
|
|
12
|
-
for (const line of lines) counts.set(ruleOf(line), (counts.get(ruleOf(line)) ?? 0) + 1);
|
|
13
|
-
return counts;
|
|
14
|
-
};
|
|
15
|
-
var missingFrom = (lines, other) => {
|
|
16
|
-
const remaining = /* @__PURE__ */ new Map();
|
|
17
|
-
for (const line of other) remaining.set(line, (remaining.get(line) ?? 0) + 1);
|
|
18
|
-
return lines.filter((line) => {
|
|
19
|
-
const left = remaining.get(line) ?? 0;
|
|
20
|
-
if (left === 0) return true;
|
|
21
|
-
remaining.set(line, left - 1);
|
|
22
|
-
return false;
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
var compareFindings = ({ a, b }) => {
|
|
26
|
-
const inA = countByRule(a);
|
|
27
|
-
const inB = countByRule(b);
|
|
28
|
-
const onlyInA = missingFrom(a, b);
|
|
29
|
-
return {
|
|
30
|
-
a,
|
|
31
|
-
b,
|
|
32
|
-
lost: onlyInA.length > 0,
|
|
33
|
-
onlyInA,
|
|
34
|
-
onlyInB: missingFrom(b, a),
|
|
35
|
-
tally: [.../* @__PURE__ */ new Set([...inA.keys(), ...inB.keys()])].toSorted().map((rule) => ({
|
|
36
|
-
a: inA.get(rule) ?? 0,
|
|
37
|
-
b: inB.get(rule) ?? 0,
|
|
38
|
-
rule
|
|
39
|
-
}))
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
var formatSummary = (parity) => {
|
|
43
|
-
const rows = parity.tally.map(
|
|
44
|
-
(one) => `| \`${one.rule}\` | ${one.a} | ${one.b} | ${one.b - one.a >= 0 ? "+" : ""}${one.b - one.a} |`
|
|
45
|
-
);
|
|
46
|
-
const lost = parity.onlyInA.length === 0 ? "None. Every finding A reported, B reported too.\n" : `${parity.onlyInA.map((line) => `- \`${line}\``).join("\n")}
|
|
47
|
-
`;
|
|
48
|
-
const gained = parity.onlyInB.length === 0 ? "None.\n" : `${parity.onlyInB.map((line) => `- \`${line}\``).join("\n")}
|
|
49
|
-
`;
|
|
50
|
-
return [
|
|
51
|
-
"# findings parity",
|
|
52
|
-
"",
|
|
53
|
-
`- findings A: **${parity.a.length}**`,
|
|
54
|
-
`- findings B: **${parity.b.length}**`,
|
|
55
|
-
`- only in A (lost): **${parity.onlyInA.length}**`,
|
|
56
|
-
`- only in B (gained): **${parity.onlyInB.length}**`,
|
|
57
|
-
"",
|
|
58
|
-
`**${parity.lost ? "FAIL" : "PASS"}** \u2014 ${parity.lost ? "B lost findings A reported. A rule that fired under A and fires nowhere under B stops the adoption." : "B reported everything A did."}`,
|
|
59
|
-
"",
|
|
60
|
-
"## per rule",
|
|
61
|
-
"",
|
|
62
|
-
"| rule | A | B | delta |",
|
|
63
|
-
"|---|---:|---:|---:|",
|
|
64
|
-
...rows,
|
|
65
|
-
"",
|
|
66
|
-
"## only in A (lost)",
|
|
67
|
-
"",
|
|
68
|
-
lost,
|
|
69
|
-
"## only in B (gained)",
|
|
70
|
-
"",
|
|
71
|
-
gained
|
|
72
|
-
].join("\n");
|
|
73
|
-
};
|
|
74
|
-
var FLAGS = { "--a": "configA", "--b": "configB", "--out": "out", "--oxlint": "oxlint" };
|
|
75
|
-
var parseParityArgs = (argv) => {
|
|
76
|
-
const at = argv.indexOf("--");
|
|
77
|
-
const flags = at === -1 ? argv : argv.slice(0, at);
|
|
78
|
-
const paths = at === -1 ? [] : argv.slice(at + 1);
|
|
79
|
-
const read = {};
|
|
80
|
-
for (let index = 0; index < flags.length; index += 1) {
|
|
81
|
-
const flag = flags[index];
|
|
82
|
-
const name = FLAGS[flag];
|
|
83
|
-
if (name === void 0) throw new Error(`geonosis-lint-parity: unknown argument "${flag}"`);
|
|
84
|
-
const value = flags[index + 1];
|
|
85
|
-
if (value === void 0 || value.startsWith("--")) {
|
|
86
|
-
throw new Error(`geonosis-lint-parity: ${flag} needs a value`);
|
|
87
|
-
}
|
|
88
|
-
read[name] = value;
|
|
89
|
-
index += 1;
|
|
90
|
-
}
|
|
91
|
-
if (read.configA === void 0 || read.configB === void 0) {
|
|
92
|
-
throw new Error(
|
|
93
|
-
"geonosis-lint-parity: both --a and --b are required \u2014 one config compares to nothing"
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
configA: read.configA,
|
|
98
|
-
configB: read.configB,
|
|
99
|
-
...read.out === void 0 ? {} : { out: read.out },
|
|
100
|
-
...read.oxlint === void 0 ? {} : { oxlint: read.oxlint },
|
|
101
|
-
paths: paths.length === 0 ? ["."] : paths
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
var lint = ({
|
|
105
|
-
config,
|
|
106
|
-
cwd,
|
|
107
|
-
oxlint,
|
|
108
|
-
paths
|
|
109
|
-
}) => {
|
|
110
|
-
try {
|
|
111
|
-
return execFileSync(oxlint, ["--format=unix", "--config", config, ...paths], {
|
|
112
|
-
cwd,
|
|
113
|
-
encoding: "utf8",
|
|
114
|
-
env: { ...process.env, NO_COLOR: "1" },
|
|
115
|
-
maxBuffer: 64 * 1024 * 1024,
|
|
116
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
117
|
-
});
|
|
118
|
-
} catch (error) {
|
|
119
|
-
const failed = error;
|
|
120
|
-
if (failed.stdout === void 0) throw error;
|
|
121
|
-
return failed.stdout;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
var parityOf = ({
|
|
125
|
-
configA,
|
|
126
|
-
configB,
|
|
127
|
-
cwd,
|
|
128
|
-
out,
|
|
129
|
-
oxlint,
|
|
130
|
-
paths
|
|
131
|
-
}) => {
|
|
132
|
-
const parity = compareFindings({
|
|
133
|
-
a: normaliseFindings(lint({ config: configA, cwd, oxlint, paths }), cwd),
|
|
134
|
-
b: normaliseFindings(lint({ config: configB, cwd, oxlint, paths }), cwd)
|
|
135
|
-
});
|
|
136
|
-
if (out !== void 0) {
|
|
137
|
-
mkdirSync(out, { recursive: true });
|
|
138
|
-
const asFile = (lines) => lines.length === 0 ? "" : `${lines.join("\n")}
|
|
139
|
-
`;
|
|
140
|
-
writeFileSync(join(out, "a.txt"), asFile(parity.a));
|
|
141
|
-
writeFileSync(join(out, "b.txt"), asFile(parity.b));
|
|
142
|
-
writeFileSync(join(out, "only-in-a.txt"), asFile(parity.onlyInA));
|
|
143
|
-
writeFileSync(join(out, "only-in-b.txt"), asFile(parity.onlyInB));
|
|
144
|
-
writeFileSync(join(out, "SUMMARY.md"), formatSummary(parity));
|
|
145
|
-
}
|
|
146
|
-
return parity;
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
export {
|
|
150
|
-
normaliseFindings,
|
|
151
|
-
compareFindings,
|
|
152
|
-
formatSummary,
|
|
153
|
-
parseParityArgs,
|
|
154
|
-
parityOf
|
|
155
|
-
};
|