Checks for the use of format!("string literal with no argument")
and format!("{}", foo)
where foo is a string.
Apply with the Grit CLI
grit apply no_useless_format
Replaces a string literal with no argument
BEFORE
let hi = format!("hello");
AFTER
let hi = "hello".to_string();
Replaces with one string literal argument
BEFORE
let greeting = "hello"; let hi = format!("{}", greeting);
AFTER
let greeting = "hello"; let hi = greeting.to_string();
Does not replace necessary formats
RUST
let hi = format!("hello {}", "world"); let another = format!("{:?}", strawberry);