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

Circular dependency error when using recommended #49

Closed
woodrunner opened this issue Jan 10, 2025 · 3 comments · Fixed by #59
Closed

Circular dependency error when using recommended #49

woodrunner opened this issue Jan 10, 2025 · 3 comments · Fixed by #59
Labels
bug Something isn't working

Comments

@woodrunner
Copy link

woodrunner commented Jan 10, 2025

Describe the bug
When I lint a project of mine that contains your recommended plugin I get a circular dependency error:

nx run bo-modules-empty-modules:lint

Linting "bo-modules-empty-modules"...

NX Converting circular structure to JSON

--> starting at object with constructor 'Object'
| property '@smarttools/rxjs' -> object with constructor 'Object'
| property 'configs' -> object with constructor 'Object'
| property 'recommended' -> object with constructor 'Object'
--- property 'plugins' closes the circle
Referenced from: /Users/davinja/Documents/WgkProjects/front-end/tools/eslint-plugin-wgk/typescript/eslintrc.js

If I manually add the recommended rules to my project it works. So this means that the problem is located in your library.

const rxjsRules = {
  '@smarttools/rxjs/no-async-subscribe': 'error',
  ...
};

module.exports = [
  {
    plugins: {
      '@smarttools/rxjs': rxjs,
    },
    rules: {
      ...rxjsRules,
    },
  },
];

I located the circular dependency by logging a util.inspect for your library:

const util = require('util');
const rxjs = require('@smarttools/eslint-plugin-rxjs');

console.log(util.inspect(rxjs, { depth: null }));

In this output you can see the cause of the circular dependency:

configs: {
  recommended: {
    plugins: { '@smarttools/rxjs': [Circular *1] }, // Circular reference
    rules: {
      // rules here...
    }
  }
}

The plugins key in the recommended configuration is set to { '@smarttools/rxjs': [Circular *1] } which refers back to the main plugin object (rxjs) itself.

I fixed this issue by removing this redundant plugins property both index.ts and recommended.ts.

index.ts:

if (plugin.configs) {
  Object.assign(plugin.configs, {
    recommended: {
      name: '@smarttools/rxjs/recommended',
      rules: {
        ...recommended.rules,
      },
    },
    'recommended-legacy': recommended,
  });
}

recommended.ts:

import { Linter } from '@typescript-eslint/utils/ts-eslint';

export = {
  rules: {
    '@smarttools/rxjs/no-async-subscribe': 'error',
    ...
  } as Linter.RulesRecord,
};

Repro
Version of @smarttools/eslint-plugin-rxjs you are using: 1.0.13

@woodrunner woodrunner added the bug Something isn't working label Jan 10, 2025
@woodrunner woodrunner changed the title Circular dependency error when linting Circular dependency error when using recommended Jan 10, 2025
@DaveMBush DaveMBush moved this from New to In progress in eslint-plugin-rxjs Jan 11, 2025
@DaveMBush
Copy link
Owner

I tried to replicate the problem here https://github.com/DaveMBush/eslint-plugin-rxjs/tree/dmb/circular-dependency-error-when-using-recommended/49/tests/using-recommended and I don't see the circular dependency issue (even though I admit it is probably there). I would like to be able to produce a test that replicates this issue, but for that I need to know more about what you are doing. Could you create a small sample in a repository I can access so I can create the test please?

@woodrunner
Copy link
Author

I reproduced the error on this stackblitz:
https://stackblitz.com/~/github.com/woodrunner/angular-eslint-bug?branch=recommended-circular-bug

I think it has something to do with the external eslintrc.js file of mine.

@DaveMBush
Copy link
Owner

This has been addressed in 1.0.16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants