-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 allowAliasing
option to import/no-default-export
#1767
base: main
Are you sure you want to change the base?
Conversation
If aliasing is allowed, what's the point of disallowing default exports at all? (note that I severely disagree with this rule existing, as I think a default export is what a module is, and a named export is something a module has, and most modules should be something) |
In general we don't want to allow default exports, but aliassing should be allowed for when we need to use React's code-splitting. |
Right, but why does "React.lazy requires default exports" not suggest that you should use default exports? Aliasing would just be a hack for using the wrong kind of export. |
within the folder we still want to use named imports. We find named imports much more useful. If something outside of that folder wants to lazy load it, the |
In that case, you could use |
for our specific case that could work. but is there a harm in adding an option? |
There's always harm in adding things :-) it's just got to be weighed against the benefit. Since a) this rule imo should never have existed in the first place, and b) your use case is trivially solved with overrides, unless there's a use case for an option it doesn't seem worth it. |
@ljharb Hey! I was about to suggest adding an option with a glob pattern for files to ignore... like import/no-extraneous-dependencies allows, for instance, and didn't know of the overrides you just mentioned. -- I'm curious as to why you think import/no-default-export should never have existed, though? I favour named exports because they allow me to more easily refactor/auto-import bits and pieces from other parts of the project, and came to believe that now that ES Modules are pretty commonplace and well-established, maybe I could simply enforce avoiding default exports consistently, except when dealing with external libraries that require a "default" export. I don't want to argue or anything, I genuinely want to know what your take on this matter is! Welp, so much for asking a quick question, it already looks like a wall of text :') Again, I'm just asking for you to elaborate, out of curiosity! Thanks for mentioning ESLint's overrides :) |
@ccjmne It's a shame that IDEs have failed to implement the same autocorrect and auto-refactor tooling for default imports - there's zero technical reason why this is difficult that I'm aware of - but I'd encourage you not to alter how you architect your codebase solely based on the momentary flaws of your tooling. |
The
import/no-default-export
rule has two partsexport default function () {}
andexport default foo;
export { foo as default } from "./foot";
)In our use case, we only want to ban the first syntax, but allow aliased importing. This is because we use React lazy/suspense which requires default exports to be used.
This PR adds an
allowAliasing
option to allow just aliased exportsHope this PR is okay. Haven't worked with eslint plugins much