shared-utils.ts — react Source File
Architecture documentation for shared-utils.ts, a typescript file in the react codebase. 6 imports, 7 dependents.
Entity Profile
Dependency Diagram
graph LR 799656f0_feaf_2c82_77fc_4a08283ea146["shared-utils.ts"] 09f2574e_a7bc_f280_9531_89cfe9b31a61["index.ts"] 799656f0_feaf_2c82_77fc_4a08283ea146 --> 09f2574e_a7bc_f280_9531_89cfe9b31a61 cc8eb92a_b0c5_c461_8a5e_7435585bbc6e["ReactCompilerRule.ts"] 799656f0_feaf_2c82_77fc_4a08283ea146 --> cc8eb92a_b0c5_c461_8a5e_7435585bbc6e c2fb1111_dc32_da0a_d43a_b38b8d13f4e9["allRules"] 799656f0_feaf_2c82_77fc_4a08283ea146 --> c2fb1111_dc32_da0a_d43a_b38b8d13f4e9 e023ae51_0bf7_c8b1_0545_8e7304e4bb72["eslint"] 799656f0_feaf_2c82_77fc_4a08283ea146 --> e023ae51_0bf7_c8b1_0545_8e7304e4bb72 f1417319_0940_9839_f3b2_304147ce4f9d["CompilerError"] 799656f0_feaf_2c82_77fc_4a08283ea146 --> f1417319_0940_9839_f3b2_304147ce4f9d 994f21f2_b6d1_a88d_e817_be301a12d1ea["regexp.escape"] 799656f0_feaf_2c82_77fc_4a08283ea146 --> 994f21f2_b6d1_a88d_e817_be301a12d1ea fe900090_ffb7_69bc_e43c_31d1506aebdf["ImpureFunctionCallsRule-test.ts"] fe900090_ffb7_69bc_e43c_31d1506aebdf --> 799656f0_feaf_2c82_77fc_4a08283ea146 7b06326c_10b5_45ec_3ebb_f8b909c17ef4["InvalidHooksRule-test.ts"] 7b06326c_10b5_45ec_3ebb_f8b909c17ef4 --> 799656f0_feaf_2c82_77fc_4a08283ea146 bef2af1f_8aae_95c1_7312_e60ab412c9ae["NoAmbiguousJsxRule-test.ts"] bef2af1f_8aae_95c1_7312_e60ab412c9ae --> 799656f0_feaf_2c82_77fc_4a08283ea146 7f76a9cf_909b_bef1_2557_38a00b1190af["NoCapitalizedCallsRule-test.ts"] 7f76a9cf_909b_bef1_2557_38a00b1190af --> 799656f0_feaf_2c82_77fc_4a08283ea146 08707db7_da45_6476_8614_d872c7abc3f1["NoRefAccessInRender-tests.ts"] 08707db7_da45_6476_8614_d872c7abc3f1 --> 799656f0_feaf_2c82_77fc_4a08283ea146 a4e0a434_c5ac_2a3c_80f4_783788be4192["PluginTest-test.ts"] a4e0a434_c5ac_2a3c_80f4_783788be4192 --> 799656f0_feaf_2c82_77fc_4a08283ea146 d018a273_4188_8c38_a8a8_a65b8c0dad2c["ReactCompilerRuleTypescript-test.ts"] d018a273_4188_8c38_a8a8_a65b8c0dad2c --> 799656f0_feaf_2c82_77fc_4a08283ea146 style 799656f0_feaf_2c82_77fc_4a08283ea146 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import {RuleTester as ESLintTester, Rule} from 'eslint';
import {type ErrorCategory} from 'babel-plugin-react-compiler/src/CompilerError';
import escape from 'regexp.escape';
import {configs} from '../src/index';
import {allRules} from '../src/rules/ReactCompilerRule';
/**
* 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)
*/
export 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');
}
export type CompilerTestCases = {
valid: ESLintTester.ValidTestCase[];
invalid: ESLintTester.InvalidTestCase[];
};
export function makeTestCaseError(reason: string): ESLintTester.TestCaseError {
return {
message: new RegExp(escape(reason)),
};
}
export function testRule(
name: string,
rule: Rule.RuleModule,
tests: {
valid: ESLintTester.ValidTestCase[];
invalid: ESLintTester.InvalidTestCase[];
},
): void {
const eslintTester = new ESLintTester({
// @ts-ignore[2353] - outdated types
parser: require.resolve('hermes-eslint'),
parserOptions: {
ecmaVersion: 2015,
sourceType: 'module',
enableExperimentalComponentSyntax: true,
},
});
eslintTester.run(name, rule, tests);
}
/**
* Aggregates all recommended rules from the plugin.
*/
export const TestRecommendedRules: Rule.RuleModule = {
meta: {
type: 'problem',
docs: {
description: 'Disallow capitalized function calls',
category: 'Possible Errors',
recommended: true,
},
// validation is done at runtime with zod
schema: [{type: 'object', additionalProperties: true}],
},
create(context) {
for (const ruleConfig of Object.values(
configs.recommended.plugins['react-compiler'].rules,
)) {
const listener = ruleConfig.rule.create(context);
if (Object.entries(listener).length !== 0) {
throw new Error('TODO: handle rules that return listeners to eslint');
}
}
return {};
},
};
test('no test', () => {});
Domain
Subdomains
Types
Dependencies
- CompilerError
- ReactCompilerRule.ts
- allRules
- eslint
- index.ts
- regexp.escape
Imported By
- compiler/packages/eslint-plugin-react-compiler/__tests__/ImpureFunctionCallsRule-test.ts
- compiler/packages/eslint-plugin-react-compiler/__tests__/InvalidHooksRule-test.ts
- compiler/packages/eslint-plugin-react-compiler/__tests__/NoAmbiguousJsxRule-test.ts
- compiler/packages/eslint-plugin-react-compiler/__tests__/NoCapitalizedCallsRule-test.ts
- compiler/packages/eslint-plugin-react-compiler/__tests__/NoRefAccessInRender-tests.ts
- compiler/packages/eslint-plugin-react-compiler/__tests__/PluginTest-test.ts
- compiler/packages/eslint-plugin-react-compiler/__tests__/ReactCompilerRuleTypescript-test.ts
Source
Frequently Asked Questions
What does shared-utils.ts do?
shared-utils.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 shared-utils.ts?
shared-utils.ts defines 4 function(s): TestRecommendedRules.create, makeTestCaseError, normalizeIndent, testRule.
What does shared-utils.ts depend on?
shared-utils.ts imports 6 module(s): CompilerError, ReactCompilerRule.ts, allRules, eslint, index.ts, regexp.escape.
What files import shared-utils.ts?
shared-utils.ts is imported by 7 file(s): ImpureFunctionCallsRule-test.ts, InvalidHooksRule-test.ts, NoAmbiguousJsxRule-test.ts, NoCapitalizedCallsRule-test.ts, NoRefAccessInRender-tests.ts, PluginTest-test.ts, ReactCompilerRuleTypescript-test.ts.
Where is shared-utils.ts in the architecture?
shared-utils.ts is located at compiler/packages/eslint-plugin-react-compiler/__tests__/shared-utils.ts (domain: BabelCompiler, subdomain: Validation, directory: compiler/packages/eslint-plugin-react-compiler/__tests__).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free