Aller au contenu

noDefaultExport

Ce contenu n’est pas encore disponible dans votre langue.

Diagnostic Category: lint/style/noDefaultExport

Since: v1.4.0 Sources:

Disallow default exports.

Default exports cannot be easily discovered inside an editor: They cannot be suggested by the editor when the user tries to import a name.

Also, default exports don’t encourage consistency over a code base: the module that imports the default export must choose a name. It is likely that different modules use different names.

Moreover, default exports encourage exporting an object that acts as a namespace. This is a legacy pattern used to mimic CommonJS modules.

For all these reasons, a team may want to disallow default exports.

Note that this rule disallows only default exports in EcmaScript Module. It ignores CommonJS default exports.

export default function f() {};
code-block.js:1:8 lint/style/noDefaultExport ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid default exports.

> 1 │ export default function f() {};
^^^^^^^
2 │

Default exports cannot be easily discovered inside an editor and don’t encourage the use of consistent names through a code base.

Use a named export instead.

export default class C {};
code-block.js:1:8 lint/style/noDefaultExport ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid default exports.

> 1 │ export default class C {};
^^^^^^^
2 │

Default exports cannot be easily discovered inside an editor and don’t encourage the use of consistent names through a code base.

Use a named export instead.

export default {
f() {},
g() {},
};
code-block.js:1:8 lint/style/noDefaultExport ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid default exports.

> 1 │ export default {
^^^^^^^
2 │ f() {},
3 │ g() {},

Default exports cannot be easily discovered inside an editor and don’t encourage the use of consistent names through a code base.

Use a named export instead.

export { X as default };
code-block.js:1:15 lint/style/noDefaultExport ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid default exports.

> 1 │ export { X as default };
^^^^^^^
2 │

Default exports cannot be easily discovered inside an editor and don’t encourage the use of consistent names through a code base.

Use a named export instead.

export function f () {};
export class C {};
export { default as X } from "mod";
module.exports = class {};