@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,228 +0,0 @@
1
- // src/parity.ts
2
- import { spawnSync } from "child_process";
3
- import { mkdirSync, readFileSync, writeFileSync } from "fs";
4
- import { join } from "path";
5
- var ANSI = /\[[0-9;]*m/g;
6
- var SUMMARY_COUNT = /^(\d+) problems?$/m;
7
- var RULE_IN_LINE = /\[(?:Error|Warning)\/([^\]]+)\]$/;
8
- var UNIX_FINDING = /^\S[^\n]*:\d+:\d+: .*\[(?:Error|Warning)\/[^\]\n]+\]$/;
9
- var ParityError = class extends Error {
10
- constructor(message) {
11
- super(message);
12
- this.name = "ParityError";
13
- }
14
- };
15
- var normaliseFindings = (output, cwd) => output.replaceAll(ANSI, "").split("\n").map((line) => line.trim().replace(`${cwd}/`, "").replace(/^\.\//, "")).filter((line) => UNIX_FINDING.test(line)).toSorted();
16
- var readRun = ({ code, output }, cwd, side) => {
17
- const findings = normaliseFindings(output, cwd);
18
- const summary = SUMMARY_COUNT.exec(output);
19
- const refuse = (why) => {
20
- throw new ParityError(`config ${side}: ${why}
21
- ${output.trim()}`);
22
- };
23
- if (summary?.[1] !== void 0 && Number(summary[1]) !== findings.length) {
24
- return refuse(`oxlint says ${summary[1]} problems, ${findings.length} lines parsed as findings`);
25
- }
26
- if (findings.length === 0 && code !== 0) {
27
- return refuse(`oxlint exited ${code} without reporting a single finding`);
28
- }
29
- return findings;
30
- };
31
- var ruleOf = (line) => RULE_IN_LINE.exec(line)?.[1] ?? "(unattributed)";
32
- var asFile = (lines) => lines.length === 0 ? "" : `${lines.join("\n")}
33
- `;
34
- var countByRule = (lines) => {
35
- const counts = /* @__PURE__ */ new Map();
36
- for (const line of lines) counts.set(ruleOf(line), (counts.get(ruleOf(line)) ?? 0) + 1);
37
- return counts;
38
- };
39
- var missingFrom = (lines, other) => {
40
- const remaining = /* @__PURE__ */ new Map();
41
- for (const line of other) remaining.set(line, (remaining.get(line) ?? 0) + 1);
42
- return lines.filter((line) => {
43
- const left = remaining.get(line) ?? 0;
44
- if (left === 0) return true;
45
- remaining.set(line, left - 1);
46
- return false;
47
- });
48
- };
49
- var compareFindings = ({ a, b }) => {
50
- const inA = countByRule(a);
51
- const inB = countByRule(b);
52
- const onlyInA = missingFrom(a, b);
53
- return {
54
- a,
55
- b,
56
- lost: onlyInA.length > 0,
57
- onlyInA,
58
- onlyInB: missingFrom(b, a),
59
- tally: [.../* @__PURE__ */ new Set([...inA.keys(), ...inB.keys()])].toSorted().map((rule) => ({
60
- a: inA.get(rule) ?? 0,
61
- b: inB.get(rule) ?? 0,
62
- rule
63
- }))
64
- };
65
- };
66
- var formatSummary = (parity) => {
67
- const rows = parity.tally.map(
68
- (one) => `| \`${one.rule}\` | ${one.a} | ${one.b} | ${one.b - one.a >= 0 ? "+" : ""}${one.b - one.a} |`
69
- );
70
- const lost = parity.onlyInA.length === 0 ? "None. Every finding A reported, B reported too.\n" : `${parity.onlyInA.map((line) => `- \`${line}\``).join("\n")}
71
- `;
72
- const gained = parity.onlyInB.length === 0 ? "None.\n" : `${parity.onlyInB.map((line) => `- \`${line}\``).join("\n")}
73
- `;
74
- return [
75
- "# findings parity",
76
- "",
77
- `- findings A: **${parity.a.length}**`,
78
- `- findings B: **${parity.b.length}**`,
79
- `- only in A (lost): **${parity.onlyInA.length}**`,
80
- `- only in B (gained): **${parity.onlyInB.length}**`,
81
- "",
82
- `**${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."}`,
83
- "",
84
- "## per rule",
85
- "",
86
- "| rule | A | B | delta |",
87
- "|---|---:|---:|---:|",
88
- ...rows,
89
- "",
90
- "## only in A (lost)",
91
- "",
92
- lost,
93
- "## only in B (gained)",
94
- "",
95
- gained
96
- ].join("\n");
97
- };
98
- var rulesNamedBy = (config) => {
99
- const parsed = JSON.parse(readFileSync(config, "utf8"));
100
- return Object.keys(parsed.rules ?? {}).map((id) => id.slice(id.indexOf("/") + 1));
101
- };
102
- var nameOf = (rule) => rule.replace(/^.*[(/]/, "").replace(")", "");
103
- var corpusOf = ({
104
- configA,
105
- configB,
106
- corpus,
107
- cwd,
108
- oxlint
109
- }) => {
110
- const firedIn = (config, side) => new Set(
111
- readRun(lint({ config, cwd, oxlint, paths: [corpus] }), cwd, side).map(
112
- (line) => nameOf(ruleOf(line))
113
- )
114
- );
115
- const inA = firedIn(configA, "A");
116
- const inB = firedIn(configB, "B");
117
- const configured = [.../* @__PURE__ */ new Set([...rulesNamedBy(configA), ...rulesNamedBy(configB)])].toSorted();
118
- const reach = configured.map((rule) => ({
119
- firedInA: inA.has(rule),
120
- firedInB: inB.has(rule),
121
- rule
122
- }));
123
- return { neither: reach.filter((one) => !one.firedInA && !one.firedInB).map((one) => one.rule), reach };
124
- };
125
- var formatCorpus = (report) => {
126
- const rows = report.reach.map(
127
- (one) => `| \`${one.rule}\` | ${one.firedInA ? "yes" : "NO"} | ${one.firedInB ? "yes" : "NO"} |`
128
- );
129
- return [
130
- "# corpus reach",
131
- "",
132
- `- rules configured: **${report.reach.length}**`,
133
- `- fired under neither config: **${report.neither.length}**`,
134
- "",
135
- 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:
136
- ${report.neither.map((rule) => `- \`${rule}\``).join("\n")}`,
137
- "",
138
- "## per rule",
139
- "",
140
- "| rule | fired under A | fired under B |",
141
- "|---|---|---|",
142
- ...rows,
143
- ""
144
- ].join("\n");
145
- };
146
- var FLAGS = { "--a": "configA", "--b": "configB", "--out": "out", "--oxlint": "oxlint" };
147
- var CORPUS_FLAG = "--corpus";
148
- var parseParityArgs = (argv) => {
149
- const at = argv.indexOf("--");
150
- const flags = (at === -1 ? argv : argv.slice(0, at)).filter((one) => one !== CORPUS_FLAG);
151
- const paths = at === -1 ? [] : argv.slice(at + 1);
152
- const corpus = (at === -1 ? argv : argv.slice(0, at)).includes(CORPUS_FLAG);
153
- const read = {};
154
- for (let index = 0; index < flags.length; index += 1) {
155
- const flag = flags[index];
156
- const name = FLAGS[flag];
157
- if (name === void 0) throw new Error(`geonosis-lint-parity: unknown argument "${flag}"`);
158
- const value = flags[index + 1];
159
- if (value === void 0 || value.startsWith("--")) {
160
- throw new Error(`geonosis-lint-parity: ${flag} needs a value`);
161
- }
162
- read[name] = value;
163
- index += 1;
164
- }
165
- if (read.configA === void 0 || read.configB === void 0) {
166
- throw new Error(
167
- "geonosis-lint-parity: both --a and --b are required \u2014 one config compares to nothing"
168
- );
169
- }
170
- return {
171
- configA: read.configA,
172
- configB: read.configB,
173
- corpus,
174
- ...read.out === void 0 ? {} : { out: read.out },
175
- ...read.oxlint === void 0 ? {} : { oxlint: read.oxlint },
176
- paths: paths.length === 0 ? ["."] : paths
177
- };
178
- };
179
- var lint = ({
180
- config,
181
- cwd,
182
- oxlint,
183
- paths
184
- }) => {
185
- const run = spawnSync(oxlint, ["--format=unix", "--config", config, ...paths], {
186
- cwd,
187
- encoding: "utf8",
188
- env: { ...process.env, NO_COLOR: "1" },
189
- maxBuffer: 64 * 1024 * 1024
190
- });
191
- if (run.error !== void 0) throw new ParityError(`could not run ${oxlint}: ${run.error.message}`);
192
- return { code: run.status ?? -1, output: `${run.stdout ?? ""}${run.stderr ?? ""}` };
193
- };
194
- var parityOf = ({
195
- configA,
196
- configB,
197
- cwd,
198
- out,
199
- oxlint,
200
- paths
201
- }) => {
202
- const parity = compareFindings({
203
- a: readRun(lint({ config: configA, cwd, oxlint, paths }), cwd, "A"),
204
- b: readRun(lint({ config: configB, cwd, oxlint, paths }), cwd, "B")
205
- });
206
- if (out !== void 0) {
207
- mkdirSync(out, { recursive: true });
208
- writeFileSync(join(out, "a.txt"), asFile(parity.a));
209
- writeFileSync(join(out, "b.txt"), asFile(parity.b));
210
- writeFileSync(join(out, "only-in-a.txt"), asFile(parity.onlyInA));
211
- writeFileSync(join(out, "only-in-b.txt"), asFile(parity.onlyInB));
212
- writeFileSync(join(out, "SUMMARY.md"), formatSummary(parity));
213
- }
214
- return parity;
215
- };
216
-
217
- export {
218
- ParityError,
219
- normaliseFindings,
220
- readRun,
221
- compareFindings,
222
- formatSummary,
223
- rulesNamedBy,
224
- corpusOf,
225
- formatCorpus,
226
- parseParityArgs,
227
- parityOf
228
- };
@@ -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 asFile = (lines) => lines.length === 0 ? "" : `${lines.join("\n")}
11
- `;
12
- var countByRule = (lines) => {
13
- const counts = /* @__PURE__ */ new Map();
14
- for (const line of lines) counts.set(ruleOf(line), (counts.get(ruleOf(line)) ?? 0) + 1);
15
- return counts;
16
- };
17
- var missingFrom = (lines, other) => {
18
- const remaining = /* @__PURE__ */ new Map();
19
- for (const line of other) remaining.set(line, (remaining.get(line) ?? 0) + 1);
20
- return lines.filter((line) => {
21
- const left = remaining.get(line) ?? 0;
22
- if (left === 0) return true;
23
- remaining.set(line, left - 1);
24
- return false;
25
- });
26
- };
27
- var compareFindings = ({ a, b }) => {
28
- const inA = countByRule(a);
29
- const inB = countByRule(b);
30
- const onlyInA = missingFrom(a, b);
31
- return {
32
- a,
33
- b,
34
- lost: onlyInA.length > 0,
35
- onlyInA,
36
- onlyInB: missingFrom(b, a),
37
- tally: [.../* @__PURE__ */ new Set([...inA.keys(), ...inB.keys()])].toSorted().map((rule) => ({
38
- a: inA.get(rule) ?? 0,
39
- b: inB.get(rule) ?? 0,
40
- rule
41
- }))
42
- };
43
- };
44
- var formatSummary = (parity) => {
45
- const rows = parity.tally.map(
46
- (one) => `| \`${one.rule}\` | ${one.a} | ${one.b} | ${one.b - one.a >= 0 ? "+" : ""}${one.b - one.a} |`
47
- );
48
- const lost = parity.onlyInA.length === 0 ? "None. Every finding A reported, B reported too.\n" : `${parity.onlyInA.map((line) => `- \`${line}\``).join("\n")}
49
- `;
50
- const gained = parity.onlyInB.length === 0 ? "None.\n" : `${parity.onlyInB.map((line) => `- \`${line}\``).join("\n")}
51
- `;
52
- return [
53
- "# findings parity",
54
- "",
55
- `- findings A: **${parity.a.length}**`,
56
- `- findings B: **${parity.b.length}**`,
57
- `- only in A (lost): **${parity.onlyInA.length}**`,
58
- `- only in B (gained): **${parity.onlyInB.length}**`,
59
- "",
60
- `**${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."}`,
61
- "",
62
- "## per rule",
63
- "",
64
- "| rule | A | B | delta |",
65
- "|---|---:|---:|---:|",
66
- ...rows,
67
- "",
68
- "## only in A (lost)",
69
- "",
70
- lost,
71
- "## only in B (gained)",
72
- "",
73
- gained
74
- ].join("\n");
75
- };
76
- var FLAGS = { "--a": "configA", "--b": "configB", "--out": "out", "--oxlint": "oxlint" };
77
- var parseParityArgs = (argv) => {
78
- const at = argv.indexOf("--");
79
- const flags = at === -1 ? argv : argv.slice(0, at);
80
- const paths = at === -1 ? [] : argv.slice(at + 1);
81
- const read = {};
82
- for (let index = 0; index < flags.length; index += 1) {
83
- const flag = flags[index];
84
- const name = FLAGS[flag];
85
- if (name === void 0) throw new Error(`geonosis-lint-parity: unknown argument "${flag}"`);
86
- const value = flags[index + 1];
87
- if (value === void 0 || value.startsWith("--")) {
88
- throw new Error(`geonosis-lint-parity: ${flag} needs a value`);
89
- }
90
- read[name] = value;
91
- index += 1;
92
- }
93
- if (read.configA === void 0 || read.configB === void 0) {
94
- throw new Error(
95
- "geonosis-lint-parity: both --a and --b are required \u2014 one config compares to nothing"
96
- );
97
- }
98
- return {
99
- configA: read.configA,
100
- configB: read.configB,
101
- ...read.out === void 0 ? {} : { out: read.out },
102
- ...read.oxlint === void 0 ? {} : { oxlint: read.oxlint },
103
- paths: paths.length === 0 ? ["."] : paths
104
- };
105
- };
106
- var lint = ({
107
- config,
108
- cwd,
109
- oxlint,
110
- paths
111
- }) => {
112
- try {
113
- return execFileSync(oxlint, ["--format=unix", "--config", config, ...paths], {
114
- cwd,
115
- encoding: "utf8",
116
- env: { ...process.env, NO_COLOR: "1" },
117
- maxBuffer: 64 * 1024 * 1024,
118
- stdio: ["ignore", "pipe", "pipe"]
119
- });
120
- } catch (error) {
121
- const failed = error;
122
- if (failed.stdout === void 0) throw error;
123
- return failed.stdout;
124
- }
125
- };
126
- var parityOf = ({
127
- configA,
128
- configB,
129
- cwd,
130
- out,
131
- oxlint,
132
- paths
133
- }) => {
134
- const parity = compareFindings({
135
- a: normaliseFindings(lint({ config: configA, cwd, oxlint, paths }), cwd),
136
- b: normaliseFindings(lint({ config: configB, cwd, oxlint, paths }), cwd)
137
- });
138
- if (out !== void 0) {
139
- mkdirSync(out, { recursive: true });
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
- };
@@ -1,83 +0,0 @@
1
- // src/presets.ts
2
- var FRONTEND = [
3
- "atom-no-deps",
4
- "cell-must-be-stateful",
5
- "cell-must-not-compose-cell",
6
- "cell-no-tissues",
7
- "cells-folder-index-is-barrel",
8
- "compound-must-be-stateless",
9
- "compound-no-stores",
10
- "effect-hook-naming",
11
- "molecule-atoms-only",
12
- "molecule-must-compose",
13
- "next-route-segment-is-thin-delegate",
14
- "no-brand-names",
15
- "no-card-shaped-div",
16
- "no-cross-feature-stores",
17
- "no-duplicate-jsx-patterns",
18
- "no-hook-in-component-disguise",
19
- "no-inert-hidden-jsx",
20
- "no-inline-data-in-jsx",
21
- "no-invalid-feature-folders",
22
- "no-logic-in-component-files",
23
- "no-raw-html-atoms",
24
- "no-react-namespace",
25
- "no-renamed-html-props",
26
- "no-render-prop-reader",
27
- "no-trivial-wrapper-component",
28
- "no-ts-in-bio-folders",
29
- "no-type-definitions-in-components",
30
- "organelle-dependency",
31
- "organelle-single-source",
32
- "tissue-must-compose",
33
- "tissue-no-data-props",
34
- "tissue-no-hooks",
35
- "tissue-no-organelles",
36
- "tissue-no-stores",
37
- "zustand-v5-best-practices"
38
- ];
39
- var BACKEND_WORKFLOWS = [
40
- "constants-in-constants-file",
41
- "dialect-through-the-seam",
42
- "document-sagas-are-generic",
43
- "documents-share-one-table",
44
- "no-orm-outside-db",
45
- "no-raw-sql-outside-allowed",
46
- "no-void-port",
47
- "queue-loop-is-the-library",
48
- "ssot-no-inline-facts",
49
- "ssot-no-process-env",
50
- "tables-declare-their-plane",
51
- "time-through-the-door"
52
- ];
53
- var BACKEND_D1 = ["no-d1-transaction", "worker-handles-are-scoped"];
54
- var BACKEND_MEDUSA = ["store-route-scopes-tenant-data"];
55
- var TENANT_SCOPING = [
56
- "queries-require-org-scope",
57
- "store-route-scopes-tenant-data",
58
- "tables-declare-their-plane",
59
- "tenant-tables-carry-org-id"
60
- ];
61
- var RULE_PREFIX = "biological-architecture";
62
- var asRules = (names) => Object.fromEntries(names.map((name) => [`${RULE_PREFIX}/${name}`, "error"]));
63
- var COMMENT_CEILING = {
64
- rules: {
65
- ...asRules(["max-comment-density"]),
66
- "capitalized-comments": "error"
67
- }
68
- };
69
- var PRESETS = {
70
- "backend-d1": { rules: asRules(BACKEND_D1) },
71
- "backend-medusa": { rules: asRules(BACKEND_MEDUSA) },
72
- "backend-workflows": { rules: asRules(BACKEND_WORKFLOWS) },
73
- "comment-ceiling": COMMENT_CEILING,
74
- frontend: { rules: asRules(FRONTEND) },
75
- recommended: { rules: asRules(FRONTEND) },
76
- "tenant-scoping": { rules: asRules(TENANT_SCOPING) }
77
- };
78
- var rulesOfPreset = (preset) => Object.keys(PRESETS[preset].rules).filter((id) => id.startsWith(`${RULE_PREFIX}/`)).map((id) => id.slice(RULE_PREFIX.length + 1));
79
-
80
- export {
81
- PRESETS,
82
- rulesOfPreset
83
- };