Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow std::env::var #177

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use fs_err as fs;
fn main() {
// The workspace root directory is not available without walking up the tree
// https://github.com/rust-lang/cargo/issues/3946
#[allow(clippy::disallowed_methods)]
let workspace_root = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).to_path_buf();

commit_info(&workspace_root);
Expand Down
4 changes: 4 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
disallowed-methods = [
"std::env::var",
"std::env::var_os",
]
1 change: 1 addition & 0 deletions lib/constants/src/env_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl EnvVars {
impl EnvVars {
/// Read an environment variable, falling back to pre-commit corresponding variable if not found.
pub fn var_os(name: &str) -> Option<OsString> {
#[allow(clippy::disallowed_methods)]
std::env::var_os(name).or_else(|| {
if let Some(name) = Self::pre_commit_name(name) {
if let Some(val) = std::env::var_os(name) {
Expand Down
3 changes: 1 addition & 2 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![allow(dead_code, unreachable_pub)]

use std::env;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use std::process::Command;
Expand Down Expand Up @@ -65,7 +64,7 @@ impl TestContext {
}

pub fn test_bucket_dir() -> PathBuf {
env::var(EnvVars::PREFLIGIT_INTERNAL__TEST_DIR)
EnvVars::var(EnvVars::PREFLIGIT_INTERNAL__TEST_DIR)
.map(PathBuf::from)
.unwrap_or_else(|_| {
etcetera::base_strategy::choose_base_strategy()
Expand Down
Loading