only-export-name
Restrict exports to configured names.
Targeted pattern scopeโ
This rule enforces an allow-list of export names.
It checks:
ExportDefaultDeclarationas namedefaultExportNamedDeclarationnames from specifiers, class/function declarations, and variable declaration identifiers
For export { local as publicName }, the rule validates publicName.
What this rule reportsโ
This rule reports exports whose names are not included in names.
Why this rule existsโ
This rule is useful for defining strict module contracts (for example, default-only modules or curated public names).
โ Incorrectโ
export const value = 1;
with default options (["default"]).
โ Correctโ
export default 1;
or:
export const value = 1;
with options:
{
names: ["value"];
}
Behavior and migration notesโ
This rule reports only and does not provide an autofix.
Default allow-list is ['default'], so named exports are blocked unless
explicitly allowed.
Optionsโ
type Options = {
names?: string[];
};
Default:
{ "names": ["default"] }
Additional examplesโ
// config: { names: ["createClient", "default"] }
export function createClient() {}
export default createClient;
// โ
valid
export const version = "1.0.0";
// โ reported unless "version" is added to names
export { buildClient as client };
// checks "client" (exported name), not "buildClient"
ESLint flat config exampleโ
import etcMisc from "eslint-plugin-etc-misc";
export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/only-export-name": ["error", { names: ["value"] }],
},
},
];
When not to use itโ
Disable this rule if exported symbol names do not need to be constrained.
Package documentationโ
Rule catalog ID: R054
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.