mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 22:55:08 +00:00
Fix clippy::uninlined_format_args (pedantic)
https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
parent
3205473612
commit
9a66cf2ffb
15 changed files with 29 additions and 29 deletions
|
@ -92,7 +92,7 @@ impl State {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => eprintln!("Skipping unrecognized prefix: {}", code),
|
Err(_) => eprintln!("Skipping unrecognized prefix: {code}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
codes
|
codes
|
||||||
|
|
|
@ -106,7 +106,7 @@ pub fn main(cli: &Cli) -> Result<()> {
|
||||||
2 => "Tens",
|
2 => "Tens",
|
||||||
1 => "Hundreds",
|
1 => "Hundreds",
|
||||||
0 => "Category",
|
0 => "Category",
|
||||||
_ => panic!("Invalid prefix: {}", prefix),
|
_ => panic!("Invalid prefix: {prefix}"),
|
||||||
};
|
};
|
||||||
gen = gen.line(format!(
|
gen = gen.line(format!(
|
||||||
"CheckCodePrefix::{prefix} => PrefixSpecificity::{},",
|
"CheckCodePrefix::{prefix} => PrefixSpecificity::{},",
|
||||||
|
@ -132,10 +132,10 @@ pub fn main(cli: &Cli) -> Result<()> {
|
||||||
|
|
||||||
// Write the output to `src/checks_gen.rs` (or stdout).
|
// Write the output to `src/checks_gen.rs` (or stdout).
|
||||||
if cli.dry_run {
|
if cli.dry_run {
|
||||||
println!("{}", output);
|
println!("{output}");
|
||||||
} else {
|
} else {
|
||||||
let mut f = OpenOptions::new().write(true).truncate(true).open(FILE)?;
|
let mut f = OpenOptions::new().write(true).truncate(true).open(FILE)?;
|
||||||
write!(f, "{}", output)?;
|
write!(f, "{output}")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -61,7 +61,7 @@ pub fn main(cli: &Cli) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if cli.dry_run {
|
if cli.dry_run {
|
||||||
print!("{}", output);
|
print!("{output}");
|
||||||
} else {
|
} else {
|
||||||
// Read the existing file.
|
// Read the existing file.
|
||||||
let file = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
let file = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||||
|
@ -84,9 +84,9 @@ pub fn main(cli: &Cli) -> Result<()> {
|
||||||
|
|
||||||
// Write the prefix, new contents, and suffix.
|
// Write the prefix, new contents, and suffix.
|
||||||
let mut f = OpenOptions::new().write(true).truncate(true).open(&file)?;
|
let mut f = OpenOptions::new().write(true).truncate(true).open(&file)?;
|
||||||
write!(f, "{}\n\n", prefix)?;
|
write!(f, "{prefix}\n\n")?;
|
||||||
write!(f, "{}", output)?;
|
write!(f, "{output}")?;
|
||||||
write!(f, "{}", suffix)?;
|
write!(f, "{suffix}")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -17,6 +17,6 @@ pub struct Cli {
|
||||||
pub fn main(cli: &Cli) -> Result<()> {
|
pub fn main(cli: &Cli) -> Result<()> {
|
||||||
let contents = fs::read_to_string(&cli.file)?;
|
let contents = fs::read_to_string(&cli.file)?;
|
||||||
let python_ast = parser::parse_program(&contents, &cli.file.to_string_lossy())?;
|
let python_ast = parser::parse_program(&contents, &cli.file.to_string_lossy())?;
|
||||||
println!("{:#?}", python_ast);
|
println!("{python_ast:#?}");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub fn main(cli: &Cli) -> Result<()> {
|
||||||
let contents = fs::read_to_string(&cli.file)?;
|
let contents = fs::read_to_string(&cli.file)?;
|
||||||
match libcst_native::parse_module(&contents, None) {
|
match libcst_native::parse_module(&contents, None) {
|
||||||
Ok(python_cst) => {
|
Ok(python_cst) => {
|
||||||
println!("{:#?}", python_cst);
|
println!("{python_cst:#?}");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(_) => Err(anyhow::anyhow!("Failed to parse CST")),
|
Err(_) => Err(anyhow::anyhow!("Failed to parse CST")),
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub struct Cli {
|
||||||
pub fn main(cli: &Cli) -> Result<()> {
|
pub fn main(cli: &Cli) -> Result<()> {
|
||||||
let contents = fs::read_to_string(&cli.file)?;
|
let contents = fs::read_to_string(&cli.file)?;
|
||||||
for (_, tok, _) in lexer::make_tokenizer(&contents).flatten() {
|
for (_, tok, _) in lexer::make_tokenizer(&contents).flatten() {
|
||||||
println!("{:#?}", tok);
|
println!("{tok:#?}");
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -807,7 +807,7 @@ where
|
||||||
let name = alias.node.asname.as_ref().unwrap_or(&alias.node.name);
|
let name = alias.node.asname.as_ref().unwrap_or(&alias.node.name);
|
||||||
let full_name = match module {
|
let full_name = match module {
|
||||||
None => alias.node.name.to_string(),
|
None => alias.node.name.to_string(),
|
||||||
Some(parent) => format!("{}.{}", parent, alias.node.name),
|
Some(parent) => format!("{parent}.{}", alias.node.name),
|
||||||
};
|
};
|
||||||
self.add_binding(
|
self.add_binding(
|
||||||
name,
|
name,
|
||||||
|
|
|
@ -1334,13 +1334,13 @@ impl CheckKind {
|
||||||
match self {
|
match self {
|
||||||
// pycodestyle errors
|
// pycodestyle errors
|
||||||
CheckKind::AmbiguousClassName(name) => {
|
CheckKind::AmbiguousClassName(name) => {
|
||||||
format!("Ambiguous class name: `{}`", name)
|
format!("Ambiguous class name: `{name}`")
|
||||||
}
|
}
|
||||||
CheckKind::AmbiguousFunctionName(name) => {
|
CheckKind::AmbiguousFunctionName(name) => {
|
||||||
format!("Ambiguous function name: `{}`", name)
|
format!("Ambiguous function name: `{name}`")
|
||||||
}
|
}
|
||||||
CheckKind::AmbiguousVariableName(name) => {
|
CheckKind::AmbiguousVariableName(name) => {
|
||||||
format!("Ambiguous variable name: `{}`", name)
|
format!("Ambiguous variable name: `{name}`")
|
||||||
}
|
}
|
||||||
CheckKind::AssertTuple => {
|
CheckKind::AssertTuple => {
|
||||||
"Assert test is a non-empty tuple, which is always `True`".to_string()
|
"Assert test is a non-empty tuple, which is always `True`".to_string()
|
||||||
|
@ -1383,7 +1383,7 @@ impl CheckKind {
|
||||||
CheckKind::ImportStarUsage(name, sources) => {
|
CheckKind::ImportStarUsage(name, sources) => {
|
||||||
let sources = sources
|
let sources = sources
|
||||||
.iter()
|
.iter()
|
||||||
.map(|source| format!("`{}`", source))
|
.map(|source| format!("`{source}`"))
|
||||||
.join(", ");
|
.join(", ");
|
||||||
format!("`{name}` may be undefined, or defined from star imports: {sources}")
|
format!("`{name}` may be undefined, or defined from star imports: {sources}")
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ impl SourceGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_fmt(&mut self, f: fmt::Arguments<'_>) -> fmt::Result {
|
fn write_fmt(&mut self, f: fmt::Arguments<'_>) -> fmt::Result {
|
||||||
self.buffer.extend(format!("{}", f).as_bytes());
|
self.buffer.extend(format!("{f}").as_bytes());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -797,7 +797,7 @@ impl SourceGenerator {
|
||||||
{
|
{
|
||||||
self.p(&value.to_string().replace("inf", inf_str))?
|
self.p(&value.to_string().replace("inf", inf_str))?
|
||||||
}
|
}
|
||||||
_ => self.p(&format!("{}", value))?,
|
_ => self.p(&format!("{value}"))?,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExprKind::Attribute { value, attr, .. } => {
|
ExprKind::Attribute { value, attr, .. } => {
|
||||||
|
@ -900,7 +900,7 @@ impl SourceGenerator {
|
||||||
.checked_sub(defaults_start)
|
.checked_sub(defaults_start)
|
||||||
.and_then(|i| args.kw_defaults.get(i))
|
.and_then(|i| args.kw_defaults.get(i))
|
||||||
{
|
{
|
||||||
write!(self, "={}", default)?;
|
write!(self, "={default}")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(kwarg) = &args.kwarg {
|
if let Some(kwarg) = &args.kwarg {
|
||||||
|
|
|
@ -396,7 +396,7 @@ fn main() -> ExitCode {
|
||||||
match inner_main() {
|
match inner_main() {
|
||||||
Ok(code) => code,
|
Ok(code) => code,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("{} {:?}", "error".red().bold(), err);
|
eprintln!("{} {err:?}", "error".red().bold());
|
||||||
ExitCode::FAILURE
|
ExitCode::FAILURE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ mod tests {
|
||||||
#[test_case(3)]
|
#[test_case(3)]
|
||||||
#[test_case(10)]
|
#[test_case(10)]
|
||||||
fn max_complexity_zero(max_complexity: usize) -> Result<()> {
|
fn max_complexity_zero(max_complexity: usize) -> Result<()> {
|
||||||
let snapshot = format!("max_complexity_{}", max_complexity);
|
let snapshot = format!("max_complexity_{max_complexity}");
|
||||||
let mut checks = test_path(
|
let mut checks = test_path(
|
||||||
Path::new("./resources/test/fixtures/C901.py"),
|
Path::new("./resources/test/fixtures/C901.py"),
|
||||||
&Settings {
|
&Settings {
|
||||||
|
|
|
@ -66,7 +66,7 @@ impl fmt::Display for Message {
|
||||||
self.kind.body(),
|
self.kind.body(),
|
||||||
);
|
);
|
||||||
match &self.source {
|
match &self.source {
|
||||||
None => write!(f, "{}", label),
|
None => write!(f, "{label}"),
|
||||||
Some(source) => {
|
Some(source) => {
|
||||||
let snippet = Snippet {
|
let snippet = Snippet {
|
||||||
title: Some(Annotation {
|
title: Some(Annotation {
|
||||||
|
@ -97,7 +97,7 @@ impl fmt::Display for Message {
|
||||||
// `split_once(' ')` strips "error: " from `message`.
|
// `split_once(' ')` strips "error: " from `message`.
|
||||||
let message = DisplayList::from(snippet).to_string();
|
let message = DisplayList::from(snippet).to_string();
|
||||||
let (_, message) = message.split_once(' ').unwrap();
|
let (_, message) = message.split_once(' ').unwrap();
|
||||||
write!(f, "{}", message)
|
write!(f, "{message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ impl<'a> Printer<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
for message in outstanding {
|
for message in outstanding {
|
||||||
println!("{}", message)
|
println!("{message}")
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.log_level >= &LogLevel::Default {
|
if self.log_level >= &LogLevel::Default {
|
||||||
|
@ -119,7 +119,7 @@ impl<'a> Printer<'a> {
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
for message in messages {
|
for message in messages {
|
||||||
println!("{}", message)
|
println!("{message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ pub fn deprecated_unittest_alias(checker: &mut Checker, expr: &Expr) {
|
||||||
);
|
);
|
||||||
if checker.patch(check.kind.code()) {
|
if checker.patch(check.kind.code()) {
|
||||||
check.amend(Fix::replacement(
|
check.amend(Fix::replacement(
|
||||||
format!("self.{}", target),
|
format!("self.{target}"),
|
||||||
expr.location,
|
expr.location,
|
||||||
expr.end_location.unwrap(),
|
expr.end_location.unwrap(),
|
||||||
));
|
));
|
||||||
|
|
|
@ -41,13 +41,13 @@ fn get_member_import_name_alias(checker: &Checker, module: &str, member: &str) -
|
||||||
// `import sys` -> `sys.exit`
|
// `import sys` -> `sys.exit`
|
||||||
// `import sys as sys2` -> `sys2.exit`
|
// `import sys as sys2` -> `sys2.exit`
|
||||||
BindingKind::Importation(name, full_name, _) if full_name == module => {
|
BindingKind::Importation(name, full_name, _) if full_name == module => {
|
||||||
Some(format!("{}.{}", name, member))
|
Some(format!("{name}.{member}"))
|
||||||
}
|
}
|
||||||
// e.g. module=os.path object=join
|
// e.g. module=os.path object=join
|
||||||
// `from os.path import join` -> `join`
|
// `from os.path import join` -> `join`
|
||||||
// `from os.path import join as join2` -> `join2`
|
// `from os.path import join as join2` -> `join2`
|
||||||
BindingKind::FromImportation(name, full_name, _)
|
BindingKind::FromImportation(name, full_name, _)
|
||||||
if full_name == &format!("{}.{}", module, member) =>
|
if full_name == &format!("{module}.{member}") =>
|
||||||
{
|
{
|
||||||
Some(name.to_string())
|
Some(name.to_string())
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ fn get_member_import_name_alias(checker: &Checker, module: &str, member: &str) -
|
||||||
// e.g. module=os.path object=join
|
// e.g. module=os.path object=join
|
||||||
// `import os.path ` -> `os.path.join`
|
// `import os.path ` -> `os.path.join`
|
||||||
BindingKind::SubmoduleImportation(_, full_name, _) if full_name == module => {
|
BindingKind::SubmoduleImportation(_, full_name, _) if full_name == module => {
|
||||||
Some(format!("{}.{}", full_name, member))
|
Some(format!("{full_name}.{member}"))
|
||||||
}
|
}
|
||||||
// Non-imports.
|
// Non-imports.
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue