noDefaultExport
Diagnostic Category: lint/style/noDefaultExport
Since: v1.4.0
Sources:
- Same as:
import/no-default-export
Description
Section titled DescriptionDisallow 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.
Examples
Section titled ExamplesInvalid
Section titled Invalidexport 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.
Valid
Section titled Validexport function f () {};export class C {};export { default as X } from "mod";
module.exports = class {};
How to configure
Section titled How to configure{ "linter": { "rules": { "style": { "noDefaultExport": "error" } } }}