Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[New] no-parent-barrel-import: Forbid import from parent barrel file#2779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
jonioni wants to merge1 commit intoimport-js:main
base:main
Choose a base branch
Loading
fromjonioni:feat/no-parent-barrel-import

Conversation

jonioni
Copy link

@jonionijonioni commentedMay 8, 2023
edited
Loading

Resolves:#2318 (comment)

Forbid import from parent barrel file which often leads to runtime errorcannot read ... of undefined.

Gien:

  • foo/
    • index.ts
    • bar/
      • index.ts
      • baz.ts
      • qux.ts
    • quux/
      • index.ts
      • ...
// foo/bar/baz.tsimport{T}from'../..';// forbiddenimport{T}from'..';// forbiddenimport{T}from'.';// forbiddenimport{T}from'foo';// forbiddenimport{T}from'foo/bar';// forbiddenimport{T}from'./qux';// permittedimport{T}from'foo/bar/qux';// permittedimport{U}from'../quux';// permittedimport{U}from'foo/quux';// permitted

It resolves the missing cycle check fromno-self-import, while being computationally cheap (overno-cycle)

Rationale

Though it seems that the issue should have been covered by existing rules, there actually isn't one that prevents this circular import / runtime error via parent barrel file (index.js) efficiently.

Related Issue

There is a related rule of a larger scope:#2408 but further adjustment might be needed. Also it seems to be overly restrictive on importing from non-parent folder (forbidsimport example2 from '../dir2'; fromdir1/file.js) which might need more justification.

@jonionijonioni marked this pull request as draftMay 8, 2023 08:26
@jonionijonioniforce-pushed thefeat/no-parent-barrel-import branch from0620062 to9a811b4CompareMay 8, 2023 10:04
@jonioni
Copy link
Author

Hi@ljharb, wondering if you could point out why the tests failed withcontext.report is not a function?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@jonioni

[8]ページ先頭

©2009-2025 Movatter.jp