You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
killercup opened this issue
Feb 7, 2016
· 2 comments
Labels
A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.L-styleLint: Belongs in the style lint group
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 nota 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 nota 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.
The text was updated successfully, but these errors were encountered:
mcarton
added
E-medium
Call for participation: Medium difficulty level problem and requires some initial experience.
T-AST
Type: Requires working with the AST
A-lint
Area: New lints
labels
Feb 25, 2016
I think this issue can be closed as "completed" 🎉 I believe the lint uninlined_format_args implements @killercup 's original feature request. I'm not sure when it was introduced, but it appears to me to be equivalent to the requested feature. Feel free to correct me. 😸
Kind of. It was about naming the parameters using =, but now that we can inline format arguments, it's not as big of an issue. It's still applicable when it's not a single segment path to a local though, like original_name = get_original_name(self) (I believe you can do that?)
A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.L-styleLint: Belongs in the style lint group
I propose a new lint which suggests to use named parameters in
format!
string, ifformat!
is the syntax extension used inprintln!
,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:
to this:
The code is from cargo, I added the renames just to show they are supported and to make the substitutions more readable.
The text was updated successfully, but these errors were encountered: