import-js / import-js/eslint-plugin-import
`import/no-extraneous-dependencies` does not properly respect src symlinks
- Dominant language
- JavaScript
- Stars
- 5.9k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
When running against a symlink target, eslint generates erroneous issues such as the following (`scavenger-hunt-chrome-extension` is the name of my project as named in `package.json`):
```
'scavenger-hunt-chrome-extension' should be listed in the project's dependencies. Run 'npm i -S scavenger-hunt-chrome-extension' to add it
```
I use [Trunk](https://trunk.io/products/check) to run linters on my Typescript project. Running normally, eslint works perfectly as intended. However, when running as a `pre-commit` hook, Trunk creates a shadow tree of the workspace, using symlinks for all unchanged files and copying any changes in order to run on a specific git workspace state (I can include Trunk re-run instructions if desired). This shadow tree can look something like:
ls -l output
```
lrwxrwxrwx 1 taj taj 48 Jul 26 00:08 .eslintrc.js -> /home/taj/repos/Scav_Hunt_Extension/.eslintrc.js
lrwxrwxrwx 1 taj taj 40 Jul 26 00:08 .git -> /home/taj/repos/Scav_Hunt_Extension/.git
lrwxrwxrwx 1 taj taj 43 Jul 26 00:08 .github -> /home/taj/repos/Scav_Hunt_Extension/.github
lrwxrwxrwx 1 taj taj 46 Jul 26 00:08 .gitignore -> /home/taj/repos/Scav_Hunt_Extension/.gitignore
lrwxrwxrwx 1 taj taj 42 Jul 26 00:08 .trunk -> /home/taj/repos/Scav_Hunt_Extension/.trunk
lrwxrwxrwx 1 taj taj 51 Jul 26 00:08 CONTRIBUTING.md -> /home/taj/repos/Scav_Hunt_Extension/CONTRIBUTING.md
lrwxrwxrwx 1 taj taj 47 Jul 26 00:08 LICENSE.txt -> /home/taj/repos/Scav_Hunt_Extension/LICENSE.txt
lrwxrwxrwx 1 taj taj 45 Jul 26 00:08 README.md -> /home/taj/repos/Scav_Hunt_Extension/README.md
lrwxrwxrwx 1 taj taj 44 Jul 26 00:08 TODO.txt -> /home/taj/repos/Scav_Hunt_Extension/TODO.txt
lrwxrwxrwx 1 taj taj 40 Jul 26 00:08 dist -> /home/taj/repos/Scav_Hunt_Extension/dist
lrwxrwxrwx 1 taj taj 50 Jul 26 00:08 jest.config.js -> /home/taj/repos/Scav_Hunt_Extension/jest.config.js
lrwxrwxrwx 1 taj taj 49 Jul 26 00:08 jest_setup.ts -> /home/taj/repos/Scav_Hunt_Extension/jest_setup.ts
lrwxrwxrwx 1 taj taj 48 Jul 26 00:08 node_modules -> /home/taj/repos/Scav_Hunt_Extension/node_modules
lrwxrwxrwx 1 taj taj 53 Jul 26 00:08 package-lock.json -> /home/taj/repos/Scav_Hunt_Extension/package-lock.json
lrwxrwxrwx 1 taj taj 48 Jul 26 00:08 package.json -> /home/taj/repos/Scav_Hunt_Extension/package.json
lrwxrwxrwx 1 taj taj 42 Jul 26 00:08 public -> /home/taj/repos/Scav_Hunt_Extension/public
lrwxrwxrwx 1 taj taj 39 Jul 26 00:08 src -> /home/taj/repos/Scav_Hunt_Extension/src
lrwxrwxrwx 1 taj taj 49 Jul 26 00:08 tsconfig.json -> /home/taj/repos/Scav_Hunt_Extension/tsconfig.json
lrwxrwxrwx 1 taj taj 43 Jul 26 00:08 webpack -> /home/taj/repos/Scav_Hunt_Extension/webpack
```
Trunk then runs `eslint src/utils/parse.ts` from this shadow directory, outputting the issue as above. I've confirmed that this does not seem to be an issue with Trunk itself and is unique to this eslint plugin when running in this symlinked context.
I've tried a few different configuration setups in order to try to have `scavenger-hunt-chrome-extension` resolve correctly in the context of this rule, but to no avail. Some things I've tried include:
- Setting `preserveSymlinks: true` in the node `import/resolver` setting
- Setting `project` manually to my workspace root
- A custom resolver that uses an additional `fs.realPath` call in the node `import/resolver` setting
- Adding an `allowModules` entry in `node/no-extraneous-import` for my package
At this point, it's possible this is a config error on my end, but nothing I've tried has worked, so I'm leaning this is a resolution bug in the plugin itself. I haven't had a chance to get a minimal repro, but here are my config files and the repo I'm running this on:
- [.eslintrc.js](https://github.com/TylerJang27/Scav_Hunt_Extension/blob/tyler/eslint-issues/.eslintrc.js)
- [tsconfig.json](https://github.com/TylerJang27/Scav_Hunt_Extension/blob/tyler/eslint-issues/tsconfig.json)
- [full branch](https://github.com/TylerJang27/Scav_Hunt_Extension/tree/tyler/eslint-issues)
Contributor guide
Research direction
Start with the import/no-extraneous-dependencies rule and reproduce the report against src/utils/parse.ts in the symlinked shadow tree. Review the supplied .eslintrc.js and tsconfig.json, then compare resolution from the shadow directory with the workspace; done means the project package is not falsely reported as an extraneous dependency.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- eslint, javascript, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100