Skip to content

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.

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 '…' and export * from '…' re-export laundering

Both the alias form (<alias>/<feature>/…) and relative paths that climb into another feature (../../projects/…) are detected.

Correct · src/components/board/Board/Board.tsx
// rule options: {"featureRoot":"components","alias":"@/components","sharedFeatures":["ui"]}
import { Button } from '@/components/ui/Button'; // shared feature
import { cn } from '@/lib/utils'; // non-feature module
import { TaskCard } from '../TaskCard/TaskCard'; // same feature
Incorrect · src/components/board/Board/Board.tsx
// rule options: {"featureRoot":"components","alias":"@/components","sharedFeatures":["ui"]}
import { ProjectCard } from '@/components/projects/ProjectCard'; // cross-feature
  • Imports of the current feature, of a shared feature, or of non-feature modules (@/lib/utils, bare packages like zod).
  • Type-only imports and re-exports, by default (flip allowTypeImports to 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.
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,
}]

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.