Home / File/ RulesOfHooks.ts — react Source File

RulesOfHooks.ts — react Source File

Architecture documentation for RulesOfHooks.ts, a typescript file in the react codebase. 6 imports, 1 dependents.

File typescript BabelCompiler Validation 6 imports 1 dependents 17 functions

Entity Profile

Dependency Diagram

graph LR
  47fb9f02_49dd_1d0d_5027_9353a6a77f1e["RulesOfHooks.ts"]
  09a1c78a_21af_9be8_1cc6_22cf0ceb9f8f["code-path-analyzer.js"]
  47fb9f02_49dd_1d0d_5027_9353a6a77f1e --> 09a1c78a_21af_9be8_1cc6_22cf0ceb9f8f
  879ae635_0722_8285_b0bd_4d1ab153e2e3["CodePathAnalyzer"]
  47fb9f02_49dd_1d0d_5027_9353a6a77f1e --> 879ae635_0722_8285_b0bd_4d1ab153e2e3
  09c0f942_dfde_7720_a179_0571ede43aad["Utils.ts"]
  47fb9f02_49dd_1d0d_5027_9353a6a77f1e --> 09c0f942_dfde_7720_a179_0571ede43aad
  1a929da5_96c8_bcab_86db_7fe06b23af38["getAdditionalEffectHooksFromSettings"]
  47fb9f02_49dd_1d0d_5027_9353a6a77f1e --> 1a929da5_96c8_bcab_86db_7fe06b23af38
  e023ae51_0bf7_c8b1_0545_8e7304e4bb72["eslint"]
  47fb9f02_49dd_1d0d_5027_9353a6a77f1e --> e023ae51_0bf7_c8b1_0545_8e7304e4bb72
  14c74228_2987_7343_cb97_b89a9b190db6["estree"]
  47fb9f02_49dd_1d0d_5027_9353a6a77f1e --> 14c74228_2987_7343_cb97_b89a9b190db6
  b4590b6e_50d1_c664_5047_3e6e187f6b97["index.ts"]
  b4590b6e_50d1_c664_5047_3e6e187f6b97 --> 47fb9f02_49dd_1d0d_5027_9353a6a77f1e
  style 47fb9f02_49dd_1d0d_5027_9353a6a77f1e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
/* eslint-disable no-for-of-loops/no-for-of-loops */

import type {Rule, Scope} from 'eslint';
import type {
  CallExpression,
  CatchClause,
  DoWhileStatement,
  Expression,
  Identifier,
  Node,
  Super,
  TryStatement,
} from 'estree';

// @ts-expect-error untyped module
import CodePathAnalyzer from '../code-path-analysis/code-path-analyzer';
import {getAdditionalEffectHooksFromSettings} from '../shared/Utils';

/**
 * Catch all identifiers that begin with "use" followed by an uppercase Latin
 * character to exclude identifiers like "user".
 */
function isHookName(s: string): boolean {
  return s === 'use' || /^use[A-Z0-9]/.test(s);
}

/**
 * We consider hooks to be a hook name identifier or a member expression
 * containing a hook name.
 */
function isHook(node: Node): boolean {
  if (node.type === 'Identifier') {
    return isHookName(node.name);
  } else if (
    node.type === 'MemberExpression' &&
    !node.computed &&
    isHook(node.property)
  ) {
    const obj = node.object;
    const isPascalCaseNameSpace = /^[A-Z].*/;
    return obj.type === 'Identifier' && isPascalCaseNameSpace.test(obj.name);
  } else {
    return false;
  }
}

/**
 * Checks if the node is a React component name. React component names must
 * always start with an uppercase letter.
 */
function isComponentName(node: Node): boolean {
  return node.type === 'Identifier' && /^[A-Z]/.test(node.name);
}

// ... (875 more lines)

Domain

Subdomains

Frequently Asked Questions

What does RulesOfHooks.ts do?
RulesOfHooks.ts is a source file in the react codebase, written in typescript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in RulesOfHooks.ts?
RulesOfHooks.ts defines 17 function(s): getFunctionName, getNodeWithoutReactNamespace, isComponentName, isEffectIdentifier, isForwardRefCallback, isHook, isHookName, isInsideComponentOrHook, isInsideDoWhileLoop, isInsideTryCatch, and 7 more.
What does RulesOfHooks.ts depend on?
RulesOfHooks.ts imports 6 module(s): CodePathAnalyzer, Utils.ts, code-path-analyzer.js, eslint, estree, getAdditionalEffectHooksFromSettings.
What files import RulesOfHooks.ts?
RulesOfHooks.ts is imported by 1 file(s): index.ts.
Where is RulesOfHooks.ts in the architecture?
RulesOfHooks.ts is located at packages/eslint-plugin-react-hooks/src/rules/RulesOfHooks.ts (domain: BabelCompiler, subdomain: Validation, directory: packages/eslint-plugin-react-hooks/src/rules).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free