-
-
Notifications
You must be signed in to change notification settings - Fork 390
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
Rule proposal: prefer-export-from
#334
Comments
This is a great idea. A lot of people don't know about "export from". There are many supported ways to re-export: export * from …;
export { name1, name2, …, nameN } from …;
export { import1 as name1, import2 as name2, …, nameN } from …;
export { default } from …;
export { default as something } from …;
export * as utils from …; |
I would like to make this new rule as my first issue |
@zamboney Go for it! |
prefer-export-from
@zamboney Still interested to implement this rule? |
I like JSLint's stance on import/export:
I don't really see benefit in this: export { default as foo } from './foo';
export { bar } from './bar'; over this: import foo from './foo';
import { bar } from './bar';
export {foo, bar}; I would say that it's the |
@EvgenyOrekhov I disagree. But you can just disable the rule if you don't want this. |
This rule should also catch cases like: import * as utils from './utils.js';
export {utils}; and enforce this instead: export * as utils from './utils.js'; |
I think we should ignore this : if some specifier is used import {foo, bar} from './foo';
bar();
export {foo} Otherwise import {bar} from './foo';
bar();
export {foo} from './foo'; Seems weried. |
About autofix import {foo} from './foo';
import {another} from './bar';
another();
// ...
export {foo}; Should we put export on top or bottom? export {foo} from './foo';
import {another} from './bar';
another();
// ... VS import {another} from './bar';
another();
// ...
export {foo} from './foo'; |
I disagree. It only seems weird because of the articifical example. In real-world code, there would be a lot more code in a file. The reason I disagree is that re-exporting directly improves readability and makes it clear that this one thing is just re-exported and not modified/mutated on the way. I think will also help static analysis tools to guarantee that it was just re-exported, which might alow better tree-shaking. |
Bottom |
FYI, I just tried to adopt this and discovered that it breaks IntelliJ IDEA auto-import functionality (IDE does't auto-suggest imports anymore). Example how it worked before: // Works
import { something } from './somewhere'
export { something } // Doesn't work:
export { something } from './somewhere'
// This doesn't work too:
export * from './somewhere' Clarification: it does work in the same project, but does not work when this export style is used in the library and it's in your I know I should probably report it to Jetbrains too, but I start here. Maybe more people can confirm it and then it'll make sense to understand why it doesn't work in IDEA (and I assume WebStorm too). |
The rule just enforces valid ESM syntax. You should open an issue on IntelliJ. It just sounds like their ESM import/exports implementation is incomplete. |
Yes, I agree that ESM syntax is valid. FYI, reported to Jetbrains here: https://youtrack.jetbrains.com/issue/IDEA-281957 |
There are lots of ways to
export
but one pattern that is unnecessary is importing something and then immediately exporting it.Fail
Pass
The text was updated successfully, but these errors were encountered: