@antelopejs/tooling-configs 0.4.1 → 0.5.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/README.md +68 -29
- package/dist/bin/api-diff.mjs +235 -37
- package/dist/bin/body-check.mjs +14 -11
- package/dist/bin/capture.mjs +173 -54
- package/dist/bin/check-size.mjs +1 -1
- package/dist/bin/checks.mjs +166 -11
- package/dist/bin/comment-proof.mjs +29 -7
- package/dist/bin/garden.mjs +8 -58
- package/dist/bin/lease.mjs +48 -11
- package/dist/bin/ratchet.mjs +48 -14
- package/dist/bin/suppressions.mjs +3 -3
- package/dist/bin/sync.mjs +199 -80
- package/dist/bin/verify.mjs +1163 -474
- package/dist/capture/index.d.mts +6 -1
- package/dist/capture/index.mjs +1 -1
- package/dist/{ci-workflow-37qJa9LX.mjs → ci-workflow-COJUT12b.mjs} +121 -1
- package/dist/eslint.d.mts +16 -3
- package/dist/eslint.mjs +21 -6
- package/dist/formal/index.d.mts +20 -4
- package/dist/formal/index.mjs +71 -19
- package/dist/{map-B23_WMGE.mjs → map-DRyYz_Fw.mjs} +20 -1
- package/dist/oxc/anti-slop/index.mjs +156 -421
- package/dist/oxc/guardrails/index.d.mts +1 -1
- package/dist/oxc/guardrails/index.mjs +789 -103
- package/dist/oxc/lint.d.mts +13 -15
- package/dist/oxc/lint.mjs +19 -29
- package/dist/{package-CqqBgE8Y.mjs → package-Dn7VTFUW.mjs} +71 -17
- package/dist/{proof-stamp-DDDC0J6l.mjs → proof-stamp-DLWpPwQE.mjs} +72 -10
- package/dist/{ratchet-Q-JXuZIX.mjs → ratchet-ClfblHNJ.mjs} +18 -15
- package/dist/require-safety-comment-for-type-assertion-mnb0CIxa.mjs +181 -0
- package/dist/{scenes-DZVXkcxS.mjs → scenes-d-VQ0LOm.mjs} +4 -1
- package/dist/semver-BDxeEcP_.mjs +57 -0
- package/dist/{suppression-base-9L8dlMQK.mjs → suppression-base-Drnl6Y7F.mjs} +2 -2
- package/dist/{suppression-budget-C0SkPO5R.mjs → suppression-budget-Dvb_IqBo.mjs} +1 -1
- package/dist/{suppressions-DM60NkvL.mjs → suppressions-BroaaGJ_.mjs} +1 -1
- package/dist/{templates-BKZv-BRw.mjs → templates-lJBZFskp.mjs} +8 -3
- package/dist/type-aware-rules-DMuN6sHb.mjs +30 -0
- package/dist/{typescript-DAgQIAAR.mjs → typescript-BBbry7uU.mjs} +123 -27
- package/dist/verify/index.d.mts +60 -15
- package/package.json +3 -1
- package/dist/require-safety-comment-for-type-assertion-BBQ669kj.mjs +0 -83
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
//#region src/oxc/anti-slop/shared/type-guards.ts
|
|
3
|
+
/** JavaScript files, where TypeScript reads types from JSDoc instead of from syntax. */
|
|
4
|
+
const JSDOC_TYPED_FILE = /\.[cm]?js$/;
|
|
5
|
+
/** A `@returns {x is T}` type, `x` captured: `asserts x is T` does not match. */
|
|
6
|
+
const JSDOC_PREDICATE = /^\s*([A-Za-z_$][\w$]*)\s+is\s+\S/;
|
|
7
|
+
function isRuntimeFunction(node) {
|
|
8
|
+
return node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression";
|
|
9
|
+
}
|
|
10
|
+
/** Return the statement or member a JSDoc block documenting this function is attached to. */
|
|
11
|
+
function documentedNode(fn) {
|
|
12
|
+
const parent = fn.parent;
|
|
13
|
+
if ((parent.type === "Property" || parent.type === "MethodDefinition") && parent.value === fn) return parent;
|
|
14
|
+
let node = fn;
|
|
15
|
+
if (parent.type === "VariableDeclarator" && parent.init === fn && parent.parent.type === "VariableDeclaration" && parent.parent.declarations.length === 1) node = parent.parent;
|
|
16
|
+
const container = node.parent;
|
|
17
|
+
return container !== null && (container.type === "ExportNamedDeclaration" || container.type === "ExportDefaultDeclaration") ? container : node;
|
|
18
|
+
}
|
|
19
|
+
/** Return the type inside the braces of the first `@<tag> {...}` tag of a JSDoc block. */
|
|
20
|
+
function jsDocTagType(text, tag) {
|
|
21
|
+
const match = new RegExp(String.raw`@${tag}\s*\{`, "u").exec(text);
|
|
22
|
+
if (match === null) return null;
|
|
23
|
+
const start = match.index + match[0].length;
|
|
24
|
+
let depth = 1;
|
|
25
|
+
for (let index = start; index < text.length; index++) if (text[index] === "{") depth++;
|
|
26
|
+
else if (text[index] === "}" && --depth === 0) return text.slice(start, index);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
/** Return whether the JSDoc block right before the function declares `@returns {param is T}` for one of its parameters. */
|
|
30
|
+
function hasJsDocTypePredicate(fn, sourceCode) {
|
|
31
|
+
const comment = sourceCode.getCommentsBefore(documentedNode(fn)).at(-1);
|
|
32
|
+
if (comment === void 0 || comment.type !== "Block" || !comment.value.startsWith("*")) return false;
|
|
33
|
+
const returnType = jsDocTagType(comment.value, "returns");
|
|
34
|
+
const subject = returnType === null ? void 0 : JSDOC_PREDICATE.exec(returnType)?.[1];
|
|
35
|
+
return subject !== void 0 && fn.params.some((parameter) => parameter.type === "Identifier" && parameter.name === subject);
|
|
36
|
+
}
|
|
37
|
+
/** Return whether a function declares a type predicate or assertion, or a JSDoc `@returns {x is T}` in a `.js`, `.mjs` or `.cjs` file. */
|
|
38
|
+
function isTypeGuard(fn, sourceCode, filename) {
|
|
39
|
+
if (fn.returnType?.typeAnnotation.type === "TSTypePredicate") return true;
|
|
40
|
+
return JSDOC_TYPED_FILE.test(filename) && hasJsDocTypePredicate(fn, sourceCode);
|
|
41
|
+
}
|
|
42
|
+
/** Return the nearest runtime function around a node when that function is a type guard. */
|
|
43
|
+
function enclosingTypeGuard(node, sourceCode, filename) {
|
|
44
|
+
let current = node.parent;
|
|
45
|
+
while (current !== null && current.type !== "Program") {
|
|
46
|
+
if (isRuntimeFunction(current)) return isTypeGuard(current, sourceCode, filename) ? current : null;
|
|
47
|
+
current = current.parent;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/oxc/anti-slop/rules/require-safety-comment-for-type-assertion.ts
|
|
53
|
+
const DEFAULT_SAFETY_MARKERS = ["SAFETY"];
|
|
54
|
+
const commentOwnerKinds = /* @__PURE__ */ new Set([
|
|
55
|
+
"ExpressionStatement",
|
|
56
|
+
"PropertyDefinition",
|
|
57
|
+
"ReturnStatement",
|
|
58
|
+
"ThrowStatement",
|
|
59
|
+
"VariableDeclaration"
|
|
60
|
+
]);
|
|
61
|
+
function isConstAssertion(node) {
|
|
62
|
+
return node.typeAnnotation.type === "TSTypeReference" && node.typeAnnotation.typeName.type === "Identifier" && node.typeAnnotation.typeName.name === "const";
|
|
63
|
+
}
|
|
64
|
+
function configuredSafetyMarkers(option) {
|
|
65
|
+
if (typeof option !== "object" || option === null || !("markers" in option)) return DEFAULT_SAFETY_MARKERS;
|
|
66
|
+
const configured = option.markers;
|
|
67
|
+
if (!Array.isArray(configured)) return DEFAULT_SAFETY_MARKERS;
|
|
68
|
+
const markers = configured.flatMap((marker) => typeof marker === "string" && marker.trim().length > 0 ? [marker.trim()] : []);
|
|
69
|
+
return markers.length > 0 ? markers : DEFAULT_SAFETY_MARKERS;
|
|
70
|
+
}
|
|
71
|
+
function markerPattern(markers) {
|
|
72
|
+
const alternation = markers.map((marker) => marker.replaceAll(/[.*+?^${}()|[\]\\]/gu, String.raw`\$&`)).join("|");
|
|
73
|
+
return new RegExp(String.raw`(?:^|[^\p{L}\p{N}_])(?:${alternation})\s*:\s*\S`, "u");
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Return the cast a JSDoc `@type {T}` block makes of the parenthesized expression after it,
|
|
77
|
+
* unless `T` is `const` or the `(` opens the parameters of an annotated arrow function.
|
|
78
|
+
*/
|
|
79
|
+
function jsDocCast(sourceCode, comment) {
|
|
80
|
+
if (comment.type !== "Block" || !comment.value.startsWith("*")) return null;
|
|
81
|
+
const type = jsDocTagType(comment.value, "type");
|
|
82
|
+
if (type === null || type.trim() === "const") return null;
|
|
83
|
+
const paren = sourceCode.getTokenAfter(comment);
|
|
84
|
+
if (paren?.type !== "Punctuator" || paren.value !== "(") return null;
|
|
85
|
+
const owner = sourceCode.getNodeByRangeIndex(paren.start);
|
|
86
|
+
if (owner === null) return null;
|
|
87
|
+
return owner.type === "ArrowFunctionExpression" && owner.start === paren.start ? null : {
|
|
88
|
+
paren,
|
|
89
|
+
owner
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Return whether a marker comment ends before `assertion` starts, either right before it
|
|
94
|
+
* or before a node between `owner` and its statement or class property.
|
|
95
|
+
*/
|
|
96
|
+
function hasSafetyComment(sourceCode, assertion, owner, pattern) {
|
|
97
|
+
const justifies = (target) => sourceCode.getCommentsBefore(target).some((comment) => comment.end <= assertion.start && pattern.test(comment.value));
|
|
98
|
+
if (justifies(assertion)) return true;
|
|
99
|
+
let current = owner;
|
|
100
|
+
while (current.type !== "Program") {
|
|
101
|
+
if (justifies(current)) return true;
|
|
102
|
+
if (commentOwnerKinds.has(current.type)) {
|
|
103
|
+
const exportDeclaration = current.parent;
|
|
104
|
+
return exportDeclaration.type === "ExportNamedDeclaration" && exportDeclaration.declaration === current && justifies(exportDeclaration);
|
|
105
|
+
}
|
|
106
|
+
current = current.parent;
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
/** Require every non-const type assertion, JSDoc casts in JavaScript files included, to state the invariant TypeScript cannot express. */
|
|
111
|
+
const requireSafetyCommentForTypeAssertionRule = defineRule({
|
|
112
|
+
meta: {
|
|
113
|
+
type: "problem",
|
|
114
|
+
docs: { description: "Require a nearby SAFETY comment for every type assertion, TypeScript or JSDoc cast, except const assertions." },
|
|
115
|
+
messages: { missingSafetyComment: "This type assertion has no `{{marker}}:` justification. State the checked invariant immediately before the assertion or its containing statement." },
|
|
116
|
+
schema: [{
|
|
117
|
+
type: "object",
|
|
118
|
+
properties: { markers: {
|
|
119
|
+
type: "array",
|
|
120
|
+
items: {
|
|
121
|
+
type: "string",
|
|
122
|
+
minLength: 1
|
|
123
|
+
},
|
|
124
|
+
minItems: 1,
|
|
125
|
+
uniqueItems: true
|
|
126
|
+
} },
|
|
127
|
+
additionalProperties: false
|
|
128
|
+
}],
|
|
129
|
+
defaultOptions: [{ markers: ["SAFETY"] }]
|
|
130
|
+
},
|
|
131
|
+
createOnce(context) {
|
|
132
|
+
const patterns = /* @__PURE__ */ new Map();
|
|
133
|
+
const markerSettings = () => {
|
|
134
|
+
const markers = configuredSafetyMarkers(context.options?.[0]);
|
|
135
|
+
const patternKey = markers.join("\0");
|
|
136
|
+
const pattern = patterns.get(patternKey) ?? markerPattern(markers);
|
|
137
|
+
patterns.set(patternKey, pattern);
|
|
138
|
+
return {
|
|
139
|
+
pattern,
|
|
140
|
+
data: { marker: markers[0] ?? DEFAULT_SAFETY_MARKERS[0] }
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
const checkAssertion = (node) => {
|
|
144
|
+
if (isConstAssertion(node)) return;
|
|
145
|
+
const { pattern, data } = markerSettings();
|
|
146
|
+
if (node.parent === null || hasSafetyComment(context.sourceCode, node, node.parent, pattern)) return;
|
|
147
|
+
context.report({
|
|
148
|
+
node,
|
|
149
|
+
messageId: "missingSafetyComment",
|
|
150
|
+
data
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
const checkJsDocCasts = () => {
|
|
154
|
+
if (!JSDOC_TYPED_FILE.test(context.filename)) return;
|
|
155
|
+
const { sourceCode } = context;
|
|
156
|
+
const { pattern, data } = markerSettings();
|
|
157
|
+
const castParens = /* @__PURE__ */ new Set();
|
|
158
|
+
for (const comment of sourceCode.getAllComments()) {
|
|
159
|
+
const cast = jsDocCast(sourceCode, comment);
|
|
160
|
+
if (cast === null || castParens.has(cast.paren.start)) continue;
|
|
161
|
+
castParens.add(cast.paren.start);
|
|
162
|
+
if (hasSafetyComment(sourceCode, comment, cast.owner, pattern)) continue;
|
|
163
|
+
context.report({
|
|
164
|
+
loc: {
|
|
165
|
+
start: comment.loc.start,
|
|
166
|
+
end: cast.paren.loc.end
|
|
167
|
+
},
|
|
168
|
+
messageId: "missingSafetyComment",
|
|
169
|
+
data
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
return {
|
|
174
|
+
Program: checkJsDocCasts,
|
|
175
|
+
TSAsExpression: checkAssertion,
|
|
176
|
+
TSTypeAssertion: checkAssertion
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
//#endregion
|
|
181
|
+
export { isRuntimeFunction as a, enclosingTypeGuard as i, markerPattern as n, requireSafetyCommentForTypeAssertionRule as r, DEFAULT_SAFETY_MARKERS as t };
|
|
@@ -63,12 +63,15 @@ function parseScene(entry, position) {
|
|
|
63
63
|
const route = optStr(entry, "route");
|
|
64
64
|
if (route === void 0 || !route.startsWith("/")) throw new Error("route must start with \"/\"");
|
|
65
65
|
const setup = entry.setup === true;
|
|
66
|
+
const signedOut = entry.signedOut === true;
|
|
67
|
+
if (setup && signedOut) throw new Error("a setup scene cannot be signed out");
|
|
66
68
|
const scene = {
|
|
67
69
|
id,
|
|
68
70
|
route,
|
|
69
71
|
viewport: parseViewport(entry),
|
|
70
72
|
steps: Object.hasOwn(entry, "steps") ? children(entry, "steps").map(parseStep) : [],
|
|
71
|
-
setup
|
|
73
|
+
setup,
|
|
74
|
+
signedOut
|
|
72
75
|
};
|
|
73
76
|
const crop = optStr(entry, "crop");
|
|
74
77
|
if (crop !== void 0 && crop !== "") scene.crop = crop;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
//#region src/garden/semver.ts
|
|
2
|
+
const VERSION = /^v?(\d+)\.(\d+)\.(\d+)/;
|
|
3
|
+
function parse(text) {
|
|
4
|
+
const match = VERSION.exec(text.trim());
|
|
5
|
+
return match ? [
|
|
6
|
+
Number(match[1]),
|
|
7
|
+
Number(match[2]),
|
|
8
|
+
Number(match[3])
|
|
9
|
+
] : void 0;
|
|
10
|
+
}
|
|
11
|
+
function compare(a, b) {
|
|
12
|
+
return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
|
|
13
|
+
}
|
|
14
|
+
function caret(floor) {
|
|
15
|
+
if (floor[0] > 0) return [
|
|
16
|
+
floor[0] + 1,
|
|
17
|
+
0,
|
|
18
|
+
0
|
|
19
|
+
];
|
|
20
|
+
return floor[1] > 0 ? [
|
|
21
|
+
0,
|
|
22
|
+
floor[1] + 1,
|
|
23
|
+
0
|
|
24
|
+
] : [
|
|
25
|
+
0,
|
|
26
|
+
0,
|
|
27
|
+
floor[2] + 1
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
function comparator(term, version) {
|
|
31
|
+
const operator = /^(>=|<=|>|<|=|\^|~)?\s*(.*)$/.exec(term.trim());
|
|
32
|
+
const bound = parse(operator?.[2] ?? "");
|
|
33
|
+
if (!operator || !bound) return true;
|
|
34
|
+
switch (operator[1]) {
|
|
35
|
+
case ">=": return compare(version, bound) >= 0;
|
|
36
|
+
case ">": return compare(version, bound) > 0;
|
|
37
|
+
case "<=": return compare(version, bound) <= 0;
|
|
38
|
+
case "<": return compare(version, bound) < 0;
|
|
39
|
+
case "^": return compare(version, bound) >= 0 && compare(version, caret(bound)) < 0;
|
|
40
|
+
case "~": return compare(version, bound) >= 0 && compare(version, [
|
|
41
|
+
bound[0],
|
|
42
|
+
bound[1] + 1,
|
|
43
|
+
0
|
|
44
|
+
]) < 0;
|
|
45
|
+
default: return compare(version, bound) === 0;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Whether a plain npm range (`^`, `~`, comparators, `||`, `*`) admits a release; wildcards and tags admit everything. */
|
|
49
|
+
function admits(range, release) {
|
|
50
|
+
const version = parse(release);
|
|
51
|
+
if (!version) return true;
|
|
52
|
+
return range.split("||").some((alternative) => {
|
|
53
|
+
return alternative.replace(/(>=|<=|>|<|=|\^|~)\s+/g, "$1").trim().split(/\s+/).every((term) => comparator(term, version));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { admits as t };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { l as resolveRevision, o as isAgentFile } from "./files-DJ0TeaTU.mjs";
|
|
2
|
-
import { a as parseBudget, n as SUPPRESSIONS_FILE, o as safetyCeiling, p as coveredLimits } from "./suppression-budget-
|
|
3
|
-
import { o as revisionSuppressions, r as countSuppressions } from "./suppressions-
|
|
2
|
+
import { a as parseBudget, n as SUPPRESSIONS_FILE, o as safetyCeiling, p as coveredLimits } from "./suppression-budget-Dvb_IqBo.mjs";
|
|
3
|
+
import { o as revisionSuppressions, r as countSuppressions } from "./suppressions-BroaaGJ_.mjs";
|
|
4
4
|
import { readFileSync } from "node:fs";
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { spawnSync } from "node:child_process";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as renamedPaths } from "./renames-L2owF5GD.mjs";
|
|
2
2
|
import { o as isAgentFile, r as changedFiles } from "./files-DJ0TeaTU.mjs";
|
|
3
|
-
import { a as openDisablesIn, i as inWorktree, l as worktreeSuppressions, n as configKey, o as revisionSuppressions, r as countSuppressions, s as sortedKeys, t as atRevision } from "./suppressions-
|
|
3
|
+
import { a as openDisablesIn, i as inWorktree, l as worktreeSuppressions, n as configKey, o as revisionSuppressions, r as countSuppressions, s as sortedKeys, t as atRevision } from "./suppressions-BroaaGJ_.mjs";
|
|
4
4
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { join, matchesGlob } from "node:path";
|
|
6
6
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as markerPattern, t as DEFAULT_SAFETY_MARKERS } from "./require-safety-comment-for-type-assertion-
|
|
1
|
+
import { n as markerPattern, t as DEFAULT_SAFETY_MARKERS } from "./require-safety-comment-for-type-assertion-mnb0CIxa.mjs";
|
|
2
2
|
import { a as gitFiles, i as generatedOutput } from "./files-DJ0TeaTU.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { existsSync, lstatSync, readFileSync } from "node:fs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as execCommand } from "./package-Dn7VTFUW.mjs";
|
|
2
2
|
import { isMap, parseDocument } from "yaml";
|
|
3
3
|
//#region src/guardrails/templates.ts
|
|
4
4
|
const PRESET_CONFIGS = [
|
|
@@ -56,7 +56,7 @@ function lefthook(current, manager, tools, ratchet = true) {
|
|
|
56
56
|
"antelopejs-size": { run: `${tools.hookPrefix}${tools.commands.size} --staged {staged_files}` },
|
|
57
57
|
"antelopejs-ratchet": {
|
|
58
58
|
glob,
|
|
59
|
-
run: `${tools.hookPrefix}${tools.commands.ratchet} --staged
|
|
59
|
+
run: `${tools.hookPrefix}${tools.commands.ratchet} --staged`
|
|
60
60
|
},
|
|
61
61
|
"antelopejs-suppressions": {
|
|
62
62
|
glob,
|
|
@@ -105,7 +105,12 @@ if [[ "$(node -p 'process.versions.node.split(".")[0]')" != "$major" ]]; then
|
|
|
105
105
|
fi
|
|
106
106
|
pin="$(node -p 'JSON.parse(require("node:fs").readFileSync("package.json", "utf8")).packageManager || "pnpm"')"
|
|
107
107
|
manager="\${pin%%@*}"
|
|
108
|
-
corepack enable
|
|
108
|
+
if ! corepack enable >/dev/null 2>&1; then
|
|
109
|
+
shims="$HOME/.local/bin"
|
|
110
|
+
mkdir -p "$shims"
|
|
111
|
+
corepack enable --install-directory "$shims"
|
|
112
|
+
export PATH="$shims:$PATH"
|
|
113
|
+
fi
|
|
109
114
|
if [[ "$pin" == *@* ]]; then
|
|
110
115
|
corepack prepare "$pin" --activate
|
|
111
116
|
fi
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/type-aware-rules.ts
|
|
2
|
+
/**
|
|
3
|
+
* The typescript-eslint rules the preset runs with type information, by their
|
|
4
|
+
* name without a plugin prefix. oxlint runs them as `typescript/<rule>` through
|
|
5
|
+
* oxlint-tsgolint, which reads only TypeScript files; the Nuxt ESLint config
|
|
6
|
+
* runs them as `@typescript-eslint/<rule>` on the script blocks of `.vue` files.
|
|
7
|
+
*
|
|
8
|
+
* Five reject an `any` or a type parameter that stands in for `unknown`, which
|
|
9
|
+
* the anti-slop `unknown` and assertion rules never see: a once-used type
|
|
10
|
+
* parameter, `any` passed as a typed argument, assigned to a typed binding or
|
|
11
|
+
* returned as a typed result, and an untyped `.catch` callback variable.
|
|
12
|
+
*/
|
|
13
|
+
const TYPE_AWARE_RULES = [
|
|
14
|
+
"no-unnecessary-type-parameters",
|
|
15
|
+
"no-unsafe-argument",
|
|
16
|
+
"no-unsafe-assignment",
|
|
17
|
+
"no-unsafe-return",
|
|
18
|
+
"use-unknown-in-catch-callback-variable",
|
|
19
|
+
"no-floating-promises",
|
|
20
|
+
"await-thenable",
|
|
21
|
+
"unbound-method",
|
|
22
|
+
"no-meaningless-void-operator",
|
|
23
|
+
"no-misused-spread",
|
|
24
|
+
"no-base-to-string",
|
|
25
|
+
"no-redundant-type-constituents",
|
|
26
|
+
"restrict-template-expressions",
|
|
27
|
+
"require-array-sort-compare"
|
|
28
|
+
];
|
|
29
|
+
//#endregion
|
|
30
|
+
export { TYPE_AWARE_RULES as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as parseManifest } from "./package-Dn7VTFUW.mjs";
|
|
2
2
|
import { u as trackedManifests } from "./files-DJ0TeaTU.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
@@ -97,21 +97,43 @@ function resolveTypeScript(directory) {
|
|
|
97
97
|
} catch (error) {
|
|
98
98
|
if (declaresTypeScript(directory)) throw new Error(`${describePackage(directory)} declares typescript but it cannot be resolved from the package directory, so the compiler it builds with is not available. Install dependencies (run pnpm install) and retry.`, { cause: error });
|
|
99
99
|
return {
|
|
100
|
-
file:
|
|
100
|
+
file: packTypeScript(),
|
|
101
101
|
fallback: true
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
/**
|
|
106
|
-
function
|
|
107
|
-
|
|
105
|
+
/** The TypeScript `dts-bundle-generator` brings, which the pack falls back to. */
|
|
106
|
+
function packTypeScript() {
|
|
107
|
+
return createRequire(createRequire(import.meta.url).resolve("dts-bundle-generator")).resolve("typescript");
|
|
108
|
+
}
|
|
109
|
+
/** Loads the TypeScript at `file`; one without the programmatic API (7 and later) yields only its `version`, so the caller reports it rather than crashing. */
|
|
110
|
+
function requireTypeScript(file) {
|
|
108
111
|
const compiler = createRequire(file)("typescript");
|
|
109
112
|
const root = packageRoot(file);
|
|
110
|
-
if (compiler.sys === void 0 || !("createProgram" in compiler))
|
|
113
|
+
if (compiler.sys === void 0 || !("createProgram" in compiler)) return {
|
|
114
|
+
root,
|
|
115
|
+
version: compiler.version
|
|
116
|
+
};
|
|
111
117
|
return {
|
|
112
|
-
compiler,
|
|
113
118
|
root,
|
|
114
|
-
|
|
119
|
+
compiler
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/** Loads the compiler a package builds with, including a package-local installation in a workspace. A package that declares `typescript` (itself or through its workspace root) but cannot resolve it is an error; only a package that declares none falls back to the one `dts-bundle-generator` brings, with a `notice`. A TypeScript without the programmatic API (7 and later) is an error, unless `javascriptOnly` says the caller only strips comments and emits JavaScript, so the pack's TypeScript emits both revisions instead, with a `notice`. */
|
|
123
|
+
function loadTypeScript(directory, javascriptOnly = false) {
|
|
124
|
+
const { file, fallback } = resolveTypeScript(directory);
|
|
125
|
+
const loaded = requireTypeScript(file);
|
|
126
|
+
if (loaded.compiler !== void 0) return {
|
|
127
|
+
compiler: loaded.compiler,
|
|
128
|
+
root: loaded.root,
|
|
129
|
+
notice: fallback ? `${repositoryDirectory(directory)}: declares no typescript; using the pack's TypeScript ${loaded.compiler.version}\n` : void 0
|
|
130
|
+
};
|
|
131
|
+
const pack = javascriptOnly && !fallback ? requireTypeScript(packTypeScript()) : loaded;
|
|
132
|
+
if (pack.compiler === void 0) throw new Error(`TypeScript ${loaded.version} at ${loaded.root} has no programmatic compiler API (sys, createProgram), so this package cannot be analysed. Build it with a TypeScript that has one, or mark the package private.`);
|
|
133
|
+
return {
|
|
134
|
+
compiler: pack.compiler,
|
|
135
|
+
root: pack.root,
|
|
136
|
+
notice: `${repositoryDirectory(directory)}: TypeScript ${loaded.version} has no programmatic compiler API; emitting JavaScript with the pack's TypeScript ${pack.compiler.version}\n`
|
|
115
137
|
};
|
|
116
138
|
}
|
|
117
139
|
const TEST_SOURCE_GLOBS = [
|
|
@@ -125,16 +147,19 @@ function isTestSource(root, file) {
|
|
|
125
147
|
const path = relative(root, file).split("\\").join("/");
|
|
126
148
|
return TEST_SOURCE_GLOBS.some((pattern) => matchesGlob(path, pattern));
|
|
127
149
|
}
|
|
128
|
-
function
|
|
129
|
-
|
|
130
|
-
if (errors.length) throw new Error(compiler.formatDiagnostics(errors, {
|
|
150
|
+
function formatErrors(compiler, diagnostics) {
|
|
151
|
+
return compiler.formatDiagnostics(diagnostics.filter((item) => item.category === compiler.DiagnosticCategory.Error), {
|
|
131
152
|
getCanonicalFileName: (file) => file,
|
|
132
153
|
getCurrentDirectory: () => process.cwd(),
|
|
133
154
|
getNewLine: () => "\n"
|
|
134
|
-
})
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function failDiagnostics(compiler, diagnostics) {
|
|
158
|
+
const errors = formatErrors(compiler, diagnostics);
|
|
159
|
+
if (errors) throw new Error(errors);
|
|
135
160
|
}
|
|
136
161
|
/** Declaration inputs are part of the local closure but TypeScript does not emit copies of them. */
|
|
137
|
-
function copyDeclarations(program, directory, output) {
|
|
162
|
+
function copyDeclarations(program, directory, output, modules) {
|
|
138
163
|
const sources = program.getSourceFiles().filter((source) => !program.isSourceFileDefaultLibrary(source) && !program.isSourceFileFromExternalLibrary(source) && !relative(directory, source.fileName).startsWith(`..${sep}`) && !isTestSource(directory, source.fileName));
|
|
139
164
|
const authored = sources.filter((source) => !source.isDeclarationFile);
|
|
140
165
|
let root = dirname((authored[0] ?? sources[0])?.fileName ?? join(directory, "index.ts"));
|
|
@@ -149,29 +174,79 @@ function copyDeclarations(program, directory, output) {
|
|
|
149
174
|
mkdirSync(dirname(target), { recursive: true });
|
|
150
175
|
writeFileSync(target, source.text);
|
|
151
176
|
files.push(target);
|
|
177
|
+
modules.set(resolve(target), source.fileName);
|
|
152
178
|
}
|
|
153
179
|
return files;
|
|
154
180
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
181
|
+
/** TS18002: `"files": []` without references. */
|
|
182
|
+
const EMPTY_FILES_LIST = 18002;
|
|
183
|
+
function readConfig(directory, javascriptOnly = false) {
|
|
184
|
+
const { compiler, root, notice } = loadTypeScript(directory, javascriptOnly);
|
|
185
|
+
const file = join(directory, "tsconfig.json");
|
|
186
|
+
const config = compiler.readConfigFile(file, compiler.sys.readFile);
|
|
158
187
|
if (config.error) failDiagnostics(compiler, [config.error]);
|
|
159
|
-
const parsed = compiler.parseJsonConfigFileContent(config.config, compiler.sys, directory);
|
|
160
|
-
failDiagnostics(compiler, parsed.errors);
|
|
161
188
|
return {
|
|
162
189
|
compiler,
|
|
163
190
|
root,
|
|
164
191
|
notice,
|
|
165
|
-
parsed
|
|
192
|
+
parsed: compiler.parseJsonConfigFileContent(config.config, compiler.sys, directory, void 0, file)
|
|
166
193
|
};
|
|
167
194
|
}
|
|
195
|
+
/** Parses `tsconfig.json` as `tsc -p` would from the package directory, failing on any configuration error. */
|
|
196
|
+
function parseConfig(directory, javascriptOnly = false) {
|
|
197
|
+
const config = readConfig(directory, javascriptOnly);
|
|
198
|
+
failDiagnostics(config.compiler, config.parsed.errors);
|
|
199
|
+
return config;
|
|
200
|
+
}
|
|
201
|
+
/** Whether `tsconfig.json` has an empty `files` list, references nothing, and so parses to no inputs; read for a JavaScript-only emit, so a compiler without the API falls back as `emitPackage` does. */
|
|
202
|
+
function listsNoFiles(directory) {
|
|
203
|
+
const { parsed } = readConfig(directory, true);
|
|
204
|
+
return parsed.fileNames.length === 0 && parsed.errors.some((error) => error.code === EMPTY_FILES_LIST);
|
|
205
|
+
}
|
|
206
|
+
/** The absolute paths of the configs `tsconfig.json` extends, directly or through another config; read for a JavaScript-only emit, as `listsNoFiles` is. */
|
|
207
|
+
function extendedConfigs(directory) {
|
|
208
|
+
const { compiler } = loadTypeScript(directory, true);
|
|
209
|
+
const file = join(directory, "tsconfig.json");
|
|
210
|
+
const source = compiler.readJsonConfigFile(file, compiler.sys.readFile);
|
|
211
|
+
compiler.parseJsonSourceFileConfigFileContent(source, compiler.sys, directory, void 0, file);
|
|
212
|
+
return (source.extendedSourceFiles ?? []).map((path) => resolve(path));
|
|
213
|
+
}
|
|
214
|
+
/** TypeScript records on parsed options, untyped, the directory of the config that declares `paths`, which its targets resolve against when no `baseUrl` is set. */
|
|
215
|
+
function isRecordedDirectory(value) {
|
|
216
|
+
return typeof value === "string";
|
|
217
|
+
}
|
|
218
|
+
/** The configured `paths`, each target made absolute against `baseUrl`, else the directory of the config that declares `paths`. */
|
|
219
|
+
function absolutePaths(options) {
|
|
220
|
+
const { paths, baseUrl, pathsBasePath } = options;
|
|
221
|
+
if (paths === void 0 || !isRecordedDirectory(pathsBasePath)) return void 0;
|
|
222
|
+
const base = baseUrl ?? pathsBasePath;
|
|
223
|
+
return Object.fromEntries(Object.entries(paths).map(([key, targets]) => [key, targets.map((target) => resolve(base, target))]));
|
|
224
|
+
}
|
|
168
225
|
/** The configured `outDir`, the root under which the declaration half already judges a built path as test output. */
|
|
169
226
|
function outputRoot(directory) {
|
|
170
227
|
return resolve(directory, parseConfig(directory).parsed.options.outDir ?? ".");
|
|
171
228
|
}
|
|
172
|
-
/**
|
|
229
|
+
/** The root TypeScript lays its emit out under: `rootDir`, else the common directory of every authored source in `program`, wherever it sits. */
|
|
230
|
+
function emitRoot(program) {
|
|
231
|
+
const authored = program.getSourceFiles().filter((source) => !source.isDeclarationFile && !program.isSourceFileFromExternalLibrary(source)).map((source) => source.fileName);
|
|
232
|
+
let root = dirname(authored[0] ?? ".");
|
|
233
|
+
for (const file of authored) while (relative(root, file).startsWith(`..${sep}`)) root = dirname(root);
|
|
234
|
+
return program.getCompilerOptions().rootDir ?? root;
|
|
235
|
+
}
|
|
236
|
+
/** The declaration TypeScript withheld for each module with a declaration error, at the path its emit would have used, mapped to that module. */
|
|
237
|
+
function withheldDeclarations(program, diagnostics, output, directory) {
|
|
238
|
+
const root = emitRoot(program);
|
|
239
|
+
const withheld = /* @__PURE__ */ new Map();
|
|
240
|
+
for (const { file } of diagnostics) {
|
|
241
|
+
if (file === void 0 || isTestSource(directory, file.fileName)) continue;
|
|
242
|
+
const path = resolve(output, relative(root, file.fileName)).replace(/\.([cm]?)[jt]sx?$/u, ".d.$1ts");
|
|
243
|
+
withheld.set(path, file.fileName);
|
|
244
|
+
}
|
|
245
|
+
return withheld;
|
|
246
|
+
}
|
|
247
|
+
/** Emits with the package's compiler and config, or for JavaScript alone with the pack's when the package's has no compiler API; test roots and outputs never enter either proof. `modules` maps each emitted, copied or `withheld` file to its source module; `paths` is the configured `paths` with absolute targets. */
|
|
173
248
|
function emitPackage(directory, output, declarations) {
|
|
174
|
-
const { compiler, root, notice, parsed } = parseConfig(directory);
|
|
249
|
+
const { compiler, root, notice, parsed } = parseConfig(directory, !declarations);
|
|
175
250
|
const options = {
|
|
176
251
|
...parsed.options,
|
|
177
252
|
rootDir: parsed.options.rootDir ?? (parsed.options.outDir ? void 0 : directory),
|
|
@@ -196,10 +271,17 @@ function emitPackage(directory, output, declarations) {
|
|
|
196
271
|
options,
|
|
197
272
|
projectReferences: parsed.projectReferences
|
|
198
273
|
});
|
|
199
|
-
if (declarations) failDiagnostics(compiler,
|
|
274
|
+
if (declarations) failDiagnostics(compiler, [
|
|
275
|
+
...program.getConfigFileParsingDiagnostics(),
|
|
276
|
+
...program.getOptionsDiagnostics(),
|
|
277
|
+
...program.getSyntacticDiagnostics(),
|
|
278
|
+
...program.getGlobalDiagnostics(),
|
|
279
|
+
...program.getSemanticDiagnostics()
|
|
280
|
+
]);
|
|
281
|
+
const declarationDiagnostics = declarations ? program.getDeclarationDiagnostics() : [];
|
|
200
282
|
const files = [];
|
|
201
283
|
const modules = /* @__PURE__ */ new Map();
|
|
202
|
-
|
|
284
|
+
program.emit(void 0, (file, text, _bom, _onError, sources) => {
|
|
203
285
|
if (sources?.some((source) => isTestSource(directory, source.fileName))) return;
|
|
204
286
|
if (declarations ? !/\.d\.[cm]?ts$/.test(file) : !/\.[cm]?jsx?$/.test(file)) return;
|
|
205
287
|
mkdirSync(dirname(file), { recursive: true });
|
|
@@ -207,16 +289,30 @@ function emitPackage(directory, output, declarations) {
|
|
|
207
289
|
files.push(file);
|
|
208
290
|
if (sources?.[0] !== void 0) modules.set(resolve(file), sources[0].fileName);
|
|
209
291
|
});
|
|
210
|
-
|
|
211
|
-
if (declarations) files.push(...copyDeclarations(program, directory, output));
|
|
292
|
+
const withheld = withheldDeclarations(program, declarationDiagnostics, output, directory);
|
|
293
|
+
if (declarations) files.push(...copyDeclarations(program, directory, output, modules));
|
|
294
|
+
for (const [file, source] of withheld) modules.set(file, source);
|
|
212
295
|
return {
|
|
213
296
|
compiler,
|
|
214
297
|
compilerRoot: root,
|
|
215
298
|
notice,
|
|
216
299
|
files,
|
|
300
|
+
withheld: [...withheld.keys()],
|
|
217
301
|
modules,
|
|
218
|
-
options: parsed.options
|
|
302
|
+
options: parsed.options,
|
|
303
|
+
paths: absolutePaths(parsed.options),
|
|
304
|
+
/** The formatted declaration errors of the modules `sources` reach; empty when there are none. A declaration error in a module no published entry reaches never fails the proof. */
|
|
305
|
+
declarationErrors(sources) {
|
|
306
|
+
if (!declarationDiagnostics.length) return "";
|
|
307
|
+
const reached = new Set(compiler.createProgram({
|
|
308
|
+
rootNames: sources,
|
|
309
|
+
options,
|
|
310
|
+
projectReferences: parsed.projectReferences,
|
|
311
|
+
oldProgram: program
|
|
312
|
+
}).getSourceFiles().map((source) => source.fileName));
|
|
313
|
+
return formatErrors(compiler, declarationDiagnostics.filter((item) => item.file !== void 0 && reached.has(item.file.fileName)));
|
|
314
|
+
}
|
|
219
315
|
};
|
|
220
316
|
}
|
|
221
317
|
//#endregion
|
|
222
|
-
export {
|
|
318
|
+
export { listsNoFiles as a, packagesAt as c, isTestSource as i, unpublishedAt as l, extendedConfigs as n, loadTypeScript as o, isExportPath as r, outputRoot as s, emitPackage as t };
|