Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demo getting require cycles working #2706

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

srsudar
Copy link

@srsudar srsudar commented Feb 4, 2023

This is a potential solution for the issue described here.

I haven't tested this extensively, but it finds require cycles in this project:

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

It seems to have been going wrong in two places:

  1. the unambiguous() test, which is a regex I'm not really following
  2. it wasn't processing requires as imports (though it never got to this step thanks to 1).

@srsudar
Copy link
Author

srsudar commented Feb 4, 2023

x-posting my own comment with more details from the issue. This now detects cycles, like so, as well as how I got it working locally.

eslint-import-cycle-example [main*?] $ 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

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

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

✖ 4 problems (4 errors, 0 warnings)

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

@ljharb ljharb marked this pull request as draft April 13, 2023 21:31
@ljharb
Copy link
Member

ljharb commented Apr 13, 2023

This will need some test cases to be able to land.

@srsudar
Copy link
Author

srsudar commented Apr 25, 2023

If I fix this up, is it something you'd be interested in merging? It seems like this might break a lot of projects, if I'm correct that require() cycles aren't being reported correctly as circular deps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants