Skip to content

Commit b8be034

Browse files
authored
[lint] move use lint to non-experimental (#27768)
`use` is being stabilized, so let's make sure the lint is updated for the next release.
1 parent 60ad369 commit b8be034

File tree

2 files changed

+93
-99
lines changed

2 files changed

+93
-99
lines changed

packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js

Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,45 @@ const tests = {
479479
}
480480
`,
481481
},
482+
{
483+
code: normalizeIndent`
484+
function App() {
485+
const text = use(Promise.resolve('A'));
486+
return <Text text={text} />
487+
}
488+
`,
489+
},
490+
{
491+
code: normalizeIndent`
492+
function App() {
493+
if (shouldShowText) {
494+
const text = use(query);
495+
return <Text text={text} />
496+
}
497+
return <Text text={shouldFetchBackupText ? use(backupQuery) : "Nothing to see here"} />
498+
}
499+
`,
500+
},
501+
{
502+
code: normalizeIndent`
503+
function App() {
504+
let data = [];
505+
for (const query of queries) {
506+
const text = use(item);
507+
data.push(text);
508+
}
509+
return <Child data={data} />
510+
}
511+
`,
512+
},
513+
{
514+
code: normalizeIndent`
515+
function App() {
516+
const data = someCallback((x) => use(x));
517+
return <Child data={data} />
518+
}
519+
`,
520+
},
482521
],
483522
invalid: [
484523
{
@@ -1058,6 +1097,58 @@ const tests = {
10581097
`,
10591098
errors: [asyncComponentHookError('useState')],
10601099
},
1100+
{
1101+
code: normalizeIndent`
1102+
Hook.use();
1103+
Hook._use();
1104+
Hook.useState();
1105+
Hook._useState();
1106+
Hook.use42();
1107+
Hook.useHook();
1108+
Hook.use_hook();
1109+
`,
1110+
errors: [
1111+
topLevelError('Hook.use'),
1112+
topLevelError('Hook.useState'),
1113+
topLevelError('Hook.use42'),
1114+
topLevelError('Hook.useHook'),
1115+
],
1116+
},
1117+
{
1118+
code: normalizeIndent`
1119+
function notAComponent() {
1120+
use(promise);
1121+
}
1122+
`,
1123+
errors: [functionError('use', 'notAComponent')],
1124+
},
1125+
{
1126+
code: normalizeIndent`
1127+
const text = use(promise);
1128+
function App() {
1129+
return <Text text={text} />
1130+
}
1131+
`,
1132+
errors: [topLevelError('use')],
1133+
},
1134+
{
1135+
code: normalizeIndent`
1136+
class C {
1137+
m() {
1138+
use(promise);
1139+
}
1140+
}
1141+
`,
1142+
errors: [classError('use')],
1143+
},
1144+
{
1145+
code: normalizeIndent`
1146+
async function AsyncComponent() {
1147+
use();
1148+
}
1149+
`,
1150+
errors: [asyncComponentHookError('use')],
1151+
},
10611152
],
10621153
};
10631154

@@ -1159,45 +1250,6 @@ if (__EXPERIMENTAL__) {
11591250
}
11601251
`,
11611252
},
1162-
{
1163-
code: normalizeIndent`
1164-
function App() {
1165-
const text = use(Promise.resolve('A'));
1166-
return <Text text={text} />
1167-
}
1168-
`,
1169-
},
1170-
{
1171-
code: normalizeIndent`
1172-
function App() {
1173-
if (shouldShowText) {
1174-
const text = use(query);
1175-
return <Text text={text} />
1176-
}
1177-
return <Text text={shouldFetchBackupText ? use(backupQuery) : "Nothing to see here"} />
1178-
}
1179-
`,
1180-
},
1181-
{
1182-
code: normalizeIndent`
1183-
function App() {
1184-
let data = [];
1185-
for (const query of queries) {
1186-
const text = use(item);
1187-
data.push(text);
1188-
}
1189-
return <Child data={data} />
1190-
}
1191-
`,
1192-
},
1193-
{
1194-
code: normalizeIndent`
1195-
function App() {
1196-
const data = someCallback((x) => use(x));
1197-
return <Child data={data} />
1198-
}
1199-
`,
1200-
},
12011253
];
12021254
tests.invalid = [
12031255
...tests.invalid,
@@ -1272,58 +1324,6 @@ if (__EXPERIMENTAL__) {
12721324
`,
12731325
errors: [useEffectEventError('onClick')],
12741326
},
1275-
{
1276-
code: normalizeIndent`
1277-
Hook.use();
1278-
Hook._use();
1279-
Hook.useState();
1280-
Hook._useState();
1281-
Hook.use42();
1282-
Hook.useHook();
1283-
Hook.use_hook();
1284-
`,
1285-
errors: [
1286-
topLevelError('Hook.use'),
1287-
topLevelError('Hook.useState'),
1288-
topLevelError('Hook.use42'),
1289-
topLevelError('Hook.useHook'),
1290-
],
1291-
},
1292-
{
1293-
code: normalizeIndent`
1294-
function notAComponent() {
1295-
use(promise);
1296-
}
1297-
`,
1298-
errors: [functionError('use', 'notAComponent')],
1299-
},
1300-
{
1301-
code: normalizeIndent`
1302-
const text = use(promise);
1303-
function App() {
1304-
return <Text text={text} />
1305-
}
1306-
`,
1307-
errors: [topLevelError('use')],
1308-
},
1309-
{
1310-
code: normalizeIndent`
1311-
class C {
1312-
m() {
1313-
use(promise);
1314-
}
1315-
}
1316-
`,
1317-
errors: [classError('use')],
1318-
},
1319-
{
1320-
code: normalizeIndent`
1321-
async function AsyncComponent() {
1322-
use();
1323-
}
1324-
`,
1325-
errors: [asyncComponentHookError('use')],
1326-
},
13271327
];
13281328
}
13291329

packages/eslint-plugin-react-hooks/src/RulesOfHooks.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
*/
1717

1818
function isHookName(s) {
19-
if (__EXPERIMENTAL__) {
20-
return s === 'use' || /^use[A-Z0-9]/.test(s);
21-
}
22-
return /^use[A-Z0-9]/.test(s);
19+
return s === 'use' || /^use[A-Z0-9]/.test(s);
2320
}
2421

2522
/**
@@ -111,10 +108,7 @@ function isUseEffectEventIdentifier(node) {
111108
}
112109

113110
function isUseIdentifier(node) {
114-
if (__EXPERIMENTAL__) {
115-
return node.type === 'Identifier' && node.name === 'use';
116-
}
117-
return false;
111+
return node.type === 'Identifier' && node.name === 'use';
118112
}
119113

120114
export default {

0 commit comments

Comments
 (0)