Skip to content

file_exists

Every glob match in paths must correspond to a real file. Use an array to accept any of several names.

Fix: file_create — write a declared content. With an array of paths, the fix creates the first entry.

Optional git_tracked_only: true further requires that the matching file be in git's index — useful for rules like "every release must commit a CHANGELOG entry" where local-only files shouldn't satisfy the requirement. If Git cannot be run or the lint root is not a Git repository, the rule reports a resource_read analysis failure. See The walker and .gitignore for the full semantics.

OptionTypeRequiredDefaultDescription
git_tracked_onlybooleanfalseRestrict matches to files tracked in git's index: entries present in the walked tree but not in git ls-files are skipped. Repository unavailability is an analysis failure when enabled. Default false.
respect_gitignorebooleannullPer-rule override for the workspace respect_gitignore setting. When false, this rule's literal-path checks also stat the filesystem directly, so it sees files that are tracked AND .gitignore-masked (the bazel-style .bazelversion pattern - pitfall #18 in docs/development/CONFIG-AUTHORING.md). Honoured only by file_exists literal paths; glob patterns fall through to the workspace setting. Default: inherit the workspace respect_gitignore.
root_onlybooleanfalseIf true, only files directly at the repository root satisfy the rule.

Plus the common paths, level, id, when, and fix fields. This kind does not support expect_matches; its empty-scope semantics are kind-specific. This table is generated from the JSON Schema; option types and defaults are authoritative.

The rule fires on this repository:

  • the repository

    ✗ error has-readme

    expected a file matching [README.md] at the repo root

  • Cargo.toml✓
Cargo.toml
[package]
name = "demo"

With this .alint.yml:

version: 1
rules:
- id: has-readme
kind: file_exists
paths: README.md
root_only: true
level: error

alint check reports:

Terminal window
--- Repository-level -----------------------------------------------------------
x error has-readme
expected a file matching [README.md] at the repo root
Summary (1 violation):
x 1 error
0 passing * 1 failing

A repository with the README present

Section titled "A repository with the README present"

This repository is compliant:

  • Cargo.toml✓
  • README.md✓
Cargo.toml
[package]
name = "demo"
README.md
# demo

With this .alint.yml:

version: 1
rules:
- id: has-readme
kind: file_exists
paths: README.md
root_only: true
level: error

alint check reports:

Terminal window
v All 1 rule(s) passed.