Skip to content

Commit 85e71ba

Browse files
authored
[flake8-bandit] Check S105 for annotated assignment (#15059)
## Summary A follow up PR on #14991 Ruff ignores hardcoded passwords for typed variables. Add a rule to catch passwords in typed code bases ## Test Plan Includes 2 more test typed variables
1 parent 2802cbd commit 85e71ba

File tree

3 files changed

+185
-154
lines changed

3 files changed

+185
-154
lines changed

crates/ruff_linter/resources/test/fixtures/flake8_bandit/S105.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
password = safe = "s3cr3t"
2222
PASSWORD = "s3cr3t"
2323
PassWord = "s3cr3t"
24+
password: str = "s3cr3t"
25+
password: Final = "s3cr3t"
2426

2527
d["password"] = "s3cr3t"
2628
d["pass"] = "s3cr3t"

crates/ruff_linter/src/checkers/ast/analyze/statement.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,15 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
16581658
if checker.enabled(Rule::NonPEP695TypeAlias) {
16591659
pyupgrade::rules::non_pep695_type_alias(checker, assign_stmt);
16601660
}
1661+
if checker.enabled(Rule::HardcodedPasswordString) {
1662+
if let Some(value) = value.as_deref() {
1663+
flake8_bandit::rules::assign_hardcoded_password_string(
1664+
checker,
1665+
value,
1666+
std::slice::from_ref(target),
1667+
);
1668+
}
1669+
}
16611670
if checker.settings.rules.enabled(Rule::UnsortedDunderAll) {
16621671
ruff::rules::sort_dunder_all_ann_assign(checker, assign_stmt);
16631672
}

0 commit comments

Comments
 (0)