From 2e563b15e36ba60dabf14fd4b20e5e9650e8a005 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Mon, 19 Feb 2024 12:40:18 -0500 Subject: [PATCH] Accept clippy suggestions --- src/config.rs | 4 ++-- src/features/hyperlinks.rs | 7 ++----- src/features/line_numbers.rs | 5 +++-- src/format.rs | 10 +++++----- src/handlers/blame.rs | 2 +- src/handlers/diff_header.rs | 2 +- src/options/get.rs | 10 +++++----- src/options/set.rs | 18 +++++++++--------- src/parse_styles.rs | 12 ++++++++---- src/tests/ansi_test_utils.rs | 1 + src/tests/mod.rs | 1 + src/tests/test_example_diffs.rs | 8 ++++---- src/utils/process.rs | 22 ++-------------------- src/utils/regex_replacement.rs | 2 +- src/wrapping.rs | 2 +- 15 files changed, 46 insertions(+), 60 deletions(-) diff --git a/src/config.rs b/src/config.rs index c5c57bb22..7d3d442d0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -484,9 +484,9 @@ pub mod tests { Some(git_config_contents), Some(git_config_path), ); - assert_eq!(config.true_color, false); + assert!(!config.true_color); assert_eq!(config.decorations_width, cli::Width::Fixed(100)); - assert_eq!(config.background_color_extends_to_terminal_width, true); + assert!(config.background_color_extends_to_terminal_width); assert_eq!(config.inspect_raw_lines, cli::InspectRawLines::True); assert_eq!(config.paging_mode, PagingMode::Never); assert!(config.syntax_theme.is_none()); diff --git a/src/features/hyperlinks.rs b/src/features/hyperlinks.rs index f96922b48..4771a0769 100644 --- a/src/features/hyperlinks.rs +++ b/src/features/hyperlinks.rs @@ -113,7 +113,7 @@ pub mod tests { let true_location_of_file_relative_to_repo_root = PathBuf::from("a"); let git_prefix_env_var = Some(""); - for (delta_relative_paths_option, calling_cmd) in vec![ + for (delta_relative_paths_option, calling_cmd) in [ (false, Some("git diff")), (false, Some("git diff --relative")), (true, Some("git diff")), @@ -474,10 +474,7 @@ __path__: some matching line .with_input(&GIT_GREP_OUTPUT.replace("__path__", test_case.path_in_delta_input)), }; let make_expected_hyperlink = |text| { - format_osc8_hyperlink( - &PathBuf::from(test_case.expected_hyperlink_path()).to_string_lossy(), - text, - ) + format_osc8_hyperlink(&test_case.expected_hyperlink_path().to_string_lossy(), text) }; match test_case.calling_process() { CallingProcess::GitDiff(_) => { diff --git a/src/features/line_numbers.rs b/src/features/line_numbers.rs index 99a977752..0c488000c 100644 --- a/src/features/line_numbers.rs +++ b/src/features/line_numbers.rs @@ -142,7 +142,8 @@ pub fn format_and_paint_line_numbers<'a>( } lazy_static! { - static ref LINE_NUMBERS_PLACEHOLDER_REGEX: Regex = format::make_placeholder_regex(&["nm", "np"]); + static ref LINE_NUMBERS_PLACEHOLDER_REGEX: Regex = + format::make_placeholder_regex(&["nm", "np"]); } #[derive(Default, Debug)] @@ -618,7 +619,7 @@ pub mod tests { assert_eq!(data.formatted_width(), MinusPlus::new(32, 0)); } - fn _get_capture<'a>(i: usize, j: usize, caps: &'a Vec) -> &'a str { + fn _get_capture<'a>(i: usize, j: usize, caps: &'a [Captures]) -> &'a str { caps[i].get(j).map_or("", |m| m.as_str()) } diff --git a/src/format.rs b/src/format.rs index 0dc05fa1f..17218d955 100644 --- a/src/format.rs +++ b/src/format.rs @@ -17,8 +17,8 @@ impl<'a> TryFrom> for Placeholder<'a> { type Error = (); fn try_from(from: Option<&'a str>) -> Result { match from { - Some(placeholder) if placeholder == "nm" => Ok(Placeholder::NumberMinus), - Some(placeholder) if placeholder == "np" => Ok(Placeholder::NumberPlus), + Some("nm") => Ok(Placeholder::NumberMinus), + Some("np") => Ok(Placeholder::NumberPlus), Some(placeholder) => Ok(Placeholder::Str(placeholder)), _ => Err(()), } @@ -38,9 +38,9 @@ impl TryFrom> for Align { // 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), - Some(alignment) if alignment == "^" => Ok(Align::Center), + Some("<") => Ok(Align::Left), + Some(">") => Ok(Align::Right), + Some("^") => Ok(Align::Center), Some(alignment) => { debug_assert!(false, "Unknown Alignment: {}", alignment); Err(()) diff --git a/src/handlers/blame.rs b/src/handlers/blame.rs index 7578a5c47..e8c2e435a 100644 --- a/src/handlers/blame.rs +++ b/src/handlers/blame.rs @@ -361,7 +361,7 @@ pub fn parse_blame_line_numbers(arg: &str) -> BlameLineNumbers { match f.fmt_type.as_str() { t if t.is_empty() || t == "every" => BlameLineNumbers::On(set_defaults(f.into_simple())), - t if t == "block" => BlameLineNumbers::PerBlock(set_defaults(f.into_simple())), + "block" => BlameLineNumbers::PerBlock(set_defaults(f.into_simple())), every_n if every_n.starts_with("every-") => { let n = every_n["every-".len()..] .parse::() diff --git a/src/handlers/diff_header.rs b/src/handlers/diff_header.rs index b07e04c7c..334ca76c8 100644 --- a/src/handlers/diff_header.rs +++ b/src/handlers/diff_header.rs @@ -390,7 +390,7 @@ fn _parse_file_path(s: &str, git_diff_name: bool) -> String { // ---·a/a·b├──┤␊ // +++·b/c·d├──┤␊ let path = match s.strip_suffix('\t').unwrap_or(s) { - path if path == "/dev/null" => "/dev/null", + "/dev/null" => "/dev/null", path if git_diff_name && DIFF_PREFIXES.iter().any(|s| path.starts_with(s)) => &path[2..], path if git_diff_name => path, path => path.split('\t').next().unwrap_or(""), diff --git a/src/options/get.rs b/src/options/get.rs index 974b9a836..fcea8c5a2 100644 --- a/src/options/get.rs +++ b/src/options/get.rs @@ -225,8 +225,8 @@ pub mod tests { git_config_contents, git_config_path, "'delta.side-by-side=false'".into(), - &|opt: Opt| assert_eq!(opt.side_by_side, true), - &|opt: Opt| assert_eq!(opt.side_by_side, false), + &|opt: Opt| assert!(opt.side_by_side), + &|opt: Opt| assert!(!opt.side_by_side), ); } @@ -276,7 +276,7 @@ pub mod tests { Some(git_config_path), ); assert_eq!(opt.features.unwrap(), "feature-from-gitconfig"); - assert_eq!(opt.side_by_side, false); + assert!(!opt.side_by_side); let opt = integration_test_utils::make_options_from_args_and_git_config_with_custom_env( DeltaEnv { @@ -289,7 +289,7 @@ pub mod tests { ); // `line-numbers` is a builtin feature induced by side-by-side assert_eq!(opt.features.unwrap(), "line-numbers side-by-side"); - assert_eq!(opt.side_by_side, true); + assert!(opt.side_by_side); let opt = integration_test_utils::make_options_from_args_and_git_config_with_custom_env( DeltaEnv { @@ -304,7 +304,7 @@ pub mod tests { opt.features.unwrap(), "feature-from-gitconfig line-numbers side-by-side" ); - assert_eq!(opt.side_by_side, true); + assert!(opt.side_by_side); remove_file(git_config_path).unwrap(); } diff --git a/src/options/set.rs b/src/options/set.rs index 732806a7c..262096c59 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -578,7 +578,7 @@ fn parse_width_specifier(width_arg: &str, terminal_width: usize) -> Result parse(width_arg, false, false)?.try_into().unwrap(), - Some(index) if index == 0 => (terminal_width as isize + parse(width_arg, true, false)?) + Some(0) => (terminal_width as isize + parse(width_arg, true, false)?) .try_into() .map_err(|_| { format!( @@ -730,10 +730,10 @@ pub mod tests { ); assert_eq!(opt.true_color, "never"); - assert_eq!(opt.color_only, false); + assert!(!opt.color_only); assert_eq!(opt.commit_decoration_style, "black black"); assert_eq!(opt.commit_style, "black black"); - assert_eq!(opt.dark, false); + assert!(!opt.dark); assert_eq!(opt.default_language, Some("rs".to_owned())); // TODO: should set_options not be called on any feature flags? // assert_eq!(opt.diff_highlight, true); @@ -753,9 +753,9 @@ pub mod tests { assert_eq!(opt.file_regex_replacement, Some("s/foo/bar/".to_string())); assert_eq!(opt.hunk_header_decoration_style, "black black"); assert_eq!(opt.hunk_header_style, "black black"); - assert_eq!(opt.keep_plus_minus_markers, true); - assert_eq!(opt.light, true); - assert_eq!(opt.line_numbers, true); + assert!(opt.keep_plus_minus_markers); + assert!(opt.light); + assert!(opt.line_numbers); assert_eq!(opt.line_numbers_left_format, "xxxyyyzzz"); assert_eq!(opt.line_numbers_left_style, "black black"); assert_eq!(opt.line_numbers_minus_style, "black black"); @@ -769,15 +769,15 @@ pub mod tests { assert_eq!(opt.minus_empty_line_marker_style, "black black"); assert_eq!(opt.minus_non_emph_style, "black black"); assert_eq!(opt.minus_style, "black black"); - assert_eq!(opt.navigate, true); + assert!(opt.navigate); assert_eq!(opt.navigate_regex, Some("xxxyyyzzz".to_string())); assert_eq!(opt.paging_mode, "never"); assert_eq!(opt.plus_emph_style, "black black"); assert_eq!(opt.plus_empty_line_marker_style, "black black"); assert_eq!(opt.plus_non_emph_style, "black black"); assert_eq!(opt.plus_style, "black black"); - assert_eq!(opt.raw, true); - assert_eq!(opt.side_by_side, true); + assert!(opt.raw); + assert!(opt.side_by_side); assert_eq!(opt.syntax_theme, Some("xxxyyyzzz".to_string())); assert_eq!(opt.tab_width, 77); assert_eq!(opt.true_color, "never"); diff --git a/src/parse_styles.rs b/src/parse_styles.rs index 0cd97f391..f1611c8fb 100644 --- a/src/parse_styles.rs +++ b/src/parse_styles.rs @@ -590,8 +590,10 @@ mod tests { #[test] fn test_resolve_style_references_1() { let style_1 = Style::default(); - let mut style_2 = Style::default(); - style_2.is_syntax_highlighted = !style_1.is_syntax_highlighted; + let style_2 = style::Style { + is_syntax_highlighted: !style_1.is_syntax_highlighted, + ..Default::default() + }; let edges: HashMap<&str, StyleReference> = [ ("a", StyleReference::Style(style_1)), @@ -613,8 +615,10 @@ mod tests { #[test] fn test_resolve_style_references_2() { let style_1 = Style::default(); - let mut style_2 = Style::default(); - style_2.is_syntax_highlighted = !style_1.is_syntax_highlighted; + let style_2 = style::Style { + is_syntax_highlighted: !style_1.is_syntax_highlighted, + ..Default::default() + }; let edges: HashMap<&str, StyleReference> = [ ("a", StyleReference::Reference("b".to_string())), diff --git a/src/tests/ansi_test_utils.rs b/src/tests/ansi_test_utils.rs index 37a7b69c7..5e60223ba 100644 --- a/src/tests/ansi_test_utils.rs +++ b/src/tests/ansi_test_utils.rs @@ -1,4 +1,5 @@ #[cfg(test)] +#[allow(clippy::module_inception)] pub mod ansi_test_utils { use ansi_term; diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 582eeee0d..b6633a3b2 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -10,6 +10,7 @@ pub const TESTING: bool = false; pub const TESTING: bool = true; #[test] +#[allow(clippy::assertions_on_constants)] fn am_testing() { assert!(TESTING); } diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs index a3df1e364..1b7104293 100644 --- a/src/tests/test_example_diffs.rs +++ b/src/tests/test_example_diffs.rs @@ -154,7 +154,7 @@ mod tests { #[test] fn test_certain_bugs_are_not_present() { - for input in vec![ + for input in [ DIFF_EXHIBITING_PARSE_FILE_NAME_BUG, DIFF_EXHIBITING_STATE_MACHINE_PARSER_BUG, DIFF_EXHIBITING_TRUNCATION_BUG, @@ -168,7 +168,7 @@ mod tests { #[test] fn test_delta_paints_diff_when_there_is_unrecognized_initial_content() { - for input in vec![ + for input in [ DIFF_WITH_UNRECOGNIZED_PRECEDING_MATERIAL_1, DIFF_WITH_UNRECOGNIZED_PRECEDING_MATERIAL_2, ] { @@ -594,7 +594,7 @@ commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e "omit", ]); let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, &config); - for (i, line) in vec![ + for (i, line) in [ "diff --git a/src/align.rs b/src/align.rs", "index 8e37a9e..6ce4863 100644", "--- a/src/align.rs", @@ -642,7 +642,7 @@ index 8e37a9e..6ce4863 100644 GIT_DIFF_SINGLE_HUNK_WITH_ANSI_ESCAPE_SEQUENCES, &config, ); - for (i, line) in vec![ + for (i, line) in [ "diff --git a/src/align.rs b/src/align.rs", "index 8e37a9e..6ce4863 100644", "--- a/src/align.rs", diff --git a/src/utils/process.rs b/src/utils/process.rs index 7c3003d85..1876d679e 100644 --- a/src/utils/process.rs +++ b/src/utils/process.rs @@ -746,7 +746,7 @@ pub mod tests { assert_eq!(guess_git_blame_filename_extension(&args), Args("".into())); } - #[derive(Debug)] + #[derive(Debug, Default)] struct FakeProc { #[allow(dead_code)] pid: DeltaPid, @@ -754,16 +754,6 @@ pub mod tests { cmd: Vec, ppid: Option, } - impl Default for FakeProc { - fn default() -> Self { - Self { - pid: 0, - start_time: 0, - cmd: Vec::new(), - ppid: None, - } - } - } impl FakeProc { fn new(pid: DeltaPid, start_time: u64, cmd: Vec, ppid: Option) -> Self { FakeProc { @@ -790,19 +780,11 @@ pub mod tests { } } - #[derive(Debug)] + #[derive(Debug, Default)] struct MockProcInfo { delta_pid: DeltaPid, info: HashMap, } - impl Default for MockProcInfo { - fn default() -> Self { - Self { - delta_pid: 0, - info: HashMap::new(), - } - } - } impl MockProcInfo { fn with(processes: &[(DeltaPid, u64, &str, Option)]) -> Self { MockProcInfo { diff --git a/src/utils/regex_replacement.rs b/src/utils/regex_replacement.rs index 5f07902e6..eec8480f5 100644 --- a/src/utils/regex_replacement.rs +++ b/src/utils/regex_replacement.rs @@ -68,7 +68,7 @@ mod tests { let rr = RegexReplacement::from_sed_command(command).unwrap(); assert_eq!(rr.regex.as_str(), "foo"); assert_eq!(rr.replacement, "bar"); - assert_eq!(rr.replace_all, false); + assert!(!rr.replace_all); assert_eq!(rr.execute("foo"), "bar"); } diff --git a/src/wrapping.rs b/src/wrapping.rs index 40eff4f24..3fe97b9c5 100644 --- a/src/wrapping.rs +++ b/src/wrapping.rs @@ -315,7 +315,7 @@ where right_aligned_line.push((symbol_style, &wrap_config.right_prefix_symbol)); - right_aligned_line.extend(curr_line.line_segments.into_iter()); + right_aligned_line.extend(curr_line.line_segments); curr_line.line_segments = right_aligned_line;