Ban direct `useEffect` in React components. Use when writing, refactoring, or reviewing React code so derived state, data fetching, user actions, resets, and mount-only external synchronization use declarative replacement patterns instead of dependency-array choreography.
95
95%
Does it follow best practices?
Impact
98%
1.02xAverage score across 4 eval scenarios
Passed
No known issues
A React repository wants to enforce the no-direct-useEffect policy. It uses ESLint flat config and already has a shared src/hooks/ directory. Add a policy that blocks direct useEffect imports and React.useEffect(...) namespace calls in application code, while allowing one reviewed domain-specific hook for its chat connection.
The hook must call the existing connectChat({ serverUrl, roomId }) API, open the returned connection, close it during cleanup, and reconnect when either serverUrl or roomId changes. Do not add a generic effect-callback wrapper, accept a dependency array from callers, or suppress exhaustive-deps.
Do not disable hooks linting globally. Do not block unrelated APIs like useLayoutEffect unless asked.
Produce:
eslint.config.ts with the policysrc/hooks/useChatConnection.ts as the allowed external-integration hookpolicy-report.md explaining the enforcement boundary and verification=============== FILE: eslint.config.ts =============== import js from "@eslint/js"; import tseslint from "typescript-eslint"; import reactHooks from "eslint-plugin-react-hooks";
export default tseslint.config( js.configs.recommended, ...tseslint.configs.recommended, { plugins: { "react-hooks": reactHooks, }, rules: { "react-hooks/rules-of-hooks": "error", "react-hooks/exhaustive-deps": "warn", }, }, ); =============== END FILE ===============
=============== FILE: src/chat/connectChat.ts =============== export type ChatConnection = { open(): void; close(): void; };
export function connectChat(input: { serverUrl: string; roomId: string }): ChatConnection {
throw new Error(runtime implementation omitted for ${input.serverUrl}/${input.roomId});
}
=============== END FILE ===============