visibility
Category: restriction. Default: off. Fixable: no. Since: 0.1.0.
What it does
Restricts what a folder shows to the code outside it. A module inside a folder can import every module in that folder. A module outside it can import only the modules that the folder makes visible. The rule checks dependencies on local modules.
Options
folders: a list of entries. Each entry has apathand at least one ofpublicandprivate. The rule does nothing when the list is empty.path: globs of the folders.{name}captures a path segment.**matches every folder.public: globs of the modules that code outside the folder can import. The globs are relative to the folder. Withoutpublic, every module is public.private: globs of the modules that code outside the folder cannot import. The globs are relative to the folder.privatewins overpublic.message: Oxcruise shows this text instead of the generic message.
public and private can use the captures of path, and path must capture each one that they use.
A folder is relevant to a dependency only when it contains the target and not the importing module.
If several folders hide the target, the rule reports the outermost one.
Example
A feature shows only its index.ts, and a folder named internal is private to its parent folder, as in the Go language:
{ "folders": [
{ "path": "src/features/{f}", "public": "index.ts", "message": "Import a feature through its index.ts." },
{ "path": "**", "private": "internal" }
] }Ignoring a violation
Put // oxcruise-ignore-next-line visibility -- reason above the dependency.
Configure the rule
{
"rules": {
"visibility": {
"level": "error",
"folders": [
{
"path": "src/features/{f}",
"public": "index.ts",
"message": "Import a feature through its index.ts."
},
{
"path": "**",
"private": "internal"
}
]
}
}
}The object has the level first, then the options of the rule.

