From 9a66cf2ffb5fe6139fa9d9eb79b4c280bb0dfa43 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 21 Nov 2022 19:14:01 -0800 Subject: [PATCH] Fix clippy::uninlined_format_args (pedantic) https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args Signed-off-by: Anders Kaseorg --- flake8_to_ruff/src/parser.rs | 2 +- ruff_dev/src/generate_check_code_prefix.rs | 6 +++--- ruff_dev/src/generate_rules_table.rs | 8 ++++---- ruff_dev/src/print_ast.rs | 2 +- ruff_dev/src/print_cst.rs | 2 +- ruff_dev/src/print_tokens.rs | 2 +- src/check_ast.rs | 2 +- src/checks.rs | 8 ++++---- src/code_gen.rs | 6 +++--- src/main.rs | 2 +- src/mccabe/mod.rs | 2 +- src/message.rs | 4 ++-- src/printer.rs | 4 ++-- src/pyupgrade/plugins/deprecated_unittest_alias.rs | 2 +- src/rules/plugins/convert_exit_to_sys_exit.rs | 6 +++--- 15 files changed, 29 insertions(+), 29 deletions(-) diff --git a/flake8_to_ruff/src/parser.rs b/flake8_to_ruff/src/parser.rs index 03b60e3709..b2b2106cd5 100644 --- a/flake8_to_ruff/src/parser.rs +++ b/flake8_to_ruff/src/parser.rs @@ -92,7 +92,7 @@ impl State { }); } } - Err(_) => eprintln!("Skipping unrecognized prefix: {}", code), + Err(_) => eprintln!("Skipping unrecognized prefix: {code}"), } } codes diff --git a/ruff_dev/src/generate_check_code_prefix.rs b/ruff_dev/src/generate_check_code_prefix.rs index 5e937b15de..d52d803b0b 100644 --- a/ruff_dev/src/generate_check_code_prefix.rs +++ b/ruff_dev/src/generate_check_code_prefix.rs @@ -106,7 +106,7 @@ pub fn main(cli: &Cli) -> Result<()> { 2 => "Tens", 1 => "Hundreds", 0 => "Category", - _ => panic!("Invalid prefix: {}", prefix), + _ => panic!("Invalid prefix: {prefix}"), }; gen = gen.line(format!( "CheckCodePrefix::{prefix} => PrefixSpecificity::{},", @@ -132,10 +132,10 @@ pub fn main(cli: &Cli) -> Result<()> { // Write the output to `src/checks_gen.rs` (or stdout). if cli.dry_run { - println!("{}", output); + println!("{output}"); } else { let mut f = OpenOptions::new().write(true).truncate(true).open(FILE)?; - write!(f, "{}", output)?; + write!(f, "{output}")?; } Ok(()) diff --git a/ruff_dev/src/generate_rules_table.rs b/ruff_dev/src/generate_rules_table.rs index 0cae692f96..7cffb09367 100644 --- a/ruff_dev/src/generate_rules_table.rs +++ b/ruff_dev/src/generate_rules_table.rs @@ -61,7 +61,7 @@ pub fn main(cli: &Cli) -> Result<()> { } if cli.dry_run { - print!("{}", output); + print!("{output}"); } else { // Read the existing file. 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. let mut f = OpenOptions::new().write(true).truncate(true).open(&file)?; - write!(f, "{}\n\n", prefix)?; - write!(f, "{}", output)?; - write!(f, "{}", suffix)?; + write!(f, "{prefix}\n\n")?; + write!(f, "{output}")?; + write!(f, "{suffix}")?; } Ok(()) diff --git a/ruff_dev/src/print_ast.rs b/ruff_dev/src/print_ast.rs index edcfebfe3f..1fccc29415 100644 --- a/ruff_dev/src/print_ast.rs +++ b/ruff_dev/src/print_ast.rs @@ -17,6 +17,6 @@ pub struct Cli { pub fn main(cli: &Cli) -> Result<()> { let contents = fs::read_to_string(&cli.file)?; let python_ast = parser::parse_program(&contents, &cli.file.to_string_lossy())?; - println!("{:#?}", python_ast); + println!("{python_ast:#?}"); Ok(()) } diff --git a/ruff_dev/src/print_cst.rs b/ruff_dev/src/print_cst.rs index 7d31f77e3b..fa4782df00 100644 --- a/ruff_dev/src/print_cst.rs +++ b/ruff_dev/src/print_cst.rs @@ -17,7 +17,7 @@ pub fn main(cli: &Cli) -> Result<()> { let contents = fs::read_to_string(&cli.file)?; match libcst_native::parse_module(&contents, None) { Ok(python_cst) => { - println!("{:#?}", python_cst); + println!("{python_cst:#?}"); Ok(()) } Err(_) => Err(anyhow::anyhow!("Failed to parse CST")), diff --git a/ruff_dev/src/print_tokens.rs b/ruff_dev/src/print_tokens.rs index db1d4d2b51..be867c80d2 100644 --- a/ruff_dev/src/print_tokens.rs +++ b/ruff_dev/src/print_tokens.rs @@ -17,7 +17,7 @@ pub struct Cli { pub fn main(cli: &Cli) -> Result<()> { let contents = fs::read_to_string(&cli.file)?; for (_, tok, _) in lexer::make_tokenizer(&contents).flatten() { - println!("{:#?}", tok); + println!("{tok:#?}"); } Ok(()) } diff --git a/src/check_ast.rs b/src/check_ast.rs index 7ea22fb375..3c6d6ab5bc 100644 --- a/src/check_ast.rs +++ b/src/check_ast.rs @@ -807,7 +807,7 @@ where let name = alias.node.asname.as_ref().unwrap_or(&alias.node.name); let full_name = match module { None => alias.node.name.to_string(), - Some(parent) => format!("{}.{}", parent, alias.node.name), + Some(parent) => format!("{parent}.{}", alias.node.name), }; self.add_binding( name, diff --git a/src/checks.rs b/src/checks.rs index 23e99b41fb..c58876ab39 100644 --- a/src/checks.rs +++ b/src/checks.rs @@ -1334,13 +1334,13 @@ impl CheckKind { match self { // pycodestyle errors CheckKind::AmbiguousClassName(name) => { - format!("Ambiguous class name: `{}`", name) + format!("Ambiguous class name: `{name}`") } CheckKind::AmbiguousFunctionName(name) => { - format!("Ambiguous function name: `{}`", name) + format!("Ambiguous function name: `{name}`") } CheckKind::AmbiguousVariableName(name) => { - format!("Ambiguous variable name: `{}`", name) + format!("Ambiguous variable name: `{name}`") } CheckKind::AssertTuple => { "Assert test is a non-empty tuple, which is always `True`".to_string() @@ -1383,7 +1383,7 @@ impl CheckKind { CheckKind::ImportStarUsage(name, sources) => { let sources = sources .iter() - .map(|source| format!("`{}`", source)) + .map(|source| format!("`{source}`")) .join(", "); format!("`{name}` may be undefined, or defined from star imports: {sources}") } diff --git a/src/code_gen.rs b/src/code_gen.rs index f9f2f98c2d..e5e818566c 100644 --- a/src/code_gen.rs +++ b/src/code_gen.rs @@ -100,7 +100,7 @@ impl SourceGenerator { } 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(()) } @@ -797,7 +797,7 @@ impl SourceGenerator { { self.p(&value.to_string().replace("inf", inf_str))? } - _ => self.p(&format!("{}", value))?, + _ => self.p(&format!("{value}"))?, } } ExprKind::Attribute { value, attr, .. } => { @@ -900,7 +900,7 @@ impl SourceGenerator { .checked_sub(defaults_start) .and_then(|i| args.kw_defaults.get(i)) { - write!(self, "={}", default)?; + write!(self, "={default}")?; } } if let Some(kwarg) = &args.kwarg { diff --git a/src/main.rs b/src/main.rs index 79464c929e..2d2359e7b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -396,7 +396,7 @@ fn main() -> ExitCode { match inner_main() { Ok(code) => code, Err(err) => { - eprintln!("{} {:?}", "error".red().bold(), err); + eprintln!("{} {err:?}", "error".red().bold()); ExitCode::FAILURE } } diff --git a/src/mccabe/mod.rs b/src/mccabe/mod.rs index 316bbaac9c..785c1639b4 100644 --- a/src/mccabe/mod.rs +++ b/src/mccabe/mod.rs @@ -17,7 +17,7 @@ mod tests { #[test_case(3)] #[test_case(10)] 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( Path::new("./resources/test/fixtures/C901.py"), &Settings { diff --git a/src/message.rs b/src/message.rs index c5ff24f158..132b32442e 100644 --- a/src/message.rs +++ b/src/message.rs @@ -66,7 +66,7 @@ impl fmt::Display for Message { self.kind.body(), ); match &self.source { - None => write!(f, "{}", label), + None => write!(f, "{label}"), Some(source) => { let snippet = Snippet { title: Some(Annotation { @@ -97,7 +97,7 @@ impl fmt::Display for Message { // `split_once(' ')` strips "error: " from `message`. let message = DisplayList::from(snippet).to_string(); let (_, message) = message.split_once(' ').unwrap(); - write!(f, "{}", message) + write!(f, "{message}") } } } diff --git a/src/printer.rs b/src/printer.rs index e2e9b6cd5b..9e1f690919 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -88,7 +88,7 @@ impl<'a> Printer<'a> { } for message in outstanding { - println!("{}", message) + println!("{message}") } if self.log_level >= &LogLevel::Default { @@ -119,7 +119,7 @@ impl<'a> Printer<'a> { println!(); } for message in messages { - println!("{}", message) + println!("{message}") } } diff --git a/src/pyupgrade/plugins/deprecated_unittest_alias.rs b/src/pyupgrade/plugins/deprecated_unittest_alias.rs index 53f807221e..09c69ebcf3 100644 --- a/src/pyupgrade/plugins/deprecated_unittest_alias.rs +++ b/src/pyupgrade/plugins/deprecated_unittest_alias.rs @@ -39,7 +39,7 @@ pub fn deprecated_unittest_alias(checker: &mut Checker, expr: &Expr) { ); if checker.patch(check.kind.code()) { check.amend(Fix::replacement( - format!("self.{}", target), + format!("self.{target}"), expr.location, expr.end_location.unwrap(), )); diff --git a/src/rules/plugins/convert_exit_to_sys_exit.rs b/src/rules/plugins/convert_exit_to_sys_exit.rs index 5451e81556..173d22a8b7 100644 --- a/src/rules/plugins/convert_exit_to_sys_exit.rs +++ b/src/rules/plugins/convert_exit_to_sys_exit.rs @@ -41,13 +41,13 @@ fn get_member_import_name_alias(checker: &Checker, module: &str, member: &str) - // `import sys` -> `sys.exit` // `import sys as sys2` -> `sys2.exit` BindingKind::Importation(name, full_name, _) if full_name == module => { - Some(format!("{}.{}", name, member)) + Some(format!("{name}.{member}")) } // e.g. module=os.path object=join // `from os.path import join` -> `join` // `from os.path import join as join2` -> `join2` BindingKind::FromImportation(name, full_name, _) - if full_name == &format!("{}.{}", module, member) => + if full_name == &format!("{module}.{member}") => { 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 // `import os.path ` -> `os.path.join` BindingKind::SubmoduleImportation(_, full_name, _) if full_name == module => { - Some(format!("{}.{}", full_name, member)) + Some(format!("{full_name}.{member}")) } // Non-imports. _ => None,