-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discourage the use of default exports #274
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with this 👍. Might make sense to introduce the lint rule at some point too in web
. I think the only case where we might need default exports is when using react-async
README.md
Outdated
|
||
```js | ||
// bad | ||
const BadImport = require('./BadImport'); | ||
module.exports = BadImport.feelBadAboutIt(); | ||
export default BadImport(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is having cjs and esm style exports in a single example confusing as this is invalid syntax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parens were already there, I just pushed up a commit removing them.
Does it read any better to you now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm onboard with telling people to use named exports, but input from a few more people across the org before we say "yep, everyone should do this" would be nice.
While I have personally grown to prefer named exports in most cases, they are occasionally still quite handy. In particular, many tools that operate on async imports, like React's Personally, my vote would be to leave it up to developers to do the thing that works for them, but if it's going to be something people won't stop debating in PRs, I guess a rule would be better. |
I think it's reasonable to have a recommended way of doing it (this PR). Maybe we don't need to enforce it with a rule though. Perhaps using wording like It may warrant a new rule over modification of this rule perhaps if we go that route? |
If you want to go that route, you'll need more nuance in the recommendation, and if you opt not to lint, we won't be able to enforce it in tooling so you probably won't get the discussion to go away (if that's what you're after). |
@lemonmade, yeah linting will always be up to the repo owners but I was hoping to have some docs to point to in these cases as best practice. I'm totally open to adding exceptions (like you mentioned) if you think that's warranted 👍
@BPScott I'm good with that, I'll put up a poll in #fed to gauge opinions.
@jgodson reasonable, I think this makes a lot of sense if there are good exceptional cases (like Chris mentioned). |
IMO default exports confuse things by creating 2 ways to import/export components while offering no perceivable benefit/advantage.
I believe a world with only named imports would be more consistent, but I’m happy to hear and and all thoughts and opinions that are different (that's what PRs are for!).
polaris-react
already enforces they not be used with theimport/no-default-export
rule (Shopify/polaris#1959) and web-admin also shies away from them.Let's document it and make it official, OR be more specific about when and how they're used so we're consistent across repos.