prefer-only-export
Disallow additional exports alongside a default export.
Targeted pattern scopeโ
This rule targets program bodies where both are true:
- a
defaultexport exists, and - the file has more than one top-level statement.
What this rule reportsโ
This rule reports files that contain export default plus any additional
top-level statement (including non-export statements).
Why this rule existsโ
Some teams enforce a strict module contract: either a module exposes one default value, or it exposes named exports, but not both. Mixing both styles can make imports inconsistent across the codebase.
โ Incorrectโ
export default 1;
export const x = 1;
โ Correctโ
export default 1;
export const x = 1;
export const y = 2;
Behavior and migration notesโ
This rule has no options.
Additional examplesโ
export default function main() {}
const helper = 1;
// โ reported by current implementation (second top-level statement)
export default function main() {}
// โ
valid
ESLint flat config exampleโ
import etcMisc from "eslint-plugin-etc-misc";
export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/prefer-only-export": "error",
},
},
];
When not to use itโ
Disable this rule if combining default and named exports is allowed in your modules.
Package documentationโ
Rule catalog ID: R061
Further readingโ
Adoption resourcesโ
- Start at warning level in CI, then move to error after cleanup.
- Use focused codemods/autofix batches per package or directory.