Created
November 28, 2023 09:12
-
-
Save AriPerkkio/fab0f24753b0f8457b63da187a4aee9e to your computer and use it in GitHub Desktop.
import/no-restricted-paths config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Forbid importing modules directly from feature directories | |
// Allow importing from feature directory's entrypoint, e.g. src/site/index.ts | |
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-restricted-paths.md | |
"import/no-restricted-paths": [ | |
"error", | |
{ | |
zones: ["actions", "admin", "api", "site", "shared"] | |
.map((directory) => [ | |
{ | |
from: `./src/${directory}/!(index.ts|pages)/**`, | |
target: [`./src/!(${directory})/**`], | |
message: 'Importing feature specific files directly is forbidden. Add required exports to entrypoint, e.g. "src/site/index.ts"', | |
}, | |
{ | |
from: `./src/${directory}/index.ts`, | |
target: [`./src/${directory}/**`], | |
message: "Importing feature directory's entrypoint from the feature directory is forbidden as it may lead to circular imports. Import the module directly instead.", | |
}, | |
]) | |
.flat(), | |
}, | |
], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment