@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.
@@ -1,268 +0,0 @@
1
- import {
2
- PLUGIN_NAME
3
- } from "./chunk-BFFWNFJM.js";
4
-
5
- // src/parity.ts
6
- import { spawnSync } from "child_process";
7
- import { cpSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "fs";
8
- import { tmpdir } from "os";
9
- import { join } from "path";
10
- var ANSI = /\[[0-9;]*m/g;
11
- var SUMMARY_COUNT = /^(\d+) problems?$/m;
12
- var RULE_IN_LINE = /\[(?:Error|Warning)\/([^\]]+)\]$/;
13
- var UNIX_FINDING = /^\S[^\n]*:\d+:\d+: .*\[(?:Error|Warning)\/[^\]\n]+\]$/;
14
- var ParityError = class extends Error {
15
- constructor(message) {
16
- super(message);
17
- this.name = "ParityError";
18
- }
19
- };
20
- var normaliseFindings = (output, cwd) => output.replaceAll(ANSI, "").split("\n").map((line) => line.trim().replace(`${cwd}/`, "").replace(/^\.\//, "")).filter((line) => UNIX_FINDING.test(line)).toSorted();
21
- var readRun = ({ code, output }, cwd, side) => {
22
- const findings = normaliseFindings(output, cwd);
23
- const summary = SUMMARY_COUNT.exec(output);
24
- const refuse = (why) => {
25
- throw new ParityError(`config ${side}: ${why}
26
- ${output.trim()}`);
27
- };
28
- if (summary?.[1] !== void 0 && Number(summary[1]) !== findings.length) {
29
- return refuse(`oxlint says ${summary[1]} problems, ${findings.length} lines parsed as findings`);
30
- }
31
- if (findings.length === 0 && code !== 0) {
32
- return refuse(`oxlint exited ${code} without reporting a single finding`);
33
- }
34
- return findings;
35
- };
36
- var UNATTRIBUTED = "(unattributed)";
37
- var ruleOf = (line) => RULE_IN_LINE.exec(line)?.[1] ?? UNATTRIBUTED;
38
- var asFile = (lines) => lines.length === 0 ? "" : `${lines.join("\n")}
39
- `;
40
- var countByRule = (lines) => {
41
- const counts = /* @__PURE__ */ new Map();
42
- for (const line of lines) counts.set(ruleOf(line), (counts.get(ruleOf(line)) ?? 0) + 1);
43
- return counts;
44
- };
45
- var missingFrom = (lines, other) => {
46
- const remaining = /* @__PURE__ */ new Map();
47
- for (const line of other) remaining.set(line, (remaining.get(line) ?? 0) + 1);
48
- return lines.filter((line) => {
49
- const left = remaining.get(line) ?? 0;
50
- if (left === 0) return true;
51
- remaining.set(line, left - 1);
52
- return false;
53
- });
54
- };
55
- var compareFindings = ({ a, b }) => {
56
- const inA = countByRule(a);
57
- const inB = countByRule(b);
58
- const onlyInA = missingFrom(a, b);
59
- return {
60
- a,
61
- b,
62
- lost: onlyInA.length > 0,
63
- onlyInA,
64
- onlyInB: missingFrom(b, a),
65
- tally: [.../* @__PURE__ */ new Set([...inA.keys(), ...inB.keys()])].toSorted().map((rule) => ({
66
- a: inA.get(rule) ?? 0,
67
- b: inB.get(rule) ?? 0,
68
- rule
69
- }))
70
- };
71
- };
72
- var formatSummary = (parity) => {
73
- const rows = parity.tally.map(
74
- (one) => `| \`${one.rule}\` | ${one.a} | ${one.b} | ${one.b - one.a >= 0 ? "+" : ""}${one.b - one.a} |`
75
- );
76
- const lost = parity.onlyInA.length === 0 ? "None. Every finding A reported, B reported too.\n" : `${parity.onlyInA.map((line) => `- \`${line}\``).join("\n")}
77
- `;
78
- const gained = parity.onlyInB.length === 0 ? "None.\n" : `${parity.onlyInB.map((line) => `- \`${line}\``).join("\n")}
79
- `;
80
- return [
81
- "# findings parity",
82
- "",
83
- `- findings A: **${parity.a.length}**`,
84
- `- findings B: **${parity.b.length}**`,
85
- `- only in A (lost): **${parity.onlyInA.length}**`,
86
- `- only in B (gained): **${parity.onlyInB.length}**`,
87
- "",
88
- `**${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."}`,
89
- "",
90
- "## per rule",
91
- "",
92
- "| rule | A | B | delta |",
93
- "|---|---:|---:|---:|",
94
- ...rows,
95
- "",
96
- "## only in A (lost)",
97
- "",
98
- lost,
99
- "## only in B (gained)",
100
- "",
101
- gained
102
- ].join("\n");
103
- };
104
- var rulesNamedBy = (config) => {
105
- const parsed = JSON.parse(readFileSync(config, "utf8"));
106
- return Object.keys(parsed.rules ?? {});
107
- };
108
- var ruleIdOf = (line) => {
109
- const token = RULE_IN_LINE.exec(line)?.[1];
110
- if (token === void 0) return UNATTRIBUTED;
111
- const at = token.indexOf("(");
112
- return at === -1 ? token : `${token.slice(0, at)}/${token.slice(at + 1, -1)}`;
113
- };
114
- var CORPUS_PLUGIN = `${PLUGIN_NAME}/`;
115
- var corpusOf = ({
116
- configA,
117
- configB,
118
- corpus,
119
- oxlint
120
- }) => {
121
- const root = mkdtempSync(join(tmpdir(), "geonosis-corpus-"));
122
- const here = join(root, "corpus");
123
- const firedIn = (config, side) => new Set(
124
- readRun(
125
- lint({
126
- config,
127
- cwd: root,
128
- extra: ["--no-ignore", "--disable-nested-config"],
129
- oxlint,
130
- paths: [here]
131
- }),
132
- root,
133
- side
134
- ).map(ruleIdOf)
135
- );
136
- let inA = /* @__PURE__ */ new Set();
137
- let inB = /* @__PURE__ */ new Set();
138
- try {
139
- cpSync(corpus, here, { recursive: true });
140
- inA = firedIn(configA, "A");
141
- inB = firedIn(configB, "B");
142
- } finally {
143
- rmSync(root, { force: true, recursive: true });
144
- }
145
- const configured = [.../* @__PURE__ */ new Set([...rulesNamedBy(configA), ...rulesNamedBy(configB)])].toSorted();
146
- const reach = configured.filter((rule) => rule.startsWith(CORPUS_PLUGIN)).map((rule) => ({ firedInA: inA.has(rule), firedInB: inB.has(rule), rule }));
147
- return {
148
- neither: reach.filter((one) => !one.firedInA && !one.firedInB).map((one) => one.rule),
149
- outside: configured.filter((rule) => !rule.startsWith(CORPUS_PLUGIN)),
150
- reach
151
- };
152
- };
153
- var formatCorpus = (report) => {
154
- const rows = report.reach.map(
155
- (one) => `| \`${one.rule}\` | ${one.firedInA ? "yes" : "NO"} | ${one.firedInB ? "yes" : "NO"} |`
156
- );
157
- const outside = report.outside.length === 0 ? "None \u2014 every configured rule belongs to this plugin.\n" : `${report.outside.map((rule) => `- \`${rule}\``).join("\n")}
158
- `;
159
- return [
160
- "# corpus reach",
161
- "",
162
- `- rules in scope of this corpus: **${report.reach.length}**`,
163
- `- fired under neither config: **${report.neither.length}**`,
164
- `- outside this corpus: **${report.outside.length}**`,
165
- "",
166
- 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:
167
- ${report.neither.map((rule) => `- \`${rule}\``).join("\n")}`,
168
- "",
169
- "## per rule",
170
- "",
171
- "| rule | fired under A | fired under B |",
172
- "|---|---|---|",
173
- ...rows,
174
- "",
175
- `## outside this corpus`,
176
- "",
177
- `Configured rules from other plugins and the built-ins. This corpus exercises \`${CORPUS_PLUGIN}\``,
178
- "only, so it is no evidence either way about these and passes no verdict on them.",
179
- "",
180
- outside
181
- ].join("\n");
182
- };
183
- var FLAGS = { "--a": "configA", "--b": "configB", "--out": "out", "--oxlint": "oxlint" };
184
- var CORPUS_FLAG = "--corpus";
185
- var parseParityArgs = (argv) => {
186
- const at = argv.indexOf("--");
187
- const flags = (at === -1 ? argv : argv.slice(0, at)).filter((one) => one !== CORPUS_FLAG);
188
- const paths = at === -1 ? [] : argv.slice(at + 1);
189
- const corpus = (at === -1 ? argv : argv.slice(0, at)).includes(CORPUS_FLAG);
190
- const read = {};
191
- for (let index = 0; index < flags.length; index += 1) {
192
- const flag = flags[index];
193
- const name = FLAGS[flag];
194
- if (name === void 0) throw new Error(`geonosis-lint-parity: unknown argument "${flag}"`);
195
- const value = flags[index + 1];
196
- if (value === void 0 || value.startsWith("--")) {
197
- throw new Error(`geonosis-lint-parity: ${flag} needs a value`);
198
- }
199
- read[name] = value;
200
- index += 1;
201
- }
202
- if (read.configA === void 0 || read.configB === void 0) {
203
- throw new Error(
204
- "geonosis-lint-parity: both --a and --b are required \u2014 one config compares to nothing"
205
- );
206
- }
207
- return {
208
- configA: read.configA,
209
- configB: read.configB,
210
- corpus,
211
- ...read.out === void 0 ? {} : { out: read.out },
212
- ...read.oxlint === void 0 ? {} : { oxlint: read.oxlint },
213
- paths: paths.length === 0 ? ["."] : paths
214
- };
215
- };
216
- var lint = ({
217
- config,
218
- cwd,
219
- extra = [],
220
- oxlint,
221
- paths
222
- }) => {
223
- const run = spawnSync(oxlint, ["--format=unix", ...extra, "--config", config, ...paths], {
224
- cwd,
225
- encoding: "utf8",
226
- env: { ...process.env, NO_COLOR: "1" },
227
- maxBuffer: 64 * 1024 * 1024
228
- });
229
- if (run.error !== void 0)
230
- throw new ParityError(`could not run ${oxlint}: ${run.error.message}`);
231
- return { code: run.status ?? -1, output: `${run.stdout ?? ""}${run.stderr ?? ""}` };
232
- };
233
- var parityOf = ({
234
- configA,
235
- configB,
236
- cwd,
237
- out,
238
- oxlint,
239
- paths
240
- }) => {
241
- const parity = compareFindings({
242
- a: readRun(lint({ config: configA, cwd, oxlint, paths }), cwd, "A"),
243
- b: readRun(lint({ config: configB, cwd, oxlint, paths }), cwd, "B")
244
- });
245
- if (out !== void 0) {
246
- mkdirSync(out, { recursive: true });
247
- writeFileSync(join(out, "a.txt"), asFile(parity.a));
248
- writeFileSync(join(out, "b.txt"), asFile(parity.b));
249
- writeFileSync(join(out, "only-in-a.txt"), asFile(parity.onlyInA));
250
- writeFileSync(join(out, "only-in-b.txt"), asFile(parity.onlyInB));
251
- writeFileSync(join(out, "SUMMARY.md"), formatSummary(parity));
252
- }
253
- return parity;
254
- };
255
-
256
- export {
257
- ParityError,
258
- normaliseFindings,
259
- readRun,
260
- compareFindings,
261
- formatSummary,
262
- rulesNamedBy,
263
- ruleIdOf,
264
- corpusOf,
265
- formatCorpus,
266
- parseParityArgs,
267
- parityOf
268
- };
@@ -1,250 +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 ParityError = class extends Error {
11
- constructor(message) {
12
- super(message);
13
- this.name = "ParityError";
14
- }
15
- };
16
- var normaliseFindings = (output, cwd) => output.replaceAll(ANSI, "").split("\n").map((line) => line.trim().replace(`${cwd}/`, "").replace(/^\.\//, "")).filter((line) => UNIX_FINDING.test(line)).toSorted();
17
- var readRun = ({ code, output }, cwd, side) => {
18
- const findings = normaliseFindings(output, cwd);
19
- const summary = SUMMARY_COUNT.exec(output);
20
- const refuse = (why) => {
21
- throw new ParityError(`config ${side}: ${why}
22
- ${output.trim()}`);
23
- };
24
- if (summary?.[1] !== void 0 && Number(summary[1]) !== findings.length) {
25
- return refuse(`oxlint says ${summary[1]} problems, ${findings.length} lines parsed as findings`);
26
- }
27
- if (findings.length === 0 && code !== 0) {
28
- return refuse(`oxlint exited ${code} without reporting a single finding`);
29
- }
30
- return findings;
31
- };
32
- var ruleOf = (line) => RULE_IN_LINE.exec(line)?.[1] ?? "(unattributed)";
33
- var asFile = (lines) => lines.length === 0 ? "" : `${lines.join("\n")}
34
- `;
35
- var countByRule = (lines) => {
36
- const counts = /* @__PURE__ */ new Map();
37
- for (const line of lines) counts.set(ruleOf(line), (counts.get(ruleOf(line)) ?? 0) + 1);
38
- return counts;
39
- };
40
- var missingFrom = (lines, other) => {
41
- const remaining = /* @__PURE__ */ new Map();
42
- for (const line of other) remaining.set(line, (remaining.get(line) ?? 0) + 1);
43
- return lines.filter((line) => {
44
- const left = remaining.get(line) ?? 0;
45
- if (left === 0) return true;
46
- remaining.set(line, left - 1);
47
- return false;
48
- });
49
- };
50
- var compareFindings = ({ a, b }) => {
51
- const inA = countByRule(a);
52
- const inB = countByRule(b);
53
- const onlyInA = missingFrom(a, b);
54
- return {
55
- a,
56
- b,
57
- lost: onlyInA.length > 0,
58
- onlyInA,
59
- onlyInB: missingFrom(b, a),
60
- tally: [.../* @__PURE__ */ new Set([...inA.keys(), ...inB.keys()])].toSorted().map((rule) => ({
61
- a: inA.get(rule) ?? 0,
62
- b: inB.get(rule) ?? 0,
63
- rule
64
- }))
65
- };
66
- };
67
- var formatSummary = (parity) => {
68
- const rows = parity.tally.map(
69
- (one) => `| \`${one.rule}\` | ${one.a} | ${one.b} | ${one.b - one.a >= 0 ? "+" : ""}${one.b - one.a} |`
70
- );
71
- const lost = parity.onlyInA.length === 0 ? "None. Every finding A reported, B reported too.\n" : `${parity.onlyInA.map((line) => `- \`${line}\``).join("\n")}
72
- `;
73
- const gained = parity.onlyInB.length === 0 ? "None.\n" : `${parity.onlyInB.map((line) => `- \`${line}\``).join("\n")}
74
- `;
75
- return [
76
- "# findings parity",
77
- "",
78
- `- findings A: **${parity.a.length}**`,
79
- `- findings B: **${parity.b.length}**`,
80
- `- only in A (lost): **${parity.onlyInA.length}**`,
81
- `- only in B (gained): **${parity.onlyInB.length}**`,
82
- "",
83
- `**${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."}`,
84
- "",
85
- "## per rule",
86
- "",
87
- "| rule | A | B | delta |",
88
- "|---|---:|---:|---:|",
89
- ...rows,
90
- "",
91
- "## only in A (lost)",
92
- "",
93
- lost,
94
- "## only in B (gained)",
95
- "",
96
- gained
97
- ].join("\n");
98
- };
99
- var rulesNamedBy = (config) => {
100
- const parsed = JSON.parse(readFileSync(config, "utf8"));
101
- return Object.keys(parsed.rules ?? {}).map((id) => id.slice(id.indexOf("/") + 1));
102
- };
103
- var nameOf = (rule) => rule.replace(/^.*[(/]/, "").replace(")", "");
104
- var corpusOf = ({
105
- configA,
106
- configB,
107
- corpus,
108
- oxlint
109
- }) => {
110
- const root = mkdtempSync(join(tmpdir(), "geonosis-corpus-"));
111
- const here = join(root, "corpus");
112
- const firedIn = (config, side) => new Set(
113
- readRun(
114
- lint({
115
- config,
116
- cwd: root,
117
- extra: ["--no-ignore", "--disable-nested-config"],
118
- oxlint,
119
- paths: [here]
120
- }),
121
- root,
122
- side
123
- ).map((line) => nameOf(ruleOf(line)))
124
- );
125
- let inA = /* @__PURE__ */ new Set();
126
- let inB = /* @__PURE__ */ new Set();
127
- try {
128
- cpSync(corpus, here, { recursive: true });
129
- inA = firedIn(configA, "A");
130
- inB = firedIn(configB, "B");
131
- } finally {
132
- rmSync(root, { force: true, recursive: true });
133
- }
134
- const configured = [.../* @__PURE__ */ new Set([...rulesNamedBy(configA), ...rulesNamedBy(configB)])].toSorted();
135
- const reach = configured.map((rule) => ({
136
- firedInA: inA.has(rule),
137
- firedInB: inB.has(rule),
138
- rule
139
- }));
140
- return {
141
- neither: reach.filter((one) => !one.firedInA && !one.firedInB).map((one) => one.rule),
142
- reach
143
- };
144
- };
145
- var formatCorpus = (report) => {
146
- const rows = report.reach.map(
147
- (one) => `| \`${one.rule}\` | ${one.firedInA ? "yes" : "NO"} | ${one.firedInB ? "yes" : "NO"} |`
148
- );
149
- return [
150
- "# corpus reach",
151
- "",
152
- `- rules configured: **${report.reach.length}**`,
153
- `- fired under neither config: **${report.neither.length}**`,
154
- "",
155
- report.neither.length === 0 ? "**PASS** \u2014 every configured 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:
156
- ${report.neither.map((rule) => `- \`${rule}\``).join("\n")}`,
157
- "",
158
- "## per rule",
159
- "",
160
- "| rule | fired under A | fired under B |",
161
- "|---|---|---|",
162
- ...rows,
163
- ""
164
- ].join("\n");
165
- };
166
- var FLAGS = { "--a": "configA", "--b": "configB", "--out": "out", "--oxlint": "oxlint" };
167
- var CORPUS_FLAG = "--corpus";
168
- var parseParityArgs = (argv) => {
169
- const at = argv.indexOf("--");
170
- const flags = (at === -1 ? argv : argv.slice(0, at)).filter((one) => one !== CORPUS_FLAG);
171
- const paths = at === -1 ? [] : argv.slice(at + 1);
172
- const corpus = (at === -1 ? argv : argv.slice(0, at)).includes(CORPUS_FLAG);
173
- const read = {};
174
- for (let index = 0; index < flags.length; index += 1) {
175
- const flag = flags[index];
176
- const name = FLAGS[flag];
177
- if (name === void 0) throw new Error(`geonosis-lint-parity: unknown argument "${flag}"`);
178
- const value = flags[index + 1];
179
- if (value === void 0 || value.startsWith("--")) {
180
- throw new Error(`geonosis-lint-parity: ${flag} needs a value`);
181
- }
182
- read[name] = value;
183
- index += 1;
184
- }
185
- if (read.configA === void 0 || read.configB === void 0) {
186
- throw new Error(
187
- "geonosis-lint-parity: both --a and --b are required \u2014 one config compares to nothing"
188
- );
189
- }
190
- return {
191
- configA: read.configA,
192
- configB: read.configB,
193
- corpus,
194
- ...read.out === void 0 ? {} : { out: read.out },
195
- ...read.oxlint === void 0 ? {} : { oxlint: read.oxlint },
196
- paths: paths.length === 0 ? ["."] : paths
197
- };
198
- };
199
- var lint = ({
200
- config,
201
- cwd,
202
- extra = [],
203
- oxlint,
204
- paths
205
- }) => {
206
- const run = spawnSync(oxlint, ["--format=unix", ...extra, "--config", config, ...paths], {
207
- cwd,
208
- encoding: "utf8",
209
- env: { ...process.env, NO_COLOR: "1" },
210
- maxBuffer: 64 * 1024 * 1024
211
- });
212
- if (run.error !== void 0)
213
- throw new ParityError(`could not run ${oxlint}: ${run.error.message}`);
214
- return { code: run.status ?? -1, output: `${run.stdout ?? ""}${run.stderr ?? ""}` };
215
- };
216
- var parityOf = ({
217
- configA,
218
- configB,
219
- cwd,
220
- out,
221
- oxlint,
222
- paths
223
- }) => {
224
- const parity = compareFindings({
225
- a: readRun(lint({ config: configA, cwd, oxlint, paths }), cwd, "A"),
226
- b: readRun(lint({ config: configB, cwd, oxlint, paths }), cwd, "B")
227
- });
228
- if (out !== void 0) {
229
- mkdirSync(out, { recursive: true });
230
- writeFileSync(join(out, "a.txt"), asFile(parity.a));
231
- writeFileSync(join(out, "b.txt"), asFile(parity.b));
232
- writeFileSync(join(out, "only-in-a.txt"), asFile(parity.onlyInA));
233
- writeFileSync(join(out, "only-in-b.txt"), asFile(parity.onlyInB));
234
- writeFileSync(join(out, "SUMMARY.md"), formatSummary(parity));
235
- }
236
- return parity;
237
- };
238
-
239
- export {
240
- ParityError,
241
- normaliseFindings,
242
- readRun,
243
- compareFindings,
244
- formatSummary,
245
- rulesNamedBy,
246
- corpusOf,
247
- formatCorpus,
248
- parseParityArgs,
249
- parityOf
250
- };