eslint-plugin-restrict-imports

0.0.3 • Public • Published

eslint-plugin-restrict-imports

CircleCI

Eslint plugin to ban specified imports in specified directories

This is useful to ban not using a barrelled import in multi-package repositories.

Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install eslint-plugin-restrict-imports:

$ npm install eslint-plugin-restrict-imports --save-dev

Usage

Add restrict-imports to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": ["restrict-imports"]
}

Then configure the rules you want to use under the rules section.

{
    "rules": {
        "restrict-imports/restrict-imports": [
            "error",
            {
                "../../clientA(.*)": {
                    "locations": ["(.*)/clientB(.*)"],
                    "message": "Do not import client A in client B"
                },
                "(.*)/common/(.*)": {
                    "locations": ["(.*)/client(.*)"],
                    "message": "Use barrelled import '@common'"
                }
            }
        ]
    }
}

Rule configuration:

[
    "error",
    {
        "../../clientA(.*)": {                              // regex for the import path to ban
            "locations": ["(.*)/clientB(.*)"],              // regex for the absoulte file names to enforce in
            "message": "Do not import client A in client B" // optional - customised error message
        }
    }
]

Default Rule configuration:

[
    "error",
    {
        "/(.*)": {                // Ban absoulte imports
            "locations": ["(.*)"] // in all files
        }
    }
]

Supported Rules

  • restrict-imports - Ban imports from a location in any directory.

Package Sidebar

Install

npm i eslint-plugin-restrict-imports

Weekly Downloads

7,684

Version

0.0.3

License

ISC

Unpacked Size

79.2 kB

Total Files

17

Last publish

Collaborators

  • billlynch