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

"No cycle" rule isn't working #373

Open
5 tasks done
arpowers opened this issue Dec 23, 2023 · 5 comments
Open
5 tasks done

"No cycle" rule isn't working #373

arpowers opened this issue Dec 23, 2023 · 5 comments

Comments

@arpowers
Copy link

Describe the bug

One of the handiest eslint rules is the no-cycle rule which detects circular imports (because these can be such a nightmare)

However, the rule doesn't appear to be working inside this library.

Config:

// @ts-check
import antfu from "@antfu/eslint-config";

export default antfu(
  {
    typescript: {
      tsconfigPath: "./tsconfig.json",
      parserOptions: {
        project: "./tsconfig.json",
        extraFileExtensions: [".vue", ".json"],
      },
    },
    rules: {
      eqeqeq: "warn",

      "import/no-cycle": [
        "error",
        {
          maxDepth: 5,
          ignoreExternal: true,
        },
      ],
      "ts/no-floating-promises": "error",
    },
  },
  {
    ignores: [
      "**/.ref/**/*",
      "**/__*",
      "node_modules",
      "dist",
      "**/.factor/**",
      ".pnpmfile.cjs",
    ],
  }
);

Reproduction

https://github.com/arpowers/eslint-testing

System Info

MacOS

Used Package Manager

npm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@arpowers
Copy link
Author

arpowers commented Feb 6, 2024

any update on this? @antfu as a work around, if there is a better way to make sure there are no circular imports I'm interested.

@antfu
Copy link
Owner

antfu commented Feb 6, 2024

I don't know. I am not using that rule and not sure if it's a problem with this config or the plugin - Investigating yourself might get your problem solved faster.

@InfiniteXyy
Copy link

Hi, @arpowers

I found that this issue might caused by eslint-plugin-import doesn't support flatConfig, see un-ts/eslint-plugin-import-x#29

But we could use @eslint/eslintrc compact as a workaround 👇

I'm not sure if it's the best workaround, at least it works for me. Also, I don't know how to override the import settings in antfu() composer, looks like import doesn't provide override options like other rule sets (for example react)

import { combine, javascript, renamePluginInConfigs, typescript } from '@antfu/eslint-config';
import { FlatCompat } from '@eslint/eslintrc';
import importPlugin from 'eslint-plugin-import-x';

const compat = new FlatCompat({});

export default combine(
  javascript(),
  typescript(),
  // rename the `import-x` to `import` to keep sync with antfu default naming
  renamePluginInConfigs([...compat.config(importPlugin.configs.recommended), importPlugin.configs.typescript], { 'import-x': 'import' }),
  [{
    rules: {
      'import/no-cycle': 'error',
    },
  }],
);

@SukkaW
Copy link

SukkaW commented Aug 2, 2024

eslint-plugin-import-x doesn't have built-in flat config exports, but almost all rules work with flat config (except no-unused-modules). You can always compose your own flat config just like how @antfu/eslint-config already did. No compat util is needed.

@InfiniteXyy
Copy link

Hi @SukkaW

You are right.

Adding these settings into antfu config also makes the import/no-cycle rule work.

{
 settings: {
    'import-x/parsers': {
      '@typescript-eslint/parser': ['.ts'],
    },
    'import-x/resolver': {
      node: {
        extensions: ['.ts'],
      },
    },
  },
}

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

No branches or pull requests

4 participants