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.

imports/prefer-default-export idiomatic use

See original GitHub issue

hi,

how is the case where a file grows from containing only 1 function to containing 2 handled best?

example:

let’s say i have a file called window.js, which contains only one function, showWindow(). it’s imported as import { showWindow } from 'window'.

of course this goes against imports/prefer-default-export. how should this be fixed? i guess i move the code to window/showWindow.js.

if i do that, then my import becomes import showWindow from 'window/showWindow'. now what happens when a want to create another function, countWindows() ?

2 possibilities:

A. i move showWindow back to window.js and add countWindows there. if i do this, now i have to find all the places that imports showWindow and change those imports.

B. i create another file called window/countWindows.js and put the function there. if i do this, it means that nearly all my files will only contain 1 function.

so i wonder, how does airbnb handle this?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
ljharbcommented, Oct 18, 2016

@tleunen that’s potentially a fine way to go also - it really depends on the use case.

I’m suggesting that the default be one function default exported per file - and that if you think carefully about a use case, and you need multiple exports, then great! Make an exception.

The point of the defaults is so that you have to think about if and why you deviate - not that you can never deviate.

0reactions
ljharbcommented, Oct 25, 2016

Yes, it should disable named exports - the problem is that named exports make sense for a few specific use cases, like reducers, action_creators, constants, exporting a wrapped HOC for testing, etc - and a rule that prevented all named exports would be too restrictive.

We try to make the linter cover as much as possible, but there are times when you do still have to read the guide and apply human judgement 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint-plugin-import/prefer-default-export.md at main - GitHub
Definition: When there is only a single export from a module, prefer using default export over named export. How to setup config file...
Read more >
Prefer default export eslint error - Stack Overflow
From eslint-plugin-import. When there is only a single export from a module, prefer using default export over named export.
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 >
import/prefer-default-export - GitLab
import/prefer-default-export. When there is only a single export from a module, prefer using default export over named export.
Read more >
rollup.js
rollup.config.js import fetch from 'node-fetch'; export default ... This allows you to use CommonJS idioms like __dirname or require.resolve in your ...
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