question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New rule: no-restricted-exports

See original GitHub issue

(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 means Promise.resolve(foo) or await 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:

export function then() {
  return "foo";
}

function v() {return 123;}
export {v as then};

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:21 (18 by maintainers)

github_iconTop GitHub Comments

4reactions
platinumazurecommented, Mar 27, 2019

I don’t see why we couldn’t do no-restricted-exports. I will champion this rule proposal.

2reactions
kaicataldocommented, May 29, 2019

This has now been accepted.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-restricted-exports - ESLint - Pluggable JavaScript Linter
This rule disallows specified names from being used as exported names. ... is an array of strings, where each string is a name...
Read more >
[no-restricted-exports] Fails on export { default } from ... #2500
As the title states. Fails when re-exporting the default from another module. export { default } from 'another-module'; This feels like it ...
Read more >
Disallow specified names in exports (no-restricted-exports)
Rule Details. This rule disallows specified names from being used as exported names. Options. By default, this rule doesn't disallow any names.
Read more >
No-restricted-exports - ESLint - W3cubDocs
Rule Details. This rule disallows specified names from being used as exported names. Options. By default, this rule doesn't disallow any names.
Read more >
Implementation of Additional Export Controls: Certain ...
With this rule, BIS imposes new export controls on certain advanced computing semiconductor chips and computer commodities that contain such ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found