Skip to content

Commit d17907f

Browse files
authored
chore: clippy & fmt (#378)
1 parent ff43264 commit d17907f

File tree

10 files changed

+32
-35
lines changed

10 files changed

+32
-35
lines changed

src/argc_value.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl ArgcValue {
7777
}
7878
ArgcValue::PositionalSingleFn(id, fn_name) => {
7979
list.push(format!("{}=`{}`", argc_var_name(id), &fn_name));
80-
positional_args.push(format!("`{}`", fn_name));
80+
positional_args.push(format!("`{fn_name}`"));
8181
}
8282
ArgcValue::PositionalMultiple(id, values) => {
8383
let values = values
@@ -98,7 +98,7 @@ impl ArgcValue {
9898
list.push(format!("export {}={}", name, escape_shell_words(value)));
9999
}
100100
ArgcValue::EnvFn(id, fn_name) => {
101-
list.push(format!("export {}=`{}`", id, fn_name,));
101+
list.push(format!("export {id}=`{fn_name}`",));
102102
}
103103
ArgcValue::Hook((before, after)) => {
104104
if *before {
@@ -122,7 +122,7 @@ impl ArgcValue {
122122
} else {
123123
last = format!("{} {}", name, positional_args.join(" "));
124124
}
125-
list.push(format!("{}_fn={}", VARIABLE_PREFIX, name));
125+
list.push(format!("{VARIABLE_PREFIX}_fn={name}"));
126126
}
127127
ArgcValue::ParamFn(name) => {
128128
if positional_args.is_empty() {
@@ -133,7 +133,7 @@ impl ArgcValue {
133133
exit = true;
134134
}
135135
ArgcValue::Error((error, exit)) => {
136-
return format!("command cat >&2 <<-'EOF' \n{}\nEOF\nexit {}", error, exit)
136+
return format!("command cat >&2 <<-'EOF' \n{error}\nEOF\nexit {exit}")
137137
}
138138
}
139139
}

src/bin/argc/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn run() -> Result<i32> {
5252
match argc_cmd {
5353
"--argc-eval" => match run_eval(runtime, args) {
5454
Ok(output) => {
55-
println!("{}", output);
55+
println!("{output}");
5656
}
5757
Err(err) => {
5858
println!(
@@ -122,7 +122,7 @@ fn run() -> Result<i32> {
122122
})?;
123123
}
124124
} else {
125-
print!("{}", script);
125+
print!("{script}");
126126
}
127127
}
128128
"--argc-mangen" => {
@@ -144,7 +144,7 @@ fn run() -> Result<i32> {
144144
};
145145
let commands = [vec!["argc".to_string()], args[3..].to_vec()].concat();
146146
let script = argc::generate_completions(shell, &commands);
147-
print!("{}", script);
147+
print!("{script}");
148148
}
149149
"--argc-compgen" => {
150150
run_compgen(runtime, args.to_vec());
@@ -172,7 +172,7 @@ fn run() -> Result<i32> {
172172
}
173173
"--argc-shell-path" => {
174174
let shell = runtime.shell_path()?;
175-
println!("{}", shell);
175+
println!("{shell}");
176176
}
177177
"--argc-help" => {
178178
println!("{}", get_argc_help(runtime)?)
@@ -433,7 +433,7 @@ fn parse_script_args(args: &[String]) -> Result<(String, String, Vec<String>)> {
433433
let script_file = normalize_script_path(script_file);
434434
let args: Vec<String> = args[1..].to_vec();
435435
let source = fs::read_to_string(&script_file)
436-
.with_context(|| format!("Failed to load script at '{}'", script_file))?;
436+
.with_context(|| format!("Failed to load script at '{script_file}'"))?;
437437
let name = get_script_name(&script_file)?;
438438
let name = name.strip_suffix(".sh").unwrap_or(name);
439439
let mut cmd_args = vec![name.to_string()];

src/command/names_checker.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl NamesChecker {
2424
bail!("{}", Self::conflict_error(tag_name, pos, name, *exist_pos));
2525
}
2626
self.flag_options
27-
.insert(name.to_string(), (pos, format!("{} {}", tag_name, name)));
27+
.insert(name.to_string(), (pos, format!("{tag_name} {name}")));
2828
}
2929
Ok(())
3030
}
@@ -63,9 +63,6 @@ impl NamesChecker {
6363
name_desc: &str,
6464
exist_pos: Position,
6565
) -> String {
66-
format!(
67-
"{}(line {}) has '{}' already exists at line {}",
68-
tag_name, pos, name_desc, exist_pos,
69-
)
66+
format!("{tag_name}(line {pos}) has '{name_desc}' already exists at line {exist_pos}",)
7067
}
7168
}

src/compgen.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pub fn compgen<T: Runtime>(
227227

228228
let break_chars = shell.need_break_chars(runtime, &argc_prefix);
229229
if !break_chars.is_empty() {
230-
let prefix = format!("{}{}", argc_prefix, argc_filter);
230+
let prefix = format!("{argc_prefix}{argc_filter}");
231231
let prefix = match unbalance_quote(&prefix) {
232232
Some((_, i)) => prefix.chars().take(i.saturating_sub(1)).collect(),
233233
None => prefix,
@@ -569,7 +569,7 @@ impl ArgcPathValue {
569569
continue;
570570
}
571571
let path_value = if is_dir {
572-
format!("{value_prefix}{file_name}{}", path_sep)
572+
format!("{value_prefix}{file_name}{path_sep}")
573573
} else {
574574
format!("{value_prefix}{file_name}{suffix}")
575575
};
@@ -638,7 +638,7 @@ impl ArgcPathValue {
638638
cwd = runtime.chdir(&cwd, cd)?;
639639
}
640640
let trims = cwd.len() + 1;
641-
let new_value = format!("{}{sep}{value}", cwd).replace('\\', "/");
641+
let new_value = format!("{cwd}{sep}{value}").replace('\\', "/");
642642
(new_value, trims, FILE_PROTO.into())
643643
}
644644
} else if is_home || value.starts_with(home_p) {
@@ -657,7 +657,7 @@ impl ArgcPathValue {
657657
(path_s, trims, prefix.into())
658658
} else if value.starts_with(sep) {
659659
let new_value = if is_windows_mode {
660-
format!("C:{}", value)
660+
format!("C:{value}")
661661
} else {
662662
value.clone()
663663
};
@@ -679,7 +679,7 @@ impl ArgcPathValue {
679679
if let Some(cd) = cd {
680680
cwd = runtime.chdir(&cwd, cd)?;
681681
}
682-
let new_value = format!("{}{sep}{new_value}", cwd);
682+
let new_value = format!("{cwd}{sep}{new_value}");
683683
let trims = cwd.len() + 1;
684684
(new_value, trims, prefix.to_string())
685685
};

src/mangen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn render_subcommands_section(roff: &mut Roff, cmd: &Command, section: &str) {
155155
for subcmd in &cmd.subcommands {
156156
roff.control("TP", []);
157157
let name = subcmd.full_name();
158-
roff.text([roman(format!("{}({})", name, section))]);
158+
roff.text([roman(format!("{name}({section})"))]);
159159
for line in subcmd.describe.lines() {
160160
roff.text([roman(line)]);
161161
}

src/matcher.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,15 +1393,15 @@ fn comp_symbol(cmd: &Command, ch: char) -> Vec<CompItem> {
13931393
match choices_fn {
13941394
Some(choices_fn) => {
13951395
vec![(
1396-
format!("__argc_fn={}", choices_fn),
1396+
format!("__argc_fn={choices_fn}"),
13971397
String::new(),
13981398
false,
13991399
CompColor::of_value(),
14001400
)]
14011401
}
14021402
None => {
14031403
vec![(
1404-
format!("__argc_value={}", name),
1404+
format!("__argc_value={name}"),
14051405
String::new(),
14061406
false,
14071407
CompColor::of_value(),
@@ -1444,21 +1444,21 @@ fn comp_param(describe: &str, value_name: &str, data: &ParamData) -> Vec<CompIte
14441444
.map(|v| (v.to_string(), String::new(), false, CompColor::of_value()))
14451445
.collect(),
14461446
Either::Right(choices_fn) => vec![(
1447-
format!("__argc_fn={}", choices_fn),
1447+
format!("__argc_fn={choices_fn}"),
14481448
String::new(),
14491449
false,
14501450
CompColor::of_value(),
14511451
)],
14521452
}
14531453
} else {
1454-
let value = format!("__argc_value={}", value_name);
1454+
let value = format!("__argc_value={value_name}");
14551455
vec![(value, describe.into(), false, CompColor::of_value())]
14561456
};
14571457
if let Some(ch) = data.args_delimiter() {
14581458
output.insert(
14591459
0,
14601460
(
1461-
format!("__argc_multi={}", ch),
1461+
format!("__argc_multi={ch}"),
14621462
String::new(),
14631463
false,
14641464
CompColor::of_value(),

src/param.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl Param for FlagOptionParam {
150150
}
151151

152152
for raw_notation in &self.raw_notations {
153-
output.push(format!("<{}>", raw_notation));
153+
output.push(format!("<{raw_notation}>"));
154154
}
155155

156156
if !self.data.describe.is_empty() {
@@ -184,7 +184,7 @@ impl FlagOptionParam {
184184
}
185185
let name = data.name.clone();
186186
let id = if long_prefix.starts_with('+') {
187-
format!("plus_{}", name)
187+
format!("plus_{name}")
188188
} else {
189189
name.clone()
190190
};
@@ -552,7 +552,7 @@ impl Param for PositionalParam {
552552
}
553553
}
554554
if let Some(raw_notation) = self.raw_notation.as_ref() {
555-
output.push(format!("<{}>", raw_notation));
555+
output.push(format!("<{raw_notation}>"));
556556
}
557557
if !self.data.describe.is_empty() {
558558
output.push(self.data.describe.clone());
@@ -891,7 +891,7 @@ impl ParamData {
891891
.iter()
892892
.map(|value| {
893893
if value.chars().any(is_choice_value_terminate) {
894-
format!("\"{}\"", value)
894+
format!("\"{value}\"")
895895
} else {
896896
value.to_string()
897897
}
@@ -902,7 +902,7 @@ impl ParamData {
902902

903903
fn render_default_value(value: &str) -> String {
904904
if value.chars().any(is_default_value_terminate) {
905-
format!("\"{}\"", value)
905+
format!("\"{value}\"")
906906
} else {
907907
value.to_string()
908908
}

src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ fn parse_with_long_flag_name(input: &str) -> nom::IResult<&str, ParamData> {
377377
fn parse_no_long_flag_name(input: &str) -> nom::IResult<&str, ParamData> {
378378
fn parser(input: &str) -> nom::IResult<&str, ParamData> {
379379
map(satisfy(is_short_char), |ch| {
380-
ParamData::new(&format!("{}", ch))
380+
ParamData::new(&format!("{ch}"))
381381
})(input)
382382
}
383383
map(pair(parser, opt(tag("*"))), |(mut arg, multiple)| {

src/runtime/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ where
9090
.and_then(|exe_path| self.parent_path(&exe_path))
9191
{
9292
if self.is_windows() {
93-
path_env = format!("{};{}", exe_dir, path_env)
93+
path_env = format!("{exe_dir};{path_env}")
9494
} else {
95-
path_env = format!("{}:{}", exe_dir, path_env)
95+
path_env = format!("{exe_dir}:{path_env}")
9696
}
9797
}
9898
path_env

src/shell.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl Shell {
134134
value
135135
};
136136
if i == 0 && add_space_to_first_candidate {
137-
new_value = format!(" {}", new_value)
137+
new_value = format!(" {new_value}")
138138
};
139139
let description = self.comp_description(&description, "(", ")");
140140
if description.is_empty() {
@@ -492,7 +492,7 @@ impl Shell {
492492
description
493493
} else {
494494
let truncated: String = description.chars().take(max_width).collect();
495-
format!("{}...", truncated)
495+
format!("{truncated}...")
496496
}
497497
}
498498

0 commit comments

Comments
 (0)