noctcore-architecture/no-cross-feature-imports
A file in one feature may not import runtime code from another feature.
Recommended preset: error · Autofix: no · Suggestions: no · Type information: not needed
Features are meant to be decoupled: a change inside feature board should never be able to ripple
into feature projects. When one feature reaches directly into another’s internals, that boundary
erodes and the two become one tangled unit. Shared code belongs outside the feature root (a lib,
hooks, or similar module) or in a designated shared feature (default ui) that everything is
allowed to import.
What it flags
Section titled “What it flags”For a file that lives under <featureRoot>/<feature>/…, the rule reports any import whose target
resolves to a different feature under the same root, on every source-carrying construct:
- static
import … from '…' - dynamic
import('…') export … from '…'andexport * from '…'re-export laundering
Both the alias form (<alias>/<feature>/…) and relative paths that climb into another feature
(../../projects/…) are detected.
// rule options: {"featureRoot":"components","alias":"@/components","sharedFeatures":["ui"]}import { Button } from '@/components/ui/Button'; // shared featureimport { cn } from '@/lib/utils'; // non-feature moduleimport { TaskCard } from '../TaskCard/TaskCard'; // same feature// rule options: {"featureRoot":"components","alias":"@/components","sharedFeatures":["ui"]}import { ProjectCard } from '@/components/projects/ProjectCard'; // cross-featureWhat it does not flag
Section titled “What it does not flag”- Imports of the current feature, of a shared feature, or of non-feature modules (
@/lib/utils, bare packages likezod). - Type-only imports and re-exports, by default (flip
allowTypeImportsto forbid them). - Files outside any feature, such as
routes/projects.tsx. - A dynamic
import(name)whose source is not a string literal, since it cannot be resolved statically.
Options
Section titled “Options”| Option | Type | Default | Meaning |
|---|---|---|---|
featureRoot |
string |
'components' |
The directory segment whose immediate children are features. |
alias |
string |
'@/components' |
The import-alias prefix that maps onto featureRoot. |
sharedFeatures |
string[] |
['ui'] |
Features every other feature is allowed to import. |
allowTypeImports |
boolean |
true |
When true, import type / export type cross-feature imports are permitted. |
'noctcore-architecture/no-cross-feature-imports': ['error', { featureRoot: 'components', alias: '@/components', sharedFeatures: ['ui'], allowTypeImports: true,}]When not to use it
Section titled “When not to use it”If your app is not organized as sibling features under a single root, or you allow features to depend on each other freely, this rule does not apply.