Skip to content

may-only-import

Markdown for agents

Rule violations. This text is what archangel docs may-only-import prints.

A file in the files of a mayOnlyImport rule imports a file or package that is neither on the rule’s list nor in those files. When files is a part with a capture, only the files of the same instance count as those files.

src/views/cart.view.tsx
// rule({ files: 'view', mayOnlyImport: ['shared', { packages: ['react'] }] })
import { store } from '../model/store';

An import of a stylesheet counts like any other, so a rule that permits stylesheets lists them, such as '**/*.css'. The options names, specifier, instance and dependency narrow the imports the rule checks, as on may-not-import.

Add within to judge only imports into an area. The rule does not judge an import whose target is outside the area. An empty list is permitted only with an area.

apps/api/src/order/domain/order.entity.ts
// rule({ files: 'entity', mayOnlyImport: ['value-object'], within: 'apps/api/src/**' })
import { save } from '../application/save.use-case'; // reported
import { z } from 'zod'; // outside the area, so not judged

When files names exactly one part with a capture, the rule permits its own files only in the same instance. With a list, such as files: ['feature'], the rule permits all instances of its own files. To permit all instances of one part, list the part in mayOnlyImport.

Import only what the rule lists, or add the import’s target to the list if the architecture permits it.