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_caseandpath_case. - 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 ofgenerated_file_fresh: run a user-declared formatter/checker in its--checkmode once (single-shot); exit0= formatter-clean, non-zero = violation(s). Optionalfiles_from/files_patternattributes 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_ value_ equals cross_file_value_equals— a value extracted from one authoritative file must equal a value extracted from one or more other files. The cross-file value-coherence sibling ofregistry_paths_resolve(path existence); sharescrate::extract. Design + open-question resolutions:docs/design/v0.10/cross_file_value_equals.md.- dir_
absent dir_absent— no directory matchingpathsmay exist.- dir_
contains dir_contains— every directory matchingselectmust have at least one direct child matching each glob inrequire. Sugar overfor_each_dir+file_existsfor the common shape “this dir must have X, Y, and Z.”- dir_
exists dir_exists— at least one directory matchingpathsmust exist.- dir_
only_ contains dir_only_contains— every direct child file of a directory matchingselect:must match at least one glob inallow:. Subdirectories are not checked (usedir_absentif you need to forbid nested directories).- every_
matching_ has every_matching_has— every file OR directory matchingselectmust satisfy every rule inrequire. Sugar overfor_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+xbit set (require: true) or does not (require: false).- executable_
has_ shebang executable_has_shebang— every+xfile in scope must begin with a shebang line (#!).- file_
absent file_absent— emit a violation for every file matchingpaths.- 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_
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.- 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 MOSTmax_lineslines. Mirror ofcrate::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 mostmax_bytesbytes.- file_
min_ lines file_min_lines— files in scope must have at leastmin_lineslines.- file_
min_ size file_min_size— files in scope must be at leastmin_bytesbytes.- 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
Fixerimplementations, grouped by family. - for_
each_ dir for_each_dir— iterate over every directory matchingselect:and evaluate a nestedrequire: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 matchingselect:and evaluate a nestedrequire:block against each. Same mechanics ascrate::for_each_dir— differs only in iterating files instead of directories from theFileIndex.- generated_
file_ fresh generated_file_fresh— a committed file must match a declared generator’s stdout. A non-mutating freshness check: alint does NOT run codegen as a build step; this only verifies that the committed artefact equals what the user-declared, maintainer-trusted generator produces, by capturing its stdout — it never writes the working tree.- git_
blame_ age git_blame_age— fire on lines matching a regex whosegit blameauthor-time is older than a configured threshold.- git_
commit_ message git_commit_message— assert commit messages match a shape (regex, max subject length, body required).- 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 (k8sstaging/layering, airflow core/providers,torch._C, prometheus-imports). Matches the extracted import target (not the raw line) and supportsallowexemptions — the precise, low-false-positive specialisation offile_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:tabsorspaces.- 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 (lforcrlf). 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.gitmodulesfile 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 astart/endmarker pair must stay sorted (optionally unique) under a configurable comparator. The generic form of the per-projectkeep-sorted/keep_sortedscripts (protobuffailure_listsis the highest-stakes source). Per-file rule (thePerFileRulefast path), not cross-file. Design + open-question resolutions:docs/design/v0.10/ordered_block.md.- pair
pair— for every file matchingprimary, require a file matching thepartnertemplate to exist somewhere in the tree.- 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+xbit set.- structured_
path - Structured-query rule family:
{json,yaml,toml,xml}_path_{equals,matches}. - unique_
by unique_by— flag any group of files (matchingselect:) that share the same renderedkey. 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.