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
react/no-unused-class-comp-methods #2166
Comments
You can’t possibly know it’s unused statically - anything that imports Component could reference Component.prototype.someMethod or similar. |
Similarly, you never directly use, say, componentDidUpdate, but React does - and there’s no way for a general purpose linter to catch things like that. |
I know that, but AFAIK it's not a good practice to reference
Exactly - you never directly use those and you probably shouldn't also use other component methods outside of it. Knowing this you can filter out |
I suppose that might make sense for a React class component, sure. maybe |
@ljharb Yeah! I'm sorry, maybe I wasn't specific enough about the request :) I've edited my first post to make it more clear. |
Can i take this? |
Anything with the help wanted label, without a linked PR, is always up for grabs. |
I saw that recently there was no action taken regarding this topic. I prepared solution that might help. Let me know, if there is something I should fix there. #2239 |
@ljharb Do you have time for checking, if this PR is helpful? |
This would make such a great lint rule! ❤️ |
It would be so wonderful to have this rule 🙏 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There already is a separate npm plugin released for this, but unfortunately I didn't get it to work. Here it is, if somebody has better luck with it, let me know: https://www.npmjs.com/package/eslint-plugin-no-unused-react-component-methods |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@ljharb
|
@jakeleventhal that's because it's not released yet - if you click to the PR, and to the commit that merged it (1371f71) you'll see it's not in any tags. |
@ljharb ah, i was reading the changelog. I didn't realize it was in the "Unreleased" section |
I'd like to have a rule to detect unused
React
class methods. The rule would filter outReact
lifecycle methods, take the other ones and check if they are used anywhere in the class itself.Example:
The motivation behind this rule is that it's actually a bad practice to reference
React.Component
instance methods outside of the instance itself, so it would make sense to check if any methods inside the class are being used or are some kind of unused leftover.The text was updated successfully, but these errors were encountered: