main
ts 74 lines 1.87 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7 import {
8 ErrorCategory,
9 getRuleForCategory,
10 } from 'babel-plugin-react-compiler/src/CompilerError';
11 import {normalizeIndent, makeTestCaseError, testRule} from './shared-utils';
12 import {allRules} from '../src/rules/ReactCompilerRule';
13
14 testRule(
15 'no-capitalized-calls',
16 allRules[getRuleForCategory(ErrorCategory.CapitalizedCalls).name].rule,
17 {
18 valid: [],
19 invalid: [
20 {
21 name: 'Simple violation',
22 code: normalizeIndent`
23 import Child from './Child';
24 function Component() {
25 return <>
26 {Child()}
27 </>;
28 }
29 `,
30 errors: [
31 makeTestCaseError(
32 'Capitalized functions are reserved for components',
33 ),
34 ],
35 },
36 {
37 name: 'Method call violation',
38 code: normalizeIndent`
39 import myModule from './MyModule';
40 function Component() {
41 return <>
42 {myModule.Child()}
43 </>;
44 }
45 `,
46 errors: [
47 makeTestCaseError(
48 'Capitalized functions are reserved for components',
49 ),
50 ],
51 },
52 {
53 name: 'Multiple diagnostics within the same function are surfaced',
54 code: normalizeIndent`
55 import Child1 from './Child1';
56 import MyModule from './MyModule';
57 function Component() {
58 return <>
59 {Child1()}
60 {MyModule.Child2()}
61 </>;
62 }`,
63 errors: [
64 makeTestCaseError(
65 'Capitalized functions are reserved for components',
66 ),
67 makeTestCaseError(
68 'Capitalized functions are reserved for components',
69 ),
70 ],
71 },
72 ],
73 },
74 );