andykao1213 / eslint-plugin-react-hook-form Goto Github PK
View Code? Open in Web Editor NEWESLint plugin for react-hook-form
License: MIT License
ESLint plugin for react-hook-form
License: MIT License
Describe the bug
The plugin crashes unexpectedly when not destructuring the result of calling useForm.
To Reproduce
const { useForm } = require('react-hook-form')
export function Component() {
const formMethods = useForm()
return null
}
{
...
'react-hook-form/no-nested-object-setvalue': ['error', { bracketAsArrayIndex: true }],
}
Expected behavior
I expect the React Hook Form Eslint plugin to not crash.
Actual behavior
The React Hook Form ESLing plugin crashes with the following error message:
TypeError: Cannot read property 'find' of undefined
Occurred while linting my-project/components/TestComponent.jsx:3
at check (my-project/node_modules/eslint-plugin-react-hook-form/lib/rules/no-nested-object-setvalue.js:48:53)
at my-project/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (my-project/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (my-project/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
at NodeEventGenerator.applySelectors (my-project/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
at NodeEventGenerator.enterNode (my-project/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
at CodePathAnalyzer.enterNode (my-project/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)
at my-project/node_modules/eslint/lib/linter/linter.js:952:32
at Array.forEach (<anonymous>)
Enviornment (please complete the following information):
Additional context
n/a
Describe the bug
ESLint exits with fatal error.
To Reproduce
for (const element of array) {
bar(element);
}
{
"parserOptions": {
"ecmaVersion": "latest"
},
"plugins": ["react-hook-form"],
"rules": {
"react-hook-form/destructuring-formstate": "error"
}
}
Expected behavior
No fatal error.
Actual behavior
Oops! Something went wrong! :(
ESLint: 8.6.0
TypeError: Cannot read property 'type' of null
Occurred while linting /example/example.js:1
Rule: "react-hook-form/destructuring-formstate"
at check (/example/node_modules/eslint-plugin-react-hook-form/lib/rules/destructuring-formstate.js:45:19)
at ruleErrorHandler (/example/node_modules/eslint/lib/linter/linter.js:1079:28)
at /example/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (/example/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/example/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
at NodeEventGenerator.applySelectors (/example/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
at NodeEventGenerator.enterNode (/example/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
at CodePathAnalyzer.enterNode (/example/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:795:23)
at /example/node_modules/eslint/lib/linter/linter.js:1110:32
Enviornment (please complete the following information):
Additional context
As mentioned in the #13 , we should probably support useFormContext
.
Describe the bug
The plugin crashes unexpectedly when using ...rest
syntax in the destructuring of the result of calling useForm.
To Reproduce
const { useForm } = require('react-hook-form')
export function Component() {
const { watch, ...restFormMethods } = useForm()
return null
}
{
...
'react-hook-form/no-nested-object-setvalue': ['error', { bracketAsArrayIndex: true }],
}
Expected behavior
I expect the React Hook Form Eslint plugin to not crash.
Actual behavior
The React Hook Form ESLing plugin crashes with the following error message:
TypeError: Cannot read property 'name' of undefined
Occurred while linting my-project/components/TestComponent.jsx:3
at my-project/node_modules/eslint-plugin-react-hook-form/lib/rules/no-nested-object-setvalue.js:49:24
at Array.find (<anonymous>)
at check (my-project/node_modules/eslint-plugin-react-hook-form/lib/rules/no-nested-object-setvalue.js:48:53)
at my-project/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (my-project/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (my-project/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
at NodeEventGenerator.applySelectors (my-project/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
at NodeEventGenerator.enterNode (my-project/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
at CodePathAnalyzer.enterNode (my-project/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)
Enviornment (please complete the following information):
Additional context
n/a
Describe the bug
react-hook-form/no-nested-object-setvalue
is thrown with message Avoid passing object or array as second argument in setValue since this is less performant
, when using the following syntax:
setValue("someName", myFunctionReturningANumber())
To Reproduce
function Component() {
const {useValue} = useForm();
const myFunctionReturningANumber = () => 5
setValue("someName", myFunctionReturningANumber())
return null;
}
{
...
'react-hook-form/no-nested-object-setvalue': ['error', { bracketAsArrayIndex: true }],
}
Expected behavior
Expect react-hook-form/no-nested-object-setvalue
not to throw an error.
Actual behavior
react-hook-form/no-nested-object-setvalue
throws with message Avoid passing object or array as second argument in setValue since this is less performant
Enviornment (please complete the following information):
Additional context
n/a
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.