Adrien Joly
Adrien Joly

Reputation: 5336

How to get a warning whenever a given function is imported, even indirectly?

In my current TypeScript/Node.js project, we have implemented an internal cache module that we are progressively getting rid of.

To achieve that, I would like to progressively reduce the parts of the codebase that can import that module, directly or indirectly. And to be warned during development whenever we violate that rule.

Example:

Do you know a way to enforce that rule with TSC, Eslint, or another static code analysis tool?

Upvotes: 1

Views: 279

Answers (2)

Romain Linsolas
Romain Linsolas

Reputation: 81627

Since you want to remove your cache module, I would recommend to use @deprecated jsdoc statement. This way, you will be warned every time you want to use it in new development. In addition to that, you can use an ESLint plugin to warn

Upvotes: 1

matt helliwell
matt helliwell

Reputation: 2678

The closest thing I know is the eslint-plugin-boundaries project. It might be worth refactoring your modules for the cache so you can use some of these rules.

Failing that, writing a custom ESLint rule is fairly straight forward so long as you've got a set of rules you can apply to the AST.

Upvotes: 2

Related Questions