@@ -34,7 +34,7 @@ function normalizeIndent(strings) {
34
34
// }
35
35
// ***************************************************
36
36
37
- const tests = {
37
+ const allTests = {
38
38
valid : [
39
39
{
40
40
code : normalizeIndent `
@@ -44,6 +44,25 @@ const tests = {
44
44
}
45
45
` ,
46
46
} ,
47
+ {
48
+ syntax : 'flow' ,
49
+ code : normalizeIndent `
50
+ // Component syntax
51
+ component Button() {
52
+ useHook();
53
+ return <div>Button!</div>;
54
+ }
55
+ ` ,
56
+ } ,
57
+ {
58
+ syntax : 'flow' ,
59
+ code : normalizeIndent `
60
+ // Hook syntax
61
+ hook useSampleHook() {
62
+ useHook();
63
+ }
64
+ ` ,
65
+ } ,
47
66
{
48
67
code : normalizeIndent `
49
68
// Valid because components can use hooks.
@@ -563,6 +582,28 @@ const tests = {
563
582
} ,
564
583
] ,
565
584
invalid : [
585
+ {
586
+ syntax : 'flow' ,
587
+ code : normalizeIndent `
588
+ component Button(cond: boolean) {
589
+ if (cond) {
590
+ useConditionalHook();
591
+ }
592
+ }
593
+ ` ,
594
+ errors : [ conditionalError ( 'useConditionalHook' ) ] ,
595
+ } ,
596
+ {
597
+ syntax : 'flow' ,
598
+ code : normalizeIndent `
599
+ hook useTest(cond: boolean) {
600
+ if (cond) {
601
+ useConditionalHook();
602
+ }
603
+ }
604
+ ` ,
605
+ errors : [ conditionalError ( 'useConditionalHook' ) ] ,
606
+ } ,
566
607
{
567
608
code : normalizeIndent `
568
609
// Invalid because it's dangerous and might not warn otherwise.
@@ -1287,8 +1328,8 @@ const tests = {
1287
1328
} ;
1288
1329
1289
1330
if ( __EXPERIMENTAL__ ) {
1290
- tests . valid = [
1291
- ...tests . valid ,
1331
+ allTests . valid = [
1332
+ ...allTests . valid ,
1292
1333
{
1293
1334
code : normalizeIndent `
1294
1335
// Valid because functions created with useEffectEvent can be called in a useEffect.
@@ -1385,8 +1426,8 @@ if (__EXPERIMENTAL__) {
1385
1426
` ,
1386
1427
} ,
1387
1428
] ;
1388
- tests . invalid = [
1389
- ...tests . invalid ,
1429
+ allTests . invalid = [
1430
+ ...allTests . invalid ,
1390
1431
{
1391
1432
code : normalizeIndent `
1392
1433
function MyComponent({ theme }) {
@@ -1536,7 +1577,7 @@ function asyncComponentHookError(fn) {
1536
1577
if ( ! process . env . CI ) {
1537
1578
let only = [ ] ;
1538
1579
let skipped = [ ] ;
1539
- [ ...tests . valid , ...tests . invalid ] . forEach ( t => {
1580
+ [ ...allTests . valid , ...allTests . invalid ] . forEach ( t => {
1540
1581
if ( t . skip ) {
1541
1582
delete t . skip ;
1542
1583
skipped . push ( t ) ;
@@ -1555,10 +1596,23 @@ if (!process.env.CI) {
1555
1596
}
1556
1597
return true ;
1557
1598
} ;
1558
- tests . valid = tests . valid . filter ( predicate ) ;
1559
- tests . invalid = tests . invalid . filter ( predicate ) ;
1599
+ allTests . valid = allTests . valid . filter ( predicate ) ;
1600
+ allTests . invalid = allTests . invalid . filter ( predicate ) ;
1601
+ }
1602
+
1603
+ function filteredTests ( predicate ) {
1604
+ return {
1605
+ valid : allTests . valid . filter ( predicate ) ,
1606
+ invalid : allTests . invalid . filter ( predicate ) ,
1607
+ } ;
1560
1608
}
1561
1609
1610
+ const flowTests = filteredTests ( t => t . syntax == null || t . syntax === 'flow' ) ;
1611
+ const tests = filteredTests ( t => t . syntax !== 'flow' ) ;
1612
+
1613
+ allTests . valid . forEach ( t => delete t . syntax ) ;
1614
+ allTests . invalid . forEach ( t => delete t . syntax ) ;
1615
+
1562
1616
describe ( 'rules-of-hooks/rules-of-hooks' , ( ) => {
1563
1617
const parserOptionsV7 = {
1564
1618
ecmaFeatures : {
@@ -1594,6 +1648,25 @@ describe('rules-of-hooks/rules-of-hooks', () => {
1594
1648
tests
1595
1649
) ;
1596
1650
1651
+ new ESLintTesterV7 ( {
1652
+ parser : require . resolve ( 'hermes-eslint' ) ,
1653
+ parserOptions : {
1654
+ sourceType : 'module' ,
1655
+ enableExperimentalComponentSyntax : true ,
1656
+ } ,
1657
+ } ) . run ( 'eslint: v7, parser: hermes-eslint' , ReactHooksESLintRule , flowTests ) ;
1658
+
1659
+ new ESLintTesterV9 ( {
1660
+ languageOptions : {
1661
+ ...languageOptionsV9 ,
1662
+ parser : require ( 'hermes-eslint' ) ,
1663
+ parserOptions : {
1664
+ sourceType : 'module' ,
1665
+ enableExperimentalComponentSyntax : true ,
1666
+ } ,
1667
+ } ,
1668
+ } ) . run ( 'eslint: v9, parser: hermes-eslint' , ReactHooksESLintRule , flowTests ) ;
1669
+
1597
1670
new ESLintTesterV7 ( {
1598
1671
parser : require . resolve ( '@typescript-eslint/parser-v2' ) ,
1599
1672
parserOptions : parserOptionsV7 ,
0 commit comments