Skip to main content

Crate alint_rules

Crate alint_rules 

Source
Expand description

Built-in rule implementations for alint.

Rules are registered into an alint_core::RuleRegistry via register_builtin. Each kind has its own submodule.

Modules§

case
Case-convention detectors used by filename_case and path_case.
changeset_requires_path
changeset_requires_path — the <since>...HEAD diff must ADD a file matching add_glob:. The “did you add a changelog entry?” gate (prettier changelog_unreleased/, cpython Misc/NEWS.d/next/, pnpm .changeset/*.md).
command
command — shell out to an external CLI per matched file.
command_idempotent
command_idempotent — a declared check-mode command must be a no-op. The check-mode-idempotence sibling of generated_file_fresh: run a user-declared formatter/checker in its --check mode once (single-shot); exit 0 = formatter-clean, non-zero = violation(s). Optional files_from / files_pattern attributes per-file violations from the tool’s own offender list. alint never runs a mutating formatter and never writes the working tree itself.
commented_out_code
commented_out_code — heuristic detector for blocks of commented-out source code (as opposed to prose comments, license headers, doc comments, or ASCII banners).
cross_file
cross_file — a value (or set of values, or the whole content, or a set of paths) extracted from one authoritative source file must hold a relation: to one or more targets (or the filesystem). The unified cross-file value-relation kind (architecture-synthesis primitive A): one kind, a relation: knob, over the shared crate::extract + normalize. Design + open questions: docs/design/v0.12/cross_file.md.
dir_absent
dir_absent — no directory matching paths may exist.
dir_contains
dir_contains — every directory matching select must have at least one direct child matching each glob in require. Sugar over for_each_dir + file_exists for the common shape “this dir must have X, Y, and Z.”
dir_exists
dir_exists — at least one directory matching paths must exist.
dir_only_contains
dir_only_contains — every direct child file of a directory matching select: must match at least one glob in allow:. Subdirectories are not checked (use dir_absent if you need to forbid nested directories).
every_matching_has
every_matching_has — every file OR directory matching select must satisfy every rule in require. Sugar over for_each_file + for_each_dir: one rule that iterates both entry kinds so users who don’t care whether a glob matches files or dirs can write a single rule instead of two.
executable_bit
executable_bit — assert every file in scope either has the Unix +x bit set (require: true) or does not (require: false).
executable_has_shebang
executable_has_shebang — every +x file in scope must begin with a shebang line (#!).
file_absent
file_absent — emit a violation for every file matching paths.
file_content_forbidden
file_content_forbidden — files in scope must NOT match a regex.
file_content_matches
file_content_matches — every file in scope must match a regex.
file_ends_with
file_ends_with — every file in scope must end with the configured suffix (byte-level).
file_exists
file_exists — require that at least one file matching any of the given globs exists in the repository.
file_footer
file_footer — last N lines of each file in scope must match a pattern.
file_graph
file_graph — assemble the repo’s file → file reference graph from path-based edges and assert a global structural property. The graph layer the 1-level cross-file kinds (registry_paths_resolve, import_gate, pair_hash) can’t express. require: modes: acyclic (no dependency cycle), forbidden_edges (layering firewall), no_dangling (every edge resolves to an existing path), no_orphans (no unreferenced node, save declared roots), and fresh (a generated file embeds its source’s current content hash).
file_hash
file_hash — assert a file’s SHA-256 equals a declared hex string.
file_header
file_header — first N lines of each file in scope must match a pattern.
file_is_ascii
file_is_ascii — every byte in the file must be < 0x80, except codepoints listed in allow:.
file_is_text
file_is_text — every file in scope must be detected as text (not binary).
file_max_lines
file_max_lines — files in scope must have AT MOST max_lines lines. Mirror of crate::file_min_lines; shares the line-counting semantics so the two compose cleanly when both are applied to the same file.
file_max_size
file_max_size — files in scope must be at most max_bytes bytes.
file_min_lines
file_min_lines — files in scope must have at least min_lines lines.
file_min_size
file_min_size — files in scope must be at least min_bytes bytes.
file_shebang
file_shebang — first line of each file in scope must match a shebang regex.
file_starts_with
file_starts_with — every file in scope must begin with the configured prefix (byte-level).
filename_case
filename_case — every file in scope must have a basename whose stem matches a case convention.
filename_regex
filename_regex — every file in scope must have a basename matching a regex. Anchored with ^...$ automatically; use the full basename (including extension) in your pattern.
final_newline
final_newline — every non-empty file in scope must end with a newline byte.
fixers
Shared Fixer implementations, grouped by family.
for_each_dir
for_each_dir — iterate over every directory matching select: and evaluate a nested require: block against each. Path-template tokens in the nested specs are pre-substituted per iteration using the iterated directory as the anchor.
for_each_file
for_each_file — iterate over every file matching select: and evaluate a nested require: block against each. Same mechanics as crate::for_each_dir — differs only in iterating files instead of directories from the FileIndex.
for_each_match
for_each_match — for each line matching select, the line must satisfy a conjunction of require: predicates (matches / forbid / capture equal). The in-file line quantifier (axis ④) and the missing dual of ordered_block’s select: — where ordered_block orders selected lines, this asserts predicates over each one. Per-file rule (the PerFileRule fast path), not cross-file. Design
generated_file_fresh
generated_file_fresh — a committed artefact must match what a declared generator produces. Two modes, selected by shape:
git_blame_age
git_blame_age — fire on lines matching a regex whose git blame author-time is older than a configured threshold.
git_commit_author_allowlist
git_commit_author_allowlist — assert every commit author matches an allowed email and/or name pattern.
git_commit_gpg_signed
git_commit_gpg_signed — assert every commit in scope has a verifying signature (git verify-commit exits 0).
git_commit_message
git_commit_message — assert commit messages match a shape (regex, max subject length, body required).
git_commit_no_fixup
git_commit_no_fixup — fail on residual fixup! / squash! / amend! commits left in the range.
git_commit_signed_off
git_commit_signed_off — assert every commit in scope carries a DCO Signed-off-by: trailer.
git_commit_subject_matches
git_commit_subject_matches — each commit’s subject line (the first line of its message) must match a regex.
git_no_denied_paths
git_no_denied_paths — fire when any tracked file matches a configured denylist of glob patterns.
import_gate
import_gate — forbid imports whose extracted target matches a regex, within a path scope. An architectural import firewall (k8s staging/ layering, airflow core/providers, torch._C, prometheus-imports). Matches the extracted import target (not the raw line) and supports allow exemptions — the precise, low-false-positive specialisation of file_content_forbidden. Per-file rule. Design + open-question resolutions: docs/design/v0.10/import_gate.md.
indent_style
indent_style — every non-blank line in each file in scope must indent with the configured style: tabs or spaces.
io
Shared I/O helpers for content-reading rules.
json_schema_passes
json_schema_passes — assert that a set of JSON / YAML / TOML files validates against a JSON Schema.
line_endings
line_endings — every line in each file in scope must use the configured line ending (lf or crlf). Mixed endings in a single file fail.
line_max_width
line_max_width — cap on characters per line.
markdown_paths_resolve
markdown_paths_resolve — backticked workspace paths in markdown files must resolve to real files or directories.
max_consecutive_blank_lines
max_consecutive_blank_lines — cap the number of blank lines that may appear in a row. A “blank” line is one whose content is empty or only spaces/tabs.
max_directory_depth
max_directory_depth — cap the depth of any path in scope.
max_files_per_directory
max_files_per_directory — cap how many files may live directly under any directory in scope (non-recursive).
no_bidi_controls
no_bidi_controls — flag Unicode bidirectional control characters in source.
no_bom
no_bom — flag files that start with a byte-order mark.
no_case_conflicts
no_case_conflicts — flag two paths that differ only by case (e.g. README.md + readme.md). Such pairs cannot coexist on case-insensitive filesystems (macOS HFS+/APFS default, Windows NTFS in its default mode), so committing them breaks checkouts for those developers.
no_empty_files
no_empty_files — flag zero-byte files in scope.
no_illegal_windows_names
no_illegal_windows_names — reject path components that Windows can’t represent or restore from a checkout.
no_merge_conflict_markers
no_merge_conflict_markers — flag files that still carry unresolved git-merge conflict markers.
no_submodules
no_submodules — flag the presence of a .gitmodules file at the repo root.
no_symlinks
no_symlinks — flag tracked paths that are symbolic links.
no_trailing_whitespace
no_trailing_whitespace — every line in each file in scope must not end with a space or tab.
no_zero_width_chars
no_zero_width_chars — flag invisible zero-width characters that can hide text, break identifiers, or leak data.
ordered_block
ordered_block — the lines between a start / end marker pair must stay sorted (optionally unique) under a configurable comparator. Both markers are optional: omit end to sort from start to EOF, omit both to sort the whole file (the markerless “this file is one sorted list” form — dictionaries, CODEOWNERS, allow-lists). The generic form of the per-project keep-sorted / keep_sorted scripts (protobuf failure_lists is the highest-stakes source). Per-file rule (the PerFileRule fast path), not cross-file. Design + open-question resolutions: docs/design/v0.10/ordered_block.md.
pair
pair — for every file matching primary, require a file matching the partner template to exist somewhere in the tree.
pair_changed_together
pair_changed_together — if any if_changed: path is in the <since>...HEAD diff, at least one then_changed: path must be too. The co-change gate (rust rustdoc-json-types FORMAT_VERSION must bump when the format struct changes; “version.txt and the lockfile change together”). The changeset_requires_path sibling.
pair_hash
pair_hash — a target file must carry the digest of a source file.
registry_paths_resolve
registry_paths_resolve — a manifest file enumerates path-like entries; each must resolve to an on-disk artefact. Optional reverse “orphan” check: on-disk artefacts in a declared space that no entry references.
shebang_has_executable
shebang_has_executable — every file that starts with #! must have the Unix +x bit set.
structured_path
Structured-query rule family: {json,yaml,toml,xml}_path_{equals,matches}.
unique_by
unique_by — flag any group of files (matching select:) that share the same rendered key. The key is a path template evaluated per matched file; default is {basename} (catches any two files with the same name regardless of directory).

Functions§

builtin_registry
Convenience constructor that returns a fresh registry pre-populated with every built-in rule.
register_builtin
Register every built-in rule kind into the given registry.