Skip to content

react/jsx-filename-extension Restriction

🚧 An auto-fix is still under development.

What it does

Enforces consistent use of the JSX file extension.

Why is this bad?

Some bundlers or parsers need to know by the file extension that it contains JSX

Examples

Examples of incorrect code for this rule:

jsx
// filename: MyComponent.js
function MyComponent() {
  return <div />;
}

Examples of correct code for this rule:

jsx
// filename: MyComponent.jsx
function MyComponent() {
  return <div />;
}

Configuration

This rule accepts a configuration object with the following properties:

allow

type: "always" | "as-needed"

default: "always"

When to allow a JSX filename extension. By default all files may have a JSX extension. Set this to as-needed to only allow JSX file extensions in files that contain JSX syntax.

extensions

type: string[]

default: ["jsx"]

The set of allowed file extensions.

ignoreFilesWithoutCode

type: boolean

default: false

If enabled, files that do not contain code (i.e. are empty, contain only whitespaces or comments) will not be rejected.

How to use

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

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

References

Released under the MIT License.