eslint-plugin-react
eslint-plugin-react copied to clipboard
[NEW]: ensure-matching-remove-event-listener
Tentative to add a rule that enforce developers to cleanup eventListeners in the useEffect block.
Hi, appreciate the review! I wrote this rule (and actually included this in my own Eslint plugin) because this mistake is pretty frequent at my company. I usually happen to work with people of all different skill grades and not everyone knows about every single nuance of React. Eslint isn't only useful to standardize our codebases, it can also prevent mistakes like this and even help juniors learn something with minimal effort, like in this case. I think this rule has a pretty solid use-case and could be useful to many people but i'm very eager to listen to other people opinion on this, coming from different angles.
That totally makes sense - but it seems like one way to solve that is to force usage of a sanctioned custom component and ban via eslint any usage of window.addEventListener
or addEventListener
outside of that component :-)
That totally makes sense - but it seems like one way to solve that is to force usage of a sanctioned custom component and ban via eslint any usage of
window.addEventListener
oraddEventListener
outside of that component :-)
That's also an idea, but would be a vastly more complex rule than this, i think. This one is relatively simple and straightforward, and doesn't require any particular setup on part of the developers.
Hi, @ljharb, i'm not really sure why the CI is failing. What should i do?
The documentation checker seems to be erroring; there's a generation script to run.
Codecov Report
Merging #3442 (bd42395) into master (c6d082a) will increase coverage by
0.00%
. The diff coverage is98.30%
.
@@ Coverage Diff @@
## master #3442 +/- ##
=======================================
Coverage 97.57% 97.58%
=======================================
Files 129 130 +1
Lines 9200 9259 +59
Branches 3336 3372 +36
=======================================
+ Hits 8977 9035 +58
- Misses 223 224 +1
Impacted Files | Coverage Δ | |
---|---|---|
configs/all.js | 100.00% <ø> (ø) |
|
lib/rules/ensure-matching-remove-event-listener.js | 98.30% <98.30%> (ø) |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.