Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@

if env := os.environ['FOO']:
pass

os.environ['https_proxy']
os.environ.get['http_proxy']
os.getenv('no_proxy')
13 changes: 13 additions & 0 deletions crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ impl AlwaysFixableViolation for DictGetWithNoneDefault {
}
}

fn is_lowercase_allowed(env_var: &str) -> bool {
matches!(env_var, "https_proxy" | "http_proxy" | "no_proxy")
}

/// SIM112
pub(crate) fn use_capital_environment_variables(checker: &mut Checker, expr: &Expr) {
// Ex) `os.environ['foo']`
Expand Down Expand Up @@ -150,6 +154,10 @@ pub(crate) fn use_capital_environment_variables(checker: &mut Checker, expr: &Ex
return;
}

if is_lowercase_allowed(env_var) {
return;
}

let capital_env_var = env_var.to_ascii_uppercase();
if &capital_env_var == env_var {
return;
Expand Down Expand Up @@ -194,6 +202,11 @@ fn check_os_environ_subscript(checker: &mut Checker, expr: &Expr) {
else {
return;
};

if is_lowercase_allowed(env_var) {
return;
}

let capital_env_var = env_var.to_ascii_uppercase();
if &capital_env_var == env_var {
return;
Expand Down