Skip to content

TS-MODU0002 · relative_import_depth

Measure how far a module climbs out of its own directory to find what it imports.

This is a deterministic rule for typescript. Read its implementation.

Return the greatest number of parent directories any one import in this module traverses. A path that climbs three levels is telling you the two files belong to different parts of the system and somebody reached across anyway. It also breaks the moment either file moves, which is why the depth, rather than any single import, is the measurement worth having.

The finding names the module and the deepest specifier it imports through, with the number of directories that specifier climbs. The repair is a choice, since an alias and a move fix the same climb differently. The value is that depth.

A test that reaches into the tree it exercises climbs by design. A project with configured path aliases should see zero here, because an alias states the boundary the climb was hiding, which is the usual repair.

import { User } from '../../../models/user' returns 3 and wants an alias or a move. import { User } from './models/user' returns 0.

  • Cites “TypeScript documentation”, handbook, module resolution and path mapping. Open reference
  • Adapts typescript-eslint no-restricted-imports. Open reference
  • Cites “Clean Architecture”, boundaries and dependency direction