File Policies
The files policy domain validates files, directories, and symlinks across your workspace.
Each key under files is the path of a file, directory, or symlink. Its value is either a FilePolicy or an array of FilePolicys.
FilePolicy
FilePolicy extends the shared Policy, so it inherits its options.
| Option | Type | Default | Description |
|---|---|---|---|
kind | "file" | "directory" | "symlink" | — | Expected filesystem item kind. When omitted, any filesystem item kind is accepted. |
content | string | RegExp | — | Expected file contents (exact string or RegExp) |
autofix | boolean | false | Automatically create, remove, or overwrite files with moniq fix (string content only) |
Examples
presence
Control whether a file must exist, may exist, or must not exist.
"required"— the file must exist."optional"— the file may exist."forbidden"— the file must not exist.
export default defineConfig({
files: {
"README.md": {
presence: "required",
},
},
});include
Apply a policy only to selected packages.
export default defineConfig({
files: {
"README.md": {
include: ["packages/*"],
},
},
});exclude
Exclude specific packages after matching include.
export default defineConfig({
files: {
"tsconfig.json": {
include: ["*"],
exclude: ["packages/legacy"],
},
},
});content (string)
Require file contents to exactly match a string.
export default defineConfig({
files: {
".nvmrc": {
include: ["."],
kind: "file",
content: "24",
},
},
});content (RegExp)
Match file contents using a regular expression.
export default defineConfig({
files: {
"README.md": {
kind: "file",
content: /^# /,
},
},
});autofix
Autofixes are limited to the following operations:
- create missing
presence: "required"files or directories (only whenkindis explicitly set to"file"or"directory") - remove
presence: "forbidden"items - overwrite files whose
contentis an exact string when their contents differ
TIP
Run moniq fix to apply available autofixes.
export default defineConfig({
files: {
".env": {
presence: "forbidden",
autofix: true,
},
".nvmrc": {
include: ["."],
kind: "file",
content: "24",
autofix: true,
},
},
});severity
Use "warn" to report violations without failing the process.
export default defineConfig({
files: {
".editorconfig": {
include: ["."],
presence: "required",
severity: "warn",
},
},
});description
Displayed alongside diagnostics to explain why the policy exists.
export default defineConfig({
files: {
".editorconfig": {
include: ["."],
description:
"The workspace should use a single shared EditorConfig file.",
},
},
});