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

Detect Missing Exports in commonjs?

Open
#2,190 6 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

I'd like to be able to detect when I'm requiring a file that has no exports. Maybe more specifically when I try to assign it to a variable. For example:

```
// y.js

function xyz() {
console.log("HELLO")
}
```

```
// x.js
const y = require('./y'); // <- this should be a lint error because y.js exports nothing

y();
```

Apologies if this is already possible and I'm just doing something wrong.

Contributor guide

Open the contributing guide

Research direction

Use the x.js/y.js example in the issue as the reproducer: requiring y.js yields no exports, but assigning the result to y is not flagged. Identify the existing CommonJS import analysis and its tests, then consider the work complete when this case is detected without incorrectly flagging valid exports.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript
Domain
tooling
Issue type
Feature
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.