Home / File/ ReactCompilerRuleFlow-test.ts — react Source File

ReactCompilerRuleFlow-test.ts — react Source File

Architecture documentation for ReactCompilerRuleFlow-test.ts, a typescript file in the react codebase. 3 imports, 0 dependents.

File typescript BabelCompiler Validation 3 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  f23046a7_8ff6_6e84_73a1_6ab58cc3ee68["ReactCompilerRuleFlow-test.ts"]
  40190dd7_cea0_7135_9d7e_df5f2d3454b7["ReactCompiler.ts"]
  f23046a7_8ff6_6e84_73a1_6ab58cc3ee68 --> 40190dd7_cea0_7135_9d7e_df5f2d3454b7
  dc45eeec_7cda_3dde_2446_228b95f1d232["allRules"]
  f23046a7_8ff6_6e84_73a1_6ab58cc3ee68 --> dc45eeec_7cda_3dde_2446_228b95f1d232
  e023ae51_0bf7_c8b1_0545_8e7304e4bb72["eslint"]
  f23046a7_8ff6_6e84_73a1_6ab58cc3ee68 --> e023ae51_0bf7_c8b1_0545_8e7304e4bb72
  style f23046a7_8ff6_6e84_73a1_6ab58cc3ee68 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.
 */

import {RuleTester} from 'eslint';
import {allRules} from '../src/shared/ReactCompiler';

const ESLintTesterV8 = require('eslint-v8').RuleTester;

/**
 * A string template tag that removes padding from the left side of multi-line strings
 * @param {Array} strings array of code strings (only one expected)
 */
function normalizeIndent(strings: TemplateStringsArray): string {
  const codeLines = strings[0]?.split('\n') ?? [];
  const leftPadding = codeLines[1]?.match(/\s+/)![0] ?? '';
  return codeLines.map(line => line.slice(leftPadding.length)).join('\n');
}

type CompilerTestCases = {
  valid: RuleTester.ValidTestCase[];
  invalid: RuleTester.InvalidTestCase[];
};

const tests: CompilerTestCases = {
  valid: [
    // ===========================================
    // Tests for mayContainReactCode heuristic with Flow syntax
    // Files that should be SKIPPED (no React-like function names)
    // These contain code that WOULD trigger errors if compiled,
    // but since the heuristic skips them, no errors are reported.
    // ===========================================
    {
      name: '[Heuristic/Flow] Skips files with only lowercase utility functions',
      filename: 'utils.js',
      code: normalizeIndent`
        function helper(obj) {
          obj.key = 'value';
          return obj;
        }
      `,
    },
    {
      name: '[Heuristic/Flow] Skips lowercase arrow functions even with mutations',
      filename: 'helpers.js',
      code: normalizeIndent`
        const processData = (input) => {
          input.modified = true;
          return input;
        };
      `,
    },
  ],
  invalid: [
    // ===========================================
    // Tests for mayContainReactCode heuristic with Flow component/hook syntax
    // These use Flow's component/hook declarations which should be detected
// ... (88 more lines)

Domain

Subdomains

Functions

Dependencies

Frequently Asked Questions

What does ReactCompilerRuleFlow-test.ts do?
ReactCompilerRuleFlow-test.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 ReactCompilerRuleFlow-test.ts?
ReactCompilerRuleFlow-test.ts defines 1 function(s): normalizeIndent.
What does ReactCompilerRuleFlow-test.ts depend on?
ReactCompilerRuleFlow-test.ts imports 3 module(s): ReactCompiler.ts, allRules, eslint.
Where is ReactCompilerRuleFlow-test.ts in the architecture?
ReactCompilerRuleFlow-test.ts is located at packages/eslint-plugin-react-hooks/__tests__/ReactCompilerRuleFlow-test.ts (domain: BabelCompiler, subdomain: Validation, directory: packages/eslint-plugin-react-hooks/__tests__).

Analyze Your Own Codebase

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

Try Supermodel Free