import-js / import-js/eslint-plugin-import

import/export false positive with star reexports

Open
#703 0 comments 1 reaction 0 assignees View on GitHub
rule proposal
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

Sample code:

```js
// index.js

export * from './core'
// Placed here to work around a webpack bug.
// https://github.com/webpack/webpack/issues/3588
export { default } from './core'

export * from './modules'

// export { default } from './core';
// disambiguate export
export { api } from './modules'
```

```js
// (simplified) core.js that can reproduce the issue
export const api = {}
export default null
```

```js
// (simplified) modules.js that can reproduce the issue
export const api = {}
```

As the `api` exports coming via the `export *` are not `SameValue`, the lint warning would be correct if not for the `export { api } from './modules'` at the bottom, which disambiguates the exports.

Explicit exports always take precedence over any star reexports, so no exports are duplicated.

---

Note that, if both `export const api` were set to, say, `'foo'`, they would all be `SameValue`, and so would be allowed by the spec even without the disambiguating reexport. I have no idea how the spec would deal with the case where they are mutable exports 😆

There might be value in actually having a warning for this case, but it probably should be in a separate rule, or configuration option.

Contributor guide

Open the contributing guide

Research direction

Start with the index.js, core.js, and modules.js reproducer in the issue, then trace the lint rule that reports duplicate star reexports. Confirm how the explicit export { api } disambiguates the star exports, and verify that the false positive is removed without suppressing genuine duplicate-export warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.