import-js / import-js/eslint-plugin-import
no-cycle rule fails to recognize external module
- Dominant language
- JavaScript
- Stars
- 5.9k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
In a project setup with yarn workspaces, `no-cycle` fails to recognize a `@scope/package` package as external, even if the path is under `node_modules`. The reason is that `no-cycle` uses `isExternalModule`:
https://github.com/benmosher/eslint-plugin-import/blob/master/src/rules/no-cycle.js#L44
but there is a regex condition that says that module is not "external", but "scoped".
https://github.com/benmosher/eslint-plugin-import/blob/3e65a70bc73e404ace72ee858889e39732284d12/src/core/importType.js#L45
I think the right solution for consistency is to use `resolveImportType` from `importType`?
https://github.com/benmosher/eslint-plugin-import/blob/master/src/core/importType.js#L83-L93
Alternatively, replace the regular expression with "anything that does not start with a `.`.
Contributor guide
Research direction
Start with src/rules/no-cycle.js and the isExternalModule logic it uses, then compare it with resolveImportType in src/core/importType.js. Reproduce the yarn-workspace case with a scoped package under node_modules and verify that no-cycle recognizes it as external without changing other module classifications.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- eslint, javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100