Skip to content

Instantly share code, notes, and snippets.

@AriPerkkio
Created November 28, 2023 09:12
Show Gist options
  • Save AriPerkkio/fab0f24753b0f8457b63da187a4aee9e to your computer and use it in GitHub Desktop.
Save AriPerkkio/fab0f24753b0f8457b63da187a4aee9e to your computer and use it in GitHub Desktop.
import/no-restricted-paths config
{
// 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