Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested modules #171

Open
KvikullSigurdur opened this issue Jan 28, 2025 · 2 comments
Open

Nested modules #171

KvikullSigurdur opened this issue Jan 28, 2025 · 2 comments

Comments

@KvikullSigurdur
Copy link

Love the idea and would love to implement it in my projects.
I am having some trouble with nested modules. Take for example the file structure:

  • University
    • moduleIndex.ts
    • someUniversityLogic.ts
    • Department
      • moduleIndex.ts
      • someDepartmentLogic.ts

(I am using moduleIndex.ts as my barrel files since the project already includes a lot of index.ts files that are not respected as a module boundary).

In this case I want the University module to encapsulate everything underneath it but since there is a lot there I also want to organise that into further sub modules.

Sheriff does not display any error for statements like import * from "./University/Department/moduleIndex". As long as the import statement points to the moduleIndex at the bottom.

Is this the intended functionality? Or have I somehow managed to misconfigure sheriff?

@rainerhahnekamp
Copy link
Collaborator

Hey, nested modules work. Could you provide a little bit of more context?

  • Does your sheriff.config.ts have the setting { barrelFileName: 'moduleIndex.ts' }?

  • Does sheriff list print out the modules correctly?

  • Why would you expect that the import to moduleIndex would fail, if it is the barrel file?

@Katli95
Copy link

Katli95 commented Jan 31, 2025

Hey, chiming in on @KvikullSigurdur's behalf, we were hoping for sheriff to block imports from a nested "child" module from outside the "parent" module, instead requiring that external imports respect the "parent's" moduleIndex.ts. But we still want it to allow importing from other "sibling" modules within the same "parent" if that clears anything up.

Expanding on the example, we could have the following:

  • /University
    • moduleIndex.ts
    • someUniversityLogic.ts
    • /MathsDepartment
      • moduleIndex.ts
      • mathDepartmentLogic.ts
    • /LanguagesDepartment
      • moduleIndex.ts
      • langDepartmentLogic.ts
  • /Student
    • index.ts

We were expecting sheriff to enforce the following imports

// in /Student/index.ts
import { getLanguageClasses } from "../University/moduleIndex.ts";

but it seems to also allow

// in /Student/index.ts
import { getLanguageClasses } from "../University/LanguagesDepartment/moduleIndex.ts";

But we also want to be able to import from a siblings moduleIndex.ts (the example breaks up a bit here 😅 so just go with it)

// in /University/MathsDepartment/mathDepartmentLogic.ts
import { getLanguageClasses } from "../LanguagesDepartment/moduleIndex.ts";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants