[import/no-cycle] do not check node_modules
See original GitHub issueI’ve got projects with only a very few small files, which I have hard time working on because of no-cycle being too slow (99% of the full eslint
time). I wanted to speed-up this time, but I did not want to use maxDepth
because I may have some more complex projects and those are the ones where I’d mostly create an unwanted cycle.
While benchmarking the code, I found that there doesn’t seem to be a cache, or the cache is not working. For my project, most of my files import the same very big module (typescript
) and this module is analyzed at each import, instead of only at the first time.
But an easy correction which could also improve the speed would be to ignore external modules: there is very, very little chance that a dependency of my project references a file in my project.
For the moment, this should not be a big problem (except for my big typescript
dependency), because most dependencies are transpiled into CommonJS and use require
instead of import
. But if one day, issue #1056 is corrected, or because external dependencies use more and more import
, things will become worse.
I made a quick test by directly modifying the code and the time spent by no-cycle fell from more than 2mn to less than 30s.
I can submit a PR if you want. I don’t know if it could be considered an issue (the correction would be a breaking change) or if it the behavior should be controlled by an option of no-cycle.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:9 (9 by maintainers)
Top GitHub Comments
I have no time immediately, but I’ll do it within a week or two if no one else takes it before…
I’ve thought about it - I’d be willing to accept a PR with an option that specifically ignores cycles in “external” module (https://github.com/benmosher/eslint-plugin-import#importexternal-module-folders)