question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: `default-export-function-style`

See original GitHub issue

Whether to prefer a default export as a named function or a const variable with an arrow function.

It should default to function style.

It should be auto-fixable.

Fail

// "unicorn/default-export-function-style": ["error", "function"]

const foo = () => {};
export default foo;
// "unicorn/default-export-function-style": ["error", "variable"]

export default function foo() {}

Pass

// "unicorn/default-export-function-style": ["error", "function"]

export default function foo() {}
// "unicorn/default-export-function-style": ["error", "variable"]

const foo = () => {};
export default foo;

Open question. What should happen to:

export default () => {};

Should we have a separate style for that or just disallow it for both function and variable style?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sindresorhuscommented, Mar 30, 2021

I used to prefer non-inline so I could use arrow functions, but lately I’m preferring inline export default function foo () {}.

1reaction
fregantecommented, Mar 30, 2021

I use inline exports all the time. For defaults, I still prefer inline exports if they can be named inline (functions, classes)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rule proposal: export-function-style #154 - GitHub
I think this rule would be a copy of the existing function-style , except localized to exports, so this logic is in there....
Read more >
Rule proposal: `default-export-function-style` #1089 - Issuehunt
Whether to prefer a default export as a named function or a const variable with an arrow function. It should default to function...
Read more >
Change: Prefer default export to no default export (#20) · Issues
The current setup uses import/prefer-default-export to enforce a default (versus named) export when only one thing is exported from a module.
Read more >
ESLint Prefer default export import/prefer-default-export
Each file can only have one "default" export. It is often best to use export default when you are only exporting one bit...
Read more >
Modules · Styleguide JavaScript
Do not use wildcard imports. This makes sure to have a single default export. Examples. ⇣ Incorrect code for this rule: import *...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found