Add eslint-plugin-react-hooks to mozilla central
Categories
(Developer Infrastructure :: Lint and Formatting, task, P1)
Tracking
(firefox68 unaffected, firefox69 wontfix, firefox100 fixed)
Tracking | Status | |
---|---|---|
firefox68 | --- | unaffected |
firefox69 | --- | wontfix |
firefox100 | --- | fixed |
People
(Reporter: k88hudson, Assigned: Mardak)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
In Bug 1529007 we added eslint-plugin-react-hooks
to the activity-stream repository's eslint config, which has some helpful rules around using react hooks. In order to support this with ./mach lint
we would need to add this to the mozilla central package.json
Is this something that would make sense for us going forward?
Reporter | ||
Updated•6 years ago
|
Updated•6 years ago
|
Reporter | ||
Updated•6 years ago
|
Updated•6 years ago
|
Updated•6 years ago
|
Assignee | ||
Updated•6 years ago
|
Updated•6 years ago
|
Updated•6 years ago
|
Updated•6 years ago
|
Updated•6 years ago
|
Assignee | ||
Updated•6 years ago
|
Reporter | ||
Updated•5 years ago
|
Reporter | ||
Updated•5 years ago
|
Comment 1•4 years ago
|
||
We should consider doing this now that we're using hooks and effects in about:welcome.
Updated•4 years ago
|
Updated•4 years ago
|
Comment 2•3 years ago
|
||
Using effects in conditionals came up on two different Messaging systems reviews recently. We should consider revisiting this.
Updated•3 years ago
|
Comment 3•3 years ago
|
||
NI Mark for feedback on adding eslint for react hooks, thanks!
Comment 4•3 years ago
|
||
I see no problem with eslint-plugin-react-hooks
being included. The license is MIT which is acceptable, and its a small standalone module which is even better.
You'll need someone to do the work of getting the rules set up and passing. I would strongly recommend we enable them for the whole tree rather than just newtab. I don't know if that would affect some of the devtools code - they are the only other place that use react.
The approximate steps would be:
./mach npm install --save-exact --save-dev eslint-plugin-react-hooks
- Add the plugin reference and rules to enable to
tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
- Run
./mach eslint *
& fix the issues/tweat the rules as necessary.
If there are lots of issues, we can consider enabling them as warnings to begin with, but we should have a confirmed piece of work to get those down to zero.
Comment 5•3 years ago
|
||
The pocket component is using React as well these days: https://searchfox.org/mozilla-central/source/browser/components/pocket
Assignee | ||
Comment 6•3 years ago
|
||
(In reply to Mark Banner (:standard8) from comment #4)
I would strongly recommend we enable them for the whole tree rather than just newtab
Looks like the 1 default recommended "error" rule "react-hooks/rules-of-hooks" https://github.com/facebook/react/blob/cae635054e17a6f107a39d328649137b83f25972/packages/eslint-plugin-react-hooks/src/index.js#L17
… checks any camelCase variables that start with "use" https://github.com/facebook/react/blob/cae635054e17a6f107a39d328649137b83f25972/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js#L13-L18
This results in a bunch of false positive errors like…
TEST-UNEXPECTED-ERROR | toolkit/components/search/tests/xpcshell/test_region_params.js:30:9 | React Hook "SearchTestUtils.useTestEngines" is called in function "setup" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use". (react-hooks/rules-of-hooks)
I don't think we want to generally burden developers to figure out why they can't name their stuff with "use"
The parts of the codebase that does use react seem to pass fine (newtab, pocket, devtools).
Comment 7•3 years ago
|
||
(In reply to Ed Lee :Mardak from comment #6)
(In reply to Mark Banner (:standard8) from comment #4)
This results in a bunch of false positive errors like…
TEST-UNEXPECTED-ERROR | toolkit/components/search/tests/xpcshell/test_region_params.js:30:9 | React Hook "SearchTestUtils.useTestEngines" is called in function "setup" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use". (react-hooks/rules-of-hooks)
Urgh, I guess it is making the assumption that all files are React :( This might make selecting where to enable this difficult.
I don't think we want to generally burden developers to figure out why they can't name their stuff with "use"
Agreed.
Presumably not all our React code is using jsx files? If that's the case, we might have to selectively enable per various directories.
Assignee | ||
Comment 8•3 years ago
•
|
||
(In reply to Mark Banner (:standard8) from comment #7)
Presumably not all our React code is using jsx files? If that's the case, we might have to selectively enable per various directories.
Nod. Devtools uses plain .js https://searchfox.org/mozilla-central/search?q=import+React+from+%22react%22
Pocket has a mix of both .js and .jsx.
I'll conditionally extend from top level .eslintrc
Assignee | ||
Comment 9•3 years ago
|
||
Updated•3 years ago
|
Comment 10•3 years ago
|
||
Comment 11•3 years ago
|
||
bugherder |
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Description
•