mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:49:50 +00:00
Remove unnecessary quote-stripping method (#3372)
This commit is contained in:
parent
8437399496
commit
c0ad875339
2 changed files with 3 additions and 24 deletions
|
@ -1,9 +1,9 @@
|
|||
use anyhow::{bail, Result};
|
||||
use libcst_native::{Call, Codegen, CodegenState, Dict, DictElement, Expression};
|
||||
use ruff_python_stdlib::str::strip_quotes_and_prefixes;
|
||||
use rustpython_parser::ast::{Excepthandler, Expr};
|
||||
use rustpython_parser::{lexer, Mode, Tok};
|
||||
|
||||
use crate::ast::strings::raw_contents;
|
||||
use crate::ast::types::Range;
|
||||
use crate::cst::matchers::{match_expr, match_module};
|
||||
use crate::fix::Fix;
|
||||
|
@ -37,7 +37,7 @@ pub fn remove_unused_format_arguments_from_dict(
|
|||
DictElement::Simple {
|
||||
key: Expression::SimpleString(name),
|
||||
..
|
||||
} if unused_arguments.contains(&strip_quotes_and_prefixes(name.value)) => None,
|
||||
} if unused_arguments.contains(&raw_contents(name.value)) => None,
|
||||
e => Some(e.clone()),
|
||||
})
|
||||
.collect(),
|
||||
|
|
|
@ -38,22 +38,9 @@ pub fn is_upper(s: &str) -> bool {
|
|||
cased
|
||||
}
|
||||
|
||||
/// Remove prefixes (u, r, b) and quotes around a string. This expects the given
|
||||
/// string to be a valid Python string representation, it doesn't do any
|
||||
/// validation.
|
||||
pub fn strip_quotes_and_prefixes(s: &str) -> &str {
|
||||
match STRING_QUOTE_PREFIX_REGEX.captures(s) {
|
||||
Some(caps) => match caps.name("raw") {
|
||||
Some(m) => m.as_str(),
|
||||
None => s,
|
||||
},
|
||||
None => s,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::str::{is_lower, is_upper, strip_quotes_and_prefixes};
|
||||
use crate::str::{is_lower, is_upper};
|
||||
|
||||
#[test]
|
||||
fn test_is_lower() {
|
||||
|
@ -76,12 +63,4 @@ mod tests {
|
|||
assert!(!is_upper(""));
|
||||
assert!(!is_upper("_"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strip_quotes_and_prefixes() {
|
||||
assert_eq!(strip_quotes_and_prefixes(r#"'a'"#), "a");
|
||||
assert_eq!(strip_quotes_and_prefixes(r#"bur'a'"#), "a");
|
||||
assert_eq!(strip_quotes_and_prefixes(r#"UrB'a'"#), "a");
|
||||
assert_eq!(strip_quotes_and_prefixes(r#""a""#), "a");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue