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.

Export-ing conventions

See original GitHub issue

Airbnb style guides [10] do not define any specific export style, other than:

10.6 In modules with a single export, prefer default export over named export.

Which one is the preferred style in the following cases (feel free to suggest better ones):

Single export

  • Inline export
export default foo = () => { ... }
  • Separate export (after definition)
const foo = () => { ... };
export default foo;
const other = () => { ... };
  • Separate export (at the end of file)
const foo = () => { ... };
const boo = () => { ... };
export default foo;

Multiple exports

  • Inline exports
export foo = () => { ... }
export boo = () => { ... }
  • Separate export (after definition)
const foo = () => { ... }
export foo;
const boo = () => { ... }
export boo;
  • Separate export (at the end of file)
const foo = () => { ... }
const boo = () => { ... }
export { foo, boo };
  • Wrapper export
export const wrapper = {
  foo: () => { ... }
  boo: () => { ... }
}

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:8

github_iconTop GitHub Comments

9reactions
alex-mitchemcommented, Sep 28, 2017

Tests should absolutely not only be end to end, its the entire reason smaller functions are considered best practise, because its easier to test a small function than a large function. As for you previous comment, I’m not sure I understand. They don’t have to be exported but can be imported?

9reactions
ljharbcommented, Jan 22, 2017

In most cases, you should be exporting one conceptual thing from a module. In other words, if you have both “foo” and “boo”, those are two modules and thus should be export defaulted from two separate files.

If you insist on having them in the same file (there are some use cases where this makes sense, but not many), then you should be using multiple named exports.

When exporting one thing, and inline export is nicer because it ensures that you can not change the binding later (ie, export default function foo() {}; is better than function foo() {} ; export default foo;)

As far as positioning, there will soon be a linter rule in eslint-plugin-import that will require that all export statements are grouped together - so I’d recommend grouping them together and putting them at the bottom of the file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Attend An Event
Webinars, local seminars, and national conferences are a great way to connect ... recruited, and led by private and public sector export-oriented groups, ......
Read more >
Convention on the Means of Prohibiting and Preventing ...
The States Parties to this Convention recognize that the illicit import, export and transfer of ownership of cultural property is one of the...
Read more >
Exporting Corruption 2022: Assessing Enforcement…
Our report assesses foreign bribery enforcement in 43 of the 44 signatories to the OECD Anti-Bribery Convention as well as in China, Hong...
Read more >
New International Requirements for the Export and Import ...
What requirements apply, if any, to U.S. exports and imports of plastic scrap and waste not controlled under the Basel Convention (Basel ...
Read more >
Exported Designs - Custom Naming Conventions
Exported Designs - Custom Naming Conventions. If your team has a custom naming convention that all design files must follow, Flexitive can help...
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