You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From my testing, the no-cycle rule DOES NOT DETECT circular dependencies if they are imported via require() calls.
This seems to be the intended behavior, however. As mentioned in this comment, I found this quote from the no-cycle docs:
By default, this rule only detects cycles for ES6 imports, but see the no-unresolved options as this rule also supports the same commonjs and amd flags. However, these flags only impact which import types are linted; the import/export infrastructure only registers import statements in dependencies, so cycles created by require within imported modules may not be detected.
However, a follow-up comment says that require() cycles are in fact supported, and suggested I open a new issue.
As far as I can tell, the original commenter's repo on that issue shows the problem quite well:
Do you have a guide somewhere on how to do local development with this plugin? I'd like to poke around a bit, but I haven't figured out how to point eslint at a locally installed repo. Do I have to just copy the working directory into node_modules?
I have a working demo in #2706. You definitely wouldn't want to merge as-is, because I just hardcoded a return true in lieu of refining the regex there. I don't totally follow what it's doing, so I didn't try to fix it.
The output on the demo repo above, on that branch, is now:
And as an aside, for anybody else, I got this working pretty cleanly for local development via:
eslint-plugin-import $ npm run build
eslint-plugin-import $ npm link
eslint-import-cycle-example $ npm link eslint-plugin-import
eslint-import-cycle-example $ npm run lint
Following up on #941, as requested here.
From my testing, the
no-cycle
rule DOES NOT DETECT circular dependencies if they are imported viarequire()
calls.This seems to be the intended behavior, however. As mentioned in this comment, I found this quote from the no-cycle docs:
However, a follow-up comment says that
require()
cycles are in fact supported, and suggested I open a new issue.As far as I can tell, the original commenter's repo on that issue shows the problem quite well:
https://github.com/simonbuchan/eslint-import-cycle-example
Clone that, then:
It should also be detecting the cycle in
require-a.js
.Am I misusing something?
The text was updated successfully, but these errors were encountered: