@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as matcherChain, i as isAssertion, n as TEST_FILE_GLOBS, o as memberName, r as callName, s as testCallback, t as ASSERTION_FUNCTION_NAMES } from "../../shared-WC0z3y9F.mjs";
|
|
2
2
|
import { existsSync, lstatSync, readFileSync, realpathSync } from "node:fs";
|
|
3
|
-
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
4
4
|
import { defineRule, eslintCompatPlugin } from "@oxlint/plugins";
|
|
5
5
|
import ts from "typescript";
|
|
6
6
|
//#region src/oxc/guardrails/rules/no-comments.ts
|
|
@@ -394,13 +394,193 @@ function isHasOwnPropertyCall(callee) {
|
|
|
394
394
|
return callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" && callee.property.name === "call" && callee.object.type === "MemberExpression" && !callee.object.computed && callee.object.property.type === "Identifier" && callee.object.property.name === "hasOwnProperty";
|
|
395
395
|
}
|
|
396
396
|
//#endregion
|
|
397
|
+
//#region src/oxc/guardrails/own-key-guard.ts
|
|
398
|
+
const HAS_OWN_CALLS = /* @__PURE__ */ new Set(["Object.hasOwn", "hasOwnProperty.call"]);
|
|
399
|
+
const EXITS = /* @__PURE__ */ new Set([
|
|
400
|
+
"BreakStatement",
|
|
401
|
+
"ContinueStatement",
|
|
402
|
+
"ReturnStatement",
|
|
403
|
+
"ThrowStatement"
|
|
404
|
+
]);
|
|
405
|
+
function checksOwnKey(node, read) {
|
|
406
|
+
const [first, second] = node.arguments;
|
|
407
|
+
if (first === void 0) return false;
|
|
408
|
+
const text = (argument) => read.source.getText(argument);
|
|
409
|
+
if (HAS_OWN_CALLS.has(callName(node.callee) ?? "") || isHasOwnPropertyCall(node.callee)) return second !== void 0 && text(first) === read.table && text(second) === read.key;
|
|
410
|
+
const callee = node.callee;
|
|
411
|
+
return callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" && callee.property.name === "hasOwnProperty" && text(callee.object) === read.table && text(first) === read.key;
|
|
412
|
+
}
|
|
413
|
+
const EQUALITY = /* @__PURE__ */ new Set(["==", "==="]);
|
|
414
|
+
const INEQUALITY = /* @__PURE__ */ new Set(["!=", "!=="]);
|
|
415
|
+
const MAX_DEPTH$2 = 8;
|
|
416
|
+
const ASSERTS = /* @__PURE__ */ new Set([
|
|
417
|
+
"assert",
|
|
418
|
+
"assert.ok",
|
|
419
|
+
"assert.strict"
|
|
420
|
+
]);
|
|
421
|
+
/** The initializer of a `const` the identifier names, such as `has` in `const has = Object.hasOwn(t, k)`. */
|
|
422
|
+
function constValue(node, read) {
|
|
423
|
+
const [definition] = resolveVariable(read.source, node)?.defs ?? [];
|
|
424
|
+
if (definition?.type !== "Variable" || definition.parent?.type !== "VariableDeclaration" || definition.parent.kind !== "const" || definition.node.type !== "VariableDeclarator") return null;
|
|
425
|
+
return definition.node.init;
|
|
426
|
+
}
|
|
427
|
+
/** `x === true`, `x !== false` and their mirrors: the outcome `x` has when the comparison has `outcome`. */
|
|
428
|
+
function comparedOutcome(node, outcome) {
|
|
429
|
+
const equal = EQUALITY.has(node.operator);
|
|
430
|
+
if (!equal && !INEQUALITY.has(node.operator)) return null;
|
|
431
|
+
const [literal, operand] = node.right.type === "Literal" ? [node.right, node.left] : [node.left, node.right];
|
|
432
|
+
if (literal.type !== "Literal") return null;
|
|
433
|
+
const value = literal.value;
|
|
434
|
+
if (value !== true && value !== false) return null;
|
|
435
|
+
return {
|
|
436
|
+
operand,
|
|
437
|
+
outcome: outcome === equal === value
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
/** A value that is `true` or `false`, so comparing it with a boolean literal tests its truth: a call, a `!`, or a `const` of one. */
|
|
441
|
+
function isBooleanValued(node, read, depth) {
|
|
442
|
+
if (depth > MAX_DEPTH$2) return false;
|
|
443
|
+
if (node.type === "ParenthesizedExpression") return isBooleanValued(node.expression, read, depth);
|
|
444
|
+
if (node.type === "Identifier") {
|
|
445
|
+
const value = constValue(node, read);
|
|
446
|
+
return value !== null && isBooleanValued(value, read, depth + 1);
|
|
447
|
+
}
|
|
448
|
+
return node.type === "CallExpression" || node.type === "UnaryExpression" && node.operator === "!";
|
|
449
|
+
}
|
|
450
|
+
/** `Object.getOwnPropertyDescriptor(Object.prototype, key)?.value` or `Object.prototype[key]`: the value `Object.prototype` itself holds under the key. */
|
|
451
|
+
function isRootValue(node, read) {
|
|
452
|
+
const value = node.type === "ChainExpression" ? node.expression : node;
|
|
453
|
+
if (value.type !== "MemberExpression") return false;
|
|
454
|
+
const text = (part) => read.source.getText(part);
|
|
455
|
+
if (value.computed) return text(value.object) === "Object.prototype" && text(value.property) === read.key;
|
|
456
|
+
const call = value.object;
|
|
457
|
+
return value.property.type === "Identifier" && value.property.name === "value" && call.type === "CallExpression" && callName(call.callee) === "Object.getOwnPropertyDescriptor" && call.arguments.length === 2 && text(call.arguments[0]) === "Object.prototype" && text(call.arguments[1]) === read.key;
|
|
458
|
+
}
|
|
459
|
+
/** The outcome of `table[key] === <root value>` (or `!==`, either order) under which the read differs from `Object.prototype`'s own value, or `null` for another comparison. */
|
|
460
|
+
function differsFromRootWhen(node, read) {
|
|
461
|
+
const equal = EQUALITY.has(node.operator);
|
|
462
|
+
if (!equal && !INEQUALITY.has(node.operator)) return null;
|
|
463
|
+
const reads = (side) => side.type === "MemberExpression" && side.computed && read.source.getText(side.object) === read.table && read.source.getText(side.property) === read.key;
|
|
464
|
+
return reads(node.left) && isRootValue(node.right, read) || reads(node.right) && isRootValue(node.left, read) ? !equal : null;
|
|
465
|
+
}
|
|
466
|
+
/** `a && b` that is true, or `a || b` that is false, needs one operand to hold; `a || b` that is true, or `a && b` that is false, needs both. */
|
|
467
|
+
function combinedHolds(node, outcome, read, depth) {
|
|
468
|
+
const left = holds(node.left, outcome, read, depth);
|
|
469
|
+
const right = holds(node.right, outcome, read, depth);
|
|
470
|
+
if (node.operator === (outcome ? "&&" : "||")) return left || right;
|
|
471
|
+
return node.operator === (outcome ? "||" : "&&") && left && right;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Whether the key is safe to read whenever `node` evaluates to `outcome`: the table owns the key,
|
|
475
|
+
* the key is no `Object.prototype` name, or the table answers it with something other than
|
|
476
|
+
* `Object.prototype`'s own value.
|
|
477
|
+
*/
|
|
478
|
+
function holds(node, outcome, read, depth = 0) {
|
|
479
|
+
if (depth > MAX_DEPTH$2) return false;
|
|
480
|
+
switch (node.type) {
|
|
481
|
+
case "ParenthesizedExpression": return holds(node.expression, outcome, read, depth);
|
|
482
|
+
case "CallExpression": return outcome ? checksOwnKey(node, read) : checksOwnKey(node, {
|
|
483
|
+
...read,
|
|
484
|
+
table: "Object.prototype"
|
|
485
|
+
});
|
|
486
|
+
case "Identifier": {
|
|
487
|
+
const value = constValue(node, read);
|
|
488
|
+
return value !== null && holds(value, outcome, read, depth + 1);
|
|
489
|
+
}
|
|
490
|
+
case "UnaryExpression": return node.operator === "!" && holds(node.argument, !outcome, read, depth);
|
|
491
|
+
case "BinaryExpression": {
|
|
492
|
+
if (differsFromRootWhen(node, read) === outcome) return true;
|
|
493
|
+
const compared = comparedOutcome(node, outcome);
|
|
494
|
+
return compared !== null && isBooleanValued(compared.operand, read, depth) && holds(compared.operand, compared.outcome, read, depth);
|
|
495
|
+
}
|
|
496
|
+
case "LogicalExpression": return combinedHolds(node, outcome, read, depth);
|
|
497
|
+
default: return false;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
function exits(statement) {
|
|
501
|
+
if (statement.type === "BlockStatement") {
|
|
502
|
+
const last = statement.body.at(-1);
|
|
503
|
+
return last !== void 0 && exits(last);
|
|
504
|
+
}
|
|
505
|
+
if (statement.type === "IfStatement") return statement.alternate !== null && exits(statement.consequent) && exits(statement.alternate);
|
|
506
|
+
return EXITS.has(statement.type);
|
|
507
|
+
}
|
|
508
|
+
/** Whether a statement ends by storing `table[key]`, which makes the key own. */
|
|
509
|
+
function storesKey(statement, read) {
|
|
510
|
+
if (statement.type === "BlockStatement") {
|
|
511
|
+
const last = statement.body.at(-1);
|
|
512
|
+
return last !== void 0 && storesKey(last, read);
|
|
513
|
+
}
|
|
514
|
+
if (statement.type !== "ExpressionStatement") return false;
|
|
515
|
+
const assignment = statement.expression;
|
|
516
|
+
return assignment.type === "AssignmentExpression" && assignment.operator === "=" && assignment.left.type === "MemberExpression" && assignment.left.computed && read.source.getText(assignment.left.object) === read.table && read.source.getText(assignment.left.property) === read.key;
|
|
517
|
+
}
|
|
518
|
+
function settles(statement, read) {
|
|
519
|
+
return exits(statement) || storesKey(statement, read);
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* A statement after which the key is own: an `assert` of the check, or an `if` whose branch where
|
|
523
|
+
* the check fails leaves the block or stores the key.
|
|
524
|
+
*/
|
|
525
|
+
function establishes(statement, read) {
|
|
526
|
+
if (statement.type === "ExpressionStatement" && statement.expression.type === "CallExpression") {
|
|
527
|
+
const [condition] = statement.expression.arguments;
|
|
528
|
+
return ASSERTS.has(callName(statement.expression.callee) ?? "") && condition !== void 0 && holds(condition, true, read);
|
|
529
|
+
}
|
|
530
|
+
if (statement.type !== "IfStatement") return false;
|
|
531
|
+
if (settles(statement.consequent, read) && holds(statement.test, false, read)) return true;
|
|
532
|
+
return statement.alternate !== null && settles(statement.alternate, read) && holds(statement.test, true, read);
|
|
533
|
+
}
|
|
534
|
+
function statementsOf(node) {
|
|
535
|
+
if (node.type === "BlockStatement" || node.type === "Program" || node.type === "StaticBlock") return node.body;
|
|
536
|
+
return node.type === "SwitchCase" ? node.consequent : null;
|
|
537
|
+
}
|
|
538
|
+
function guardsChild(parent, child, read) {
|
|
539
|
+
if (parent.type === "ConditionalExpression" || parent.type === "IfStatement") {
|
|
540
|
+
if (child === parent.consequent) return holds(parent.test, true, read);
|
|
541
|
+
return child === parent.alternate && holds(parent.test, false, read);
|
|
542
|
+
}
|
|
543
|
+
if (parent.type === "LogicalExpression" && child === parent.right) return (parent.operator === "&&" || parent.operator === "||") && holds(parent.left, parent.operator === "&&", read);
|
|
544
|
+
if (parent.type === "WhileStatement") return child === parent.body && holds(parent.test, true, read);
|
|
545
|
+
if (parent.type === "ForStatement") return (child === parent.body || child === parent.update) && parent.test !== null && holds(parent.test, true, read);
|
|
546
|
+
const statements = statementsOf(parent);
|
|
547
|
+
if (statements === null) return false;
|
|
548
|
+
const index = statements.indexOf(child);
|
|
549
|
+
return statements.slice(0, Math.max(index, 0)).some((statement) => establishes(statement, read));
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Whether `node`, a read of `table[key]`, cannot answer a key only `Object.prototype` holds. It is
|
|
553
|
+
* compared with `Object.prototype`'s own value of the key, or a check guards it: an own-key check of
|
|
554
|
+
* `table` and `key` (`Object.hasOwn`, `hasOwnProperty.call`, `table.hasOwnProperty`), a failed
|
|
555
|
+
* `Object.prototype` membership check of `key`, or the read differing from `Object.prototype`'s
|
|
556
|
+
* value, directly, negated, combined with `&&`/`||`, compared with a boolean or held in a `const`.
|
|
557
|
+
* The check guards it when it holds in the branch of a conditional, `if`, `&&`/`||`, `while` or
|
|
558
|
+
* `for` that holds `node`, or an earlier statement asserts it, or leaves the block or stores the
|
|
559
|
+
* key where it fails.
|
|
560
|
+
*/
|
|
561
|
+
function isOwnKeyGuarded(node, table, key, source) {
|
|
562
|
+
const read = {
|
|
563
|
+
table,
|
|
564
|
+
key,
|
|
565
|
+
source
|
|
566
|
+
};
|
|
567
|
+
if (node.parent?.type === "BinaryExpression" && differsFromRootWhen(node.parent, read) !== null) return true;
|
|
568
|
+
let child = node;
|
|
569
|
+
let parent = node.parent;
|
|
570
|
+
while (parent !== null) {
|
|
571
|
+
if (guardsChild(parent, child, read)) return true;
|
|
572
|
+
child = parent;
|
|
573
|
+
parent = parent.parent;
|
|
574
|
+
}
|
|
575
|
+
return false;
|
|
576
|
+
}
|
|
577
|
+
//#endregion
|
|
397
578
|
//#region src/oxc/guardrails/rules/no-inherited-key-lookup.ts
|
|
398
579
|
const WRAPPER_TYPES = /* @__PURE__ */ new Set([
|
|
399
580
|
"Readonly",
|
|
400
581
|
"Partial",
|
|
401
582
|
"Required"
|
|
402
583
|
]);
|
|
403
|
-
const HAS_OWN_CALLS = /* @__PURE__ */ new Set(["Object.hasOwn", "hasOwnProperty.call"]);
|
|
404
584
|
const MAX_ALIAS_DEPTH$1 = 8;
|
|
405
585
|
function isStringKey(type) {
|
|
406
586
|
if (type.type === "TSStringKeyword") return true;
|
|
@@ -461,7 +641,19 @@ function variableKind(variable, environment, depth) {
|
|
|
461
641
|
const annotation = annotationOf(definition);
|
|
462
642
|
if (definition.type === "Parameter") return annotation !== void 0 && isStringKeyedType(annotation, environment, depth) ? "dictionary" : null;
|
|
463
643
|
if (definition.type !== "Variable" || definition.node.type !== "VariableDeclarator") return null;
|
|
464
|
-
|
|
644
|
+
const declared = declaredKind(annotation, definition.node.init, environment, depth);
|
|
645
|
+
if (declared !== null || depth >= MAX_ALIAS_DEPTH$1 || definition.parent?.type !== "VariableDeclaration" || definition.parent.kind !== "const" || definition.node.init === null || !isOpaqueAnnotation(annotation)) return declared;
|
|
646
|
+
return tableKind(widened(definition.node.init), environment, depth + 1);
|
|
647
|
+
}
|
|
648
|
+
/** The value under `as unknown` and `as any` casts, which widen the type without changing the value. */
|
|
649
|
+
function widened(init) {
|
|
650
|
+
let value = init;
|
|
651
|
+
while (value.type === "TSAsExpression" && isOpaqueAnnotation(value.typeAnnotation)) value = value.expression;
|
|
652
|
+
return value;
|
|
653
|
+
}
|
|
654
|
+
/** No annotation, `unknown` or `any`: the alias holds whatever its initializer holds. */
|
|
655
|
+
function isOpaqueAnnotation(annotation) {
|
|
656
|
+
return annotation === void 0 || annotation.type === "TSUnknownKeyword" || annotation.type === "TSAnyKeyword";
|
|
465
657
|
}
|
|
466
658
|
/** The table a field declares, given its type annotation and initializer. */
|
|
467
659
|
function declaredKind(annotation, init, environment, depth) {
|
|
@@ -493,27 +685,22 @@ function isWrite(node) {
|
|
|
493
685
|
if (parent.type === "UnaryExpression") return parent.operator === "delete";
|
|
494
686
|
return (parent.type === "ForInStatement" || parent.type === "ForOfStatement") && parent.left === node;
|
|
495
687
|
}
|
|
496
|
-
function ownKeyCheck(node, source) {
|
|
497
|
-
const [first, second] = node.arguments;
|
|
498
|
-
if (first === void 0) return null;
|
|
499
|
-
if (HAS_OWN_CALLS.has(callName(node.callee) ?? "") || isHasOwnPropertyCall(node.callee)) return second === void 0 ? null : {
|
|
500
|
-
table: source.getText(first),
|
|
501
|
-
key: source.getText(second)
|
|
502
|
-
};
|
|
503
|
-
const callee = node.callee;
|
|
504
|
-
if (callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" && callee.property.name === "hasOwnProperty") return {
|
|
505
|
-
table: source.getText(callee.object),
|
|
506
|
-
key: source.getText(first)
|
|
507
|
-
};
|
|
508
|
-
return null;
|
|
509
|
-
}
|
|
510
688
|
function isPredicateKey(node) {
|
|
511
689
|
const fn = enclosingFunction(node);
|
|
512
690
|
const predicate = fn === null ? null : parameterPredicate(fn);
|
|
513
691
|
return predicate !== null && node.left.type === "Identifier" && predicateName(predicate) === node.left.name;
|
|
514
692
|
}
|
|
515
|
-
|
|
516
|
-
|
|
693
|
+
/** The value a `const { [key]: x } = value` declaration or `({ [key]: x } = value)` assignment reads. */
|
|
694
|
+
function destructuredValue(pattern) {
|
|
695
|
+
const parent = pattern.parent;
|
|
696
|
+
if (parent.type === "VariableDeclarator") return parent.id === pattern ? parent.init : null;
|
|
697
|
+
return parent.type === "AssignmentExpression" && parent.left === pattern ? parent.right : null;
|
|
698
|
+
}
|
|
699
|
+
/** A destructured binding nothing reads or exports, such as `_removed` in `const { [key]: _removed, ...rest } = table`. */
|
|
700
|
+
function isDiscarded(value, source) {
|
|
701
|
+
if (value.type !== "Identifier") return false;
|
|
702
|
+
const variable = resolveVariable(source, value);
|
|
703
|
+
return variable !== null && variable.defs.every((definition) => definition.parent?.parent?.type !== "ExportNamedDeclaration") && !variable.references.some((reference) => reference.isRead());
|
|
517
704
|
}
|
|
518
705
|
/** Lookups into string-keyed object tables must not answer inherited `Object.prototype` keys. */
|
|
519
706
|
const noInheritedKeyLookupRule = defineRule({
|
|
@@ -527,56 +714,52 @@ const noInheritedKeyLookupRule = defineRule({
|
|
|
527
714
|
},
|
|
528
715
|
createOnce(context) {
|
|
529
716
|
let environment = null;
|
|
530
|
-
|
|
531
|
-
|
|
717
|
+
const report = (candidate) => {
|
|
718
|
+
if (!isOwnKeyGuarded(candidate.node, candidate.table, candidate.key, context.sourceCode)) context.report({
|
|
719
|
+
node: candidate.node,
|
|
720
|
+
messageId: candidate.messageId,
|
|
721
|
+
data: {
|
|
722
|
+
table: candidate.table,
|
|
723
|
+
key: candidate.key
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
};
|
|
727
|
+
const lookup = (node, object, key) => {
|
|
728
|
+
if (environment === null) return;
|
|
729
|
+
const kind = tableKind(object, environment);
|
|
730
|
+
if (kind === null || kind === "literal" && key.type !== "TSAsExpression") return;
|
|
731
|
+
const table = context.sourceCode.getText(object);
|
|
732
|
+
if (isKnownKey(key, table, context.sourceCode)) return;
|
|
733
|
+
report({
|
|
734
|
+
node,
|
|
735
|
+
messageId: "lookup",
|
|
736
|
+
table,
|
|
737
|
+
key: context.sourceCode.getText(key)
|
|
738
|
+
});
|
|
739
|
+
};
|
|
532
740
|
return {
|
|
533
741
|
Program(node) {
|
|
534
742
|
environment = {
|
|
535
743
|
source: context.sourceCode,
|
|
536
|
-
types: collectLocalTypes(node)
|
|
537
|
-
program: node
|
|
744
|
+
types: collectLocalTypes(node)
|
|
538
745
|
};
|
|
539
|
-
candidates = [];
|
|
540
|
-
checks = [];
|
|
541
746
|
},
|
|
542
747
|
MemberExpression(node) {
|
|
543
|
-
if (
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
const
|
|
547
|
-
if (
|
|
548
|
-
|
|
549
|
-
node,
|
|
550
|
-
messageId: "lookup",
|
|
551
|
-
table,
|
|
552
|
-
key: context.sourceCode.getText(node.property)
|
|
553
|
-
});
|
|
748
|
+
if (node.computed && !isWrite(node)) lookup(node, node.object, node.property);
|
|
749
|
+
},
|
|
750
|
+
ObjectPattern(node) {
|
|
751
|
+
const object = destructuredValue(node);
|
|
752
|
+
if (object === null) return;
|
|
753
|
+
for (const property of node.properties) if (property.type === "Property" && property.computed && !isDiscarded(property.value, context.sourceCode)) lookup(property, object, property.key);
|
|
554
754
|
},
|
|
555
755
|
BinaryExpression(node) {
|
|
556
756
|
if (environment === null || node.operator !== "in" || isStaticKey(node.left) || isPredicateKey(node) || tableKind(node.right, environment) === null) return;
|
|
557
|
-
|
|
757
|
+
report({
|
|
558
758
|
node,
|
|
559
759
|
messageId: "inOperator",
|
|
560
760
|
table: context.sourceCode.getText(node.right),
|
|
561
761
|
key: context.sourceCode.getText(node.left)
|
|
562
762
|
});
|
|
563
|
-
},
|
|
564
|
-
CallExpression(node) {
|
|
565
|
-
const check = ownKeyCheck(node, context.sourceCode);
|
|
566
|
-
if (check !== null && environment !== null) checks.push({
|
|
567
|
-
...check,
|
|
568
|
-
scope: enclosingFunction(node) ?? environment.program
|
|
569
|
-
});
|
|
570
|
-
},
|
|
571
|
-
"Program:exit"() {
|
|
572
|
-
for (const candidate of candidates) if (!checks.some((check) => check.table === candidate.table && check.key === candidate.key && contains(check.scope, candidate.node))) context.report({
|
|
573
|
-
node: candidate.node,
|
|
574
|
-
messageId: candidate.messageId,
|
|
575
|
-
data: {
|
|
576
|
-
table: candidate.table,
|
|
577
|
-
key: candidate.key
|
|
578
|
-
}
|
|
579
|
-
});
|
|
580
763
|
}
|
|
581
764
|
};
|
|
582
765
|
}
|
|
@@ -846,6 +1029,234 @@ const noPresenceOnlyTypeGuardRule = defineRule({
|
|
|
846
1029
|
}
|
|
847
1030
|
});
|
|
848
1031
|
//#endregion
|
|
1032
|
+
//#region src/oxc/guardrails/rules/no-read-then-insert.ts
|
|
1033
|
+
const READ_METHODS = /* @__PURE__ */ new Set([
|
|
1034
|
+
"get",
|
|
1035
|
+
"getBy",
|
|
1036
|
+
"getAll",
|
|
1037
|
+
"count",
|
|
1038
|
+
"find",
|
|
1039
|
+
"findOne"
|
|
1040
|
+
]);
|
|
1041
|
+
const INSERT_METHODS = /* @__PURE__ */ new Set([
|
|
1042
|
+
"insert",
|
|
1043
|
+
"insertOne",
|
|
1044
|
+
"insertMany"
|
|
1045
|
+
]);
|
|
1046
|
+
const INLINE_CALLBACK_METHODS = /* @__PURE__ */ new Set([
|
|
1047
|
+
"map",
|
|
1048
|
+
"flatMap",
|
|
1049
|
+
"forEach",
|
|
1050
|
+
"filter",
|
|
1051
|
+
"reduce",
|
|
1052
|
+
"some",
|
|
1053
|
+
"every",
|
|
1054
|
+
"then",
|
|
1055
|
+
"catch",
|
|
1056
|
+
"finally"
|
|
1057
|
+
]);
|
|
1058
|
+
const DUPLICATE_CHECK = /duplicate|unique|conflict|E11000|^11000$|23505|ER_DUP_ENTRY/iu;
|
|
1059
|
+
function contains(outer, inner) {
|
|
1060
|
+
return outer[0] <= inner[0] && inner[1] <= outer[1];
|
|
1061
|
+
}
|
|
1062
|
+
function isScope(node) {
|
|
1063
|
+
return node.type === "Program" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression";
|
|
1064
|
+
}
|
|
1065
|
+
function enclosingScope(node) {
|
|
1066
|
+
let current = node.parent;
|
|
1067
|
+
while (current !== null) {
|
|
1068
|
+
if (isScope(current)) return current;
|
|
1069
|
+
current = current.parent;
|
|
1070
|
+
}
|
|
1071
|
+
return null;
|
|
1072
|
+
}
|
|
1073
|
+
/** A callback that runs while its caller waits: handed to `map`, `then` or the like, or to a call whose value the caller awaits or returns. A handler registered by `app.post(...)` or wrapped by `export const POST = withAuth(...)` runs later, on its own. */
|
|
1074
|
+
function isInlineCallback(scope) {
|
|
1075
|
+
const call = scope.parent;
|
|
1076
|
+
if (scope.type === "Program" || scope.type === "FunctionDeclaration" || call?.type !== "CallExpression" || !call.arguments.some((argument) => argument === scope)) return false;
|
|
1077
|
+
const method = call.callee.type === "MemberExpression" ? memberName(call.callee) : null;
|
|
1078
|
+
return method !== null && INLINE_CALLBACK_METHODS.has(method) || isAwaited(call);
|
|
1079
|
+
}
|
|
1080
|
+
/** Whether the call's value reaches an `await` or a `return`, through array elements, call arguments, `?.` or a `.then` chain, or is the body of an inline arrow. */
|
|
1081
|
+
function isAwaited(call) {
|
|
1082
|
+
let node = call;
|
|
1083
|
+
let parent = node.parent;
|
|
1084
|
+
while (parent !== null) {
|
|
1085
|
+
if (parent.type === "AwaitExpression" || parent.type === "ReturnStatement") return true;
|
|
1086
|
+
if (parent.type === "ArrowFunctionExpression" && parent.body === node) return isInlineCallback(parent);
|
|
1087
|
+
if (!(parent.type === "ArrayExpression" || parent.type === "ChainExpression" || parent.type === "SpreadElement" || parent.type === "CallExpression" || parent.type === "MemberExpression" && parent.object === node)) return false;
|
|
1088
|
+
node = parent;
|
|
1089
|
+
parent = node.parent;
|
|
1090
|
+
}
|
|
1091
|
+
return false;
|
|
1092
|
+
}
|
|
1093
|
+
/** The function a read or an insert runs in, seen through inline callbacks such as `withRetry(() => model.getAll())` or `rows.map((row) => model.insert(row))`. */
|
|
1094
|
+
function runningScope(node) {
|
|
1095
|
+
let scope = enclosingScope(node);
|
|
1096
|
+
while (scope !== null && isInlineCallback(scope)) scope = enclosingScope(scope);
|
|
1097
|
+
return scope;
|
|
1098
|
+
}
|
|
1099
|
+
function chainsFrom(node, call) {
|
|
1100
|
+
let current = node;
|
|
1101
|
+
while (current !== call) if (current.type === "CallExpression") current = current.callee;
|
|
1102
|
+
else if (current.type === "MemberExpression") current = current.object;
|
|
1103
|
+
else return false;
|
|
1104
|
+
return true;
|
|
1105
|
+
}
|
|
1106
|
+
function rootName(node) {
|
|
1107
|
+
let current = node;
|
|
1108
|
+
while (current.type === "MemberExpression" || current.type === "CallExpression") current = current.type === "MemberExpression" ? current.object : current.callee;
|
|
1109
|
+
return current.type === "Identifier" ? current.name : null;
|
|
1110
|
+
}
|
|
1111
|
+
function declares(scope, name) {
|
|
1112
|
+
return scope.type !== "Program" && scope.params.some((param) => param.type === "Identifier" && param.name === name);
|
|
1113
|
+
}
|
|
1114
|
+
function calledMember(node, methods) {
|
|
1115
|
+
if (node.callee.type !== "MemberExpression") return null;
|
|
1116
|
+
const name = memberName(node.callee);
|
|
1117
|
+
return name !== null && methods.has(name) ? node.callee : null;
|
|
1118
|
+
}
|
|
1119
|
+
function isUpsert(node) {
|
|
1120
|
+
return node.arguments.slice(1).some((argument) => argument.type === "ObjectExpression" && argument.properties.some((property) => property.type === "Property" && !property.computed && (property.key.type === "Identifier" && property.key.name === "conflict" || property.key.type === "Literal" && property.key.value === "conflict") && !(property.value.type === "Literal" && property.value.value === "error")));
|
|
1121
|
+
}
|
|
1122
|
+
/** `model.get` and `model.insert` touch one table, and so do `model.get` and the model's raw `model.table.insert`, but not `db.table("a")` and `db.table("b")`, nor `this.get` and `this.audit.insert`. */
|
|
1123
|
+
function sameTable(read, insert) {
|
|
1124
|
+
return read.receivers.has(insert.receiver) || insert.receiver === `${read.receiver}.table`;
|
|
1125
|
+
}
|
|
1126
|
+
/** A catch that returns, continues or breaks in its own function without a rejection, or keeps every `throw` inside a branch, can finish without rethrowing. */
|
|
1127
|
+
function canFinish(facts, handler) {
|
|
1128
|
+
const own = handler.type === "BlockStatement" ? enclosingScope(handler) : handler;
|
|
1129
|
+
const block = handler.type === "BlockStatement" ? handler : (handler.type === "ArrowFunctionExpression" || handler.type === "FunctionExpression") && handler.body?.type === "BlockStatement" ? handler.body : null;
|
|
1130
|
+
return facts.exits.some((exit) => contains(handler.range, exit.range) && enclosingScope(exit) === own && !facts.throwRanges.some((thrown) => contains(exit.range, thrown))) || !facts.throwBlocks.some((thrownIn) => thrownIn === block);
|
|
1131
|
+
}
|
|
1132
|
+
/** A catch tolerates the lost race when it rethrows nothing, or when it can finish without rethrowing and either reads the table back or checks for a duplicate outside a `throw`. */
|
|
1133
|
+
function recovers(facts, handler, insert) {
|
|
1134
|
+
if (handler.type !== "BlockStatement" && handler.type !== "ArrowFunctionExpression" && handler.type !== "FunctionExpression") return DUPLICATE_CHECK.test(facts.text(handler));
|
|
1135
|
+
const range = handler.range;
|
|
1136
|
+
if (!facts.throwRanges.some((thrown) => contains(range, thrown))) return true;
|
|
1137
|
+
if (!canFinish(facts, handler)) return false;
|
|
1138
|
+
return facts.reads.some((read) => contains(range, read.range) && sameTable(read, insert)) || facts.duplicateChecks.some((check) => contains(range, check) && !facts.throwRanges.some((thrown) => contains(thrown, check)));
|
|
1139
|
+
}
|
|
1140
|
+
function isHandedToHelper(facts, insert, child, parent) {
|
|
1141
|
+
return (child.type === "ArrowFunctionExpression" || child.type === "FunctionExpression") && parent.type === "CallExpression" && parent.arguments.some((argument) => argument !== child && facts.text(argument) === insert.receiver);
|
|
1142
|
+
}
|
|
1143
|
+
function recoveryOf(insert, child, parent) {
|
|
1144
|
+
if (parent.type === "TryStatement" && parent.block === child) return parent.handler?.body ?? null;
|
|
1145
|
+
if (parent.type === "MemberExpression" && parent.object === child && chainsFrom(child, insert.call) && memberName(parent) === "catch" && parent.parent?.type === "CallExpression" && parent.parent.callee === parent) return parent.parent.arguments[0] ?? null;
|
|
1146
|
+
return null;
|
|
1147
|
+
}
|
|
1148
|
+
function isGuarded(facts, insert, read) {
|
|
1149
|
+
let child = insert.call;
|
|
1150
|
+
let parent = child.parent;
|
|
1151
|
+
while (parent !== null && child !== read.scope) {
|
|
1152
|
+
const between = !contains(child.range, read.range);
|
|
1153
|
+
if (between && insert.root !== null && isScope(child) && declares(child, insert.root)) return true;
|
|
1154
|
+
if (between && isHandedToHelper(facts, insert, child, parent)) return true;
|
|
1155
|
+
const recovery = recoveryOf(insert, child, parent);
|
|
1156
|
+
if (recovery !== null && recovers(facts, recovery, insert)) return true;
|
|
1157
|
+
child = parent;
|
|
1158
|
+
parent = child.parent;
|
|
1159
|
+
}
|
|
1160
|
+
return false;
|
|
1161
|
+
}
|
|
1162
|
+
function isRaced(facts, insert) {
|
|
1163
|
+
const start = insert.call.range[0];
|
|
1164
|
+
return facts.reads.some((read) => sameTable(read, insert) && read.range[1] <= start && read.scope === insert.scope && !isGuarded(facts, insert, read));
|
|
1165
|
+
}
|
|
1166
|
+
/** Writing a row that a startup read found missing races every other replica that read the same. A catch that rethrows nothing, recognises a duplicate in a condition, or reads the row back and branches, tolerates the lost race, and so does an upsert or a helper handed the table. */
|
|
1167
|
+
const noReadThenInsertRule = defineRule({
|
|
1168
|
+
meta: {
|
|
1169
|
+
type: "problem",
|
|
1170
|
+
docs: { description: "Reject an insert that follows a read of the same table unless a catch tolerates losing it." },
|
|
1171
|
+
messages: { readThenInsert: "`{{receiver}}` is read and then inserted into. Two replicas that start on an empty table both read nothing and both insert, so one writes a duplicate row or fails on the key. Key the row by a stable id, wrap the insert in try/catch, read the row back in the catch, and rethrow only when it is still missing, or upsert with `insert(row, { conflict: \"update\" })`." }
|
|
1172
|
+
},
|
|
1173
|
+
createOnce(context) {
|
|
1174
|
+
const inserts = [];
|
|
1175
|
+
const facts = {
|
|
1176
|
+
reads: [],
|
|
1177
|
+
duplicateChecks: [],
|
|
1178
|
+
throwRanges: [],
|
|
1179
|
+
throwBlocks: [],
|
|
1180
|
+
exits: [],
|
|
1181
|
+
text: (node) => context.sourceCode.getText(node)
|
|
1182
|
+
};
|
|
1183
|
+
const { reads, duplicateChecks, throwRanges, exits } = facts;
|
|
1184
|
+
function receiverChain(start) {
|
|
1185
|
+
const texts = /* @__PURE__ */ new Set();
|
|
1186
|
+
let current = start;
|
|
1187
|
+
while (current !== null) {
|
|
1188
|
+
texts.add(facts.text(current));
|
|
1189
|
+
if (current.type === "CallExpression") current = current.callee;
|
|
1190
|
+
else if (current.type === "MemberExpression") current = current.object;
|
|
1191
|
+
else current = null;
|
|
1192
|
+
}
|
|
1193
|
+
return texts;
|
|
1194
|
+
}
|
|
1195
|
+
return {
|
|
1196
|
+
before() {
|
|
1197
|
+
reads.length = 0;
|
|
1198
|
+
inserts.length = 0;
|
|
1199
|
+
duplicateChecks.length = 0;
|
|
1200
|
+
throwRanges.length = 0;
|
|
1201
|
+
facts.throwBlocks.length = 0;
|
|
1202
|
+
exits.length = 0;
|
|
1203
|
+
},
|
|
1204
|
+
ThrowStatement(node) {
|
|
1205
|
+
throwRanges.push(node.range);
|
|
1206
|
+
if (node.parent !== null) facts.throwBlocks.push(node.parent);
|
|
1207
|
+
},
|
|
1208
|
+
ReturnStatement(node) {
|
|
1209
|
+
exits.push(node);
|
|
1210
|
+
},
|
|
1211
|
+
ContinueStatement(node) {
|
|
1212
|
+
exits.push(node);
|
|
1213
|
+
},
|
|
1214
|
+
BreakStatement(node) {
|
|
1215
|
+
exits.push(node);
|
|
1216
|
+
},
|
|
1217
|
+
Identifier(node) {
|
|
1218
|
+
if (DUPLICATE_CHECK.test(node.name)) duplicateChecks.push(node.range);
|
|
1219
|
+
},
|
|
1220
|
+
TemplateLiteral(node) {
|
|
1221
|
+
if (node.quasis.some((quasi) => DUPLICATE_CHECK.test(quasi.value.raw))) duplicateChecks.push(node.range);
|
|
1222
|
+
},
|
|
1223
|
+
Literal(node) {
|
|
1224
|
+
if (DUPLICATE_CHECK.test(String(node.value))) duplicateChecks.push(node.range);
|
|
1225
|
+
},
|
|
1226
|
+
CallExpression(node) {
|
|
1227
|
+
if (facts.text(node.callee) === "Promise.reject") {
|
|
1228
|
+
throwRanges.push(node.range);
|
|
1229
|
+
const statement = node.parent;
|
|
1230
|
+
if (statement?.type === "ReturnStatement" && statement.parent !== null) facts.throwBlocks.push(statement.parent);
|
|
1231
|
+
}
|
|
1232
|
+
const read = calledMember(node, READ_METHODS);
|
|
1233
|
+
const scope = runningScope(node);
|
|
1234
|
+
if (read !== null && scope !== null) reads.push({
|
|
1235
|
+
range: node.range,
|
|
1236
|
+
scope,
|
|
1237
|
+
receiver: facts.text(read.object),
|
|
1238
|
+
receivers: receiverChain(read.object)
|
|
1239
|
+
});
|
|
1240
|
+
const insert = calledMember(node, INSERT_METHODS);
|
|
1241
|
+
if (insert !== null && scope !== null && !isUpsert(node)) inserts.push({
|
|
1242
|
+
call: node,
|
|
1243
|
+
scope,
|
|
1244
|
+
callee: insert,
|
|
1245
|
+
receiver: facts.text(insert.object),
|
|
1246
|
+
root: rootName(insert.object)
|
|
1247
|
+
});
|
|
1248
|
+
},
|
|
1249
|
+
"Program:exit"() {
|
|
1250
|
+
for (const insert of inserts) if (isRaced(facts, insert)) context.report({
|
|
1251
|
+
node: insert.callee,
|
|
1252
|
+
messageId: "readThenInsert",
|
|
1253
|
+
data: { receiver: insert.receiver }
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
};
|
|
1257
|
+
}
|
|
1258
|
+
});
|
|
1259
|
+
//#endregion
|
|
849
1260
|
//#region src/oxc/guardrails/self-package.ts
|
|
850
1261
|
function isObject(value) {
|
|
851
1262
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -861,9 +1272,11 @@ function readManifest(directory) {
|
|
|
861
1272
|
return;
|
|
862
1273
|
}
|
|
863
1274
|
if (!isObject(parsed) || !isText(parsed.name)) return void 0;
|
|
1275
|
+
const { antelopeJs } = parsed;
|
|
864
1276
|
return {
|
|
865
1277
|
name: parsed.name,
|
|
866
|
-
exports: parsed.exports
|
|
1278
|
+
exports: parsed.exports,
|
|
1279
|
+
testedByAjs: isObject(antelopeJs) && isText(antelopeJs.test)
|
|
867
1280
|
};
|
|
868
1281
|
}
|
|
869
1282
|
/** The nearest enclosing package that has a name, with the directory holding its manifest. */
|
|
@@ -913,12 +1326,15 @@ function isSelfLinked(directory, name) {
|
|
|
913
1326
|
}
|
|
914
1327
|
//#endregion
|
|
915
1328
|
//#region src/oxc/guardrails/rules/no-self-import-in-tests.ts
|
|
916
|
-
/** A test that imports its own package name must reach local code: the `exports` map publishes the subpath and `node_modules` links the package to itself. */
|
|
1329
|
+
/** A test that imports its own package name must reach local code: the `exports` map publishes the subpath and `node_modules` links the package to itself. Under `ajs module test` no self-link reaches local code, so every self-import is reported. */
|
|
917
1330
|
const noSelfImportInTestsRule = defineRule({
|
|
918
1331
|
meta: {
|
|
919
1332
|
type: "problem",
|
|
920
1333
|
docs: { description: "Tests import the module under test from local source, never their own published package name." },
|
|
921
|
-
messages: {
|
|
1334
|
+
messages: {
|
|
1335
|
+
selfImport: "This test imports its own package `{{ name }}`, which resolves to the installed published copy, so it never exercises the local code. Import the module under test by relative path, or make the self-import local: publish `{{ subpath }}` in package.json `exports` and link the package to itself (`link:.` in devDependencies).",
|
|
1336
|
+
selfImportUnderAjsTest: "This test imports its own package `{{ name }}`, and `ajs module test` resolves that name through its own module resolver, which can bind it to a copy installed with another module instead of this package, even with a `link:.` self-link. Import the module under test by relative path."
|
|
1337
|
+
}
|
|
922
1338
|
},
|
|
923
1339
|
createOnce(context) {
|
|
924
1340
|
function check(node, specifier) {
|
|
@@ -926,7 +1342,16 @@ const noSelfImportInTestsRule = defineRule({
|
|
|
926
1342
|
if (owner === void 0) return;
|
|
927
1343
|
const { directory, manifest } = owner;
|
|
928
1344
|
const subpath = selfSubpath(manifest.name, specifier);
|
|
929
|
-
if (subpath === void 0
|
|
1345
|
+
if (subpath === void 0) return;
|
|
1346
|
+
if (manifest.testedByAjs) {
|
|
1347
|
+
context.report({
|
|
1348
|
+
node,
|
|
1349
|
+
messageId: "selfImportUnderAjsTest",
|
|
1350
|
+
data: { name: manifest.name }
|
|
1351
|
+
});
|
|
1352
|
+
return;
|
|
1353
|
+
}
|
|
1354
|
+
if (exportsCover(manifest.exports, subpath) && isSelfLinked(directory, manifest.name)) return;
|
|
930
1355
|
context.report({
|
|
931
1356
|
node,
|
|
932
1357
|
messageId: "selfImport",
|
|
@@ -1032,46 +1457,60 @@ const noTypeofFunctionOnlyTestRule = defineRule({
|
|
|
1032
1457
|
}
|
|
1033
1458
|
});
|
|
1034
1459
|
//#endregion
|
|
1035
|
-
//#region src/oxc/guardrails/
|
|
1036
|
-
|
|
1037
|
-
const
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
});
|
|
1060
|
-
else recordAssertion(node);
|
|
1061
|
-
},
|
|
1062
|
-
MemberExpression: recordAssertion,
|
|
1063
|
-
"CallExpression:exit"(node) {
|
|
1064
|
-
const frame = frames.at(-1);
|
|
1065
|
-
if (frame?.node !== node) return;
|
|
1066
|
-
frames.pop();
|
|
1067
|
-
if (!frame.hasAssertion) context.report({
|
|
1068
|
-
node,
|
|
1069
|
-
messageId: "missingAssertion"
|
|
1070
|
-
});
|
|
1071
|
-
}
|
|
1072
|
-
};
|
|
1460
|
+
//#region src/oxc/guardrails/literal-fit.ts
|
|
1461
|
+
const MAX_DEPTH$1 = 8;
|
|
1462
|
+
const INDEX = /^\d+$/u;
|
|
1463
|
+
/** The type a written value has: a shorthand property reads its variable, as a direct assignment would. */
|
|
1464
|
+
function valueType(checker, value) {
|
|
1465
|
+
const shorthand = ts.isShorthandPropertyAssignment(value.parent) && value.parent.name === value ? checker.getShorthandAssignmentValueSymbol(value.parent) : void 0;
|
|
1466
|
+
return shorthand === void 0 ? checker.getTypeAtLocation(value) : checker.getTypeOfSymbolAtLocation(shorthand, value);
|
|
1467
|
+
}
|
|
1468
|
+
function propertyName(property) {
|
|
1469
|
+
if (!(ts.isPropertyAssignment(property) || ts.isShorthandPropertyAssignment(property)) || !(ts.isIdentifier(property.name) || ts.isStringLiteral(property.name) || ts.isNumericLiteral(property.name))) return void 0;
|
|
1470
|
+
return {
|
|
1471
|
+
name: property.name.text,
|
|
1472
|
+
value: ts.isPropertyAssignment(property) ? property.initializer : property.name
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
function objectFits(checker, literal, type, depth) {
|
|
1476
|
+
const names = /* @__PURE__ */ new Set();
|
|
1477
|
+
for (const property of literal.properties) {
|
|
1478
|
+
const named = propertyName(property);
|
|
1479
|
+
if (named === void 0) return false;
|
|
1480
|
+
names.add(named.name);
|
|
1481
|
+
const field = checker.getPropertyOfType(type, named.name);
|
|
1482
|
+
const fieldType = field === void 0 ? checker.getIndexTypeOfType(type, ts.IndexKind.String) : checker.getTypeOfSymbolAtLocation(field, literal);
|
|
1483
|
+
if (fieldType === void 0 || !literalFits(checker, named.value, fieldType, depth + 1)) return false;
|
|
1073
1484
|
}
|
|
1074
|
-
|
|
1485
|
+
return checker.getPropertiesOfType(type).every((field) => (field.flags & ts.SymbolFlags.Optional) !== 0 || names.has(field.name));
|
|
1486
|
+
}
|
|
1487
|
+
function arrayFits(checker, literal, type, depth) {
|
|
1488
|
+
const { elements } = literal;
|
|
1489
|
+
if (elements.some((element) => ts.isSpreadElement(element) || ts.isOmittedExpression(element))) return false;
|
|
1490
|
+
if (checker.isTupleType(type)) {
|
|
1491
|
+
const slots = checker.getPropertiesOfType(type).filter((slot) => INDEX.test(slot.name));
|
|
1492
|
+
const required = slots.filter((slot) => (slot.flags & ts.SymbolFlags.Optional) === 0);
|
|
1493
|
+
return elements.length >= required.length && elements.length <= slots.length && elements.every((element, index) => literalFits(checker, element, checker.getTypeOfSymbolAtLocation(slots[index], literal), depth + 1));
|
|
1494
|
+
}
|
|
1495
|
+
const element = checker.getIndexTypeOfType(type, ts.IndexKind.Number);
|
|
1496
|
+
return element !== void 0 && elements.every((value) => literalFits(checker, value, element, depth + 1));
|
|
1497
|
+
}
|
|
1498
|
+
/**
|
|
1499
|
+
* Whether `expression` fits `type` the way a direct assignment types it:
|
|
1500
|
+
* literals inside object and array literals keep their literal types, which
|
|
1501
|
+
* `Object.assign`'s inferred source type widens. Object literals need every
|
|
1502
|
+
* required property and no undeclared one, tuples their length. Past the
|
|
1503
|
+
* depth cap a literal fits, so the rule stays silent rather than wrong.
|
|
1504
|
+
*/
|
|
1505
|
+
function literalFits(checker, expression, type, depth = 0) {
|
|
1506
|
+
let value = expression;
|
|
1507
|
+
while (ts.isParenthesizedExpression(value)) value = value.expression;
|
|
1508
|
+
if (checker.isTypeAssignableTo(valueType(checker, value), type)) return true;
|
|
1509
|
+
if (!ts.isObjectLiteralExpression(value) && !ts.isArrayLiteralExpression(value)) return false;
|
|
1510
|
+
if (depth === MAX_DEPTH$1) return true;
|
|
1511
|
+
if (type.isUnion()) return type.types.some((member) => literalFits(checker, value, member, depth));
|
|
1512
|
+
return ts.isObjectLiteralExpression(value) ? objectFits(checker, value, type, depth) : arrayFits(checker, value, type, depth);
|
|
1513
|
+
}
|
|
1075
1514
|
//#endregion
|
|
1076
1515
|
//#region src/oxc/guardrails/tsconfig-program.ts
|
|
1077
1516
|
const CONFIG_NAMES = ["tsconfig.json", "jsconfig.json"];
|
|
@@ -1087,13 +1526,15 @@ function configAbove(directory) {
|
|
|
1087
1526
|
if (dirname(current) === current) return void 0;
|
|
1088
1527
|
}
|
|
1089
1528
|
}
|
|
1090
|
-
/** The files `config` lists and the configs it references, parsed once per lint run. */
|
|
1529
|
+
/** The files `config` lists, its compiler options and the configs it references, parsed once per lint run. */
|
|
1091
1530
|
function project(config) {
|
|
1092
1531
|
if (projects.has(config)) return projects.get(config);
|
|
1093
1532
|
const parsed = ts.getParsedCommandLineOfConfigFile(config, void 0, HOST);
|
|
1094
1533
|
const result = parsed && {
|
|
1095
1534
|
files: new Set(parsed.fileNames),
|
|
1096
|
-
|
|
1535
|
+
options: parsed.options,
|
|
1536
|
+
references: (parsed.projectReferences ?? []).map((reference) => ts.resolveProjectReferencePath(reference)),
|
|
1537
|
+
automaticTypes: parsed.options.types === void 0 ? ts.getAutomaticTypeDirectiveNames(parsed.options, ts.sys) : []
|
|
1097
1538
|
};
|
|
1098
1539
|
projects.set(config, result);
|
|
1099
1540
|
return result;
|
|
@@ -1129,9 +1570,222 @@ function programConfig(file) {
|
|
|
1129
1570
|
directory = parent;
|
|
1130
1571
|
}
|
|
1131
1572
|
}
|
|
1573
|
+
/**
|
|
1574
|
+
* The `@types` packages tsc loads into `config`'s program only because it lists no
|
|
1575
|
+
* `compilerOptions.types`. oxlint-tsgolint runs TypeScript 7, where `types` defaults
|
|
1576
|
+
* to none, so its program loads none of them.
|
|
1577
|
+
*/
|
|
1578
|
+
function automaticTypes(config) {
|
|
1579
|
+
return project(config)?.automaticTypes ?? [];
|
|
1580
|
+
}
|
|
1581
|
+
//#endregion
|
|
1582
|
+
//#region src/oxc/guardrails/type-checker.ts
|
|
1583
|
+
const programs = /* @__PURE__ */ new Map();
|
|
1584
|
+
/** The source files every program of the lint run shares, parsed once per text and per set of compiler options that change a parse. */
|
|
1585
|
+
const documents = ts.createDocumentRegistry(ts.sys.useCaseSensitiveFileNames);
|
|
1586
|
+
function normalize(file) {
|
|
1587
|
+
return resolve(file).replaceAll("\\", "/");
|
|
1588
|
+
}
|
|
1589
|
+
function build(config, path, text) {
|
|
1590
|
+
const parsed = project(config);
|
|
1591
|
+
if (parsed === void 0) return void 0;
|
|
1592
|
+
const host = ts.createCompilerHost(parsed.options, true);
|
|
1593
|
+
host.getSourceFile = (name, language) => {
|
|
1594
|
+
const content = normalize(name) === path ? text : host.readFile(name);
|
|
1595
|
+
return content === void 0 ? void 0 : documents.acquireDocument(name, parsed.options, ts.ScriptSnapshot.fromString(content), content, void 0, language);
|
|
1596
|
+
};
|
|
1597
|
+
const program = ts.createProgram({
|
|
1598
|
+
rootNames: [...parsed.files],
|
|
1599
|
+
options: parsed.options,
|
|
1600
|
+
host,
|
|
1601
|
+
oldProgram: programs.get(config)
|
|
1602
|
+
});
|
|
1603
|
+
programs.set(config, program);
|
|
1604
|
+
return program;
|
|
1605
|
+
}
|
|
1606
|
+
/**
|
|
1607
|
+
* The type checker of the tsconfig program that lists `file`, built once per
|
|
1608
|
+
* lint run and rebuilt from the previous one when `text` differs from what it
|
|
1609
|
+
* read. Undefined when no tsconfig lists the file.
|
|
1610
|
+
*/
|
|
1611
|
+
function typedFile(file, text) {
|
|
1612
|
+
const config = programConfig(file);
|
|
1613
|
+
if (config === void 0) return void 0;
|
|
1614
|
+
const path = normalize(file);
|
|
1615
|
+
const cached = programs.get(config);
|
|
1616
|
+
const program = cached?.getSourceFile(path)?.text === text ? cached : build(config, path, text);
|
|
1617
|
+
const sourceFile = program?.getSourceFile(path);
|
|
1618
|
+
return program && sourceFile ? {
|
|
1619
|
+
checker: program.getTypeChecker(),
|
|
1620
|
+
options: program.getCompilerOptions(),
|
|
1621
|
+
sourceFile
|
|
1622
|
+
} : void 0;
|
|
1623
|
+
}
|
|
1624
|
+
/** The node `test` accepts that spans exactly `start` to `end`, the span oxlint gives the matching ESTree node. */
|
|
1625
|
+
function nodeAt(sourceFile, span, test) {
|
|
1626
|
+
let found;
|
|
1627
|
+
function visit(node) {
|
|
1628
|
+
if (found !== void 0 || node.pos > span.start || node.end < span.end) return;
|
|
1629
|
+
if (test(node) && node.getStart(sourceFile) === span.start && node.end === span.end) found = node;
|
|
1630
|
+
else ts.forEachChild(node, visit);
|
|
1631
|
+
}
|
|
1632
|
+
visit(sourceFile);
|
|
1633
|
+
return found;
|
|
1634
|
+
}
|
|
1635
|
+
//#endregion
|
|
1636
|
+
//#region src/oxc/guardrails/rules/no-unsafe-object-assign.ts
|
|
1637
|
+
const UNTYPED = ts.TypeFlags.Any | ts.TypeFlags.Unknown;
|
|
1638
|
+
const MAX_DEPTH = 4;
|
|
1639
|
+
function members(type) {
|
|
1640
|
+
return type.isUnion() ? type.types : [type];
|
|
1641
|
+
}
|
|
1642
|
+
/** Whether `type` is `any`, or holds `any` in a union, an intersection or the elements of an array or tuple, as in `any[]`. */
|
|
1643
|
+
function holdsAny(checker, type, depth = 0) {
|
|
1644
|
+
if (type.flags & ts.TypeFlags.Any) return true;
|
|
1645
|
+
if (depth === MAX_DEPTH) return false;
|
|
1646
|
+
const element = checker.isArrayType(type) || checker.isTupleType(type) ? checker.getIndexTypeOfType(type, ts.IndexKind.Number) : void 0;
|
|
1647
|
+
return (type.isUnionOrIntersection() ? type.types : element === void 0 ? [] : [element]).some((member) => holdsAny(checker, member, depth + 1));
|
|
1648
|
+
}
|
|
1649
|
+
/** Whether a declaration sits inside a generic class, interface or type alias, whose type parameters the public checker API cannot instantiate for a declaration. */
|
|
1650
|
+
function insideGeneric(declaration) {
|
|
1651
|
+
for (let node = declaration.parent; !ts.isSourceFile(node); node = node.parent) if ((ts.isClassLike(node) || ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node)) && node.typeParameters !== void 0) return true;
|
|
1652
|
+
return false;
|
|
1653
|
+
}
|
|
1654
|
+
/** The types a field accepts: its read type, and its setter's parameter type. Undefined when the setter sits inside a generic declaration, whose parameter type this rule cannot instantiate. */
|
|
1655
|
+
function acceptedTypes(checker, field, source) {
|
|
1656
|
+
const setter = field.declarations?.find(ts.isSetAccessorDeclaration);
|
|
1657
|
+
const parameter = setter?.parameters[0];
|
|
1658
|
+
const read = checker.getTypeOfSymbolAtLocation(field, source);
|
|
1659
|
+
if (setter === void 0 || parameter === void 0) return [read];
|
|
1660
|
+
return insideGeneric(setter) ? void 0 : [read, checker.getTypeAtLocation(parameter)];
|
|
1661
|
+
}
|
|
1662
|
+
function untyped(type) {
|
|
1663
|
+
return (type.flags & UNTYPED) !== 0;
|
|
1664
|
+
}
|
|
1665
|
+
function typeVerdict({ checker, exactOptional }, type, accepted, optional) {
|
|
1666
|
+
if (accepted.length === 0 || accepted.some(untyped)) return void 0;
|
|
1667
|
+
if (untyped(type) || holdsAny(checker, type) && !accepted.some((member) => holdsAny(checker, member))) return "untypedField";
|
|
1668
|
+
return (optional && !exactOptional ? members(type).filter((member) => !(member.flags & ts.TypeFlags.Undefined)) : [type]).every((member) => accepted.some((field) => checker.isTypeAssignableTo(member, field))) ? void 0 : "mistypedField";
|
|
1669
|
+
}
|
|
1670
|
+
function fieldWrite(check, property, field, source) {
|
|
1671
|
+
const { checker } = check;
|
|
1672
|
+
const accepted = acceptedTypes(checker, field, source);
|
|
1673
|
+
if (accepted === void 0) return void 0;
|
|
1674
|
+
const declaration = property.valueDeclaration;
|
|
1675
|
+
const written = declaration !== void 0 && declaration.getSourceFile() === source.getSourceFile() && declaration.pos >= source.pos && declaration.end <= source.end && (ts.isPropertyAssignment(declaration) || ts.isShorthandPropertyAssignment(declaration)) ? ts.isPropertyAssignment(declaration) ? declaration.initializer : declaration.name : void 0;
|
|
1676
|
+
const kind = written === void 0 ? typeVerdict(check, checker.getTypeOfSymbolAtLocation(property, source), accepted, (property.flags & ts.SymbolFlags.Optional) !== 0) : typeVerdict(check, valueType(checker, written), accepted, false);
|
|
1677
|
+
if (kind === void 0 || kind === "mistypedField" && written !== void 0 && accepted.some((type) => literalFits(checker, written, type))) return void 0;
|
|
1678
|
+
return {
|
|
1679
|
+
kind,
|
|
1680
|
+
name: property.name
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
/** A primitive source member, such as the `false` of `flag && { ... }`, whose apparent members (`valueOf`) `Object.assign` never copies. */
|
|
1684
|
+
const PRIMITIVE = ts.TypeFlags.BooleanLike | ts.TypeFlags.NumberLike | ts.TypeFlags.StringLike | ts.TypeFlags.BigIntLike | ts.TypeFlags.ESSymbolLike | ts.TypeFlags.Null | ts.TypeFlags.Undefined | ts.TypeFlags.Void | ts.TypeFlags.Never;
|
|
1685
|
+
/** Whether the target declares a field that does not take `unknown`, which an untyped string-keyed source could overwrite. */
|
|
1686
|
+
function hasTypedField(checker, target) {
|
|
1687
|
+
return checker.getPropertiesOfType(target).some((field) => !untyped(checker.getTypeOfSymbol(field)));
|
|
1688
|
+
}
|
|
1689
|
+
function untypedKeys(checker, member) {
|
|
1690
|
+
return checker.getIndexInfosOfType(member).some((info) => (info.keyType.flags & ts.TypeFlags.String) !== 0 && untyped(info.type));
|
|
1691
|
+
}
|
|
1692
|
+
function sourceWrites(check, target, source) {
|
|
1693
|
+
const { checker } = check;
|
|
1694
|
+
const writes = /* @__PURE__ */ new Map();
|
|
1695
|
+
for (const member of members(checker.getTypeAtLocation(source))) {
|
|
1696
|
+
if (untyped(member) || untypedKeys(checker, member) && hasTypedField(checker, target)) writes.set("", { kind: "untypedSource" });
|
|
1697
|
+
if (member.flags & PRIMITIVE) continue;
|
|
1698
|
+
for (const property of checker.getPropertiesOfType(member)) {
|
|
1699
|
+
const field = checker.getPropertyOfType(target, property.name);
|
|
1700
|
+
const write = field && fieldWrite(check, property, field, source);
|
|
1701
|
+
if (write !== void 0) writes.set(property.name, write);
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
return [...writes.values()];
|
|
1705
|
+
}
|
|
1706
|
+
/** `Object.assign<T, U>` returns `T & U` without comparing `U` with `T`, so a source can write `unknown`, `any` or a wrong type over a field `T` declares. */
|
|
1707
|
+
const noUnsafeObjectAssignRule = defineRule({
|
|
1708
|
+
meta: {
|
|
1709
|
+
type: "problem",
|
|
1710
|
+
docs: { description: "Object.assign writes no unknown, any or unassignable value over a field its target declares." },
|
|
1711
|
+
messages: {
|
|
1712
|
+
untypedSource: "This Object.assign source is typed `unknown` or `any`, or holds such values under an index signature, and it overwrites fields the target declares without a check: `Object.assign<T, U>` returns `T & U`. Parse it into a typed value first.",
|
|
1713
|
+
untypedField: "Object.assign writes an `unknown` or `any` value over `{{name}}`, a field the target declares, and TypeScript never compares the two: `Object.assign<T, U>` returns `T & U`. Parse the value into the field's type first.",
|
|
1714
|
+
mistypedField: "Object.assign writes a value over `{{name}}` that the target's `{{name}}` type does not accept, and TypeScript never compares the two: `Object.assign<T, U>` returns `T & U`. Assign the field directly so the compiler checks it."
|
|
1715
|
+
}
|
|
1716
|
+
},
|
|
1717
|
+
createOnce(context) {
|
|
1718
|
+
return { CallExpression(node) {
|
|
1719
|
+
if (callName(node.callee) !== "Object.assign" || node.arguments.length < 2) return;
|
|
1720
|
+
const typed = typedFile(context.filename, context.sourceCode.text);
|
|
1721
|
+
const call = typed && nodeAt(typed.sourceFile, node, ts.isCallExpression);
|
|
1722
|
+
if (typed === void 0 || call === void 0) return;
|
|
1723
|
+
const declared = typed.checker.getTypeAtLocation(call.arguments[0]);
|
|
1724
|
+
const target = declared.isTypeParameter() ? typed.checker.getBaseConstraintOfType(declared) ?? declared : declared;
|
|
1725
|
+
if (typed.checker.getPropertiesOfType(target).length === 0) return;
|
|
1726
|
+
const check = {
|
|
1727
|
+
checker: typed.checker,
|
|
1728
|
+
exactOptional: typed.options.exactOptionalPropertyTypes === true
|
|
1729
|
+
};
|
|
1730
|
+
call.arguments.slice(1).forEach((source, index) => {
|
|
1731
|
+
if (ts.isSpreadElement(source)) return;
|
|
1732
|
+
for (const write of sourceWrites(check, target, source)) context.report({
|
|
1733
|
+
node: node.arguments[index + 1],
|
|
1734
|
+
messageId: write.kind,
|
|
1735
|
+
data: "name" in write ? { name: write.name } : {}
|
|
1736
|
+
});
|
|
1737
|
+
});
|
|
1738
|
+
} };
|
|
1739
|
+
}
|
|
1740
|
+
});
|
|
1741
|
+
//#endregion
|
|
1742
|
+
//#region src/oxc/guardrails/rules/require-assertion.ts
|
|
1743
|
+
function isInCallback(node, frame) {
|
|
1744
|
+
for (let current = node.parent; current !== null && current !== frame.node; current = current.parent) if (current === frame.callback) return true;
|
|
1745
|
+
return false;
|
|
1746
|
+
}
|
|
1747
|
+
/** Test callbacks must contain an assertion regardless of their framework or filename. */
|
|
1748
|
+
const requireAssertionRule = defineRule({
|
|
1749
|
+
meta: {
|
|
1750
|
+
type: "problem",
|
|
1751
|
+
docs: { description: "Require an assertion in every executable test callback." },
|
|
1752
|
+
messages: { missingAssertion: "Call an assertion in this test to verify its behavior." }
|
|
1753
|
+
},
|
|
1754
|
+
createOnce(context) {
|
|
1755
|
+
const frames = [];
|
|
1756
|
+
function recordAssertion(node) {
|
|
1757
|
+
const frame = frames.at(-1);
|
|
1758
|
+
if (frame !== void 0 && isAssertion(node) && isInCallback(node, frame)) frame.hasAssertion = true;
|
|
1759
|
+
}
|
|
1760
|
+
return {
|
|
1761
|
+
before() {
|
|
1762
|
+
frames.length = 0;
|
|
1763
|
+
},
|
|
1764
|
+
CallExpression(node) {
|
|
1765
|
+
const callback = testCallback(node);
|
|
1766
|
+
if (callback !== void 0) frames.push({
|
|
1767
|
+
node,
|
|
1768
|
+
callback,
|
|
1769
|
+
hasAssertion: false
|
|
1770
|
+
});
|
|
1771
|
+
else recordAssertion(node);
|
|
1772
|
+
},
|
|
1773
|
+
MemberExpression: recordAssertion,
|
|
1774
|
+
"CallExpression:exit"(node) {
|
|
1775
|
+
const frame = frames.at(-1);
|
|
1776
|
+
if (frame?.node !== node) return;
|
|
1777
|
+
frames.pop();
|
|
1778
|
+
if (!frame.hasAssertion) context.report({
|
|
1779
|
+
node,
|
|
1780
|
+
messageId: "missingAssertion"
|
|
1781
|
+
});
|
|
1782
|
+
}
|
|
1783
|
+
};
|
|
1784
|
+
}
|
|
1785
|
+
});
|
|
1132
1786
|
//#endregion
|
|
1133
1787
|
//#region src/oxc/guardrails/rules/require-tsconfig-include.ts
|
|
1134
|
-
const TYPE_LINTED = /\.[cm]?[jt]sx?$/u;
|
|
1788
|
+
const TYPE_LINTED$1 = /\.[cm]?[jt]sx?$/u;
|
|
1135
1789
|
/** A file type-aware lint reads must be listed by a tsconfig, or tsgolint types it without the repository's compiler options and `types`. */
|
|
1136
1790
|
const requireTsconfigIncludeRule = defineRule({
|
|
1137
1791
|
meta: {
|
|
@@ -1141,7 +1795,7 @@ const requireTsconfigIncludeRule = defineRule({
|
|
|
1141
1795
|
},
|
|
1142
1796
|
createOnce(context) {
|
|
1143
1797
|
return { Program(node) {
|
|
1144
|
-
if (TYPE_LINTED.test(context.filename) && programConfig(context.filename) === void 0) context.report({
|
|
1798
|
+
if (TYPE_LINTED$1.test(context.filename) && programConfig(context.filename) === void 0) context.report({
|
|
1145
1799
|
node,
|
|
1146
1800
|
messageId: "outside"
|
|
1147
1801
|
});
|
|
@@ -1149,8 +1803,37 @@ const requireTsconfigIncludeRule = defineRule({
|
|
|
1149
1803
|
}
|
|
1150
1804
|
});
|
|
1151
1805
|
//#endregion
|
|
1806
|
+
//#region src/oxc/guardrails/rules/require-tsconfig-types.ts
|
|
1807
|
+
const TYPE_LINTED = /\.[cm]?[jt]sx?$/u;
|
|
1808
|
+
/** The tsconfig of a file type-aware lint reads must list `compilerOptions.types`, or tsgolint loads none of the `@types` packages tsc loads. */
|
|
1809
|
+
const requireTsconfigTypesRule = defineRule({
|
|
1810
|
+
meta: {
|
|
1811
|
+
type: "problem",
|
|
1812
|
+
docs: { description: "The tsconfig.json of every file type-aware lint reads lists compilerOptions.types, so tsgolint loads the same @types packages as tsc." },
|
|
1813
|
+
messages: { missing: "{{config}} lists no `compilerOptions.types`, so tsc loads every `@types` package ({{packages}}) but type-aware lint, which runs TypeScript 7, loads none: Node and test-runner globals are error types, so `typescript/no-unsafe-*` reports here are false and findings that need those types go missing. Add `\"types\": [{{list}}]` to its compilerOptions, or to the config that generates it, listing the packages this code uses." }
|
|
1814
|
+
},
|
|
1815
|
+
createOnce(context) {
|
|
1816
|
+
return { Program(node) {
|
|
1817
|
+
if (!TYPE_LINTED.test(context.filename)) return;
|
|
1818
|
+
const config = programConfig(context.filename);
|
|
1819
|
+
if (config === void 0) return;
|
|
1820
|
+
const packages = automaticTypes(config);
|
|
1821
|
+
if (packages.length === 0) return;
|
|
1822
|
+
context.report({
|
|
1823
|
+
node,
|
|
1824
|
+
messageId: "missing",
|
|
1825
|
+
data: {
|
|
1826
|
+
config: relative(context.cwd, config).replaceAll("\\", "/"),
|
|
1827
|
+
packages: packages.join(", "),
|
|
1828
|
+
list: packages.map((name) => JSON.stringify(name)).join(", ")
|
|
1829
|
+
}
|
|
1830
|
+
});
|
|
1831
|
+
} };
|
|
1832
|
+
}
|
|
1833
|
+
});
|
|
1834
|
+
//#endregion
|
|
1152
1835
|
//#region src/oxc/guardrails/index.ts
|
|
1153
|
-
/** AntelopeJS rules that reject comments, inherited-key lookups, presence-only type guards, low-evidence tests
|
|
1836
|
+
/** AntelopeJS rules that reject comments, inherited-key lookups, presence-only type guards, inserts that follow a read of the same table, unchecked Object.assign writes, low-evidence tests, files no tsconfig lists and tsconfigs that list no `types`. */
|
|
1154
1837
|
const guardrailsPlugin = eslintCompatPlugin({
|
|
1155
1838
|
meta: { name: "antelopejs" },
|
|
1156
1839
|
rules: {
|
|
@@ -1158,11 +1841,14 @@ const guardrailsPlugin = eslintCompatPlugin({
|
|
|
1158
1841
|
"no-fs-read-in-tests": noFsReadInTestsRule,
|
|
1159
1842
|
"no-inherited-key-lookup": noInheritedKeyLookupRule,
|
|
1160
1843
|
"no-presence-only-type-guard": noPresenceOnlyTypeGuardRule,
|
|
1844
|
+
"no-read-then-insert": noReadThenInsertRule,
|
|
1161
1845
|
"no-constant-value-assertion": noConstantValueAssertionRule,
|
|
1162
1846
|
"no-self-import-in-tests": noSelfImportInTestsRule,
|
|
1163
1847
|
"no-typeof-function-only-test": noTypeofFunctionOnlyTestRule,
|
|
1848
|
+
"no-unsafe-object-assign": noUnsafeObjectAssignRule,
|
|
1164
1849
|
"require-assertion": requireAssertionRule,
|
|
1165
|
-
"require-tsconfig-include": requireTsconfigIncludeRule
|
|
1850
|
+
"require-tsconfig-include": requireTsconfigIncludeRule,
|
|
1851
|
+
"require-tsconfig-types": requireTsconfigTypesRule
|
|
1166
1852
|
}
|
|
1167
1853
|
});
|
|
1168
1854
|
//#endregion
|