-
-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
linter: eslint-plugin-react-hooks(rules-of-hooks) fires when it doesn't in ESLint for a wrapped component #6651
Comments
if no one has started working on this issue, can I take a stab at it? |
I did some digging into the source code of the react hooks eslint plugin. It appears that they do not currently support this use case, but they might in the future. Currently, the react hooks eslint plugin only allows React hooks in function components and in other custom React hooks, which aligns with the current behavior of oxlint. That being said, I'm not sure what the priorities are in terms of version compatibility. Does it make sense to implement a change for a use case that used to be supported, isn't supported now, but might be in the future? |
Thank you for the investigation. Let's align to eslint-plugin-react-hooks to remove ambiguity. Close as won't fix. |
The examples linked to by @taearls are not the same as the example in this Issue |
As an example, I just pulled the react repo and added this test case: {
code: normalizeIndent`
// Valid because components can call functions.
const MyComponent = makeComponent(function () {
useHook();
});
`,
}, And it passes. |
It seems like these existing tests are more or less doing the same thing, although the way they're commented makes it seem like they're special exception cases for memo/forwardRef: https://github.com/facebook/react/blob/9daabc0bf97805be23f6131be4d84d063a3ff446/packages/esli EDIT: indeed there is: https://github.com/facebook/react/blob/9daabc0bf97805be23f6131be4d84d063a3ff446/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js#L52-L85 |
OK! This fails: {
code: normalizeIndent`
// Valid because components can call functions.
const MyComponent = makeComponent(function wrappedFunc() {
useHook();
});
`,
}, It looks like |
Ah I see. My mistake. I'll take another look into this, then. Sorry about that. |
so tldr is this right? Should Pass >> const MyComponent = makeComponent(() => {
useHook();
}); Should Pass >> const MyComponent2 = makeComponent(function () {
useHook();
}); Shuold Pass >> const MyComponent4 = makeComponent(function InnerComponent() {
useHook();
}); Should Fail >> const MyComponent3 = makeComponent(function foo () {
useHook();
}); or at least that's the behaviour i see in eslint? |
Yes that seems correct to me. |
I imagine this should also pass but I haven't done it myself: const MyComponent4 = makeComponent(function InnerComponent() {
useHook();
}); |
thanks @bensaufley i checked that - you're right. i updated the tldr |
Probably should fail? const foo = makeComponent(() => {
useHook();
}); That might be covered by other tests etc, but just being thorough |
@bensaufley this currently passes in eslint so i think we should leave making that one fail out of scope for now. |
Wow, interesting! That surprises me. But yeah def out of scope for parity |
What version of Oxlint are you using?
0.9.10
What command did you run?
What does your
.oxlint.json
config file look like?What happened?
A functioncomponent declared inside a component factory does not register as a component for the purpose of linting
rules-of-hooks
. Given a very limited reproduction like this (please ignore the particular utility of the example):The call to
useState
produces the following error in oxlint:This does not occur in ESlint with the same configuration and the same code. Here's a minimal
.eslintrc.json
, with ESLint 8.56.0 (have not upgraded yet—was investigating oxlint as an alternative):The text was updated successfully, but these errors were encountered: