tslint-forbidden-imports
TSLint plugin to limit certain types of imports (configured using GLOB patterns)
Last updated a year ago by electroma .
Unlicense · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install tslint-forbidden-imports 
SYNC missed versions from official npm registry.

npm version Build Status Coverage Status

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.

Example use case

For example project code has the directory layout like:

src/
    client/
    server/
    common/

Directories client, server and common represent code scopes:

  • client - application UI
  • server - server-side logic
  • common - 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 -> client
  • common -> server

It may be implemented by adding the following rule configuration:

{
  "forbidden-imports": [true, {
          "client/**": ["server/**"],
          "server/**": ["client/**"],
          "common/**": ["client/**", "server/**"]
  }]
}

Installation

yarn install -d tslint-forbidden-imports

Configuration

  1. Add node_modules/tslint-forbidden-imports/rules to rulesDirectory parameter of your tslint.json.
  2. Enable rule forbidden-imports 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-*)
  • GLOB file path relative to project root (i.e. src/client/** or plugins/*/src/ui/**)

Advanced configuration: placeholders

Library has support for placeholder replacement. This rule will not allow imports between child directories of plugins directory

{
    'plugins/*/src/**': ['plugins/!(%0%)/**']
}

Development

To run tests, just run yarn test.

Project tests are based on test helper from tslint-microsoft-contrib.

References

Current Tags

  • 1.0.9                                ...           latest (a year ago)

7 Versions

  • 1.0.9                                ...           a year ago
  • 1.0.8                                ...           a year ago
  • 1.0.7                                ...           a year ago
  • 1.0.5                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 7
Dependencies (2)
Dev Dependencies (11)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |