noDefaultExport
Este conteúdo não está disponível em sua língua ainda.
Diagnostic Category: lint/style/noDefaultExport
Since: v1.4.0
Sources:
- Same as:
import/no-default-export
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.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-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.
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.
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.
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.