Closed Bug 1553931 Opened 6 years ago Closed 3 years ago

Add eslint-plugin-react-hooks to mozilla central

Categories

(Developer Infrastructure :: Lint and Formatting, task, P1)

Tracking

(firefox68 unaffected, firefox69 wontfix, firefox100 fixed)

RESOLVED FIXED
100 Branch
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?

Type: defect → task
Iteration: --- → 69.2 - May 27 - Jun 9
Priority: -- → P2
Priority: P2 → P1
Iteration: 69.2 - May 27 - Jun 9 → 69.3 - Jun 10 - 23
Assignee: nobody → andrei.br92
Component: Activity Streams: Newtab → Messaging System
Iteration: 69.3 - Jun 10 - 23 → 69.4 - Jun 24 - Jul 7
Iteration: 69.4 - Jun 24 - Jul 7 → 70.1 - Jul 8 - 21
Priority: P1 → P3
Iteration: 70.1 - Jul 8 - 21 → ---
Blocks: as-build-meta
No longer blocks: 1552007
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → INVALID
Status: RESOLVED → REOPENED
Resolution: INVALID → ---

We should consider doing this now that we're using hooks and effects in about:welcome.

Priority: P3 → --
Assignee: andrei.br92 → nobody
Priority: -- → P2

Using effects in conditionals came up on two different Messaging systems reviews recently. We should consider revisiting this.

Priority: P2 → --

NI Mark for feedback on adding eslint for react hooks, thanks!

Flags: needinfo?(standard8)

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.

Flags: needinfo?(standard8)

(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).

Assignee: nobody → edilee
Iteration: --- → 100.1 - March 1 - March 18

(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.

(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

Priority: -- → P1
Pushed by elee@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/8a43438413be Add eslint-plugin-react-hooks and enable for paths using React r=Standard8
Status: REOPENED → RESOLVED
Closed: 5 years ago3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 100 Branch
Component: Messaging System → Lint and Formatting
Product: Firefox → Firefox Build System
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: