Files
openchamber/tools/oxlint/anti-slop/shared/reflect-method.ts
T
Bohdan Triapitsyn 51aef5e316 chore(lint): vendor anti-slop oxlint plugin and add batched cleanup pipeline
Vendor the anti-slop Oxlint plugin at tools/oxlint/anti-slop and register it
in oxlint.config.ts, with Oxlint's own rule categories disabled so ESLint
stays the general-purpose linter.

Add scripts/anti-slop.mjs (bun run deslop) mirroring the React Doctor batch
interface: next-batch, check-batch, active, release, top, file. Batch handoff
directories now double as file claims shared across clones via
~/.openchamber/maintenance-claims, so concurrent maintenance batches from
either pipeline never select the same file.

Harden both scheduled maintenance flows: stop on a dirty worktree, stop on
NO BATCH AVAILABLE, validate per package instead of workspace-wide, and pin
react-doctor to 0.9.12. The anti-slop task command documents concrete
good and bad fixes and forbids laundering types to satisfy a rule.
2026-08-16 15:55:08 +03:00

36 lines
1.3 KiB
TypeScript

import type { ESTree, Scope, SourceCode, Variable } from "@oxlint/plugins";
function resolveVariable(
sourceCode: SourceCode,
identifier: ESTree.IdentifierReference,
): Variable | null {
let scope: Scope | null = sourceCode.getScope(identifier);
while (scope !== null) {
const variable = scope.set.get(identifier.name);
if (variable !== undefined) return variable;
scope = scope.upper;
}
return null;
}
function isGlobalReflect(sourceCode: SourceCode, expression: ESTree.Expression): boolean {
if (expression.type !== "Identifier" || expression.name !== "Reflect") return false;
if (sourceCode.isGlobalReference(expression)) return true;
const variable = resolveVariable(sourceCode, expression);
return variable === null || variable.defs.length === 0;
}
/** Reports whether a call target names one method on the global Reflect object. */
export function isGlobalReflectMethodCall(
sourceCode: SourceCode,
callee: ESTree.Expression,
methodName: string,
): boolean {
if (!("property" in callee) || !("object" in callee) || !("computed" in callee)) return false;
if (!isGlobalReflect(sourceCode, callee.object)) return false;
const property = callee.property;
return callee.computed
? property.type === "Literal" && property.value === methodName
: property.type === "Identifier" && property.name === methodName;
}