useImportRestrictions
このコンテンツはまだ日本語訳がありません。
Diagnostic Category: lint/nursery/useImportRestrictions
Since: v1.0.0
Sources:
- Inspired from:
import-access/eslint-plugin-import-access
Disallows package private imports.
This rules enforces the following restrictions:
Package private visibility
Section titled Package private visibilityAll exported symbols, such as types, functions or other things that may be exported, are considered to be “package private”. This means that modules that reside in the same directory, as well as submodules of those “sibling” modules, are allowed to import them, while any other modules that are further away in the file system are restricted from importing them. A symbol’s visibility may be extended by re-exporting from an index file.
Notes:
- This rule only applies to relative imports. External dependencies are exempted.
- This rule only applies to imports for JavaScript and TypeScript files. Imports for resources such as images or CSS files are exempted.
Source: https://github.com/uhyo/eslint-plugin-import-access
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:2:36 lint/nursery/useImportRestrictions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Importing package private symbols is prohibited from outside the module directory.
1 │ // Attempt to import from foo.js
from outside its sub
module.
> 2 │ import { fooPackageVariable } from “./sub/foo.js”;
│ ^^^^^^^^^^^^^^
3 │
ℹ Please import from ./sub instead (you may need to re-export the symbol(s) from ./sub/foo.js).
code-block.js:2:36 lint/nursery/useImportRestrictions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Importing package private symbols is prohibited from outside the module directory.
1 │ // Attempt to import from bar.ts
from outside its aunt
module.
> 2 │ import { barPackageVariable } from “../aunt/bar.ts”;
│ ^^^^^^^^^^^^^^^^
3 │
ℹ Please import from ../aunt instead (you may need to re-export the symbol(s) from ../aunt/bar.ts).
code-block.js:2:36 lint/nursery/useImportRestrictions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Importing package private symbols is prohibited from outside the module directory.
1 │ // Assumed to resolve to a JS/TS file.
> 2 │ import { fooPackageVariable } from “./sub/foo”;
│ ^^^^^^^^^^^
3 │
ℹ Please import from ./sub instead (you may need to re-export the symbol(s) from ./sub/foo).
code-block.js:2:36 lint/nursery/useImportRestrictions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Importing package private symbols is prohibited from outside the module directory.
1 │ // If the sub/foo
module is inaccessible, so is its index file.
> 2 │ import { fooPackageVariable } from “./sub/foo/index.js”;
│ ^^^^^^^^^^^^^^^^^^^^
3 │
ℹ Please import from ./sub/index.js instead (you may need to re-export the symbol(s) from ./sub/foo/index.js).