Skip to content

Commit

Permalink
Merge pull request #3251 from epage/refactor/clippy
Browse files Browse the repository at this point in the history
refactor: address clippy warnings
  • Loading branch information
epage committed Jan 4, 2022
2 parents bcbe126 + e8516a9 commit 453356e
Show file tree
Hide file tree
Showing 20 changed files with 216 additions and 39 deletions.
8 changes: 4 additions & 4 deletions clap_complete/src/shells/bash.rs
Expand Up @@ -59,7 +59,7 @@ impl Generator for Bash {
complete -F _{name} -o bashdefault -o default {name}
",
name = bin_name,
cmd = bin_name.replace("-", "__"),
cmd = bin_name.replace('-', "__"),
name_opts = all_options_for_path(app, bin_name),
name_opts_details = option_details_for_path(app, bin_name),
subcmds = all_subcommands(app),
Expand Down Expand Up @@ -88,7 +88,7 @@ fn all_subcommands(app: &App) -> String {
cmd+=\"__{fn_name}\"
;;",
name = sc,
fn_name = sc.replace("-", "__")
fn_name = sc.replace('-', "__")
)
}));

Expand All @@ -101,7 +101,7 @@ fn subcommand_details(app: &App) -> String {
let mut subcmd_dets = vec![String::new()];
let mut scs = utils::all_subcommands(app)
.iter()
.map(|x| x.1.replace(" ", "__"))
.map(|x| x.1.replace(' ', "__"))
.collect::<Vec<_>>();

scs.sort();
Expand All @@ -122,7 +122,7 @@ fn subcommand_details(app: &App) -> String {
COMPREPLY=( $(compgen -W \"${{opts}}\" -- \"${{cur}}\") )
return 0
;;",
subcmd = sc.replace("-", "__"),
subcmd = sc.replace('-', "__"),
sc_opts = all_options_for_path(app, &*sc),
level = sc.split("__").map(|_| 1).sum::<u64>(),
opts_details = option_details_for_path(app, &*sc)
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/src/shells/elvish.rs
Expand Up @@ -54,7 +54,7 @@ set edit:completion:arg-completer[{bin_name}] = [@words]{{

// Escape string inside single quotes
fn escape_string(string: &str) -> String {
string.replace("'", "''")
string.replace('\'', "''")
}

fn get_tooltip<T: ToString>(help: Option<&str>, data: T) -> String {
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/src/shells/fish.rs
Expand Up @@ -26,7 +26,7 @@ impl Generator for Fish {

// Escape string inside single quotes
fn escape_string(string: &str) -> String {
string.replace("\\", "\\\\").replace("'", "\\'")
string.replace('\\', "\\\\").replace('\'', "\\'")
}

fn gen_fish_inner(root_command: &str, parent_commands: &[&str], app: &App, buffer: &mut String) {
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/src/shells/powershell.rs
Expand Up @@ -58,7 +58,7 @@ Register-ArgumentCompleter -Native -CommandName '{bin_name}' -ScriptBlock {{

// Escape string inside single quotes
fn escape_string(string: &str) -> String {
string.replace("'", "''")
string.replace('\'', "''")
}

fn get_tooltip<T: ToString>(help: Option<&str>, data: T) -> String {
Expand Down
32 changes: 16 additions & 16 deletions clap_complete/src/shells/zsh.rs
Expand Up @@ -92,7 +92,7 @@ _{bin_name_underscore}_commands() {{
local commands; commands=({subcommands_and_args})
_describe -t commands '{bin_name} commands' commands \"$@\"
}}",
bin_name_underscore = name.replace(" ", "__"),
bin_name_underscore = name.replace(' ', "__"),
bin_name = name,
subcommands_and_args = subcommands_of(p)
);
Expand All @@ -114,7 +114,7 @@ _{bin_name_underscore}_commands() {{
local commands; commands=({subcommands_and_args})
_describe -t commands '{bin_name} commands' commands \"$@\"
}}",
bin_name_underscore = bin_name.replace(" ", "__"),
bin_name_underscore = bin_name.replace(' ', "__"),
bin_name = bin_name,
subcommands_and_args =
subcommands_of(parser_of(p, bin_name).expect(INTERNAL_ERROR_MSG))
Expand Down Expand Up @@ -259,7 +259,7 @@ fn get_subcommands_of(parent: &App) -> String {
;;
esac",
name = parent.get_name(),
name_hyphen = parent.get_bin_name().unwrap().replace(" ", "-"),
name_hyphen = parent.get_bin_name().unwrap().replace(' ', "-"),
subcommands = all_subcommands.join("\n"),
pos = parent.get_positionals().count() + 1
)
Expand Down Expand Up @@ -328,7 +328,7 @@ fn get_args_of(parent: &App, p_global: Option<&App>) -> String {
if parent.has_subcommands() {
let subcommand_bin_name = format!(
"\":: :_{name}_commands\" \\",
name = parent.get_bin_name().as_ref().unwrap().replace(" ", "__")
name = parent.get_bin_name().as_ref().unwrap().replace(' ', "__")
);
segments.push(subcommand_bin_name);

Expand Down Expand Up @@ -406,20 +406,20 @@ fn value_completion(arg: &Arg) -> Option<String> {
/// Escape help string inside single quotes and brackets
fn escape_help(string: &str) -> String {
string
.replace("\\", "\\\\")
.replace("'", "'\\''")
.replace("[", "\\[")
.replace("]", "\\]")
.replace('\\', "\\\\")
.replace('\'', "'\\''")
.replace('[', "\\[")
.replace(']', "\\]")
}

/// Escape value string inside single quotes and parentheses
fn escape_value(string: &str) -> String {
string
.replace("\\", "\\\\")
.replace("'", "'\\''")
.replace("(", "\\(")
.replace(")", "\\)")
.replace(" ", "\\ ")
.replace('\\', "\\\\")
.replace('\'', "'\\''")
.replace('(', "\\(")
.replace(')', "\\)")
.replace(' ', "\\ ")
}

fn write_opts_of(p: &App, p_global: Option<&App>) -> String {
Expand Down Expand Up @@ -631,9 +631,9 @@ fn write_positionals_of(p: &App) -> String {
help = arg
.get_help()
.map_or("".to_owned(), |v| " -- ".to_owned() + v)
.replace("[", "\\[")
.replace("]", "\\]")
.replace(":", "\\:"),
.replace('[', "\\[")
.replace(']', "\\]")
.replace(':', "\\:"),
value_completion = value_completion(arg).unwrap_or_else(|| "".to_string())
);

Expand Down
2 changes: 1 addition & 1 deletion clap_complete_fig/src/fig.rs
Expand Up @@ -38,7 +38,7 @@ impl Generator for Fig {

// Escape string inside double quotes
fn escape_string(string: &str) -> String {
string.replace("\\", "\\\\").replace("\"", "\\\"")
string.replace('\\', "\\\\").replace('\"', "\\\"")
}

fn gen_fig_inner(
Expand Down
4 changes: 2 additions & 2 deletions clap_derive/src/attrs.rs
Expand Up @@ -879,8 +879,8 @@ impl Name {
Camel => s.to_lower_camel_case(),
ScreamingSnake => s.to_shouty_snake_case(),
Snake => s.to_snake_case(),
Lower => s.to_snake_case().replace("_", ""),
Upper => s.to_shouty_snake_case().replace("_", ""),
Lower => s.to_snake_case().replace('_', ""),
Upper => s.to_shouty_snake_case().replace('_', ""),
Verbatim => s,
};
quote_spanned!(ident.span()=> #s)
Expand Down
4 changes: 2 additions & 2 deletions clap_derive/src/parse.rs
Expand Up @@ -252,8 +252,8 @@ fn raw_method_suggestion(ts: ParseBuffer) -> String {
fn to_string<T: ToTokens>(val: &T) -> String {
val.to_token_stream()
.to_string()
.replace(" ", "")
.replace(",", ", ")
.replace(' ', "")
.replace(',', ", ")
}

if let Ok((name, exprs)) = do_parse() {
Expand Down
2 changes: 1 addition & 1 deletion clap_derive/src/utils/doc_comments.rs
Expand Up @@ -78,7 +78,7 @@ fn split_paragraphs(lines: &[&str]) -> Vec<String> {
let len = slice
.iter()
.position(|s| is_blank(s))
.unwrap_or_else(|| slice.len());
.unwrap_or(slice.len());

last_line += start + len;

Expand Down
5 changes: 4 additions & 1 deletion examples/tutorial_derive/04_04_custom.rs
Expand Up @@ -72,10 +72,13 @@ fn main() {

// Check for usage of -c
if let Some(config) = cli.config.as_deref() {
// todo: remove `#[allow(clippy::or_fun_call)]` lint when MSRV is bumped.
#[allow(clippy::or_fun_call)]
let input = cli
.input_file
.as_deref()
.or_else(|| cli.spec_in.as_deref())
// 'or' is preferred to 'or_else' here since `Option::as_deref` is 'const'
.or(cli.spec_in.as_deref())
.unwrap_or_else(|| {
let mut app = Cli::into_app();
app.error(
Expand Down

0 comments on commit 453356e

Please sign in to comment.