Skip to content

react/jsx-pascal-case Style

What it does

Enforce PascalCase for user-defined JSX components

Why is this bad?

It enforces coding style that user-defined JSX components are defined and referenced in PascalCase. Note that since React's JSX uses the upper vs. lower case convention to distinguish between local component classes and HTML tags this rule will not warn on components that start with a lower case letter.

Examples

Examples of incorrect code for this rule:

jsx
<Test_component />
<TEST_COMPONENT />

Examples of correct code for this rule:

jsx
<div />

<TestComponent />

<TestComponent>
    <div />
</TestComponent>

<CSSTransitionGroup />

Examples of correct code for the "allowAllCaps" option:

jsx
<ALLOWED />

<TEST_COMPONENT />

Examples of correct code for the "allowNamespace" option:

jsx
<Allowed.div />

<TestComponent.p />

Examples of correct code for the "allowLeadingUnderscore" option:

jsx
<_AllowedComponent />

<_AllowedComponent>
    <div />
</_AllowedComponent>

Options

allowAllCaps

{ type: boolean, default: false }

Optional boolean set to true to allow components name in all caps

allowLeadingUnderscore

{ type: boolean, default: false }

Optional boolean set to true to allow components name with that starts with an underscore

allowNamespace

{ type: boolean, default: false }

Optional boolean set to true to ignore namespaced components

ignore

{ type: Array<string | RegExp>, default: [] }

Optional string-array of component names to ignore during validation

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny react/jsx-pascal-case --react-plugin
json
{
  "plugins": ["react"],
  "rules": {
    "react/jsx-pascal-case": "error"
  }
}

References

Released under the MIT License.