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

import/no-cycle should stop looking for cycles when it imports from a rule disabled folder #2439

Open
georeith opened this issue Apr 21, 2022 · 3 comments

Comments

@georeith
Copy link
Contributor

georeith commented Apr 21, 2022

I have added a test case to better describe the issue here: #2438

If you import a file from a folder that has the import/no-cycle rule disabled into a folder that has the rule enabled and that file contains a cycle the linter errors.

This is annoying in cases where we have cycles in our codebase that we want to ignore, but we can't do so by just disabling the rule for the folder they belong to as any code that ends up referencing them from anywhere outside at any point fails the lint, ignoring all of these cases as the depth of imports grows becomes unmanageable.

@ljharb
Copy link
Member

ljharb commented Aug 27, 2022

Can you elaborate on why you want to ignore any cycles?

@Alessandro-maker
Copy link

I have the same problem and I can elaborate my case.

We have most of the cycles in our code base that come from a small set of interlinked files.
We can't solve it until we do a bigger refactoring but that kind of refactoring will be possible only in the future.
For now we want to get rid of all the other cycles and to have a check to prevent new ones from entering the code base.

So the idea is that when the cycle check enters some of those files it should stop.
I found no way of doing it.
Specifying an override for those file exclude them as starting point for the check but if other import them I still get the error.

Setting all enabled as warning is not an option because new cycles would be lost inside the noise.

Any suggestion?

@vmasek
Copy link

vmasek commented Oct 19, 2024

did you consider using rule overrides?

{
  overrides: [
    {
      files: ['path/to/ignored/files.ts], // or use a glob pattern if all your ignored files are in specific folders
      extends: ['plugin:import/recommended'],
      rules: {
        'import/no-cycle': 'warn',
      },
    },
  ],
}

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

No branches or pull requests

4 participants