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.
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { defineRule } from "@oxlint/plugins";
|
|
import type { ESTree } from "@oxlint/plugins";
|
|
|
|
function unwrapParentheses(node: ESTree.Expression): ESTree.Expression {
|
|
let current = node;
|
|
while (current.type === "ParenthesizedExpression") {
|
|
current = current.expression;
|
|
}
|
|
return current;
|
|
}
|
|
|
|
function isEmptyObjectExpression(node: ESTree.Expression): boolean {
|
|
return node.type === "ObjectExpression" && node.properties.length === 0;
|
|
}
|
|
|
|
function isConditionalEmptyObjectSpread(node: ESTree.Expression): boolean {
|
|
const conditional = unwrapParentheses(node);
|
|
return (
|
|
conditional.type === "ConditionalExpression" &&
|
|
(isEmptyObjectExpression(conditional.consequent) ||
|
|
isEmptyObjectExpression(conditional.alternate))
|
|
);
|
|
}
|
|
|
|
/** Ban conditional empty-object spreads without changing their omission semantics. */
|
|
export const noConditionalEmptyObjectSpreadRule = defineRule({
|
|
meta: {
|
|
type: "suggestion",
|
|
docs: {
|
|
description:
|
|
"Disallow object spreads that conditionally spread an empty object to omit fields.",
|
|
},
|
|
messages: {
|
|
avoid:
|
|
"This conditional spread hides property omission behind an empty object. Build the object in separate statements and add the property only when present.",
|
|
},
|
|
},
|
|
createOnce(context) {
|
|
return {
|
|
SpreadElement(node) {
|
|
if (node.parent.type !== "ObjectExpression") return;
|
|
|
|
if (isConditionalEmptyObjectSpread(node.argument)) {
|
|
context.report({ node, messageId: "avoid" });
|
|
}
|
|
},
|
|
};
|
|
},
|
|
});
|