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
New rule: no-restricted-exports #10428
Comments
Thanks for creating another issue. I have a few questions:
|
Yes, it definitely would apply to all objects - but Module Namespace objects are special, because as explained in the OP, they conceptually represent a static, frozen, representation of a module. I think it was a mistake to allow them to be thenable, and had TC39 thought about it before it was web-incompatible, we would have found an alternative solution. I don't think leaving anything to As to your question, i think it's a good idea to make all things configurable, especially when the implementation to do so is as trivial as it would be here - but if the consensus was to start out with no configuration, and only deal with |
I'm not entirely convinced. If I use My concern about adding options here is that it could result in user confusion about the purpose of the rule. Effectively, the rule would be filling two different use cases: preventing In any case, I don't feel strongly about this point, so I'm open to adding options if other team members are in favor of the idea. |
I'm fine with a rule just for // x
export function then() {} let ns = await import('x'); // never resolves import * as ns 'x'; // resolves In particular having a rule to prevent behavior for |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
This is still a concern, and it'd be great to reopen this. (this is also the second related issue that's been auto-closed) |
While I think Would someone be willing to champion a |
I don't see why we couldn't do |
I'm fine with either |
This has now been accepted. |
I could work on this. Is the decision to implement one generic rule with pre-populated |
@mdjermanovic The proposal I had championed was a full implementation of |
I’d prefer the full implementation, fwiw. |
What should be the configuration for the rule? A list that defaults to Another choice is a (I'd vote for two separate rules if it isn't too late for that discussion) |
I think the general rule is more pressing; i think a separate rule should be proposed for “then” (which can have appropriate docs and messaging). Two rules in the long run is ideal. |
@mdjermanovic I would suggest empty list by default, similar to |
Okay, I definitely didn't understand what is accepted, since the proposal was 'defaults to blocking named exports named "then"'. So, the I'm working on this, should be ready soon. |
yay! |
I'd like to point out that confusion about rule purpose that was mentioned in this issue is not really resolved. |
That sounds like a great addition. |
(Continuation of #9180)
Please describe what the rule should do:
Currently, if you get an ES Module namespace object with
import * as foo from 'path'
, there's a hazard: that module might have a named function export of "then", which meansPromise.resolve(foo)
orawait foo
won't do what you expect.This is also particularly hazardous in the current stage 3
import()
proposal, so the need will increase in the future - but the need is present now, based on ES2015.I'd like to provide a rule that defaults to blocking named exports named "then", but could also be configured for any arbitrary list of restricted export names (including "default").
What category of rule is this? (place an "X" next to just one item)
[ ] Enforces code style
[x] Warns about a potential error
[ ] Suggests an alternate way of doing something
[ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
Why should this rule be included in ESLint (instead of a plugin)?
Module namespace objects are frozen - they're supposed to conceptually represent a static, pre-runtime-determined, representation of an ES Module. It's very very surprising that a module could suddenly become thenable, breaking its consumers, or suddenly become not thenable, also breaking its consumers.
This rule will help prevent problematic exports in the first place by warning when they are created.
The text was updated successfully, but these errors were encountered: