jsx-eslint/eslint-plugin-react

[jsx-handler-names] allow whitelisting of components or props (ideally both together)

Open

#2285 opened on May 22, 2019

View on GitHub
 (9 comments) (2 reactions) (0 assignees)JavaScript (8,630 stars) (2,797 forks)batch import
enhancementhelp wanted

Description

This issue is somewhat generic, as while I can think of a couple of abstract ways of solving this problem I'm pretty sure most of them would blow the rule up in terms of implementation.

Basically, while the rule is great, it doesn't care if a component is under my control or not.

For example, react-trello has a prop called handleDragEnd, which'll be flagged if I pass it this.handleDragEnd.

Ideally, I'd like to be able to whitelist ReactTrello#handeDragEnd (i.e "ignore the 'handleDragEnd' prop on components called 'ReactTrello').

While that can be done, I believe the current implementation of this rule is just a couple of regexes, which would mean expanding it to look for the name of the component a prop is on could be a lot more extra code.

A less optimal solution could be to allow whitelisting of props by name - so just "ignore any prop called 'handleDragEnd'". This could be used together with "override" so that only files that use the component that have the prop is ignored.

Regardless, the crux of the problem that I feel should be looked at solving is:

jsx-handler-names doesn't care if a component is under my control or not, meaning that it'll mark props that I can't rename as errors.

Contributor guide