Skip to content

no-cycle does not detect require()-based cycles #2702

Open
@srsudar

Description

@srsudar

Following up on #941, as requested here.

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:

https://github.com/simonbuchan/eslint-import-cycle-example

Clone that, then:

$ npm install
$ npm run lint

> eslint-import-cycle@1.0.0 lint
> eslint .


/eslint-import-cycle-example/import-a.js
  1:1  error  Dependency cycle detected  import/no-cycle

/eslint-import-cycle-example/import-b.js
  1:1  error  Dependency cycle detected  import/no-cycle

✖ 2 problems (2 errors, 0 warnings)

It should also be detecting the cycle in require-a.js.

Am I misusing something?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions