@orthograph/lint 0.0.0-stage → 0.1.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +38 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +3 -0
- package/dist/modules/baseline/internal/order.d.ts +3 -0
- package/dist/modules/baseline/internal/order.js +8 -0
- package/dist/modules/baseline/service.d.ts +2 -0
- package/dist/modules/baseline/service.js +29 -0
- package/dist/modules/baseline/types.d.ts +30 -0
- package/dist/modules/baseline/types.js +4 -0
- package/dist/modules/rules/internal/baselined.d.ts +11 -0
- package/dist/modules/rules/internal/baselined.js +45 -0
- package/dist/modules/rules/internal/drift.d.ts +3 -0
- package/dist/modules/rules/internal/drift.js +91 -0
- package/dist/modules/rules/internal/effect-only.d.ts +2 -0
- package/dist/modules/rules/internal/effect-only.js +69 -0
- package/dist/modules/rules/internal/facts.d.ts +10 -0
- package/dist/modules/rules/internal/facts.js +13 -0
- package/dist/modules/rules/internal/imports.d.ts +5 -0
- package/dist/modules/rules/internal/imports.js +36 -0
- package/dist/modules/rules/internal/max-lines.d.ts +4 -0
- package/dist/modules/rules/internal/max-lines.js +31 -0
- package/dist/modules/rules/internal/names.d.ts +2 -0
- package/dist/modules/rules/internal/names.js +23 -0
- package/dist/modules/rules/internal/old-names.d.ts +5 -0
- package/dist/modules/rules/internal/old-names.js +53 -0
- package/dist/modules/rules/internal/place.d.ts +3 -0
- package/dist/modules/rules/internal/place.js +57 -0
- package/dist/modules/rules/internal/pro.d.ts +7 -0
- package/dist/modules/rules/internal/pro.js +16 -0
- package/dist/modules/rules/internal/refusals.d.ts +3 -0
- package/dist/modules/rules/internal/refusals.js +64 -0
- package/dist/modules/rules/internal/six-slots.d.ts +2 -0
- package/dist/modules/rules/internal/six-slots.js +46 -0
- package/dist/modules/rules/internal/sql-clock.d.ts +5 -0
- package/dist/modules/rules/internal/sql-clock.js +24 -0
- package/dist/modules/rules/internal/steps.d.ts +2 -0
- package/dist/modules/rules/internal/steps.js +40 -0
- package/dist/modules/rules/internal/ui.d.ts +7 -0
- package/dist/modules/rules/internal/ui.js +16 -0
- package/dist/modules/rules/internal/viem.d.ts +2 -0
- package/dist/modules/rules/internal/viem.js +15 -0
- package/dist/modules/rules/service.d.ts +3 -0
- package/dist/modules/rules/service.js +34 -0
- package/dist/modules/rules/types.d.ts +64 -0
- package/dist/modules/rules/types.js +3 -0
- package/package.json +25 -3
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
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @orthograph/lint
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Oxlint rules for what types can't see. Built; what each part does and how far it goes is in the package map in `docs/canon/status.md`. Two sets live here:
|
|
4
|
+
|
|
5
|
+
- **The project rules** (`no-name-as-string`, `refusal-has-log`, `declared-errors-only`, `no-wall-clock`,
|
|
6
|
+
`handler-matches-path`), which `ortho check` runs on a user's project with its `ProjectFacts`.
|
|
7
|
+
- **The repository's own code rules**, which this repository's `.oxlintrc.json` runs on `packages/*/src` (AGENTS.md,
|
|
8
|
+
"The code's own rules"; `design/decisions/P1-code-rules.md`):
|
|
9
|
+
- `ortho/effect-only`: no `async`, `await`, `try`, `throw`, `Date.now`, `new Date()`, `setTimeout`/`setInterval` or
|
|
10
|
+
plain `Effect.sleep`, except in a package's `src/main.ts`, a test file, and the paths listed in the rule's `entries`.
|
|
11
|
+
It, and `no-wall-clock`, also report SQL that reads the database's clock (`now()`, `CURRENT_TIMESTAMP`,
|
|
12
|
+
`datetime('now')`) in a string or template: a world has one clock (K23, M8.06), so a time is passed as a parameter.
|
|
13
|
+
- `ortho/max-lines`: at most 250 lines of code in a source file, blank lines and comments aside.
|
|
14
|
+
- `ortho/six-slots`: every `src/modules/<name>/` holds `README.md`, `types.ts`, `service.ts`, `internal/` and
|
|
15
|
+
`<name>.test.ts`.
|
|
16
|
+
- and `no-old-names`, the framework's old names.
|
|
17
|
+
|
|
18
|
+
They judge a file by its path from oxlint's working directory, so run oxlint from the repository's root (nx does);
|
|
19
|
+
run elsewhere, they judge nothing. They read names, not values: a computed form such as `Date["now"]` is not caught.
|
|
20
|
+
|
|
21
|
+
## The baseline
|
|
22
|
+
|
|
23
|
+
The code rules arrived after the code, so each starts from a baseline of the breaches that already existed:
|
|
24
|
+
`baseline.json`, rule by rule, file by file, with a count. In a file, a rule reports nothing while its breaches are at
|
|
25
|
+
most the baseline's count, and reports all of them once there is one more. A six-slots entry is a module's folder,
|
|
26
|
+
since the rule is about the module, not about the file it reports on. So lint fails only on new breaches.
|
|
27
|
+
|
|
28
|
+
The baseline only shrinks:
|
|
29
|
+
|
|
30
|
+
- `nx run lint:lint` (and so CI's `check` job) runs `scripts/baseline.ts`, which lints package source with the
|
|
31
|
+
baselines off and compares. It fails on a new breach, and it fails on a **stale** entry: a file with fewer breaches
|
|
32
|
+
than its count, because someone fixed one.
|
|
33
|
+
- `pnpm nx run lint:baseline` lowers every entry to what is left and drops the ones at zero. It never adds or raises
|
|
34
|
+
an entry: a new breach is fixed, not listed. Commit `baseline.json` in the pull request that fixed the breach.
|
|
35
|
+
- `node packages/lint/scripts/baseline.ts --seed` rewrites the file from today's counts. Use it only when a new code
|
|
36
|
+
rule arrives, or when a branch takes the rules in for the first time (a merge of `main`), and say so in the pull
|
|
37
|
+
request.
|
|
38
|
+
|
|
39
|
+
When `baseline.json` is `{}`, the rules are plain errors and the baseline (and this section) can go.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/main.d.ts
ADDED
package/dist/main.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const byCodePoint: (a: string, b: string) => number;
|
|
2
|
+
/** The counts with rules and paths sorted, zeros and empty rules dropped. */
|
|
3
|
+
export declare const tidy: (counts: Readonly<Record<string, Readonly<Record<string, number>>>>) => Record<string, Record<string, number>>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Code-point order, so the baseline file and every listing are the same on every machine.
|
|
2
|
+
export const byCodePoint = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
3
|
+
/** The counts with rules and paths sorted, zeros and empty rules dropped. */
|
|
4
|
+
export const tidy = (counts) => Object.fromEntries(Object.keys(counts).sort(byCodePoint).flatMap((rule) => {
|
|
5
|
+
const files = counts[rule] ?? {};
|
|
6
|
+
const kept = Object.keys(files).sort(byCodePoint).filter((path) => (files[path] ?? 0) > 0).map((path) => [path, files[path] ?? 0]);
|
|
7
|
+
return kept.length === 0 ? [] : [[rule, Object.fromEntries(kept)]];
|
|
8
|
+
}));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { byCodePoint, tidy } from "./internal/order.js";
|
|
2
|
+
const at = (counts, rule, path) => counts[rule]?.[path] ?? 0;
|
|
3
|
+
/** Every (rule, path) on either side, sorted by rule, then path. */
|
|
4
|
+
const keys = (a, b) => {
|
|
5
|
+
const seen = new Set();
|
|
6
|
+
for (const c of [a, b])
|
|
7
|
+
for (const rule of Object.keys(c))
|
|
8
|
+
for (const path of Object.keys(c[rule] ?? {}))
|
|
9
|
+
seen.add(`${rule}\u0000${path}`);
|
|
10
|
+
return [...seen].sort(byCodePoint).map((k) => k.split("\u0000"));
|
|
11
|
+
};
|
|
12
|
+
const MODULE = /^(.*\/src\/modules\/[^/]+)\/.+$/;
|
|
13
|
+
export const Baseline = {
|
|
14
|
+
keyOf: (rule, path) => (rule === "six-slots" ? (MODULE.exec(path)?.[1] ?? path) : path),
|
|
15
|
+
count: (reports) => {
|
|
16
|
+
const out = {};
|
|
17
|
+
for (const { rule, path } of reports) {
|
|
18
|
+
const files = (out[rule] ??= {});
|
|
19
|
+
files[path] = (files[path] ?? 0) + 1;
|
|
20
|
+
}
|
|
21
|
+
return tidy(out);
|
|
22
|
+
},
|
|
23
|
+
compare: (baseline, actual) => {
|
|
24
|
+
const breaches = keys(baseline, actual).map(([rule, path]) => ({ rule, path, allowed: at(baseline, rule, path), actual: at(actual, rule, path) }));
|
|
25
|
+
return { over: breaches.filter((b) => b.actual > b.allowed), stale: breaches.filter((b) => b.actual < b.allowed) };
|
|
26
|
+
},
|
|
27
|
+
shrink: (baseline, actual) => tidy(Object.fromEntries(Object.keys(baseline).map((rule) => [rule, Object.fromEntries(Object.keys(baseline[rule] ?? {}).map((path) => [path, Math.min(at(baseline, rule, path), at(actual, rule, path))]))]))),
|
|
28
|
+
render: (counts) => `${JSON.stringify(tidy(counts), null, 2)}\n`,
|
|
29
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** rule (without `ortho/`) -> path from the repository's root -> how many breaches. */
|
|
2
|
+
export type Counts = Readonly<Record<string, Readonly<Record<string, number>>>>;
|
|
3
|
+
/** One file where today's count and the baseline's differ. */
|
|
4
|
+
export interface Breach {
|
|
5
|
+
readonly rule: string;
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly allowed: number;
|
|
8
|
+
readonly actual: number;
|
|
9
|
+
}
|
|
10
|
+
export interface Verdict {
|
|
11
|
+
/** More breaches than the baseline allows: new ones. Lint fails on these. Sorted by rule, then path. */
|
|
12
|
+
readonly over: ReadonlyArray<Breach>;
|
|
13
|
+
/** Fewer than the baseline allows: fixed, so the baseline must shrink to match. Sorted by rule, then path. */
|
|
14
|
+
readonly stale: ReadonlyArray<Breach>;
|
|
15
|
+
}
|
|
16
|
+
export interface BaselineApi {
|
|
17
|
+
/** The baseline's key for a breach: the file, except six-slots, which is about a module, so its key is the module's folder. */
|
|
18
|
+
readonly keyOf: (rule: string, path: string) => string;
|
|
19
|
+
/** Tally reports into counts. */
|
|
20
|
+
readonly count: (reports: ReadonlyArray<{
|
|
21
|
+
readonly rule: string;
|
|
22
|
+
readonly path: string;
|
|
23
|
+
}>) => Counts;
|
|
24
|
+
/** Today's counts against the baseline. A rule or path absent from one side counts 0. */
|
|
25
|
+
readonly compare: (baseline: Counts, actual: Counts) => Verdict;
|
|
26
|
+
/** The baseline lowered to what is left: each entry min(allowed, actual), zeros and empty rules dropped. Never adds or raises. */
|
|
27
|
+
readonly shrink: (baseline: Counts, actual: Counts) => Counts;
|
|
28
|
+
/** Stable text: rules and paths in code-point order, 2-space JSON, a trailing newline. */
|
|
29
|
+
readonly render: (counts: Counts) => string;
|
|
30
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// The lint baseline: the breaches of the repository's own code rules that existed when each rule arrived, file by file.
|
|
2
|
+
// A rule tolerates up to its count in a file; the baseline only shrinks (README.md). Pure: the script that reads oxlint's
|
|
3
|
+
// output and writes the file is packages/lint/scripts/baseline.ts.
|
|
4
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CodeRuleOptions, Context, Node } from "../types.ts";
|
|
2
|
+
export declare const optionsOf: (context: Context) => CodeRuleOptions;
|
|
3
|
+
/** The file's path from cwd, when it is package source these rules judge. */
|
|
4
|
+
export declare const sourcePath: (context: Context) => string | undefined;
|
|
5
|
+
/** How many of `rule`'s breaches the baseline tolerates in `path` (for six-slots, in its module). */
|
|
6
|
+
export declare const allowed: (context: Context, rule: string, path: string) => number;
|
|
7
|
+
/** A per-file collector: `add` while visiting, `flush` at the end of the file reports all when over the baseline. */
|
|
8
|
+
export declare const collector: (context: Context, rule: string, path: string) => {
|
|
9
|
+
add: (node: Node, message: string) => void;
|
|
10
|
+
flush: () => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// What the repository's own code rules share: which files they judge, and the baseline that tolerates today's breaches.
|
|
2
|
+
// A rule collects its reports for a file and, at the end of the file, reports all of them only when there are more than
|
|
3
|
+
// the baseline allows for that file (as ESLint's bulk suppressions do). The baseline only shrinks: packages/lint/README.md.
|
|
4
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
5
|
+
import { isAbsolute, relative, resolve } from "node:path";
|
|
6
|
+
import { Baseline } from "#modules/baseline/service.js";
|
|
7
|
+
/** Package source: `packages/<pkg>/src/…`, never generated code. */
|
|
8
|
+
const SOURCE = /^packages\/[^/]+\/src\//;
|
|
9
|
+
export const optionsOf = (context) => context.options[0] ?? {};
|
|
10
|
+
/** The file's path from cwd, when it is package source these rules judge. */
|
|
11
|
+
export const sourcePath = (context) => {
|
|
12
|
+
const path = relative(context.cwd, context.filename).split("\\").join("/");
|
|
13
|
+
if (isAbsolute(path) || path.startsWith("../") || !SOURCE.test(path) || path.includes("/generated/"))
|
|
14
|
+
return undefined;
|
|
15
|
+
return path;
|
|
16
|
+
};
|
|
17
|
+
// Every linted file asks for the same baseline: read it again only when it changed (an editor's server lives long).
|
|
18
|
+
const loaded = new Map();
|
|
19
|
+
const baselineAt = (file) => {
|
|
20
|
+
const at = existsSync(file) ? statSync(file).mtimeMs : -1;
|
|
21
|
+
const known = loaded.get(file);
|
|
22
|
+
if (known !== undefined && known.at === at)
|
|
23
|
+
return known.counts;
|
|
24
|
+
const counts = at === -1 ? {} : JSON.parse(readFileSync(file, "utf8"));
|
|
25
|
+
loaded.set(file, { at, counts });
|
|
26
|
+
return counts;
|
|
27
|
+
};
|
|
28
|
+
/** How many of `rule`'s breaches the baseline tolerates in `path` (for six-slots, in its module). */
|
|
29
|
+
export const allowed = (context, rule, path) => {
|
|
30
|
+
const file = optionsOf(context).baseline;
|
|
31
|
+
return file === undefined ? 0 : (baselineAt(resolve(context.cwd, file))[rule]?.[Baseline.keyOf(rule, path)] ?? 0);
|
|
32
|
+
};
|
|
33
|
+
/** A per-file collector: `add` while visiting, `flush` at the end of the file reports all when over the baseline. */
|
|
34
|
+
export const collector = (context, rule, path) => {
|
|
35
|
+
const found = [];
|
|
36
|
+
return {
|
|
37
|
+
add: (node, message) => void found.push({ node, message }),
|
|
38
|
+
flush: () => {
|
|
39
|
+
if (found.length <= allowed(context, rule, path))
|
|
40
|
+
return;
|
|
41
|
+
for (const r of found)
|
|
42
|
+
context.report(r);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { SCHEMA, factsOf, pathOf } from "./facts.js";
|
|
2
|
+
const nameOf = (node) => (node?.type === "Identifier" ? node["name"] : undefined);
|
|
3
|
+
/** The string literals an argument can be, or undefined when any branch of it is not a literal (then it isn't judged). */
|
|
4
|
+
const literals = (node) => {
|
|
5
|
+
if (!node)
|
|
6
|
+
return undefined;
|
|
7
|
+
if (node.type === "Literal")
|
|
8
|
+
return typeof node["value"] === "string" ? [node["value"]] : undefined;
|
|
9
|
+
if (node.type === "TemplateLiteral" && node["expressions"].length === 0) {
|
|
10
|
+
const quasi = node["quasis"][0];
|
|
11
|
+
return [String(quasi?.["value"]?.cooked ?? "")];
|
|
12
|
+
}
|
|
13
|
+
if (node.type === "ConditionalExpression") {
|
|
14
|
+
const a = literals(node["consequent"]);
|
|
15
|
+
const b = literals(node["alternate"]);
|
|
16
|
+
return a && b ? [...a, ...b] : undefined;
|
|
17
|
+
}
|
|
18
|
+
if (node.type === "LogicalExpression") {
|
|
19
|
+
const a = literals(node["left"]);
|
|
20
|
+
const b = literals(node["right"]);
|
|
21
|
+
return a && b ? [...a, ...b] : undefined;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
};
|
|
25
|
+
export const outcomeChosen = {
|
|
26
|
+
meta: { schema: SCHEMA, docs: { description: "Warns when the handler never names an outcome of its move in move(\"…\")." } },
|
|
27
|
+
create: (context) => {
|
|
28
|
+
const facts = factsOf(context);
|
|
29
|
+
const path = pathOf(context, facts);
|
|
30
|
+
const missing = new Set(path === undefined ? [] : facts.outcomes?.[path]);
|
|
31
|
+
if (missing.size === 0)
|
|
32
|
+
return {};
|
|
33
|
+
const moves = new Set(["move"]);
|
|
34
|
+
let judged = true;
|
|
35
|
+
return {
|
|
36
|
+
Property: (node) => {
|
|
37
|
+
if (node.parent?.type === "ObjectPattern" && nameOf(node["key"]) === "move") {
|
|
38
|
+
const binding = nameOf(node["value"]);
|
|
39
|
+
if (typeof binding === "string")
|
|
40
|
+
moves.add(binding);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
CallExpression: (node) => {
|
|
44
|
+
const callee = node["callee"];
|
|
45
|
+
// `move(...)`, a renamed `move`, or `context.move(...)`.
|
|
46
|
+
const named = callee.type === "MemberExpression" && node["optional"] !== true ? nameOf(callee["property"]) === "move" : moves.has(nameOf(callee));
|
|
47
|
+
if (!named)
|
|
48
|
+
return;
|
|
49
|
+
const arg = node["arguments"][0];
|
|
50
|
+
const outcomes = arg ? literals(arg) : [];
|
|
51
|
+
if (outcomes === undefined)
|
|
52
|
+
judged = false;
|
|
53
|
+
else
|
|
54
|
+
for (const outcome of outcomes)
|
|
55
|
+
missing.delete(outcome);
|
|
56
|
+
},
|
|
57
|
+
"Program:exit": (node) => {
|
|
58
|
+
if (!judged)
|
|
59
|
+
return;
|
|
60
|
+
for (const outcome of missing)
|
|
61
|
+
context.report({ node, message: `the move never ends in ${outcome}: no move("${outcome}") names it` });
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
/** An identifier that only names what is brought in: a destructured binding or an import specifier. */
|
|
67
|
+
const bindingOnly = (node) => {
|
|
68
|
+
const parent = node.parent;
|
|
69
|
+
if (parent?.type === "ImportSpecifier" || parent?.type === "ImportDefaultSpecifier")
|
|
70
|
+
return true;
|
|
71
|
+
return parent?.type === "Property" && parent.parent?.type === "ObjectPattern";
|
|
72
|
+
};
|
|
73
|
+
export const declaredErrorNamed = {
|
|
74
|
+
meta: { schema: SCHEMA, docs: { description: "Warns when the handler never names an error its operation declares." } },
|
|
75
|
+
create: (context) => {
|
|
76
|
+
const facts = factsOf(context);
|
|
77
|
+
const path = pathOf(context, facts);
|
|
78
|
+
const missing = new Set(path === undefined ? [] : facts.handlers[path]);
|
|
79
|
+
if (missing.size === 0)
|
|
80
|
+
return {};
|
|
81
|
+
return {
|
|
82
|
+
// A name brought in (`const { X } = Errors.declared`, `import { X }`) isn't a use: the refusal is where it's raised.
|
|
83
|
+
Identifier: (node) => { if (!bindingOnly(node))
|
|
84
|
+
missing.delete(node["name"]); },
|
|
85
|
+
"Program:exit": (node) => {
|
|
86
|
+
for (const error of missing)
|
|
87
|
+
context.report({ node, message: `declared error ${error} is never refused` });
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { SCHEMA, constructed } from "./facts.js";
|
|
2
|
+
import { collector, optionsOf, sourcePath } from "./baselined.js";
|
|
3
|
+
import { sqlClockMessage } from "./sql-clock.js";
|
|
4
|
+
const ENTRY = /^packages\/[^/]+\/src\/main\.ts$/;
|
|
5
|
+
const TEST = /\.test\.tsx?$/;
|
|
6
|
+
// `globalThis.setTimeout(...)` is setTimeout too. Computed forms (`Date["now"]`) are not judged: lint reads names.
|
|
7
|
+
const GLOBALS = new Set(["globalThis", "window", "self", "global"]);
|
|
8
|
+
const asyncFunction = (add) => (node) => {
|
|
9
|
+
if (node["async"] === true)
|
|
10
|
+
add(node, "an async function: return an Effect instead");
|
|
11
|
+
};
|
|
12
|
+
export const effectOnly = {
|
|
13
|
+
meta: { schema: SCHEMA, docs: { description: "No async, await, try, throw, Date.now, new Date(), setTimeout or Effect.sleep outside entry files: Effect, Clock and Timers." } },
|
|
14
|
+
create: (context) => {
|
|
15
|
+
const path = sourcePath(context);
|
|
16
|
+
if (path === undefined || ENTRY.test(path) || TEST.test(path) || (optionsOf(context).entries ?? []).includes(path))
|
|
17
|
+
return {};
|
|
18
|
+
const { add, flush } = collector(context, "effect-only", path);
|
|
19
|
+
return {
|
|
20
|
+
FunctionDeclaration: asyncFunction(add),
|
|
21
|
+
FunctionExpression: asyncFunction(add),
|
|
22
|
+
ArrowFunctionExpression: asyncFunction(add),
|
|
23
|
+
AwaitExpression: (node) => add(node, "await: yield* an Effect instead"),
|
|
24
|
+
ForOfStatement: (node) => {
|
|
25
|
+
if (node["await"] === true)
|
|
26
|
+
add(node, "for await: use a Stream instead");
|
|
27
|
+
},
|
|
28
|
+
VariableDeclaration: (node) => {
|
|
29
|
+
if (node["kind"] === "await using")
|
|
30
|
+
add(node, "await using: use Effect.acquireRelease instead");
|
|
31
|
+
},
|
|
32
|
+
TryStatement: (node) => add(node, "try: errors are values; use Effect.try or Effect.catch"),
|
|
33
|
+
ThrowStatement: (node) => add(node, "throw: fail with a tagged error (Effect.fail) instead"),
|
|
34
|
+
MemberExpression: (node) => {
|
|
35
|
+
const o = node["object"];
|
|
36
|
+
const p = node["property"];
|
|
37
|
+
if (o.type !== "Identifier" || node["computed"] === true)
|
|
38
|
+
return;
|
|
39
|
+
if (o.name === "Date" && p.name === "now")
|
|
40
|
+
add(node, "Date.now reads the wall clock: use Clock");
|
|
41
|
+
if (o.name === "Effect" && p.name === "sleep")
|
|
42
|
+
add(node, "a plain Effect.sleep waits outside counted work: use Timers");
|
|
43
|
+
},
|
|
44
|
+
NewExpression: (node) => {
|
|
45
|
+
if (constructed(node) === "Date" && node["arguments"].length === 0)
|
|
46
|
+
add(node, "new Date() reads the wall clock: use Clock");
|
|
47
|
+
},
|
|
48
|
+
CallExpression: (node) => {
|
|
49
|
+
const callee = node["callee"];
|
|
50
|
+
const global = callee.type === "MemberExpression" && callee.computed !== true && callee.object?.type === "Identifier" && GLOBALS.has(callee.object.name ?? "");
|
|
51
|
+
const name = global ? callee.property?.name : constructed(node);
|
|
52
|
+
if (name === "setTimeout" || name === "setInterval")
|
|
53
|
+
add(node, `${name} waits outside counted work: use Timers`);
|
|
54
|
+
},
|
|
55
|
+
// SQL that asks the database for the time: a world has one clock, and the database is not it (K23 section 6).
|
|
56
|
+
Literal: (node) => {
|
|
57
|
+
const message = sqlClockMessage(node);
|
|
58
|
+
if (message !== undefined)
|
|
59
|
+
add(node, message);
|
|
60
|
+
},
|
|
61
|
+
TemplateElement: (node) => {
|
|
62
|
+
const message = sqlClockMessage(node);
|
|
63
|
+
if (message !== undefined)
|
|
64
|
+
add(node, message);
|
|
65
|
+
},
|
|
66
|
+
"Program:exit": flush,
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Context, Node, ProjectFacts } from "../types.ts";
|
|
2
|
+
export declare const SCHEMA: readonly [{
|
|
3
|
+
readonly type: "object";
|
|
4
|
+
readonly additionalProperties: true;
|
|
5
|
+
}];
|
|
6
|
+
export declare const factsOf: (context: Context) => ProjectFacts;
|
|
7
|
+
/** The file's path from the project's root, or undefined when it isn't inside it. */
|
|
8
|
+
export declare const pathOf: (context: Context, facts: ProjectFacts) => string | undefined;
|
|
9
|
+
/** `new AllowanceExceeded(...)`: the class constructed, when it is a plain name. */
|
|
10
|
+
export declare const constructed: (node: Node) => string | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const SCHEMA = [{ type: "object", additionalProperties: true }];
|
|
2
|
+
const EMPTY = { root: "", names: [], errors: [], handlers: {} };
|
|
3
|
+
export const factsOf = (context) => context.options[0] ?? EMPTY;
|
|
4
|
+
/** The file's path from the project's root, or undefined when it isn't inside it. */
|
|
5
|
+
export const pathOf = (context, facts) => {
|
|
6
|
+
const root = facts.root.endsWith("/") ? facts.root : `${facts.root}/`;
|
|
7
|
+
return context.filename.startsWith(root) ? context.filename.slice(root.length) : undefined;
|
|
8
|
+
};
|
|
9
|
+
/** `new AllowanceExceeded(...)`: the class constructed, when it is a plain name. */
|
|
10
|
+
export const constructed = (node) => {
|
|
11
|
+
const callee = node["callee"];
|
|
12
|
+
return callee?.type === "Identifier" ? callee.name : undefined;
|
|
13
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Node, Rule } from "../types.ts";
|
|
2
|
+
type Visitors = ReturnType<Rule["create"]>;
|
|
3
|
+
/** Visitors that call `seen` for every module a file reaches: imports, export-froms, dynamic imports, import types and `require`. */
|
|
4
|
+
export declare const everyImport: (seen: (node: Node, name: string) => void) => Visitors;
|
|
5
|
+
export {};
|