eslint: Bug: `no-restricted-exports` fails on `export { default, ... } from ...`
Environment
Node version: v14.18.1 npm version: v8.3.0 Local ESLint version: v8.9.0 (Currently used) Global ESLint version: Not found Operating System: darwin 20.6.0
What parser are you using?
Default (Espree)
What did you do?
Minimal reproduction repo here: https://github.com/patcon/eslint-bug-reproduction-default-export
What did you expect to happen?
Expected npm run lint
to pass, since
export { default, function2 } from 'bar.js';
is just an alternative format, recommended in Mozilla web MDN docs đ
What actually happened?
Both forms of this default failed:

Participation
- I am willing to submit a pull request for this issue.
Additional comments
Re-ticketed from https://github.com/airbnb/javascript/issues/2500
Thanks a bunch! Open to pointers in the right direction, or just affirmation that this is a bug đ đ
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 6
- Comments: 28 (22 by maintainers)
Okay, here are some ideas.
a) Add a boolean option to re-allow 3 and 4. The option can be specified only if
restrictedNamedExports
contains"default"
. The following configuration would allow 1, 3, 4, and disallow 2, 5:b) Add an object option with boolean properties for each 1-5. The option can be specified only if
restrictedNamedExports
does not contain"default"
. The following configuration would allow 1, 3, 4, and disallow 2, 5:The b) is a bit more work but provides more than a), and I think itâs easier to understand. Iâd vote for b).
@mdjermanovic i think thatâs fine for
export { default }
, but this isexport { default } from
, which is a completely distinct form - meaning, itâs not as simple as those 3 options.Hi @amareshsm are you still working on this?
@patcon I would like to work on this feature. let me know if anyone working on this.
This does look like a bug because, in this case, âdefaultâ is not a named export. @mdjermanovic do you agree?
@shirshendubhowmick There is an open PR for this - https://github.com/eslint/eslint/pull/16785. It will be fixed soon.
I agree that the second option is clearer.
@ljharb which of the following would you like to disallow?
export default foo;
export { foo as default };
export { default } from "mod";
export { foo as default } from "mod";
export * as default from "mod";
The current behavior with
restrictedNamedExports: ["default"]
disallows 2, 3, 4, and 5.Either would work for me, but i agree b is clearer and preferred.
Isnât 3.
export { default } from "mod";
the same as the example this issue is about? If the rule continues to disallow it, then it doesnât seem this issue will be fixed.An option seems like the fastest way to a solution. @mdjermanovic ?
Airbnbâs intention was to force default exports to use
export default
and NOT confusingly imply that âdefaultâ is Just Another Name, butexport { default } from
is the only way to do that, so we do NOT want to forbid that.Using no-restricted-syntax, as always, isnât a viable option for a shared config because itâs a) used for many things, and is hard to disable for just one of the items; and b) it doesnât convey meaning/intent the way a dedicated rule does.
Ah, ok! In that case, if thereâs a need to disallow only specific ways to export
"default"
while allowing others, I think the best option is to configureno-restricted-syntax
with the desired combination of selectors.It seems that we have agreed to fix this problem by implementing option b) from https://github.com/eslint/eslint/issues/15617#issuecomment-1048730114, so I marked this as accepted.
@patcon would you like to submit a PR for the new option?
ohhh right, sorry, i confused myself. We do want to allow option 3 đ so looking again, we want to prohibit 2 (and maybe 5), but 1 is ideal, and 3 and 4 are the only ways to do that, so theyâd also be allowed.
The Airbnb config strongly pushes default export usage, so weâd want to disallow only number 3 (and i guess 5, but thatâs less important). 2 and 4 are valid re-export forms of the preferred export method, 1.
Could it be an option?
@mdjermanovic Though I suspect maybe the convo has moved past this question: that choice comes from airbnbâs rules, and I have no specific expectations (other than that something so highly used must know more than me đ )
https://github.com/airbnb/javascript/blob/b4377fb03089dd7f08955242695860d47f9caab4/packages/eslint-config-airbnb-base/rules/es6.js#L65-L70