Skip to content
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

jsx-handler-names support skipping prop naming checks #3722

Closed
Max10240 opened this issue Apr 2, 2024 · 3 comments · Fixed by #3772
Closed

jsx-handler-names support skipping prop naming checks #3722

Max10240 opened this issue Apr 2, 2024 · 3 comments · Fixed by #3772

Comments

@Max10240
Copy link

Max10240 commented Apr 2, 2024

My project has many components from other dependency packages, like:

<ComponentFromOtherLibraryFoo customPropNameFoo={handleSomething} />;
<ComponentFromOtherLibraryBar customPropNameBar={handleSomething} />;

Every time I come across them, I need to add an extra line of boring comments:

// eslint-disable-next-line jsx-handler-names
<ComponentFromOtherLibraryFoo customPropNameFoo={handleSomething} />;
// eslint-disable-next-line jsx-handler-names
<ComponentFromOtherLibraryBar customPropNameBar={handleSomething} />;

To be honest, I don't care about the names of these PROPS(even the components in my own project, I just want it to check my handler function's name)

To make matters worse, if the prop's name is not camelCase (e.g., all lowercase letters: "foofoo"), the option "eventHandlerPropPrefix" is not valid either, because it only applies to CamelCase naming:

/* with config: 
{
  eventHandlerPrefix: '(on|handle)',
  eventHandlerPropPrefix: '(on|foo)',
}
*/
// fine
<ComponentFromOtherLibraryFoo fooPropName={handleSomething} />;

// not work, still has error
<ComponentFromOtherLibraryFoo foo={handleSomething} />;

So, it would be nice if there were an option like "checkPropName". For those who don't care about prop naming, simply turn it off.
like:

{
  eventHandlerPrefix: '(on|handle)',
  eventHandlerPropPrefix: '(on|foo)',
  // ...
  checkPropName: false,
}

Anyway, I want to confirm if this option is necessary (and if anyone else has experienced this), and if so, I can create a PR to do it.

@ljharb
Copy link
Member

ljharb commented Apr 2, 2024

The rule's entire purpose is to check prop names.

I think it'd be reasonable to add an option with a list of component names to ignore, though.

@Max10240
Copy link
Author

I think it'd be reasonable to add an option with a list of component names to ignore, though.

Okay, let me try to implement it!

@akulsr0
Copy link
Contributor

akulsr0 commented Jun 21, 2024

Since this was inactive for sometime now, I will raise a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants