Skip to content

Commit

Permalink
Disallow std::env::var (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 authored Feb 13, 2025
1 parent 9d3f938 commit 0aae916
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
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

0 comments on commit 0aae916

Please sign in to comment.