@geonosis/lint-parity 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/LICENSE +202 -0
- package/README.md +118 -0
- package/bin/geonosis-lint-parity.mjs +4 -0
- package/dist/chunk-OLCJQ6JC.js +339 -0
- package/dist/index.d.ts +138 -0
- package/dist/index.js +32 -0
- package/dist/parity-cli.js +83 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# @geonosis/lint-parity
|
|
2
|
+
|
|
3
|
+
A repo does not delete its vendored copy of a lint plugin because the version numbers match. It
|
|
4
|
+
deletes it when the **findings** match: same tree, same rule ids, two configs, and a diff.
|
|
5
|
+
`geonosis-lint-parity` is that diff — and, before it, the answer to whether either config's rules
|
|
6
|
+
reach anything at all.
|
|
7
|
+
|
|
8
|
+
It knows no rule names and no plugin. Two oxlint configs and a tree are the whole input; a corpus,
|
|
9
|
+
when there is one, arrives as a directory whose own `manifest.json` says which rules it can speak
|
|
10
|
+
for. So it checks any plugin's adoption, including plugins it was never shipped beside.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add -D @geonosis/lint-parity oxlint
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
geonosis-lint-parity --a <config-a.json> --b <config-b.json> [--oxlint <path>] [--out <dir>] -- <paths…>
|
|
20
|
+
geonosis-lint-parity --corpus <dir> --a <config-a.json> --b <config-b.json> [--out <dir>]
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Write both configs inside the workspace being linted** — `<ws>/.oxlintrc.parity-a.json`, deleted
|
|
24
|
+
afterwards — or name the plugin by absolute path in `jsPlugins`. oxlint resolves a `jsPlugins`
|
|
25
|
+
specifier relative to the **config file's** directory, not the working directory, so a config
|
|
26
|
+
written to a temp dir cannot find a plugin installed in the workspace: it fails with
|
|
27
|
+
`Cannot find module '@…/plugin'`, and the tool correctly refuses with
|
|
28
|
+
`config A: oxlint exited 1 without reporting a single finding`.
|
|
29
|
+
|
|
30
|
+
`--oxlint` overrides the binary; by default it walks up from the working directory for
|
|
31
|
+
`node_modules/.bin/oxlint`, so the comparison runs under the consumer's own linter rather than one
|
|
32
|
+
`npx` might fetch.
|
|
33
|
+
|
|
34
|
+
## Step 0 — reach, before parity
|
|
35
|
+
|
|
36
|
+
Parity between two configs that both do nothing is perfect parity. In one repo 34 of 51 configured
|
|
37
|
+
rules fired nowhere in any corpus it had: 34 rules a consumer would inherit as claims nothing could
|
|
38
|
+
check. `--corpus` answers that directly.
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
geonosis-lint-parity \
|
|
42
|
+
--corpus node_modules/@geonosis/oxlint-plugin-biological-architecture/corpus \
|
|
43
|
+
--a oxlintrc.fork.json --b oxlintrc.published.json --out proofs/reach
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Both configs run over the corpus — copied to a temp root first, so neither a `.gitignore` nor
|
|
47
|
+
oxlint's `node_modules` skip can quietly turn "every rule fired nowhere" into the answer. It prints
|
|
48
|
+
a fired-under-A / fired-under-B row per in-scope rule and **exits 1 when one fires under neither**.
|
|
49
|
+
`--out` writes `CORPUS.md`.
|
|
50
|
+
|
|
51
|
+
**The directory is required.** This package ships no corpus, because a corpus is one plugin's
|
|
52
|
+
evidence: one deliberately broken file per rule, and a `manifest.json` naming the rules it therefore
|
|
53
|
+
speaks for. A rule the manifest does not name — another plugin's, one of oxlint's built-ins — is
|
|
54
|
+
listed under **outside this corpus** and gets no verdict. Judging those would fail every real config
|
|
55
|
+
for saying nothing.
|
|
56
|
+
|
|
57
|
+
A plugin generates its manifest from its own rules export, so a rule cannot be added and forgotten
|
|
58
|
+
in the list of what the corpus is evidence about:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { manifestOf, MANIFEST_FILE } from '@geonosis/lint-parity'
|
|
62
|
+
|
|
63
|
+
writeFileSync(join(corpus, MANIFEST_FILE), `${JSON.stringify(manifestOf(plugin), null, 2)}\n`)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Then parity
|
|
67
|
+
|
|
68
|
+
It runs oxlint twice with `--format=unix` over the same paths, strips the working-directory prefix,
|
|
69
|
+
sorts, and prints the two counts, `only in A`, `only in B` and a per-rule tally. **It exits 1 when
|
|
70
|
+
`only in A` is non-empty** — a finding the old config caught and the new one does not. New findings
|
|
71
|
+
are what an upgrade is for; lost ones stop the adoption. `--out` writes `a.txt`, `b.txt`,
|
|
72
|
+
`only-in-a.txt`, `only-in-b.txt`, `changed.txt` and `SUMMARY.md` for the proof file.
|
|
73
|
+
|
|
74
|
+
**A finding is identified by where it is and which rule found it — `path:line:col` plus
|
|
75
|
+
`plugin(rule)`.** The message is not part of it, and neither is the severity. A release that only
|
|
76
|
+
rewords a rule's message would otherwise show as one finding lost and one gained, and stop an
|
|
77
|
+
adoption over a sentence. Those pair up instead under **changed**, reported in full and never
|
|
78
|
+
reaching the exit code; a severity change lands there too, because that is a fact about the config
|
|
79
|
+
rather than a rule that stopped firing.
|
|
80
|
+
|
|
81
|
+
**A run it cannot read is an error, never a number.** oxlint exits 1 both when it reported findings
|
|
82
|
+
and when it never linted a file at all — a rule name it does not know, options a rule has no schema
|
|
83
|
+
for, a plugin it could not load. All three print a paragraph and no findings, and "0 findings" on
|
|
84
|
+
one side reads as agreement with the other. A summary counting findings no line accounts for, or a
|
|
85
|
+
non-zero exit with nothing readable on it, stops the run.
|
|
86
|
+
|
|
87
|
+
**Fork vs published**, before deleting a vendored copy — two configs identical but for `jsPlugins`:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
geonosis-lint-parity \
|
|
91
|
+
--a oxlintrc.fork.json --b oxlintrc.published.json \
|
|
92
|
+
--out proofs/adoption-parity \
|
|
93
|
+
-- apps packages
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**Version vs version**, as a release check — the same config, pointing first at the installed
|
|
97
|
+
version and then at a local build, by absolute path:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
geonosis-lint-parity \
|
|
101
|
+
--a oxlintrc.old.json --b oxlintrc.new.json \
|
|
102
|
+
--out proofs/parity-old-vs-new \
|
|
103
|
+
-- apps packages
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Programmatic use
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { compareFindings, corpusOf, normaliseFindings, parityOf, readRun } from '@geonosis/lint-parity'
|
|
110
|
+
|
|
111
|
+
const parity = parityOf({ configA, configB, cwd, oxlint, paths: ['apps', 'packages'] })
|
|
112
|
+
process.exit(parity.lost ? 1 : 0)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
`parityOf` and `corpusOf` spawn the binary; `normaliseFindings`, `readRun` and `compareFindings` are
|
|
116
|
+
pure and take output a run already produced.
|
|
117
|
+
|
|
118
|
+
Apache-2.0.
|
|
@@ -0,0 +1,339 @@
|
|
|
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;
|
|
248
|
+
for (let index = 0; index < flags.length; index += 1) {
|
|
249
|
+
const flag = flags[index];
|
|
250
|
+
const value = flags[index + 1];
|
|
251
|
+
if (flag === CORPUS_FLAG) {
|
|
252
|
+
if (value === void 0 || value.startsWith("--")) {
|
|
253
|
+
throw new Error(
|
|
254
|
+
`geonosis-lint-parity: ${CORPUS_FLAG} needs a directory \u2014 this tool ships no corpus of its own, so name the one a plugin ships`
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
corpus = value;
|
|
258
|
+
index += 1;
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
const name = FLAGS[flag];
|
|
262
|
+
if (name === void 0) throw new Error(`geonosis-lint-parity: unknown argument "${flag}"`);
|
|
263
|
+
if (value === void 0 || value.startsWith("--")) {
|
|
264
|
+
throw new Error(`geonosis-lint-parity: ${flag} needs a value`);
|
|
265
|
+
}
|
|
266
|
+
read[name] = value;
|
|
267
|
+
index += 1;
|
|
268
|
+
}
|
|
269
|
+
if (read.configA === void 0 || read.configB === void 0) {
|
|
270
|
+
throw new Error(
|
|
271
|
+
"geonosis-lint-parity: both --a and --b are required \u2014 one config compares to nothing"
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
return {
|
|
275
|
+
configA: read.configA,
|
|
276
|
+
configB: read.configB,
|
|
277
|
+
...corpus === void 0 ? {} : { corpus },
|
|
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/index.d.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/** A run that could not be read. Never a number — 0 findings against 0 findings is a PASS. */
|
|
2
|
+
declare class ParityError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
type RuleTally = {
|
|
6
|
+
a: number;
|
|
7
|
+
b: number;
|
|
8
|
+
rule: string;
|
|
9
|
+
};
|
|
10
|
+
/** One finding both runs made in the same place, worded — or graded — differently. */
|
|
11
|
+
type MessageChange = {
|
|
12
|
+
a: string;
|
|
13
|
+
b: string;
|
|
14
|
+
};
|
|
15
|
+
type Parity = {
|
|
16
|
+
a: string[];
|
|
17
|
+
b: string[];
|
|
18
|
+
/** True when A found something B did not — the only failure this tool has. */
|
|
19
|
+
lost: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Same place, same rule, different message or severity. Reported, never counted as loss: every
|
|
22
|
+
* release copy-edits a rule's wording, and a diff of whole lines called each one a finding lost
|
|
23
|
+
* AND a finding gained — a stopped adoption over a sentence.
|
|
24
|
+
*/
|
|
25
|
+
messageChanged: MessageChange[];
|
|
26
|
+
onlyInA: string[];
|
|
27
|
+
onlyInB: string[];
|
|
28
|
+
tally: RuleTally[];
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* One run's finding lines, with the root they were linted from removed and sorted. Both are what
|
|
32
|
+
* make two runs comparable: absolute paths differ between checkouts, and oxlint's file order is a
|
|
33
|
+
* thread-scheduling detail, not a finding.
|
|
34
|
+
*/
|
|
35
|
+
declare const normaliseFindings: (output: string, cwd: string) => string[];
|
|
36
|
+
/**
|
|
37
|
+
* The findings of one run, or a refusal to guess. oxlint exits 1 both when it reported errors and
|
|
38
|
+
* when it never linted a file at all — a rule name it does not know, options a rule has no schema
|
|
39
|
+
* for, a plugin it could not load. All three print a paragraph and no findings, and "0 findings" on
|
|
40
|
+
* one side of a parity run reads as agreement with the other. So: a summary counting findings no
|
|
41
|
+
* line accounts for, or a non-zero exit with nothing readable on it, is an error, not a count.
|
|
42
|
+
*/
|
|
43
|
+
declare const readRun: ({ code, output }: {
|
|
44
|
+
code: number;
|
|
45
|
+
output: string;
|
|
46
|
+
}, cwd: string, side: string) => string[];
|
|
47
|
+
declare const compareFindings: ({ a, b }: {
|
|
48
|
+
a: string[];
|
|
49
|
+
b: string[];
|
|
50
|
+
}) => Parity;
|
|
51
|
+
declare const formatSummary: (parity: Parity) => string;
|
|
52
|
+
type RuleReach = {
|
|
53
|
+
firedInA: boolean;
|
|
54
|
+
firedInB: boolean;
|
|
55
|
+
rule: string;
|
|
56
|
+
};
|
|
57
|
+
type CorpusReport = {
|
|
58
|
+
/** Rules no file in the corpus fires under either config — rules shipping with no evidence. */
|
|
59
|
+
neither: string[];
|
|
60
|
+
/**
|
|
61
|
+
* Configured rules the corpus never claimed to exercise — other plugins, the built-ins. Reported,
|
|
62
|
+
* never judged: a tree of one deliberately broken file per rule of ONE plugin is not evidence
|
|
63
|
+
* about anybody else's rule, and a verdict on one would be a guess.
|
|
64
|
+
*/
|
|
65
|
+
outside: string[];
|
|
66
|
+
/** The plugin the corpus declared itself to speak for. */
|
|
67
|
+
plugin: string;
|
|
68
|
+
reach: RuleReach[];
|
|
69
|
+
};
|
|
70
|
+
/** The rule ids an oxlint config enables, exactly as it wrote them — plugin prefix included. */
|
|
71
|
+
declare const rulesNamedBy: (config: string) => string[];
|
|
72
|
+
/**
|
|
73
|
+
* The plugin-qualified id behind a finding's `plugin(rule)` token, in the `plugin/rule` shape a
|
|
74
|
+
* config names it by. Prefix included on purpose: `typescript(no-unused-vars)` is a different rule
|
|
75
|
+
* from `biological-architecture(no-unused-vars)`, and matching on the bare name would let either
|
|
76
|
+
* one stand as evidence for the other.
|
|
77
|
+
*/
|
|
78
|
+
declare const ruleIdOf: (line: string) => string;
|
|
79
|
+
declare const MANIFEST_FILE = "manifest.json";
|
|
80
|
+
/** What a corpus declares about itself: whose rules it exercises, and which ones. */
|
|
81
|
+
type CorpusManifest = {
|
|
82
|
+
plugin: string;
|
|
83
|
+
rules: string[];
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* The manifest for a plugin, off the plugin itself. A plugin's corpus build writes what this
|
|
87
|
+
* returns beside its copied fixture tree — derived, never hand-maintained, so a rule cannot be
|
|
88
|
+
* added to the plugin and forgotten in the list of what the corpus is evidence about.
|
|
89
|
+
*/
|
|
90
|
+
declare const manifestOf: (plugin: {
|
|
91
|
+
meta: {
|
|
92
|
+
name: string;
|
|
93
|
+
};
|
|
94
|
+
rules: Record<string, unknown>;
|
|
95
|
+
}) => CorpusManifest;
|
|
96
|
+
/**
|
|
97
|
+
* A corpus says which rules it can speak for; nothing here infers it. That is what keeps the tool
|
|
98
|
+
* general: point `--corpus` at another plugin's tree and the scope moves with it, rather than a
|
|
99
|
+
* prefix welded into this file deciding what counts.
|
|
100
|
+
*/
|
|
101
|
+
declare const readManifest: (corpus: string) => CorpusManifest;
|
|
102
|
+
/**
|
|
103
|
+
* Reach, not parity: which of the configured rules any file in the corpus actually fires. A rule
|
|
104
|
+
* that fires nowhere is a rule nobody has evidence for — during.day shipped 34 of them, and a
|
|
105
|
+
* consumer inherits every one of those as a claim it cannot check. The corpus is the evidence, and
|
|
106
|
+
* `neither` is the list that has to stay empty.
|
|
107
|
+
*/
|
|
108
|
+
declare const corpusOf: ({ configA, configB, corpus, oxlint, }: {
|
|
109
|
+
configA: string;
|
|
110
|
+
configB: string;
|
|
111
|
+
corpus: string;
|
|
112
|
+
oxlint: string;
|
|
113
|
+
}) => CorpusReport;
|
|
114
|
+
declare const formatCorpus: (report: CorpusReport) => string;
|
|
115
|
+
type ParityArgs = {
|
|
116
|
+
configA: string;
|
|
117
|
+
configB: string;
|
|
118
|
+
/**
|
|
119
|
+
* The reach corpus to run over instead of a tree, reporting reach instead of parity. Absent means
|
|
120
|
+
* no corpus run: this tool ships none of its own, because a corpus is one plugin's evidence and a
|
|
121
|
+
* default would weld this tool to whichever plugin happened to be beside it.
|
|
122
|
+
*/
|
|
123
|
+
corpus?: string;
|
|
124
|
+
out?: string;
|
|
125
|
+
oxlint?: string;
|
|
126
|
+
paths: string[];
|
|
127
|
+
};
|
|
128
|
+
declare const parseParityArgs: (argv: string[]) => ParityArgs;
|
|
129
|
+
declare const parityOf: ({ configA, configB, cwd, out, oxlint, paths, }: {
|
|
130
|
+
configA: string;
|
|
131
|
+
configB: string;
|
|
132
|
+
cwd: string;
|
|
133
|
+
out?: string;
|
|
134
|
+
oxlint: string;
|
|
135
|
+
paths: string[];
|
|
136
|
+
}) => Parity;
|
|
137
|
+
|
|
138
|
+
export { type CorpusManifest, type CorpusReport, MANIFEST_FILE, type MessageChange, type Parity, type ParityArgs, ParityError, type RuleReach, type RuleTally, compareFindings, corpusOf, formatCorpus, formatSummary, manifestOf, normaliseFindings, parityOf, parseParityArgs, readManifest, readRun, ruleIdOf, rulesNamedBy };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MANIFEST_FILE,
|
|
3
|
+
ParityError,
|
|
4
|
+
compareFindings,
|
|
5
|
+
corpusOf,
|
|
6
|
+
formatCorpus,
|
|
7
|
+
formatSummary,
|
|
8
|
+
manifestOf,
|
|
9
|
+
normaliseFindings,
|
|
10
|
+
parityOf,
|
|
11
|
+
parseParityArgs,
|
|
12
|
+
readManifest,
|
|
13
|
+
readRun,
|
|
14
|
+
ruleIdOf,
|
|
15
|
+
rulesNamedBy
|
|
16
|
+
} from "./chunk-OLCJQ6JC.js";
|
|
17
|
+
export {
|
|
18
|
+
MANIFEST_FILE,
|
|
19
|
+
ParityError,
|
|
20
|
+
compareFindings,
|
|
21
|
+
corpusOf,
|
|
22
|
+
formatCorpus,
|
|
23
|
+
formatSummary,
|
|
24
|
+
manifestOf,
|
|
25
|
+
normaliseFindings,
|
|
26
|
+
parityOf,
|
|
27
|
+
parseParityArgs,
|
|
28
|
+
readManifest,
|
|
29
|
+
readRun,
|
|
30
|
+
ruleIdOf,
|
|
31
|
+
rulesNamedBy
|
|
32
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
corpusOf,
|
|
3
|
+
formatCorpus,
|
|
4
|
+
formatSummary,
|
|
5
|
+
parityOf,
|
|
6
|
+
parseParityArgs
|
|
7
|
+
} from "./chunk-OLCJQ6JC.js";
|
|
8
|
+
|
|
9
|
+
// src/parity-cli.ts
|
|
10
|
+
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
11
|
+
import { dirname, join, resolve } from "path";
|
|
12
|
+
var USAGE = `geonosis-lint-parity --a <config-a.json> --b <config-b.json> [--oxlint <path>] [--out <dir>] -- <paths\u2026>
|
|
13
|
+
geonosis-lint-parity --corpus <dir> --a <config-a.json> --b <config-b.json> [--out <dir>]
|
|
14
|
+
|
|
15
|
+
Runs oxlint twice over the same paths under two configs and diffs the findings. Exits 1 when a
|
|
16
|
+
finding config A reported is missing under config B \u2014 a rule that fired before and fires nowhere
|
|
17
|
+
now is the adoption stopping, whatever the version numbers say.
|
|
18
|
+
|
|
19
|
+
--corpus runs both configs over a reach corpus \u2014 one file per rule that the rule must fire on \u2014
|
|
20
|
+
and exits 1 when a rule the corpus claims to exercise fires under NEITHER. Run it first: a rule
|
|
21
|
+
with no reach evidence reports parity with every other rule that also does nothing. The directory
|
|
22
|
+
is required: this tool ships no corpus, because a corpus is one plugin's evidence. Point it at the
|
|
23
|
+
one a plugin ships, e.g. node_modules/<plugin>/corpus. A corpus names the rules it speaks for in
|
|
24
|
+
its own manifest.json, and rules outside that list are reported unjudged.
|
|
25
|
+
|
|
26
|
+
oxlint resolves a jsPlugins specifier relative to the CONFIG FILE's directory, not the working
|
|
27
|
+
directory. Write both configs INSIDE the workspace being linted, or name the plugin by absolute
|
|
28
|
+
path \u2014 a config in a temp dir cannot find a plugin installed in the workspace, and the run is
|
|
29
|
+
refused rather than counted as zero findings.`;
|
|
30
|
+
var resolveOxlint = (from) => {
|
|
31
|
+
let dir = from;
|
|
32
|
+
for (; ; ) {
|
|
33
|
+
const bin = resolve(dir, "node_modules/.bin/oxlint");
|
|
34
|
+
if (existsSync(bin)) return bin;
|
|
35
|
+
const parent = dirname(dir);
|
|
36
|
+
if (parent === dir) return "oxlint";
|
|
37
|
+
dir = parent;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var main = () => {
|
|
41
|
+
const argv = process.argv.slice(2);
|
|
42
|
+
if (argv.includes("--help") || argv.includes("-h") || argv.length === 0) {
|
|
43
|
+
process.stdout.write(`${USAGE}
|
|
44
|
+
`);
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
const args = parseParityArgs(argv);
|
|
48
|
+
const cwd = process.cwd();
|
|
49
|
+
const configA = resolve(cwd, args.configA);
|
|
50
|
+
const configB = resolve(cwd, args.configB);
|
|
51
|
+
const oxlint = args.oxlint ?? resolveOxlint(cwd);
|
|
52
|
+
if (args.corpus !== void 0) {
|
|
53
|
+
const corpus = resolve(cwd, args.corpus);
|
|
54
|
+
const report = corpusOf({ configA, configB, corpus, oxlint });
|
|
55
|
+
const text = formatCorpus(report);
|
|
56
|
+
process.stdout.write(`${text}
|
|
57
|
+
`);
|
|
58
|
+
if (args.out !== void 0) {
|
|
59
|
+
const out = resolve(cwd, args.out);
|
|
60
|
+
mkdirSync(out, { recursive: true });
|
|
61
|
+
writeFileSync(join(out, "CORPUS.md"), text);
|
|
62
|
+
}
|
|
63
|
+
return report.neither.length > 0 ? 1 : 0;
|
|
64
|
+
}
|
|
65
|
+
const parity = parityOf({
|
|
66
|
+
configA,
|
|
67
|
+
configB,
|
|
68
|
+
cwd,
|
|
69
|
+
...args.out === void 0 ? {} : { out: resolve(cwd, args.out) },
|
|
70
|
+
oxlint,
|
|
71
|
+
paths: args.paths
|
|
72
|
+
});
|
|
73
|
+
process.stdout.write(`${formatSummary(parity)}
|
|
74
|
+
`);
|
|
75
|
+
return parity.lost ? 1 : 0;
|
|
76
|
+
};
|
|
77
|
+
try {
|
|
78
|
+
process.exit(main());
|
|
79
|
+
} catch (error) {
|
|
80
|
+
process.stderr.write(`${error.message}
|
|
81
|
+
`);
|
|
82
|
+
process.exit(2);
|
|
83
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@geonosis/lint-parity",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Findings parity and rule reach over any two oxlint configs — the diff a fork is deleted on.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"oxlint",
|
|
7
|
+
"lint",
|
|
8
|
+
"parity",
|
|
9
|
+
"migration",
|
|
10
|
+
"adoption",
|
|
11
|
+
"corpus",
|
|
12
|
+
"ci"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/microcompanies/geonosis/tree/main/packages/lint-parity",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/microcompanies/geonosis.git",
|
|
18
|
+
"directory": "packages/lint-parity"
|
|
19
|
+
},
|
|
20
|
+
"license": "Apache-2.0",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"bin": {
|
|
24
|
+
"geonosis-lint-parity": "bin/geonosis-lint-parity.mjs"
|
|
25
|
+
},
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"bin",
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"oxlint": ">=1.77"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=22"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsup",
|
|
44
|
+
"typecheck": "tsc --noEmit"
|
|
45
|
+
}
|
|
46
|
+
}
|