Skip to content

Ban props containing an "-" for components #3681

Closed
@hornta

Description

@hornta

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions