-
-
Notifications
You must be signed in to change notification settings - Fork 32
feat: Disallow a function wrapped in useCallback or a variable wrapped in useMemo yet only used in useEffect and only in one useEffect, closes #1278 #1321
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
Conversation
|
@possum-enjoyer is attempting to deploy a commit to the Rel1cx's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
packages/plugins/eslint-plugin-react-x/src/rules/no-unnecessary-use-memo.ts
Outdated
Show resolved
Hide resolved
|
I found a problem: currently if the useCallback is double useless (i.e. no dependencies and only inside one useEffect) the rule will show up twice. Should there be a priority? |
If these two error messages are granular enough to specify a particular "useless" situation, displaying two is reasonable; otherwise, displaying only one is appropriate. |
I would say they are granular enough with a small asterisks that is: |
Showing only one message means we're hiding part of the explanation or suggestion for this bad pattern; from this perspective, I prefer to show all error messages. |
We also have a solution for this. If users report two error messages too verbose, we can define only one error message and dynamically construct it to best reflect the actual situation without information missing. Similar to the practice in a rule: eslint-react/packages/plugins/eslint-plugin-react-x/src/rules/no-nested-component-definitions.ts Lines 130 to 132 in 435e9d1
This approach is more suitable for complex rules. |
|
I think we also need to update the documentation for these two rules to include the newly introduced patterns. |
Yes that's true. Sorry I forgot about this when starting this "addition" it looked smaller and more like an edge case for the rules. |
fix both rules appearing at the same time. Now the original error message takes precedence
Ok i fixed this but currently i did a different approach where check if the error is reportable, return the report object and report only at specific points where the original error message would not report. So the original error message takes precedence. Also the documentation is now updated :) |
Rel1cx
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
What kind of change does this PR introduce?
Does this PR introduce a breaking change?
Checklist
fix: remove a typo, closes #___, #___)Other information