-
-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Did you check docs and existing issues?
- I have read the plugin docs
- I have searched the existing issues
- I have read You Might Not Need An Effect and am reasonably confident that I do need an effect
Plugin version
0.5.3
ESLint version
9.0.0
Describe the bug
When linting code with a derived setter (a function that internally calls setState), the plugin analyzes the args passed to the derived function, not the eventual setter call. This causes false negatives when the derived setter internally passes internal args to the setter, and false positives when the derived setter receives internal args but does not pass them to the setter.
Steps To Reproduce
Lint the following code for a false negative:
function Form() {
const [firstName, setFirstName] = useState('Dwayne');
const [lastName, setLastName] = useState('The Rock');
const [fullName, setFullName] = useState('');
useEffect(() => {
const doSet = () => {
setFullName(firstName + ' ' + lastName);
}
doSet();
}, [firstName, lastName]);
}Lint the following code for a false positive (contrived):
function Form() {
const [firstName, setFirstName] = useState('Dwayne');
const [lastName, setLastName] = useState('The Rock');
const [fullName, setFullName] = useState('');
useEffect(() => {
const doSet = (arg1, arg2) => {
console.log(arg1, arg2);
}
doSet(firstName, lastName);
}, [firstName, lastName]);
}Expected Behavior
The first example should flag no-derived-state.
The second example should not flag no-derived-state.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working