@antelopejs/tooling-configs 0.4.1 → 0.5.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/README.md +38 -26
- 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 +132 -11
- package/dist/bin/comment-proof.mjs +29 -7
- package/dist/bin/garden.mjs +2 -57
- package/dist/bin/ratchet.mjs +48 -14
- package/dist/bin/suppressions.mjs +3 -3
- package/dist/bin/sync.mjs +74 -41
- package/dist/bin/verify.mjs +898 -366
- 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 +50 -55
- package/dist/oxc/guardrails/index.d.mts +1 -1
- package/dist/oxc/guardrails/index.mjs +520 -103
- package/dist/oxc/lint.d.mts +7 -15
- package/dist/oxc/lint.mjs +16 -28
- 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-BTiPMqam.mjs} +17 -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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as requireSafetyCommentForTypeAssertionRule } from "../../require-safety-comment-for-type-assertion-
|
|
1
|
+
import { a as isRuntimeFunction, i as enclosingTypeGuard, r as requireSafetyCommentForTypeAssertionRule } from "../../require-safety-comment-for-type-assertion-mnb0CIxa.mjs";
|
|
2
2
|
import { defineRule, eslintCompatPlugin } from "@oxlint/plugins";
|
|
3
3
|
//#region src/oxc/anti-slop/rules/no-chained-type-assertions.ts
|
|
4
4
|
function isTypeAssertionExpression(node) {
|
|
@@ -9,6 +9,31 @@ function unwrapParenthesizedExpression(expression) {
|
|
|
9
9
|
while (current.type === "ParenthesizedExpression") current = current.expression;
|
|
10
10
|
return current;
|
|
11
11
|
}
|
|
12
|
+
function unwrapParenthesizedType(type) {
|
|
13
|
+
let current = type;
|
|
14
|
+
while (current.type === "TSParenthesizedType") current = current.typeAnnotation;
|
|
15
|
+
return current;
|
|
16
|
+
}
|
|
17
|
+
function instanceClassName(thisExpression) {
|
|
18
|
+
let scope = thisExpression.parent;
|
|
19
|
+
while (scope.type !== "FunctionExpression") {
|
|
20
|
+
if (scope.type === "Program" || scope.type === "FunctionDeclaration" || scope.type === "ClassBody") return null;
|
|
21
|
+
scope = scope.parent;
|
|
22
|
+
}
|
|
23
|
+
const declaresThis = scope.params.some((parameter) => parameter.type === "Identifier" && parameter.name === "this");
|
|
24
|
+
const method = scope.parent;
|
|
25
|
+
if (declaresThis || method.type !== "MethodDefinition" || method.static) return null;
|
|
26
|
+
const owner = method.parent.parent;
|
|
27
|
+
if (owner?.type !== "ClassDeclaration" && owner?.type !== "ClassExpression") return null;
|
|
28
|
+
return owner.id?.name ?? null;
|
|
29
|
+
}
|
|
30
|
+
function isPhantomRetypeOfThis(node) {
|
|
31
|
+
const target = unwrapParenthesizedType(node.typeAnnotation);
|
|
32
|
+
const inner = unwrapParenthesizedExpression(node.expression);
|
|
33
|
+
if (target.type !== "TSTypeReference" || target.typeName.type !== "Identifier" || (target.typeArguments?.params.length ?? 0) === 0 || !isTypeAssertionExpression(inner) || unwrapParenthesizedType(inner.typeAnnotation).type !== "TSUnknownKeyword") return false;
|
|
34
|
+
const source = unwrapParenthesizedExpression(inner.expression);
|
|
35
|
+
return source.type === "ThisExpression" && instanceClassName(source) === target.typeName.name;
|
|
36
|
+
}
|
|
12
37
|
function isConstAssertion(node) {
|
|
13
38
|
const { typeAnnotation } = node;
|
|
14
39
|
return typeAnnotation.type === "TSTypeReference" && typeAnnotation.typeName.type === "Identifier" && typeAnnotation.typeName.name === "const";
|
|
@@ -31,13 +56,19 @@ function isForbiddenAssertionChain(node) {
|
|
|
31
56
|
hasNonConstAssertion ||= !isConstAssertion(current);
|
|
32
57
|
current = unwrapParenthesizedExpression(current.expression);
|
|
33
58
|
}
|
|
34
|
-
return assertionCount > 1 && hasNonConstAssertion;
|
|
59
|
+
return assertionCount > 1 && hasNonConstAssertion && !isPhantomRetypeOfThis(node);
|
|
35
60
|
}
|
|
36
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Disallow nested TypeScript type assertions. Chains made only of const assertions pass, and so
|
|
63
|
+
* does `this as unknown as C<...>` in a non-static method of class `C`: the same instance under
|
|
64
|
+
* other type arguments, which TypeScript cannot express in one step when `C` is invariant in a
|
|
65
|
+
* phantom type parameter. require-safety-comment-for-type-assertion still asks it to state why the
|
|
66
|
+
* parameter holds no value.
|
|
67
|
+
*/
|
|
37
68
|
const noChainedTypeAssertionsRule = defineRule({
|
|
38
69
|
meta: {
|
|
39
70
|
type: "problem",
|
|
40
|
-
docs: { description: "Disallow chained TypeScript as and angle-bracket assertions, including parenthesized chains." },
|
|
71
|
+
docs: { description: "Disallow chained TypeScript as and angle-bracket assertions, including parenthesized chains, except `this as unknown as C<...>` in a non-static method of class C." },
|
|
41
72
|
messages: { chained: "This assertion chain discards type evidence. Keep the original precise type, or parse untrusted input at its boundary before narrowing it." }
|
|
42
73
|
},
|
|
43
74
|
createOnce(context) {
|
|
@@ -977,56 +1008,6 @@ function isSuppliedFromOutside(identifier, sourceCode) {
|
|
|
977
1008
|
return variable.defs.every((definition) => definition.type === "Parameter" || isModuleImport(definition)) && variable.references.every((reference) => !reference.isWrite());
|
|
978
1009
|
}
|
|
979
1010
|
//#endregion
|
|
980
|
-
//#region src/oxc/anti-slop/shared/type-guards.ts
|
|
981
|
-
/** Files whose functions may declare a type predicate in JSDoc instead of a TypeScript return type. */
|
|
982
|
-
const JSDOC_PREDICATE_FILE = /\.[cm]?js$/;
|
|
983
|
-
/** A `@returns {x is T}` type, `x` captured: `asserts x is T` does not match. */
|
|
984
|
-
const JSDOC_PREDICATE = /^\s*([A-Za-z_$][\w$]*)\s+is\s+\S/;
|
|
985
|
-
function isRuntimeFunction(node) {
|
|
986
|
-
return node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression";
|
|
987
|
-
}
|
|
988
|
-
/** Return the statement or member a JSDoc block documenting this function is attached to. */
|
|
989
|
-
function documentedNode(fn) {
|
|
990
|
-
const parent = fn.parent;
|
|
991
|
-
if ((parent.type === "Property" || parent.type === "MethodDefinition") && parent.value === fn) return parent;
|
|
992
|
-
let node = fn;
|
|
993
|
-
if (parent.type === "VariableDeclarator" && parent.init === fn && parent.parent.type === "VariableDeclaration" && parent.parent.declarations.length === 1) node = parent.parent;
|
|
994
|
-
const container = node.parent;
|
|
995
|
-
return container !== null && (container.type === "ExportNamedDeclaration" || container.type === "ExportDefaultDeclaration") ? container : node;
|
|
996
|
-
}
|
|
997
|
-
/** Return the type inside the braces of the first `@returns {...}` tag of a JSDoc block. */
|
|
998
|
-
function jsDocReturnType(text) {
|
|
999
|
-
const tag = /@returns\s*\{/.exec(text);
|
|
1000
|
-
if (tag === null) return null;
|
|
1001
|
-
const start = tag.index + tag[0].length;
|
|
1002
|
-
let depth = 1;
|
|
1003
|
-
for (let index = start; index < text.length; index++) if (text[index] === "{") depth++;
|
|
1004
|
-
else if (text[index] === "}" && --depth === 0) return text.slice(start, index);
|
|
1005
|
-
return null;
|
|
1006
|
-
}
|
|
1007
|
-
/** Return whether the JSDoc block right before the function declares `@returns {param is T}` for one of its parameters. */
|
|
1008
|
-
function hasJsDocTypePredicate(fn, sourceCode) {
|
|
1009
|
-
const comment = sourceCode.getCommentsBefore(documentedNode(fn)).at(-1);
|
|
1010
|
-
if (comment === void 0 || comment.type !== "Block" || !comment.value.startsWith("*")) return false;
|
|
1011
|
-
const returnType = jsDocReturnType(comment.value);
|
|
1012
|
-
const subject = returnType === null ? void 0 : JSDOC_PREDICATE.exec(returnType)?.[1];
|
|
1013
|
-
return subject !== void 0 && fn.params.some((parameter) => parameter.type === "Identifier" && parameter.name === subject);
|
|
1014
|
-
}
|
|
1015
|
-
/** Return whether a function declares a type predicate or assertion, or a JSDoc `@returns {x is T}` in a `.js`, `.mjs` or `.cjs` file. */
|
|
1016
|
-
function isTypeGuard(fn, sourceCode, filename) {
|
|
1017
|
-
if (fn.returnType?.typeAnnotation.type === "TSTypePredicate") return true;
|
|
1018
|
-
return JSDOC_PREDICATE_FILE.test(filename) && hasJsDocTypePredicate(fn, sourceCode);
|
|
1019
|
-
}
|
|
1020
|
-
/** Return the nearest runtime function around a node when that function is a type guard. */
|
|
1021
|
-
function enclosingTypeGuard(node, sourceCode, filename) {
|
|
1022
|
-
let current = node.parent;
|
|
1023
|
-
while (current !== null && current.type !== "Program") {
|
|
1024
|
-
if (isRuntimeFunction(current)) return isTypeGuard(current, sourceCode, filename) ? current : null;
|
|
1025
|
-
current = current.parent;
|
|
1026
|
-
}
|
|
1027
|
-
return null;
|
|
1028
|
-
}
|
|
1029
|
-
//#endregion
|
|
1030
1011
|
//#region src/oxc/anti-slop/rules/no-runtime-typeof.ts
|
|
1031
1012
|
/** Return whether typeof safely probes for the existence of a possibly absent binding. */
|
|
1032
1013
|
function isExistenceProbe(node) {
|
|
@@ -1114,6 +1095,13 @@ function constructorCheckTarget(node) {
|
|
|
1114
1095
|
if (side.type === "MemberExpression" && !side.computed && side.property.type === "Identifier" && side.property.name === "constructor" && other.type === "Identifier" && TYPEOF_CONSTRUCTORS.has(other.name)) return other.name;
|
|
1115
1096
|
}
|
|
1116
1097
|
}
|
|
1098
|
+
/** Built-ins whose `instanceof` test re-implements a `typeof` result for every value but one from another realm. */
|
|
1099
|
+
const TYPEOF_INSTANCEOF_TARGETS = /* @__PURE__ */ new Set(["Function", "Object"]);
|
|
1100
|
+
/** Return the built-in name when the comparison is `x instanceof Function` or `x instanceof Object`. */
|
|
1101
|
+
function instanceofCheckTarget(node) {
|
|
1102
|
+
if (node.operator !== "instanceof" || node.right.type !== "Identifier") return void 0;
|
|
1103
|
+
return TYPEOF_INSTANCEOF_TARGETS.has(node.right.name) ? node.right.name : void 0;
|
|
1104
|
+
}
|
|
1117
1105
|
/** Disallow runtime typeof checks that narrow unparsed values instead of decoding them. */
|
|
1118
1106
|
const noRuntimeTypeofRule = defineRule({
|
|
1119
1107
|
meta: {
|
|
@@ -1121,7 +1109,8 @@ const noRuntimeTypeofRule = defineRule({
|
|
|
1121
1109
|
docs: { description: "Disallow runtime typeof checks; external values must be decoded into meaningful types at their I/O boundary. A `typeof` that only fills in the text of a message checks nothing." },
|
|
1122
1110
|
messages: {
|
|
1123
1111
|
runtimeTypeof: "A `typeof` check narrows a representation without establishing its contract. Parse input at its I/O boundary, then branch on the domain value.",
|
|
1124
|
-
constructorCheck: "`.constructor === {{name}}` is a `typeof` check in another form. Parse input at its I/O boundary, or move the check into a type guard such as `(value: unknown): value is string`."
|
|
1112
|
+
constructorCheck: "`.constructor === {{name}}` is a `typeof` check in another form. Parse input at its I/O boundary, or move the check into a type guard such as `(value: unknown): value is string`.",
|
|
1113
|
+
instanceofCheck: "`instanceof {{name}}` is a `typeof` check in another form. Parse input at its I/O boundary, or move the check into a type guard such as `(value: unknown): value is Function`."
|
|
1125
1114
|
},
|
|
1126
1115
|
schema: [{
|
|
1127
1116
|
type: "object",
|
|
@@ -1149,6 +1138,12 @@ const noRuntimeTypeofRule = defineRule({
|
|
|
1149
1138
|
messageId: "constructorCheck",
|
|
1150
1139
|
data: { name }
|
|
1151
1140
|
});
|
|
1141
|
+
const instanceofName = instanceofCheckTarget(node);
|
|
1142
|
+
if (instanceofName !== void 0 && !allowedInTypeGuard(node)) context.report({
|
|
1143
|
+
node,
|
|
1144
|
+
messageId: "instanceofCheck",
|
|
1145
|
+
data: { name: instanceofName }
|
|
1146
|
+
});
|
|
1152
1147
|
}
|
|
1153
1148
|
};
|
|
1154
1149
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as TEST_FILE_GLOBS, t as ASSERTION_FUNCTION_NAMES } from "../../shared-BG0Nkzh0.mjs";
|
|
2
2
|
//#region src/oxc/guardrails/index.d.ts
|
|
3
|
-
/** AntelopeJS rules that reject comments, inherited-key lookups, presence-only type guards, low-evidence tests
|
|
3
|
+
/** AntelopeJS rules that reject comments, inherited-key lookups, presence-only type guards, unchecked Object.assign writes, low-evidence tests, files no tsconfig lists and tsconfigs that list no `types`. */
|
|
4
4
|
declare const guardrailsPlugin: import("@oxlint/plugins").Plugin;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { ASSERTION_FUNCTION_NAMES, TEST_FILE_GLOBS, guardrailsPlugin as default };
|