Skip to content
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
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')
18 changes: 18 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,15 @@ impl AlwaysFixableViolation for DictGetWithNoneDefault {
}
}

/// Returns whether the given environment variable is allowed to be lowercase.
///
/// References:
/// - <https://unix.stackexchange.com/a/212972/>
/// - <https://about.gitlab.com/blog/2021/01/27/we-need-to-talk-no-proxy/#http_proxy-and-https_proxy/>
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 +159,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 +207,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