question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat(lint): add import rule to prevent circular dependencies

See original GitHub issue

Current 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

#738 #741

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:13
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
twittwercommented, Aug 12, 2020

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 😄

0reactions
llwtcommented, Apr 1, 2021

Not stale 😃 Could still really use this, we might contribute this if someone doesn’t beat us to it.

Read more comments on GitHub >

github_iconTop 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 >

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