Envsentry
A command-line tool for analyzing environment variables in Rust source code and comparing them with an environment file.
Features
- Find Unused Variables: Identifies environment variables defined in your
.envfile that are not used in your source code. - Identify Missing Variables: Detects calls to
env::var,std::env::var,env!, etc., in your code where the corresponding variable is missing from your.envfile. - Detailed Reports: Provides precise file paths, line numbers, and column numbers for all occurrences and definitions.
- Fast and Efficient: Uses regular expressions for rapid source code scanning and
walkdirfor efficient file traversal.
Installation
Since envsentry is a Rust project, you can build it from source using cargo:
Usage
To run envsentry, you need to provide the path to your environment file and the directory containing your source code.
Options
-e, --env-file <ENV_FILE>: Path to the environment file (e.g.,.env) containing all the variables to check against.-s, --src-dir <SRC_DIR>: Path to the directory containing the source code (it recursively scans for.rsfiles).-h, --help: Display help information.-V, --version: Display version information.
Supported Syntax
envsentry scans for the following environment variable access patterns:
std::env::var("KEY")env::var("KEY")std::env::var_os("KEY")env::var_os("KEY")env!("KEY")option_env!("KEY")var("KEY")(if imported)
It supports standard .env file formats, including:
KEY=VALUEexport KEY=VALUE- Comments starting with
#
Example Output
Running envsentry...
Environment file: .env
Source directory: ./src
Unused env variable:
DEBUG_MODE (.env:5)
Missing env variable:
API_SECRET (./src/auth.rs:42:25)
License
This project is licensed under the MIT License - see the LICENSE file for details.