eslint-plugin-react-hook-form
eslint-plugin-react-hook-form copied to clipboard
Does not report without object destructuring
Describe the bug Hi! As I debugged why the rule wasn't working for my case, I realized it only reports if you use object destructuring:
function WorkingExample() {
const { formState } = useForm();
const onSubmit = (data) => console.log(data);
console.log(formState.isDirty); // make sure formState is read before render to enable the Proxy
return <input type="submit" />;
}
However, if you instead write the following code, the rule fails to trigger:
function ErrorExample() {
const methods = useForm();
const onSubmit = (data) => console.log(data);
console.log(methods.formState.isDirty); // make sure formState is read before render to enable the Proxy
return (
<input type='submit' />
);
}
To Reproduce
-
Paste the
ErrorExamplesnippet above and try running the lint. -
Your ESlint config Any setup should work, as the issue lies inside
findPropertyByNamefunction.
Expected behavior The rule should fire, since I'm running an example extracted directly from the docs
Actual behavior Rule doesn't fire.
Enviornment (please complete the following information):
- Eslint version: 8.0.1
- Node version: 20.11.1
- React-Hook-Form version: 7.49.3
Additional context The issue lies in this line.
Here's some AST explorer context:
Working case
Error case
Hi @MarceloPrado Thanks for the investigation! As I had limited time for the project now, I'll be super appreciated if you can create a PR for this. Thanks a lot!