New
Introducing React Bench, see how different models perform on React code

react-doctor/no-high-complexity-react-function

A React component or custom hook exceeds the cyclomatic or cognitive complexity threshold

Status
Active
Category
Maintainability
Assessment
Evidence-required risk
Required evidence
source code, repository context
Default configuration
Enabled
Default severity
warn
Show technical metadata
Scope
All supported frameworks
Active when
React components and custom hooks
Tags
test-noise, react-jsx-only
Priority
Unranked; sorts as P3
Source
oxlint-plugin-react-doctor
Rule set
oxlint-plugin-react-doctor 0.9.3 (prompt schema 2)
On this page

Validation prompt

Confirm the detector match and collect the required evidence before deciding whether an edit is warranted.

This rule checks function declarations, function expressions, and arrow functions identified as React components or custom hooks. It reports when cyclomatic or cognitive complexity exceeds 15 and includes both measurements plus maximum nesting depth. Nested callback control flow is not charged to the owning React function. Confirm the reported branches belong to the component or hook and make its React behavior difficult to follow. Reject ordinary JavaScript functions, functions without React component evidence, and metrics caused only by nested callbacks.

Evidence boundary

The diagnostic proves only that the detector’s modeled source pattern matched. It does not prove runtime impact, product intent, rendered failure, or that one remediation is correct.

Establish the environment, repository policy, exceptions, and required rendered or runtime evidence before deciding the occurrence.

Record one outcome:

  • Confirmed failure: The required evidence establishes the violation.
  • Rejected: A documented exception or false-positive predicate applies.
  • Needs evidence: Named evidence can still be collected.
  • Unavailable: Required evidence cannot be collected in this run.
  • Waived with evidence: An authorized, scoped exception applies to an established failure.
  • Observation: The review records an optional tradeoff without claiming a defect.

A waiver records its scope, authority, evidence, and review condition. It is not a pass or false positive.

Default severity is registry metadata. Use the occurrence’s JSON severity after repository configuration when ordering real findings.

Review a candidate correction

Apply this candidate correction only after the required evidence confirms the risk.

Reported pattern

const AccountPanel = ({ account }: Props) => {
  if (account.isLoading) return <Spinner />;
  if (account.isLocked) return <LockedNotice />;
  if (account.hasError) return <ErrorNotice />;
  if (account.needsReview) return <ReviewNotice />;
  if (account.isExpired) return <ExpiredNotice />;
  if (account.isSuspended) return <SuspendedNotice />;
  if (account.isReadonly) return <ReadonlyNotice />;
  if (account.needsUpgrade) return <UpgradeNotice />;
  if (account.isOffline) return <OfflineNotice />;
  if (account.isSyncing) return <SyncingNotice />;
  if (account.needsConsent) return <ConsentNotice />;
  if (account.isMigrating) return <MigrationNotice />;
  if (account.hasConflict) return <ConflictNotice />;
  if (account.isDeleting) return <DeletingNotice />;
  if (account.isArchived) return <ArchivedNotice />;
  return <AccountDetails account={account} />;
};

Candidate corrected pattern

const AccountPanel = ({ account }: Props) => {
  const status = getAccountStatus(account);
  return <AccountStatus status={status} account={account} />;
};

Fix prompt

Apply this candidate correction only after the required evidence confirms the risk.

Extract independent render branches into focused components and move cohesive state or effect logic into custom hooks. Keep state ownership, render order, hook order, event behavior, and component interfaces intact. Do not split a function only to lower the number when the resulting indirection makes the behavior harder to follow. Re-run React Doctor and the affected component tests after refactoring.

Repository-wide copy prompt

Use this repository-wide prompt only after validating each occurrence. For one occurrence, use the guidance above.

Show repository-wide prompt

Fix every confirmed react-doctor/no-high-complexity-react-function diagnostic in the current repository.

Required change:

  • Extract independent render branches into focused components and move cohesive state or effect logic into custom hooks. Keep state ownership, render order, hook order, event behavior, and component interfaces intact. Do not split a function only to lower the number when the resulting indirection makes the behavior harder to follow. Re-run React Doctor and the affected component tests after refactoring.

Validation before editing:

This rule checks function declarations, function expressions, and arrow functions identified as React components or custom hooks. It reports when cyclomatic or cognitive complexity exceeds 15 and includes both measurements plus maximum nesting depth. Nested callback control flow is not charged to the owning React function. Confirm the reported branches belong to the component or hook and make its React behavior difficult to follow. Reject ordinary JavaScript functions, functions without React component evidence, and metrics caused only by nested callbacks.

Constraints:

  • Confirm every occurrence independently.
  • Make the smallest change that addresses the root cause.
  • Preserve unrelated behavior, interfaces, content, and semantics.
  • Reuse existing project conventions and components.
  • Do not suppress the rule merely to clear the report.

Assessment:

  • Record detector evidence, applicability, missing evidence, and one outcome: Confirmed failure, Rejected, Needs evidence, Unavailable, Waived with evidence, or Observation.

Verification:

  • Run focused tests and every repository-mandated check.
  • Run React Doctor and confirm the diagnostic no longer appears from changed code.
  • Run an unfiltered scan of the affected scope before claiming no cross-category regression.
  • Report checks that were not run instead of claiming they passed.