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

An access problem in eslint-module-utils/resolve.js

Open
#2,433 5 comments 1 reaction 0 assignees View on GitHub
resolver
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

Hi!

recently ran into an access issue when working with eslint-plugin-import and found this problem:

the file is in the dependency [eslint-module-utils](https://www.npmjs.com/package/eslint-module-utils) which seem to not have it's own repo but is linked to this project

The file is **resolve.js**

here to check if a directory exists the code tries to access a list of files in its parent dir and then find parsedPath.base in received list. This makes an issue when script executor doesn't have access to the directory above

```
const parsedPath = path.parse(filepath);
const dir = parsedPath.dir;

let result = fileExistsCache.get(filepath, cacheSettings);
if (result != null) return result;

// base case
if (dir === '' || parsedPath.root === filepath) {
result = true;
} else {
const filenames = fs.readdirSync(dir);
if (filenames.indexOf(parsedPath.base) === -1) {
result = false;
} else {
result = fileExistsWithCaseSync(dir, cacheSettings, strict);
}
}
```

The same functionality can be implemented this way:

```
if (dir === '' || parsedPath.root === filepath) {
result = true;
} else {
if (!fs.existsSync(path.join(dir, parsedPath.base))) {
result = false;
} else {
result = fileExistsWithCaseSync(dir, cacheSettings, strict);
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start with eslint-module-utils/resolve.js, especially the file-existence check shown in the issue. Reproduce the access failure when the executor cannot read the parent directory, then verify the revised existence check preserves the existing case-sensitive behavior and resolves the reported access problem.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.