Skip to content

Commit

Permalink
docs: update rule README
Browse files Browse the repository at this point in the history
  • Loading branch information
jonioni authored May 8, 2023
1 parent e4833d5 commit 123ea7e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions docs/rules/no-parent-barrel-import.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

<!-- end auto-generated rule header -->

Forbid a module from importing from parent barrel file. This often leads to runtime error `Cannot read ... of undefined`.
Forbid a module from importing from parent barrel file, as it often leads to runtime error `Cannot read ... of undefined`.

It resolves the missing circular import check from [`no-self-import`], while being computationally cheap (see [`no-cycle`]).

## Rule Details

Expand All @@ -14,7 +16,8 @@ export * from "./bar";
export * from "./baz";

// foo/bar.ts (cannot read property `X` of undefined)
import { T } from '..';
import { T } from '@foo'; // absolute
import { T } from '..'; // relative

export const X = T.X;

Expand All @@ -32,7 +35,8 @@ export * from "./bar";
export * from "./baz";

// foo/bar.ts (relative import for code in `foo/`)
import { T } from "./baz";
import { T } from "@foo/baz"; // absolute
import { T } from "./baz"; // relative

export const X = T.X;

Expand All @@ -41,3 +45,11 @@ export enum T {
X = "..."
}
```

## Further Reading

- [Related Discussion](https://github.com/import-js/eslint-plugin-import/pull/2318#issuecomment-1027807460)
- Rule to detect that module imports itself: [`no-self-import`], [`no-cycle`]

[`no-self-import`]: ./no-self-import.md
[`no-cycle`]: ./no-cycle.md

0 comments on commit 123ea7e

Please sign in to comment.