may-only-import
Markdown for agentsRule 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.
Example
Section titled “Example”// 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.
Limit the rule to an area
Section titled “Limit the rule to an area”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.
// rule({ files: 'entity', mayOnlyImport: ['value-object'], within: 'apps/api/src/**' })import { save } from '../application/save.use-case'; // reportedimport { z } from 'zod'; // outside the area, so not judgedInstances
Section titled “Instances”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.
What to do
Section titled “What to do”Import only what the rule lists, or add the import’s target to the list if the architecture permits it.