mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:43 +00:00
Implement flake8-bandit rule S103
(#1636)
This commit is contained in:
parent
8b8e6e44ea
commit
1817f8752b
14 changed files with 346 additions and 49 deletions
|
@ -574,6 +574,53 @@ pub fn followed_by_multi_statement_line(stmt: &Stmt, locator: &SourceCodeLocator
|
|||
match_trailing_content(stmt, locator)
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
/// A simple representation of a call's positional and keyword arguments.
|
||||
pub struct SimpleCallArgs<'a> {
|
||||
pub args: Vec<&'a Expr>,
|
||||
pub kwargs: FxHashMap<&'a str, &'a Expr>,
|
||||
}
|
||||
|
||||
impl<'a> SimpleCallArgs<'a> {
|
||||
pub fn new(args: &'a Vec<Expr>, keywords: &'a Vec<Keyword>) -> Self {
|
||||
let mut result = SimpleCallArgs::default();
|
||||
|
||||
for arg in args {
|
||||
match &arg.node {
|
||||
ExprKind::Starred { .. } => {
|
||||
break;
|
||||
}
|
||||
_ => {
|
||||
result.args.push(arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for keyword in keywords {
|
||||
if let Some(arg) = &keyword.node.arg {
|
||||
result.kwargs.insert(arg, &keyword.node.value);
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
/// Get the argument with the given name or position.
|
||||
/// If the argument is not found with either name or position, return
|
||||
/// `None`.
|
||||
pub fn get_argument(&self, name: &'a str, position: Option<usize>) -> Option<&'a Expr> {
|
||||
if let Some(kwarg) = self.kwargs.get(name) {
|
||||
return Some(kwarg);
|
||||
}
|
||||
if let Some(position) = position {
|
||||
if position < self.args.len() {
|
||||
return Some(self.args[position]);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use anyhow::Result;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue