feat(lint): add import rule to prevent circular dependencies
See original GitHub issueCurrent Behavior
Importing from within a given library (.e.g. @proj/lib-a) should use relative paths (.e.g. ./module) instead of the paths in path-mappings (e.g. @proj/lib-a). Currently, there is no way to restrict this via linting.
Expected Behavior
Importing from @proj/lib-a from within @proj/lib-a should result in a linting error.
We can use the following rules for each library’s tslint.json or .eslintrc:
TSLint
https://palantir.github.io/tslint/rules/import-blacklist/
"import-blacklist": [true, "rxjs/Rx", "@nx-examples/shared/jsxify"]
ESLint
https://eslint.org/docs/rules/no-restricted-imports
"no-restricted-imports": ["error", "import1", "import2"]
Caveats
If the workspace has this rule in their root linting config, the generated rule should include what is there because it will be completely overwritten otherwise.
We should also write a migration which will add this rule to existing projects within the workspace.
Related Issues
Issue Analytics
- State:
- Created 4 years ago
- Reactions:13
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to Eliminate Circular Dependencies from Your JavaScript ...
In my experience, the best way to deal with circular dependencies is to avoid them altogether. Circular dependencies are usually an indication ...
Read more >How to fix nasty circular dependency issues once and for all in ...
First, this is ugly and doesn't scale. In a large code base, this will result in moving imports randomly around until stuff just...
Read more >Table of Contents - Micronaut Documentation
Provider if a circular dependency requires it or to instantiate a prototype for each get call. Provider<Engine>. BeanProvider. A io.micronaut.context.
Read more >Spinnaker Release 1.27.0
6430: Adding missing block device mappings for new launch templates (07186a01) ... deleteOp: Import log dependencies (0e9c240a); docker: filter images with ...
Read more >Changelog | Meteor API Docs
Fix tracking states with circular dependencies. ... Use lazy imports to prevent it from being added to the initial bundle ... New meteor...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Currently, we’re doing this via a workspace schematic: https://gist.github.com/twittwer/d1adb85f873b02b14b6f52d2aa9ec4f3#file-index-ts-L124
Would be nice to get this out of the box 😄
Not stale 😃 Could still really use this, we might contribute this if someone doesn’t beat us to it.