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:
users.ts
is allowed to importcache.ts
domain.ts
importsusers.ts
, but it’s not allowed to importcache.ts
(even thruusers.ts
), so we want to be warned about that.
Do you know a way to enforce that rule with TSC, Eslint, or another static code analysis tool?
CodePudding user response:
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.
CodePudding user response:
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