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

Ban props containing an "-" for components #3681

Closed
hornta opened this issue Jan 21, 2024 · 3 comments · Fixed by #3774
Closed

Ban props containing an "-" for components #3681

hornta opened this issue Jan 21, 2024 · 3 comments · Fixed by #3774

Comments

@hornta
Copy link

hornta commented Jan 21, 2024

I'm looking for a way to forbid passing props that contains a dash - for my components. I only want this to affect custom components, meaning that regular HTML components should be allowed to take <div aria-xxx="asdf"> but not <MyComp aria-label="asdf">. I want to do this because in TypeScript, props beginning with a kebab case like aria-xxx are not type checked. microsoft/TypeScript#32447

We plan on instead creating custom aria props like ariaLabel for components that can take them.

The closest thing I could find was https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/forbid-component-props.md but it doesn't allow me to specify a regex that could pick up every kebab-case named prop which is what I'm looking for.

I could contribute with an addition to this rule if deemed okay.

@ljharb
Copy link
Member

ljharb commented Jan 30, 2024

I'm trying to understand the need here. It sounds like you're saying that TypeScript should not be checking HTML element dashed props, and should be checking custom component element dashed props, but fails to differentiate between them, and has chosen to not check them all - and so you'd like to ban them from custom components so you can ensure no un-checked props?

@hornta
Copy link
Author

hornta commented Jan 31, 2024

That's that more or less what I'm thinking of, and we ran into a case much similar to what's mentioned here: microsoft/TypeScript#32447 (comment)

@ljharb
Copy link
Member

ljharb commented Jan 31, 2024

That does seem very typescript-specific, and typically we only have rules here that are broadly applicable, even if they have TS-specific enhancements.

However, while that would obstruct a new rule, perhaps this makes more sense anyways as an option on forbid-component-props, as you indicated. What about a propNameGlob property, mutually exclusive with propName, on the object option?

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

Successfully merging a pull request may close this issue.

2 participants