TSLint plugin to limit certain types of imports (configured using GLOB patterns)
npm install tslint-forbidden-imports


This rule is useful in larger code bases to control dependencies between project modules.
Rule allows to specify source file patterns and list of path patterns which should not be allowed.
For example project code has the directory layout like:
``text`
src/
client/
server/
common/
Directories client, server and common represent code scopes:client
* - application UIserver
* - server-side logiccommon
* - shared constants and interfaces
In this setup imports between following directories should not be allowed:
* client -> server (something like import server from '../../server/myAPIServer')server
* -> client (something like import Crux from '../../client/components/Crux')common
* -> clientcommon
* -> server
It may be implemented by adding the following rule configuration:
`json`
{
"forbidden-imports": [true, {
"client/": ["server/"],
"server/": ["client/"],
"common/": ["client/", "server/**"]
}]
}
yarn install -d tslint-forbidden-imports
1. Add node_modules/tslint-forbidden-imports/rules to rulesDirectory parameter of your tslint.json.forbidden-imports
2. Enable rule and pass mapping "file pattern" -> ["fordidden import patterns"...]
The pattern syntax may use any features supported by micromatch.
Supported import pattern types:
Node package (i.e. lodash or ui-)src/client/
GLOB file path relative to project root (i.e. or plugins//src/ui/)
Library has support for placeholder replacement.
This rule will not allow imports between child directories of plugins directory`js`
{
'plugins/*/src/': ['plugins/!(%0%)/']
}
To run tests, just run yarn test`.
Project tests are based on test helper from tslint-microsoft-contrib.
* TSLint Custom Rules Development
* tslint-microsoft-contrib has a ton of well-tested rule examples