Skip to content

chore: add anti-slop Oxlint rules - #2163

Open
mattzcarey wants to merge 3 commits into
cloudflare:mainfrom
mattzcarey:chore/install-anti-slop
Open

chore: add anti-slop Oxlint rules#2163
mattzcarey wants to merge 3 commits into
cloudflare:mainfrom
mattzcarey:chore/install-anti-slop

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • vendor the generic anti-slop Oxlint plugin under tools/oxlint/anti-slop
  • pin matching oxlint and @oxlint/plugins 1.80.0 releases and register the plugin in the normal root lint configuration
  • enable six generic rules, with narrow file overrides for existing proxy, prototype-call, reflective-dispatch, and module-mocking cases
  • keep high-volume migration rules explicitly disabled and document the initial findings and rationale in tools/oxlint/anti-slop/README.md
  • preserve the existing React lint policy across the Oxlint upgrade, add formatter/tooling ignores, and record the vendored MIT license
  • fix several tractable findings in Agents, Think, and Voice code and tests

The upstream Effect-specific plugin is not vendored. No package in this repository uses Effect, so its rule would have nothing to check.

A strict initial scan found 13,205 existing anti-slop findings across 824 files. This PR enables the rules the repository can adopt cleanly now. The remaining rules stay visible as off rather than disappearing from the configuration, so they can be migrated package by package.

No changeset is included because this changes repository tooling and internal implementation details without changing package behavior or public APIs.

Verification

  • pnpm run build
  • pnpm run check (sherif, exports, oxfmt, oxlint, all 121 TypeScript projects) after merging main
  • pnpm exec nx affected -t test, covering 22 affected projects
  • focused Agents, Think, Voice, and Plivo tests
  • temporary violating-file smoke test confirming an enabled anti-slop rule rejects code through the normal root configuration

@changeset-bot

changeset-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: dd26fb2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Remove the vendored anti-slop Effect plugin: no package in this repository
uses Effect, so its rule had nothing to check.

Add file-level exceptions for code that landed on main after the audit:
the voice WebSocket transport test (module mocking) and the WebSockets
callables dispatcher plus decorator scan (reflective dispatch on host
objects), matching the existing observability proxy exceptions.

Claude-Session: https://claude.ai/code/session_01LeAuE2FqjwnjJ6YBAaPMJx

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 4 potential issues.

2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment on lines +51 to +52
function moduleMockCall(sourceCode: SourceCode, callee: ESTree.Expression): boolean {
if (!("property" in callee) || !("object" in callee) || !("computed" in callee)) return false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Destructured module mocks bypass linting

After code destructures mock from vi or jest, moduleMockCall ignores the direct call. The banned module mock passes CI.

Prompt for agents
The no-module-mocking rule only recognizes member calls such as vi.mock(...). Track destructured or aliased references to the configured Vitest and Jest methods through scope definitions, then report their direct calls too. Add focused cases for destructuring and renamed destructuring from both vi and jest while preserving local-shadowing behavior.
Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +29 to +30
if (!("property" in callee) || !("object" in callee) || !("computed" in callee)) return false;
if (!isGlobalReflect(sourceCode, callee.object)) return false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Destructured reflection calls bypass linting

After code destructures apply or get from Reflect, isGlobalReflectMethodCall ignores the direct call. Both banned APIs pass CI.

Prompt for agents
The shared Reflect matcher only handles member expressions. Extend the enabled no-reflect-apply and no-reflect-get rules to resolve direct identifiers created by destructuring or aliasing the corresponding global Reflect method. Preserve shadowing checks and add cases for renamed destructuring and locally shadowed Reflect values.
Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +31 to +35
const resolvesToUnknown = (type: ESTree.TSType, visited = new Set<string>()): boolean => {
if (type.type === "TSUnknownKeyword") return true;
if (type.type === "TSParenthesizedType")
return resolvesToUnknown(type.typeAnnotation, visited);
const name = referencedAliasName(type);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Unknown unions evade alias linting

For type Payload = unknown | string, resolvesToUnknown returns false although the alias equals unknown. The prohibited alias passes CI.

Suggested change
const resolvesToUnknown = (type: ESTree.TSType, visited = new Set<string>()): boolean => {
if (type.type === "TSUnknownKeyword") return true;
if (type.type === "TSParenthesizedType")
return resolvesToUnknown(type.typeAnnotation, visited);
const name = referencedAliasName(type);
const resolvesToUnknown = (type: ESTree.TSType, visited = new Set<string>()): boolean => {
if (type.type === "TSUnknownKeyword") return true;
if (type.type === "TSParenthesizedType")
return resolvesToUnknown(type.typeAnnotation, visited);
if (type.type === "TSUnionType")
return type.types.some((member) => resolvesToUnknown(member, visited));
const name = referencedAliasName(type);
Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +101 to +112
Program(node) {
aliases.clear();
for (const statement of node.body) {
const declaration =
statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
if (
declaration?.type === "TSTypeAliasDeclaration" &&
(declaration.typeParameters === null || declaration.typeParameters === undefined)
) {
aliases.set(declaration.id.name, declaration.typeAnnotation);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Block aliases evade parameter linting

When a block declares type Payload = object, Program never records it. Parameters using that prohibited broad alias pass CI.

Prompt for agents
The no-object-parameters rule builds one map from top-level Program statements, so aliases declared inside functions, blocks, or namespaces are invisible. Resolve type alias declarations according to lexical scope, including shadowing by nested aliases and type parameters, before checking each parameter. Add focused tests for block-local, function-local, namespace, shadowed, and recursive aliases.
Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@pkg-pr-new

pkg-pr-new Bot commented Sep 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@2163

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@2163

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@2163

hono-agents

npm i https://pkg.pr.new/hono-agents@2163

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@2163

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@2163

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@2163

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@2163

commit: dd26fb2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant