summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2024-02-19 12:56:22 -0500
committerGitHub <noreply@github.com>2024-02-19 12:56:22 -0500
commit084a6d19b2054f8778c375862f8e4ed3d9145120 (patch)
tree01787a3fa67dd92908f32d8eb8b2aaf8e3f55365
parente208f4ed52759fc018ee14808717c977df57b56f (diff)
Accept clippy suggestions (#1632)
-rw-r--r--src/config.rs4
-rw-r--r--src/features/hyperlinks.rs7
-rw-r--r--src/features/line_numbers.rs5
-rw-r--r--src/format.rs10
-rw-r--r--src/handlers/blame.rs2
-rw-r--r--src/handlers/diff_header.rs2
-rw-r--r--src/options/get.rs10
-rw-r--r--src/options/set.rs18
-rw-r--r--src/parse_styles.rs12
-rw-r--r--src/tests/ansi_test_utils.rs1
-rw-r--r--src/tests/mod.rs1
-rw-r--r--src/tests/test_example_diffs.rs8
-rw-r--r--src/utils/process.rs22
-rw-r--r--src/utils/regex_replacement.rs2
-rw-r--r--src/wrapping.rs2
15 files changed, 46 insertions, 60 deletions
diff --git a/src/config.rs b/src/config.rs
index c5c57bb2..7d3d442d 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 f96922b4..4771a076 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 99a97775..0c488000 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<Captures>) -> &'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 0dc05fa1..17218d95 100644
--- a/src/format.rs
+++ b/src/format.rs
@@ -17,8 +17,8 @@ impl<'a> TryFrom<Option<&'a str>> for Placeholder<'a> {
type Error = ();
fn try_from(from: Option<&'a str>) -> Result<Self, Self::Error> {
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<Option<&str>> 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 7578a5c4..e8c2e435 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::<usize>()
diff --git a/src/handlers/diff_header.rs b/src/handlers/diff_header.rs
index b07e04c7..334ca76c 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 974b9a83..fcea8c5a 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 732806a7..262096c5 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<usize
let width = match width_arg.find('-') {
None => 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 0cd97f39..f1611c8f 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 37a7b69c..5e60223b 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 582eeee0..b6633a3b 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 a3df1e36..1b710429 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 7c3003d8..1876d679 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<String>,
ppid: Option<DeltaPid>,
}
- 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<String>, ppid: Option<DeltaPid>) -> Self {
FakeProc {
@@ -790,19 +780,11 @@ pub mod tests {
}
}
- #[derive(Debug)]
+ #[derive(Debug, Default)]
struct MockProcInfo {
delta_pid: DeltaPid,
info: HashMap<Pid, FakeProc>,
}
- impl Default for MockProcInfo {
- fn default() -> Self {
- Self {
- delta_pid: 0,
- info: HashMap::new(),
- }
- }
- }
impl MockProcInfo {
fn with(processes: &[(DeltaPid, u64, &str, Option<DeltaPid>)]) -> Self {
MockProcInfo {
diff --git a/src/utils/regex_replacement.rs b/src/utils/regex_replacement.rs
index 5f07902e..eec8480f 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 40eff4f2..3fe97b9c 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;