Contract types
Import Linter provides several contract types:
Protected
Prevent modules from being directly imported, except by modules in an allow-list.
Custom contract types
If none of the built in contract types meets your needs, you can define a custom contract type: see Custom Contract Types.
Options used by multiple contracts
-
ignore_imports: Optional list of imports, each in the formmypackage.foo.importer -> mypackage.bar.imported. These imports will be ignored: if the import would cause a contract to be broken, adding it to the list will cause the contract be kept instead. Supports wildcards. -
unmatched_ignore_imports_alerting: The alerting level for handling expressions supplied inignore_importsthat do not match any imports in the graph. Choices are:error: Error if there are any unmatched expressions (default).warn: Print a warning for each unmatched expression.none: Do not alert.
Wildcards
Many contract fields refer to sets of modules - some (but not all) of these support wildcards.
* stands in for a module name, without including subpackages. ** includes subpackages too.
Examples:
mypackage.*: matchesmypackage.foobut notmypackage.foo.bar.mypackage.*.baz: matchesmypackage.foo.bazbut notmypackage.foo.bar.baz.mypackage.*.*: matchesmypackage.foo.barandmypackage.foobar.baz.mypackage.**: matchesmypackage.foo.barandmypackage.foo.bar.baz.mypackage.**.qux: matchesmypackage.foo.bar.quxandmypackage.foo.bar.baz.qux.mypackage.foo*: not a valid expression. (The wildcard must replace a whole module name.)