summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornickelc <constantin.nickel@gmail.com>2023-02-28 12:37:20 +0100
committerGitHub <noreply@github.com>2023-02-28 06:37:20 -0500
commit28bf556897fe8945a72e8a1c32ceb8636ee428bb (patch)
treee65636fe18034fe65f278b4d872a07f036e51abb
parentce6448f9c3e8e61d06127c62ee775f9372bc1c34 (diff)
Fix clippy warnings (#1298)
* Fix clippy warnings - `clippy::uninlined_format_args` * Fix clippy warnings - `clippy::clone_on_copy` - `clippy::explicit_auto_deref` - `clippy::iter_cloned_collect` - `clippy::map_clone` - `clippy::needless_borrow` - `clippy::needless_lifetimes` - `clippy::needless_return` - `clippy::redundant_clone` - `clippy::redundant_field_names` - `clippy::seek_to_start_instead_of_rewind` - `clippy::unnecessary_cast` - `clippy::unused_unit`
-rw-r--r--src/align.rs2
-rw-r--r--src/ansi/mod.rs6
-rw-r--r--src/color.rs8
-rw-r--r--src/config.rs3
-rw-r--r--src/edits.rs4
-rw-r--r--src/features/hyperlinks.rs16
-rw-r--r--src/features/line_numbers.rs21
-rw-r--r--src/features/mod.rs2
-rw-r--r--src/features/navigate.rs2
-rw-r--r--src/features/side_by_side.rs8
-rw-r--r--src/format.rs16
-rw-r--r--src/git_config/git_config_entry.rs19
-rw-r--r--src/git_config/mod.rs2
-rw-r--r--src/handlers/blame.rs14
-rw-r--r--src/handlers/diff_header.rs6
-rw-r--r--src/handlers/diff_stat.rs4
-rw-r--r--src/handlers/draw.rs6
-rw-r--r--src/handlers/grep.rs2
-rw-r--r--src/handlers/hunk.rs3
-rw-r--r--src/handlers/hunk_header.rs5
-rw-r--r--src/handlers/merge_conflict.rs2
-rw-r--r--src/main.rs8
-rw-r--r--src/options/get.rs6
-rw-r--r--src/options/set.rs28
-rw-r--r--src/paint.rs2
-rw-r--r--src/parse_style.rs3
-rw-r--r--src/parse_styles.rs10
-rw-r--r--src/style.rs14
-rw-r--r--src/subcommands/diff.rs14
-rw-r--r--src/subcommands/list_syntax_themes.rs10
-rw-r--r--src/subcommands/show_colors.rs7
-rw-r--r--src/subcommands/show_config.rs8
-rw-r--r--src/subcommands/show_syntax_themes.rs8
-rw-r--r--src/subcommands/show_themes.rs2
-rw-r--r--src/tests/ansi_test_utils.rs6
-rw-r--r--src/tests/integration_test_utils.rs18
-rw-r--r--src/tests/test_example_diffs.rs2
-rw-r--r--src/utils/bat/assets.rs2
-rw-r--r--src/utils/bat/output.rs4
-rw-r--r--src/utils/process.rs2
-rw-r--r--src/utils/syntect.rs2
-rw-r--r--src/wrapping.rs32
42 files changed, 151 insertions, 188 deletions
diff --git a/src/align.rs b/src/align.rs
index b2e2bdfe..90491ce2 100644
--- a/src/align.rs
+++ b/src/align.rs
@@ -408,7 +408,7 @@ mod tests {
}
impl<'a> TestCase<'a> {
- pub fn run(&self) -> () {
+ pub fn run(&self) {
self.assert_string_distance_parts();
assert_eq!(operations(self.before, self.after), self.operations);
}
diff --git a/src/ansi/mod.rs b/src/ansi/mod.rs
index 2b7b2f60..64b51c8b 100644
--- a/src/ansi/mod.rs
+++ b/src/ansi/mod.rs
@@ -36,7 +36,7 @@ pub fn measure_text_width(s: &str) -> usize {
//
// 3. If tail was exhausted, then contribute graphemes and ANSI escape sequences from `s` until the
// display_width of the result would exceed `display_width`.
-pub fn truncate_str<'a, 'b>(s: &'a str, display_width: usize, tail: &'b str) -> Cow<'a, str> {
+pub fn truncate_str<'a>(s: &'a str, display_width: usize, tail: &str) -> Cow<'a, str> {
let items = ansi_strings_iterator(s).collect::<Vec<(&str, bool)>>();
let width = strip_ansi_codes_from_strings_iterator(items.iter().copied()).width();
if width <= display_width {
@@ -68,7 +68,7 @@ pub fn truncate_str<'a, 'b>(s: &'a str, display_width: usize, tail: &'b str) ->
}
}
- Cow::from(format!("{}{}", result, result_tail))
+ Cow::from(format!("{result}{result_tail}"))
}
pub fn parse_style_sections(s: &str) -> Vec<(ansi_term::Style, &str)> {
@@ -176,7 +176,7 @@ pub fn explain_ansi(line: &str, colorful: bool) -> String {
if colorful {
format!("({}){}", style.to_painted_string(), style.paint(s))
} else {
- format!("({}){}", style, s)
+ format!("({style}){s}")
}
})
.collect()
diff --git a/src/color.rs b/src/color.rs
index 52904b65..a4b96b58 100644
--- a/src/color.rs
+++ b/src/color.rs
@@ -14,7 +14,7 @@ pub fn parse_color(s: &str, true_color: bool, git_config: Option<&GitConfig>) ->
return None;
}
let die = || {
- fatal(format!("Invalid color or style attribute: {}", s));
+ fatal(format!("Invalid color or style attribute: {s}"));
};
let syntect_color = if s.starts_with('#') {
SyntectColor::from_str(s).unwrap_or_else(|_| die())
@@ -27,7 +27,7 @@ pub fn parse_color(s: &str, true_color: bool, git_config: Option<&GitConfig>) ->
.or_else(|| utils::syntect::syntect_color_from_name(s));
if syntect_color.is_none() {
if let Some(git_config) = git_config {
- if let Some(val) = git_config.get::<String>(&format!("delta.{}", s)) {
+ if let Some(val) = git_config.get::<String>(&format!("delta.{s}")) {
return parse_color(&val, true_color, None);
}
}
@@ -41,8 +41,8 @@ pub fn parse_color(s: &str, true_color: bool, git_config: Option<&GitConfig>) ->
pub fn color_to_string(color: Color) -> String {
match color {
Color::Fixed(n) if n < 16 => ansi_16_color_number_to_name(n).unwrap().to_string(),
- Color::Fixed(n) => format!("{}", n),
- Color::RGB(r, g, b) => format!("\"#{:02x?}{:02x?}{:02x?}\"", r, g, b),
+ Color::Fixed(n) => format!("{n}"),
+ Color::RGB(r, g, b) => format!("\"#{r:02x?}{g:02x?}{b:02x?}\""),
Color::Black => "black".to_string(),
Color::Red => "red".to_string(),
Color::Green => "green".to_string(),
diff --git a/src/config.rs b/src/config.rs
index 24e26a47..3856f669 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -390,9 +390,8 @@ pub fn user_supplied_option(option: &str, arg_matches: &clap::ArgMatches) -> boo
pub fn delta_unreachable(message: &str) -> ! {
fatal(format!(
- "{} This should not be possible. \
+ "{message} This should not be possible. \
Please report the bug at https://github.com/dandavison/delta/issues.",
- message
));
}
diff --git a/src/edits.rs b/src/edits.rs
index bcbead11..eb6a310a 100644
--- a/src/edits.rs
+++ b/src/edits.rs
@@ -470,7 +470,7 @@ mod tests {
}
fn assert_tokenize(text: &str, expected_tokens: &[&str]) {
- let actual_tokens = tokenize(text, &*DEFAULT_TOKENIZATION_REGEXP);
+ let actual_tokens = tokenize(text, &DEFAULT_TOKENIZATION_REGEXP);
assert_eq!(text, expected_tokens.iter().join(""));
// tokenize() guarantees that the first element of the token stream is "".
// See comment in Alignment::new()
@@ -861,7 +861,7 @@ mod tests {
Deletion,
noop_insertions,
Insertion,
- &*DEFAULT_TOKENIZATION_REGEXP,
+ &DEFAULT_TOKENIZATION_REGEXP,
max_line_distance,
0.0,
);
diff --git a/src/features/hyperlinks.rs b/src/features/hyperlinks.rs
index b45de0f8..78be83e9 100644
--- a/src/features/hyperlinks.rs
+++ b/src/features/hyperlinks.rs
@@ -31,7 +31,7 @@ pub fn format_commit_line_with_osc8_commit_hyperlink<'a>(
let suffix = captures.get(3).map(|m| m.as_str()).unwrap_or("");
let formatted_commit =
format_osc8_hyperlink(&commit_link_format.replace("{commit}", commit), commit);
- format!("{}{}{}", prefix, formatted_commit, suffix)
+ format!("{prefix}{formatted_commit}{suffix}")
})
} else if let Some(GitConfigEntry::GitRemote(repo)) =
config.git_config.as_ref().and_then(get_remote_url)
@@ -74,7 +74,7 @@ where
.hyperlinks_file_link_format
.replace("{path}", &absolute_path.as_ref().to_string_lossy());
if let Some(n) = line_number {
- url = url.replace("{line}", &format!("{}", n))
+ url = url.replace("{line}", &format!("{n}"))
} else {
url = url.replace("{line}", "")
};
@@ -138,8 +138,7 @@ pub mod tests {
] {
run_test(FilePathsTestCase {
name: &format!(
- "delta relative_paths={} calling_cmd={:?}",
- delta_relative_paths_option, calling_cmd
+ "delta relative_paths={delta_relative_paths_option} calling_cmd={calling_cmd:?}",
),
true_location_of_file_relative_to_repo_root:
true_location_of_file_relative_to_repo_root.as_path(),
@@ -452,7 +451,7 @@ __path__: some matching line
fn run_test(test_case: FilePathsTestCase) {
let mut config = integration_test_utils::make_config_from_args(
- &test_case
+ test_case
.get_args()
.iter()
.map(|s| s.as_str())
@@ -483,12 +482,11 @@ __path__: some matching line
test_case.path_in_delta_input,
test_case.path_in_grep_output()
);
- delta_test.with_input(
- &GIT_GREP_OUTPUT.replace("__path__", &test_case.path_in_delta_input),
- )
+ delta_test
+ .with_input(&GIT_GREP_OUTPUT.replace("__path__", test_case.path_in_delta_input))
}
CallingProcess::OtherGrep => delta_test
- .with_input(&GIT_GREP_OUTPUT.replace("__path__", &test_case.path_in_delta_input)),
+ .with_input(&GIT_GREP_OUTPUT.replace("__path__", test_case.path_in_delta_input)),
};
let make_expected_hyperlink = |text| {
format_osc8_hyperlink(
diff --git a/src/features/line_numbers.rs b/src/features/line_numbers.rs
index bbdeb592..99a97775 100644
--- a/src/features/line_numbers.rs
+++ b/src/features/line_numbers.rs
@@ -198,7 +198,7 @@ impl<'a> LineNumbersData<'a> {
format_data: if insert_center_space_on_odd_width {
let format_left = vec![format::FormatStringPlaceholderData::default()];
let format_right = vec![format::FormatStringPlaceholderData {
- prefix: format!("{}", ODD_PAD_CHAR).into(),
+ prefix: format!("{ODD_PAD_CHAR}").into(),
prefix_len: 1,
..Default::default()
}];
@@ -327,9 +327,9 @@ pub mod tests {
use super::*;
- pub fn parse_line_number_format_with_default_regex<'a>(
- format_string: &'a str,
- ) -> FormatStringData<'a> {
+ pub fn parse_line_number_format_with_default_regex(
+ format_string: &str,
+ ) -> FormatStringData<'_> {
format::parse_line_number_format(format_string, &LINE_NUMBERS_PLACEHOLDER_REGEX, false)
}
@@ -460,7 +460,7 @@ pub mod tests {
assert_eq!(
format::parse_line_number_format("|{nm:<4}|", &LINE_NUMBERS_PLACEHOLDER_REGEX, true),
vec![format::FormatStringPlaceholderData {
- prefix: format!("{}|", ODD_PAD_CHAR).into(),
+ prefix: format!("{ODD_PAD_CHAR}|").into(),
placeholder: Some(Placeholder::NumberMinus),
alignment_spec: Some(Align::Left),
width: Some(4),
@@ -483,7 +483,7 @@ pub mod tests {
),
vec![
format::FormatStringPlaceholderData {
- prefix: format!("{}|", ODD_PAD_CHAR).into(),
+ prefix: format!("{ODD_PAD_CHAR}|").into(),
placeholder: Some(Placeholder::NumberMinus),
alignment_spec: Some(Align::Left),
width: Some(4),
@@ -512,7 +512,7 @@ pub mod tests {
assert_eq!(
format::parse_line_number_format("|++|", &LINE_NUMBERS_PLACEHOLDER_REGEX, true),
vec![format::FormatStringPlaceholderData {
- prefix: format!("{}", ODD_PAD_CHAR).into(),
+ prefix: format!("{ODD_PAD_CHAR}").into(),
placeholder: None,
alignment_spec: None,
width: None,
@@ -530,10 +530,7 @@ pub mod tests {
let long = "line number format which is too large for SSO";
assert!(long.len() > std::mem::size_of::<smol_str::SmolStr>());
assert_eq!(
- parse_line_number_format_with_default_regex(&format!(
- "{long}{{nm}}{long}",
- long = long
- ),),
+ parse_line_number_format_with_default_regex(&format!("{long}{{nm}}{long}")),
vec![format::FormatStringPlaceholderData {
prefix: long.into(),
prefix_len: long.len(),
@@ -615,7 +612,7 @@ pub mod tests {
assert_eq!(data.formatted_width(), MinusPlus::new(32, 0));
let format = MinusPlus::new("│{np:^3}│ │{nm:<12}│ │{np}│".into(), "".into());
- let mut data = LineNumbersData::from_format_strings(&format, w.clone());
+ let mut data = LineNumbersData::from_format_strings(&format, w);
data.initialize_hunk(&[(10, 11), (10000, 100001)], "a".into());
assert_eq!(data.formatted_width(), MinusPlus::new(32, 0));
diff --git a/src/features/mod.rs b/src/features/mod.rs
index 8234d62e..dfc3582d 100644
--- a/src/features/mod.rs
+++ b/src/features/mod.rs
@@ -102,7 +102,7 @@ pub mod tests {
fn test_builtin_features_have_flags_and_these_set_features() {
let builtin_features = make_builtin_features();
let mut args = vec!["delta".to_string()];
- args.extend(builtin_features.keys().map(|s| format!("--{}", s)));
+ args.extend(builtin_features.keys().map(|s| format!("--{s}")));
let opt = cli::Opt::from_iter_and_git_config(DeltaEnv::default(), args, None);
let features: HashSet<&str> = opt
.features
diff --git a/src/features/navigate.rs b/src/features/navigate.rs
index dc31e4a0..f78a6758 100644
--- a/src/features/navigate.rs
+++ b/src/features/navigate.rs
@@ -77,7 +77,7 @@ pub fn copy_less_hist_file_and_append_navigate_regex(config: &Config) -> std::io
initial_contents
};
if !contents.ends_with(".search\n") {
- contents = format!("{}.search\n", contents);
+ contents = format!("{contents}.search\n");
}
writeln!(
std::fs::File::create(&delta_less_hist_file)?,
diff --git a/src/features/side_by_side.rs b/src/features/side_by_side.rs
index ac2de08e..02f3eebb 100644
--- a/src/features/side_by_side.rs
+++ b/src/features/side_by_side.rs
@@ -348,10 +348,10 @@ fn paint_right_panel_plus_line<'a>(
}
#[allow(clippy::too_many_arguments)]
-fn get_right_fill_style_for_panel<'a>(
+fn get_right_fill_style_for_panel(
line_is_empty: bool,
line_index: Option<usize>,
- diff_style_sections: &[LineSections<'a, Style>],
+ diff_style_sections: &[LineSections<'_, Style>],
lines_have_homolog: Option<&[bool]>,
state: &State,
panel_side: PanelSide,
@@ -468,11 +468,11 @@ fn paint_minus_or_plus_panel_line<'a>(
/// done with spaces. The right panel can be filled with spaces or using ANSI sequences
/// instructing the terminal emulator to fill the background color rightwards.
#[allow(clippy::too_many_arguments, clippy::comparison_chain)]
-fn pad_panel_line_to_width<'a>(
+fn pad_panel_line_to_width(
panel_line: &mut String,
panel_line_is_empty: bool,
line_index: Option<usize>,
- diff_style_sections: &[LineSections<'a, Style>],
+ diff_style_sections: &[LineSections<'_, Style>],
lines_have_homolog: Option<&[bool]>,
state: &State,
panel_side: PanelSide,
diff --git a/src/format.rs b/src/format.rs
index d40e417f..0dc05fa1 100644
--- a/src/format.rs
+++ b/src/format.rs
@@ -35,6 +35,8 @@ pub enum Align {
impl TryFrom<Option<&str>> for Align {
type Error = ();
fn try_from(from: Option<&str>) -> Result<Self, Self::Error> {
+ // inlined format args are not supported for `debug_assert` with edition 2018.
+ #[allow(clippy::uninlined_format_args)]
match from {
Some(alignment) if alignment == "<" => Ok(Align::Left),
Some(alignment) if alignment == ">" => Ok(Align::Right),
@@ -162,7 +164,7 @@ pub fn parse_line_number_format<'a>(
let mut expand_first_prefix = |prefix: SmolStr| {
// Only prefix the first placeholder with a space, also see `UseFullPanelWidth`
if prefix_with_space {
- let prefix = SmolStr::new(format!("{}{}", ODD_PAD_CHAR, prefix));
+ let prefix = SmolStr::new(format!("{ODD_PAD_CHAR}{prefix}"));
prefix_with_space = false;
prefix
} else {
@@ -300,14 +302,14 @@ pub fn pad<T: std::fmt::Display + CenterRightNumbers>(
let space = s.center_right_space(alignment, width);
let mut result = match precision {
None => match alignment {
- Align::Left => format!("{0}{1:<2$}", space, s, width),
- Align::Center => format!("{0}{1:^2$}", space, s, width),
- Align::Right => format!("{0}{1:>2$}", space, s, width),
+ Align::Left => format!("{space}{s:<width$}"),
+ Align::Center => format!("{space}{s:^width$}"),
+ Align::Right => format!("{space}{s:>width$}"),
},
Some(precision) => match alignment {
- Align::Left => format!("{0}{1:<2$.3$}", space, s, width, precision),
- Align::Center => format!("{0}{1:^2$.3$}", space, s, width, precision),
- Align::Right => format!("{0}{1:>2$.3$}", space, s, width, precision),
+ Align::Left => format!("{space}{s:<width$.precision$}"),
+ Align::Center => format!("{space}{s:^width$.precision$}"),
+ Align::Right => format!("{space}{s:>width$.precision$}"),
},
};
if space == " " {
diff --git a/src/git_config/git_config_entry.rs b/src/git_config/git_config_entry.rs
index b7bd6d2f..c07fc0a0 100644
--- a/src/git_config/git_config_entry.rs
+++ b/src/git_config/git_config_entry.rs
@@ -24,16 +24,16 @@ impl GitRemoteRepo {
pub fn format_commit_url(&self, commit: &str) -> String {
match self {
Self::GitHub { slug } => {
- format!("https://github.com/{}/commit/{}", slug, commit)
+ format!("https://github.com/{slug}/commit/{commit}")
}
Self::GitLab { slug } => {
- format!("https://gitlab.com/{}/-/commit/{}", slug, commit)
+ format!("https://gitlab.com/{slug}/-/commit/{commit}")
}
Self::SourceHut { slug } => {
- format!("https://git.sr.ht/{}/commit/{}", slug, commit)
+ format!("https://git.sr.ht/{slug}/commit/{commit}")
}
Self::Codeberg { slug } => {
- format!("https://codeberg.org/{}/commit/{}", slug, commit)
+ format!("https://codeberg.org/{slug}/commit/{commit}")
}
}
}
@@ -174,7 +174,7 @@ mod tests {
let commit_hash = "d3b07384d113edec49eaa6238ad5ff00";
assert_eq!(
repo.format_commit_url(commit_hash),
- format!("https://github.com/dandavison/delta/commit/{}", commit_hash)
+ format!("https://github.com/dandavison/delta/commit/{commit_hash}")
)
}
@@ -219,7 +219,7 @@ mod tests {
let commit_hash = "d3b07384d113edec49eaa6238ad5ff00";
assert_eq!(
repo.format_commit_url(commit_hash),
- format!("https://gitlab.com/proj/grp/repo/-/commit/{}", commit_hash)
+ format!("https://gitlab.com/proj/grp/repo/-/commit/{commit_hash}")
)
}
@@ -250,10 +250,7 @@ mod tests {
let commit_hash = "df41ac86f08a40e64c76062fd67e238522c14990";
assert_eq!(
repo.format_commit_url(commit_hash),
- format!(
- "https://git.sr.ht/~someuser/somerepo/commit/{}",
- commit_hash
- )
+ format!("https://git.sr.ht/~someuser/somerepo/commit/{commit_hash}")
)
}
@@ -287,7 +284,7 @@ mod tests {
let commit_hash = "1c072856ebf12419378c5098ad543c497197c6da";
assert_eq!(
repo.format_commit_url(commit_hash),
- format!("https://codeberg.org/dnkl/foot/commit/{}", commit_hash)
+ format!("https://codeberg.org/dnkl/foot/commit/{commit_hash}")
)
}
}
diff --git a/src/git_config/mod.rs b/src/git_config/mod.rs
index 6b87444e..228fd4d0 100644
--- a/src/git_config/mod.rs
+++ b/src/git_config/mod.rs
@@ -51,7 +51,7 @@ impl GitConfig {
match config {
Some(mut config) => {
let config = config.snapshot().unwrap_or_else(|err| {
- fatal(format!("Failed to read git config: {}", err));
+ fatal(format!("Failed to read git config: {err}"));
});
Some(Self {
config,
diff --git a/src/handlers/blame.rs b/src/handlers/blame.rs
index a1ec97b8..3890b7c6 100644
--- a/src/handlers/blame.rs
+++ b/src/handlers/blame.rs
@@ -363,8 +363,7 @@ pub fn parse_blame_line_numbers(arg: &str) -> BlameLineNumbers {
.parse::<usize>()
.unwrap_or_else(|err| {
fatal(format!(
- "Invalid number for blame-line-numbers in every-N argument: {}",
- err
+ "Invalid number for blame-line-numbers in every-N argument: {err}",
))
});
@@ -375,8 +374,7 @@ pub fn parse_blame_line_numbers(arg: &str) -> BlameLineNumbers {
}
}
t => fatal(format!(
- "Invalid format type \"{}\" for blame-line-numbers",
- t
+ "Invalid format type \"{t}\" for blame-line-numbers",
)),
}
}
@@ -529,13 +527,13 @@ mod tests {
}
fn make_blame_line_with_time(timestamp: &str) -> BlameLine {
- let time = chrono::DateTime::parse_from_rfc3339(&timestamp).unwrap();
- return BlameLine {
+ let time = chrono::DateTime::parse_from_rfc3339(timestamp).unwrap();
+ BlameLine {
commit: "",
author: "",
- time: time,
+ time,
line_number: 0,
code: "",
- };
+ }
}
}
diff --git a/src/handlers/diff_header.rs b/src/handlers/diff_header.rs
index 77daf843..b07e04c7 100644
--- a/