Skip to content

Commit

Permalink
[flake8-bandit] Check S105 for annotated assignment (#15059)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
tarasmatsyk authored Dec 19, 2024
1 parent 2802cbd commit 85e71ba
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
password = safe = "s3cr3t"
PASSWORD = "s3cr3t"
PassWord = "s3cr3t"
password: str = "s3cr3t"
password: Final = "s3cr3t"

d["password"] = "s3cr3t"
d["pass"] = "s3cr3t"
Expand Down
9 changes: 9 additions & 0 deletions crates/ruff_linter/src/checkers/ast/analyze/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,15 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
if checker.enabled(Rule::NonPEP695TypeAlias) {
pyupgrade::rules::non_pep695_type_alias(checker, assign_stmt);
}
if checker.enabled(Rule::HardcodedPasswordString) {
if let Some(value) = value.as_deref() {
flake8_bandit::rules::assign_hardcoded_password_string(
checker,
value,
std::slice::from_ref(target),
);
}
}
if checker.settings.rules.enabled(Rule::UnsortedDunderAll) {
ruff::rules::sort_dunder_all_ann_assign(checker, assign_stmt);
}
Expand Down
Loading

0 comments on commit 85e71ba

Please sign in to comment.