-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
A-lintArea: New lintsArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.L-styleLint: Belongs in the style lint groupLint: Belongs in the style lint group
Description
I propose a new lint which suggests to use named parameters in format!
string, if
- more than 3 parameters are used,
- or one parameter (the same binding) is used more than once
format!
is the syntax extension used in println!
, panic!
and many other string formatting macros. It supports, among a lot of other cool stuff, named parameters. This is described in the fmt docs.
Long strings with lot's of substitutions (or repeated substitutions) become much more readable with named parameters. Just compare:
bail!("\
cannot replace `{}` with `{}`, the source `{}` supports checksums,
but `{}` does not
a lock file compatible with `{}` cannot be generated in this situation
", orig_name, name, supports, no_support, orig_name);
to this:
bail!("\
cannot replace `{orig_name}` with `{new}`, the source `{supporting}` supports checksums,
but `{not_supporting}` does not
a lock file compatible with `{orig_name}` cannot be generated in this situation
", original=orig_name, new=name, supporting=supports, not_supporting=no_support);
The code is from cargo, I added the renames just to show they are supported and to make the substitutions more readable.
stanislav-tkach
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.L-styleLint: Belongs in the style lint groupLint: Belongs in the style lint group