# eslint-plugin-import-access

> ESLint rule for prohibiting package-private imports

Latest version **3.1.1** (published 2026-11-27) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.1.1 |
| Published | 2026-11-27 |
| First published | 2021-06-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 41.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 426 |
| Author | uhyo |
| Maintainers | uhyo |
| Keywords | eslint, eslintplugin |

## Links

- npm: https://www.npmjs.com/package/eslint-plugin-import-access
- Repository: https://github.com/uhyo/eslint-plugin-import-access
- Homepage: https://github.com/uhyo/eslint-plugin-import-access#readme
- Issues: https://github.com/uhyo/eslint-plugin-import-access/issues
- npm.io page: https://npm.io/package/eslint-plugin-import-access

## Dependencies (3)

- [tsutils](https://npm.io/package/tsutils.md) ^3.21.0
- [minimatch](https://npm.io/package/minimatch.md) ^11.0.4
- [@typescript-eslint/utils](https://npm.io/package/@typescript-eslint/utils.md) ^8.58.0

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@pandacss/eslint-plugin](https://npm.io/package/@pandacss/eslint-plugin.md) — 18.7K weekly downloads

## Recent versions

- 3.1.1 (latest) — 2026-11-27
- 3.1.0 — 2025-11-09
- 3.0.0 — 2025-05-15
- 3.0.0-beta.0 — 2025-05-14
- 2.2.2 — 2024-06-27
- 2.2.1 — 2024-04-30
- 2.2.0 — 2024-04-11
- 2.1.2 — 2023-10-14
- 2.1.1 — 2023-08-15
- 2.1.0 — 2023-08-10
- 2.0.0 — 2023-07-27
- 1.1.2 — 2023-05-31
- 1.1.1 — 2023-05-26
- 1.1.0 — 2023-05-26
- 1.0.2 — 2023-03-19
- … 3 more at https://npm.io/package/eslint-plugin-import-access/versions

## README

# eslint-plugin-import-access

> [!NOTE]
> **Migrating away from ESLint?** Try [ImportLint](https://github.com/uhyo/import-lint), an official port of this plugin into a standalone CLI linter. ImportLint is compatible with this plugin and is very fast.

## What?

This package provides a [typescript-eslint](https://github.com/typescript-eslint/typescript-eslint) rule that restricts importing variables marked as `@package` from a file outside the same directory. Also, this package serves as a TypeScript Language Service Plugin that prevents auto-completion of such imports.

![Illustration of how `@package` works.](./docs/images/concept.png)

## Why?

The largest encapsulation unit available for a TypeScript project is a file. That is, variables not exported from a file is only visible to code in the same file. Once a variable is exported, it is visible from the entire project.

Sometimes this is insufficient. A rational effort for proper encapsulation may result in a large file that is hard to maintain.

This package solves this problem by providing a new directory-level layer and enabling a “package-private” export that is only visible to files in the same directory.

## Installation

```sh
npm i -D eslint-plugin-import-access
```

Depending on how you configure ESLint, use either Flat Config or eslintrc to configure eslint-plugin-import-access.

Also, you can enable the TypeScript Language Service Plugin by adding it to the `plugins` array in `tsconfig.json`.

### Flat Config

In **eslint.config.js**:

```js
import typescriptEslintParser from "@typescript-eslint/parser";
import importAccess from "eslint-plugin-import-access/flat-config";

export default [
  // other settings...
  {
    // set up typescript-eslint
    languageOptions: {
      parser: typescriptEslintParser,
      parserOptions: {
        project: true,
        sourceType: "module",
      },
    },
  },
  {
    plugins: {
      "import-access": importAccess,
    },
  },
  {
    rules: {
      "import-access/jsdoc": ["error"],
    },
  },
];
```

_Note: currently you need to import the plugin from the `/flat-config` subpath. In a future version, this will be simplified._

### eslintrc

In **.eslintrc.js**:

```js
  // set up typescript-eslint
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": true,
    "sourceType": "module"
  },
  "plugins": [
    "import-access",
    // ...
  ],
  "rules": {
    "import-access/jsdoc": ["error"],
  }
```

### TypeScript Language Service Plugin

In **tsconfig.json**:

```json
{
  "compilerOptions": {
    // ...
    "plugins": [
      // ...
      {
        "name": "eslint-plugin-import-access"
      }
    ]
  }
}
```

_Note: to enable TypeScript language service plugins installed locally, you must use TypeScript in `node_modules`, not the one bundled with VSCode._

## Example

```ts
// ----- sub/foo.ts -----

/**
 * @package
 */
export const fooPackageVariable = "I am package-private export";

// ----- sub/bar.ts -----
// This is correct because foo.ts is in the same directory
import { fooPackageVariable } from "./foo";

// ----- baz.ts -----
// This is INCORRECT because package-private exports
// cannot be imported from outside the sub directory
import { fooPackageVariable } from "./sub/foo";
```

## Rule References

- [import-access/jsdoc](./docs/rule-jsdoc.md)

- [Language Service Plugin](./docs/ts-server.md)

## Contributing

Welcome

## License

MIT

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