Skip to content

import/prefer-default-export Style ​

What it does ​

In exporting files, this rule checks if there is default export or not.

Why is this bad? ​

This rule exists to standardize module exports by preferring default exports when a module only has one export, enhancing readability, maintainability.

Examples ​

Examples of incorrect code for the { target: "single" } option:

js
export const foo = "foo";

Examples of correct code for the { target: "single" } option:

js
export const foo = "foo";
const bar = "bar";
export default bar;

Examples of incorrect code for the { target: "any" } option:

js
export const foo = "foo";
export const baz = "baz";

Examples of correct code for the { target: "any" } option:

js
export default function bar() {}

How to use ​

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

bash
oxlint --deny import/prefer-default-export --import-plugin
json
{
  "plugins": ["import"],
  "rules": {
    "import/prefer-default-export": "error"
  }
}

References ​

Released under the MIT License.