eslint-plugin-react-hook-form icon indicating copy to clipboard operation
eslint-plugin-react-hook-form copied to clipboard

Does not report without object destructuring

Open MarceloPrado opened this issue 1 year ago • 1 comments

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

  1. Paste the ErrorExample snippet above and try running the lint.

  2. Your ESlint config Any setup should work, as the issue lies inside findPropertyByName function.

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

CleanShot 2024-08-19 at 07 57 45@2x

Error case CleanShot 2024-08-19 at 07 58 04@2x

MarceloPrado avatar Aug 19 '24 11:08 MarceloPrado

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!

andykao1213 avatar May 10 '25 05:05 andykao1213