adotenv-lint
Optional lint rules and verified fixes for adotenv
documents.
The linter is a companion crate: lint policy does not belong in the parser
core. Findings are structured and never contain values. A finding may carry a
fix that is applied through adotenv's verified edit or format APIs.
use ;
let doc = parse_strict?;
let findings = lint;
assert_eq!;
let fixed = apply_fix?;
assert_eq!;
# Ok::
CLI
adotenv-lint [options] <file-or-directory>...
Examples:
adotenv-lint --key-order --key-case upper .env
adotenv-lint --format=json --recursive .
adotenv-lint --format=github --key-order .
adotenv-lint --recursive --exclude='target/**' .
adotenv-lint --max-input-bytes 1048576 --max-lines 10000 .env
Without --fix the CLI is report-only. With --fix it applies compatible
verified fixes in batches and rewrites changed files through a temporary file
in the same directory. With no path it searches the current directory
recursively, even when the configuration sets recursive = false. It
discovers .env and .env.* files with --recursive, skips
.git, target and node_modules, and exits with 0 for no findings (or all
findings fixed), 1 for remaining findings and 2 for usage, read, parse or
write errors. Human output reports the configured severity as
severity[rule]; JSON includes severity, and GitHub annotations use the
matching error, warning or notice level. The Windows replace fallback is
best-effort and not crash-atomic, matching the CLI write contract.
Configuration
By default the command discovers .adotenv-lint.toml from the current
directory upward. Use --config <path> to select another file. Command-line
options override configuration values.
= "portable"
= "json"
= true
= true
= "upper"
= "double"
= "none"
= true
= ["target/**", "vendor/**"]
[]
= "error"
= "warning"
= "off"
All fields are optional. Unknown fields and unknown rules are rejected so
typos are visible. rules values are off, warning or error; off
disables the rule. key-order is enabled by its rule severity. warning and
error for key-case, quote-style and whitespace only set the reported
severity; those rules still need their top-level policy values. CLI options
override the corresponding configuration values, and --exclude replaces
configured ignore patterns. Ignore globs match a full path, a basename, a
path relative to the discovery root, or a path suffix for LSP document URIs,
so patterns such as target/** also apply to absolute editor URIs.
Configuration is searched from the working directory upward until a
.adotenv-lint.toml is found. --config <path> selects an explicit file.
Library policy API
The same configuration model is available without the CLI:
use ;
let start = current_dir?;
let config = load_effective_config?;
let mut policy = default;
if let Some = config
assert_eq!;
# Ok::
load_effective_config handles explicit paths and ancestor discovery.
LintConfig::from_toml is available for callers that already have the source.
LintPolicy carries the resolved dialect, format, recursive mode, lint rules
and ignored glob patterns, so the language server can share the CLI policy
without a second parser or discovery implementation.
Rules
The default policy reports duplicate keys only. Enable the other rules explicitly:
| Rule | Default | Rationale |
|---|---|---|
duplicate-key |
on | Repeated declarations are usually accidental and make lookup depend on dialect policy. |
key-order |
off | Sorting is a style choice; some files group related keys deliberately. |
key-case |
off | Upper- and lowercase keys are both common in the wild. |
quote-style |
preserve | Quote policy depends on the project and on values that contain references. |
whitespace |
preserve | Whitespace policy is project-specific; formatting is opt-in. |
Findings include the rule, configured severity, one-based line, source span,
key and an optional verified fix. Key-order findings cover a whole group and
have no key; groups that Document::sort refuses to reorder are still reported
without a fix because no verified sort edit exists. apply_fix applies one
fix; apply_batch applies
independent renames together and can follow them with sorting and one format
policy. Parse diagnostics remain available from adotenv::parse.
This crate requires Rust 1.81 and does not change the core crate's no_std or
dependency-free guarantees.
Version 0.1.0 was the first published release of the companion crate. Version 0.2.0 added the shared configuration loader and ignored-path API used by the CLI and language server. Version 0.2.1 fixes rooted ignore matching, severity output and explicit whitespace-option precedence, and reports unsortable key-order groups without a fix.