Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7746,6 +7746,34 @@ const testsFlow = {
},
],
invalid: [
{
code: normalizeIndent`
hook useExample(a) {
useEffect(() => {
console.log(a);
}, []);
}
`,
errors: [
{
message:
"React Hook useEffect has a missing dependency: 'a'. " +
'Either include it or remove the dependency array.',
suggestions: [
{
desc: 'Update the dependencies array to be: [a]',
output: normalizeIndent`
hook useExample(a) {
useEffect(() => {
console.log(a);
}, [a]);
}
`,
},
],
},
],
},
{
code: normalizeIndent`
function Foo() {
Expand Down Expand Up @@ -8311,7 +8339,9 @@ describe('rules-of-hooks/exhaustive-deps', () => {
},
};

const testsBabelEslint = {
const testsBabelEslint = tests;

const testsHermesParser = {
valid: [...testsFlow.valid, ...tests.valid],
invalid: [...testsFlow.invalid, ...tests.invalid],
};
Expand All @@ -8336,6 +8366,33 @@ describe('rules-of-hooks/exhaustive-deps', () => {
testsBabelEslint
);

new ESLintTesterV7({
parser: require.resolve('hermes-eslint'),
parserOptions: {
sourceType: 'module',
enableExperimentalComponentSyntax: true,
},
}).run(
'eslint: v7, parser: hermes-eslint',
ReactHooksESLintRule,
testsHermesParser
);

new ESLintTesterV9({
languageOptions: {
...languageOptionsV9,
parser: require('hermes-eslint'),
parserOptions: {
sourceType: 'module',
enableExperimentalComponentSyntax: true,
},
},
}).run(
'eslint: v9, parser: hermes-eslint',
ReactHooksESLintRule,
testsHermesParser
);

const testsTypescriptEslintParser = {
valid: [...testsTypescript.valid, ...tests.valid],
invalid: [...testsTypescript.invalid, ...tests.invalid],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,13 @@ const rule = {
let currentScope = scope.upper;
while (currentScope) {
pureScopes.add(currentScope);
if (currentScope.type === 'function') {
if (
currentScope.type === 'function' ||
// @ts-expect-error incorrect TS types
currentScope.type === 'hook' ||
// @ts-expect-error incorrect TS types
currentScope.type === 'component'
) {
break;
}
currentScope = currentScope.upper;
Expand Down
Loading