# eslint-plugin-import-isolation

> ESLint plugin for restricting imports between specified directories.

Latest version **0.0.1** (published 2023-08-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install eslint-plugin-import-isolation
pnpm add eslint-plugin-import-isolation
yarn add eslint-plugin-import-isolation
bun add eslint-plugin-import-isolation
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2023-08-31 |
| First published | 2023-08-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | lsdsjy |
| Maintainers | lsdsjy |

## Links

- npm: https://www.npmjs.com/package/eslint-plugin-import-isolation
- Repository: https://github.com/kwai-explore/basic-configs
- Homepage: https://github.com/kwai-explore/basic-configs#readme
- Issues: https://github.com/kwai-explore/basic-configs/issues
- npm.io page: https://npm.io/package/eslint-plugin-import-isolation

## Recent versions

- 0.0.1 (latest) — 2023-08-31

## README

# eslint-plugin-import-isolation

## The Problem

Suppose you have two subdirectories under `pages`:

```
my-project
└── pages
   └── a
   └── b
```

You don't want modules under `a` to import anything from `b`. Existing plugins like [eslint-plugin-import](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-restricted-paths.md) and [eslint-plugin-code-import-patterns](https://www.npmjs.com/package/eslint-plugin-code-import-patterns) address this issue well. However, when you have tens of subdirectories under `pages`, configuring the rules becomes burdensome. This plugin is designed to solve this problem.

## Usage

To use this plugin, configure ESLint as following:

```js
plugins: ['import-isolation'],
rules: {
    'import-isolation/isolation': [
        'error',
        {
            isolationGroups: [
                {
                    directories: [
                        "modules/*",
                        // equivalent to
                        // "modules/a"
                        // "modules/b"
                        // ...
                    ]
                },
                {
                    directories: [
                        "modules/*/pages/*",
                        // equivalent to
                        // "modules/a/pages/aa",
                        // "modules/a/pages/ab",
                        // "modules/b/pages/ba",
                        // ...
                    ]
                },
            ]
        }
    ]
}
```

- `isolationGroups` includes several "isolation groups", where each group uses `directories` to specify multiple directories.
- All directories inside one isolation group cannot import from each other.
- You can use the wildcard `*` to specify multiple directories.
- Taking the example above, `modules/a/a.js` cannot import from `modules/b/b.js`, and `modules/a/pages/pa.js` cannot import from either `modules/a/pages/pb.js` or `modules/b/pages/pa.js`.

---
_Source: https://npm.io/package/eslint-plugin-import-isolation · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
