@@ -34,16 +34,38 @@ function normalizeIndent(strings) {
34
34
// }
35
35
// ***************************************************
36
36
37
- const tests = {
37
+ const allTests = {
38
38
valid : [
39
39
{
40
+ only : true ,
40
41
code : normalizeIndent `
41
42
// Valid because components can use hooks.
42
43
function ComponentWithHook() {
43
44
useHook();
44
45
}
45
46
` ,
46
47
} ,
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
+ } ,
47
69
{
48
70
code : normalizeIndent `
49
71
// Valid because components can use hooks.
@@ -1287,8 +1309,8 @@ const tests = {
1287
1309
} ;
1288
1310
1289
1311
if ( __EXPERIMENTAL__ ) {
1290
- tests . valid = [
1291
- ...tests . valid ,
1312
+ allTests . valid = [
1313
+ ...allTests . valid ,
1292
1314
{
1293
1315
code : normalizeIndent `
1294
1316
// Valid because functions created with useEffectEvent can be called in a useEffect.
@@ -1385,8 +1407,8 @@ if (__EXPERIMENTAL__) {
1385
1407
` ,
1386
1408
} ,
1387
1409
] ;
1388
- tests . invalid = [
1389
- ...tests . invalid ,
1410
+ allTests . invalid = [
1411
+ ...allTests . invalid ,
1390
1412
{
1391
1413
code : normalizeIndent `
1392
1414
function MyComponent({ theme }) {
@@ -1536,7 +1558,7 @@ function asyncComponentHookError(fn) {
1536
1558
if ( ! process . env . CI ) {
1537
1559
let only = [ ] ;
1538
1560
let skipped = [ ] ;
1539
- [ ...tests . valid , ...tests . invalid ] . forEach ( t => {
1561
+ [ ...allTests . valid , ...allTests . invalid ] . forEach ( t => {
1540
1562
if ( t . skip ) {
1541
1563
delete t . skip ;
1542
1564
skipped . push ( t ) ;
@@ -1555,10 +1577,23 @@ if (!process.env.CI) {
1555
1577
}
1556
1578
return true ;
1557
1579
} ;
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 ) ;
1560
1582
}
1561
1583
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
+
1562
1597
describe ( 'rules-of-hooks/rules-of-hooks' , ( ) => {
1563
1598
const parserOptionsV7 = {
1564
1599
ecmaFeatures : {
@@ -1594,6 +1629,17 @@ describe('rules-of-hooks/rules-of-hooks', () => {
1594
1629
tests
1595
1630
) ;
1596
1631
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
+
1597
1643
new ESLintTesterV7 ( {
1598
1644
parser : require . resolve ( '@typescript-eslint/parser-v2' ) ,
1599
1645
parserOptions : parserOptionsV7 ,
0 commit comments