@@ -34,16 +34,38 @@ function normalizeIndent(strings) {
3434// }
3535// ***************************************************
3636
37- const tests = {
37+ const allTests = {
3838 valid : [
3939 {
40+ only : true ,
4041 code : normalizeIndent `
4142 // Valid because components can use hooks.
4243 function ComponentWithHook() {
4344 useHook();
4445 }
4546 ` ,
4647 } ,
48+ {
49+ only : true ,
50+ syntax : 'flow' ,
51+ code : normalizeIndent `
52+ // Component syntax
53+ component Button() {
54+ useHook();
55+ return <div>Button!</div>;
56+ }
57+ ` ,
58+ } ,
59+ {
60+ only : true ,
61+ syntax : 'flow' ,
62+ code : normalizeIndent `
63+ // Component syntax
64+ hook useSampleHook() {
65+ useHook();
66+ }
67+ ` ,
68+ } ,
4769 {
4870 code : normalizeIndent `
4971 // Valid because components can use hooks.
@@ -1287,8 +1309,8 @@ const tests = {
12871309} ;
12881310
12891311if ( __EXPERIMENTAL__ ) {
1290- tests . valid = [
1291- ...tests . valid ,
1312+ allTests . valid = [
1313+ ...allTests . valid ,
12921314 {
12931315 code : normalizeIndent `
12941316 // Valid because functions created with useEffectEvent can be called in a useEffect.
@@ -1385,8 +1407,8 @@ if (__EXPERIMENTAL__) {
13851407 ` ,
13861408 } ,
13871409 ] ;
1388- tests . invalid = [
1389- ...tests . invalid ,
1410+ allTests . invalid = [
1411+ ...allTests . invalid ,
13901412 {
13911413 code : normalizeIndent `
13921414 function MyComponent({ theme }) {
@@ -1536,7 +1558,7 @@ function asyncComponentHookError(fn) {
15361558if ( ! process . env . CI ) {
15371559 let only = [ ] ;
15381560 let skipped = [ ] ;
1539- [ ...tests . valid , ...tests . invalid ] . forEach ( t => {
1561+ [ ...allTests . valid , ...allTests . invalid ] . forEach ( t => {
15401562 if ( t . skip ) {
15411563 delete t . skip ;
15421564 skipped . push ( t ) ;
@@ -1555,10 +1577,23 @@ if (!process.env.CI) {
15551577 }
15561578 return true ;
15571579 } ;
1558- tests . valid = tests . valid . filter ( predicate ) ;
1559- tests . invalid = tests . invalid . filter ( predicate ) ;
1580+ allTests . valid = allTests . valid . filter ( predicate ) ;
1581+ allTests . invalid = allTests . invalid . filter ( predicate ) ;
15601582}
15611583
1584+ function filteredTests ( predicate ) {
1585+ return {
1586+ valid : allTests . valid . filter ( predicate ) ,
1587+ invalid : allTests . invalid . filter ( predicate ) ,
1588+ } ;
1589+ }
1590+
1591+ const flowTests = filteredTests ( t => t . syntax == null || t . syntax == 'flow' ) ;
1592+ const tests = filteredTests ( t => t . syntax !== 'flow' ) ;
1593+
1594+ allTests . valid . forEach ( t => delete t . syntax ) ;
1595+ allTests . invalid . forEach ( t => delete t . syntax ) ;
1596+
15621597describe ( 'rules-of-hooks/rules-of-hooks' , ( ) => {
15631598 const parserOptionsV7 = {
15641599 ecmaFeatures : {
@@ -1594,6 +1629,17 @@ describe('rules-of-hooks/rules-of-hooks', () => {
15941629 tests
15951630 ) ;
15961631
1632+ new ESLintTesterV9 ( {
1633+ languageOptions : {
1634+ ...languageOptionsV9 ,
1635+ parser : require ( 'hermes-eslint' ) ,
1636+ parserOptions : {
1637+ sourceType : 'module' ,
1638+ enableExperimentalComponentSyntax : true ,
1639+ } ,
1640+ } ,
1641+ } ) . run ( 'eslint: v9, parser: hermes-eslint' , ReactHooksESLintRule , flowTests ) ;
1642+
15971643 new ESLintTesterV7 ( {
15981644 parser : require . resolve ( '@typescript-eslint/parser-v2' ) ,
15991645 parserOptions : parserOptionsV7 ,
0 commit comments