-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
Add prefer-export-from
rule
#1453
Conversation
With this case: import foo from 'foo';
unicorn(foo);
export default foo; I would personally prefer this instead (re-exporting, even if it was imported): import foo from 'foo';
unicorn(foo);
export default from 'foo'; As it's IMHO more readable and also makes a guarantee that the export is just re-exported and not modified on the way. Thoughts? |
Personally, I only use import foo from 'foo';
foo.bar = 1;
export default from 'foo'; Still prefer |
Yes. It's still more readable. You can immediately see what is exported from where instead of having to read and understand all the code in the file. |
# Conflicts: # index.js
Co-authored-by: Sindre Sorhus <[email protected]>
…unicorn into prefer-export-from
// Strange case | ||
// TODO: confirm how should this work | ||
test.snapshot({ | ||
valid: [ | ||
outdent` | ||
import * as namespace from 'foo'; | ||
export default namespace; | ||
export {namespace}; | ||
`, | ||
], | ||
invalid: [ | ||
outdent` | ||
import * as namespace from 'foo'; | ||
export {namespace}; | ||
export default namespace; | ||
`, | ||
], | ||
}); |
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.
These seem strange, I don't have time to confirm how should them work, but I guess we are fine to ignore it for 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.
Seems like a bug in ESLint. Both of those should be valid.
This PR has been a while, I forgot if I left something to do, but seems fine to merge. |
Thanks for finishing this 👍 |
Fixes #334