`import/no-cycle` not throwing errors

See original GitHub issue

I’m trying to add this plugin only for the import/no-cycle rule and running into problems configuring it. Versions:

package version
eslint 8.18.0
eslint-plugin-import 2.26.0
eslint-config-prettier 8.5.0
eslint-plugin-prettier 4.1.0
eslint-plugin-react 7.30.1

src/utils/index.ts:

import * as consts from '../consts';
export * from './oneUtilsFile';
export * from './anotherUtilsFile';
...

src/consts/index.ts:

import * as utils from '../utils';
export * from './oneConstsFile';
export * from './anotherConstsFile';
...

My .eslintrc.js (abbreviated):

module.exports = {
    parser: '@typescript-eslint/parser',
    parserOptions: {
        ecmaVersion: 2020,
        sourceType: 'module'
    },
    extends: ['eslint:recommended', 'plugin:react/recommended', 'prettier'],
    plugins: ['prettier', 'test-selectors', 'import'],
    rules: {
        'no-console': 'error',
        'import/no-cycle': 'error'
    },
}

Running eslint throws no errors with this config.

I’ve also tried adding each of the canned rule sets to extends, and being more explicit with the import/no-cycle rule: 'import/no-cycle': ['error', { ignoreExternal: true }]. None of these trigger errors with the no-cycle rule.

Am I using the rule incorrectly? Or doing something else wrong? Thanks!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ebbishopcommented, Nov 7, 2022

@ljharb I eventually added 'plugin:import/typescript' to the extends list in my config file and that solved the problem. I’d thought that having the parser and parserOptions I do, that wouldn’t be necessary, but it seems it is.

If that’s expected, I’ll close this issue.

0reactions
ljharbcommented, Nov 16, 2022

@ebbishop on rereading this, i think this is working as intended - you definitely must extend import/typescript (or the equivalent) to have this plugin work properly with TS.

Read more comments on GitHub >

github_iconTop Results From Across the Web

import/no-cycle constantly throws false positives when a file ...
It seems this rule only checks the list of imports rather than checking what is actually imported and whether it has a cycle...
Read more >
Eslint error, configuration for rule "import/no-cycle" is invalid
I changed the node_modules/eslint-config-airbnb-base/rules/imports. js "∞" to an integer to continue debugging. Next run showed this error, ...
Read more >
Understanding import/no-cycle problem in eslint
I have a some code in which eslint thrown an error of the type: import/no-cycle , but I don't understand where this cyclic...
Read more >
throw - JavaScript - MDN Web Docs - Mozilla
The throw statement throws a user-defined exception. ... If no catch block exists among caller functions, the program will terminate.
Read more >
8. Errors and Exceptions — Python 3.11.1 documentation
If an exception occurs which does not match the exception named in the except clause, it is passed on to outer try statements;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found