Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept clippy suggestions #1632

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
7 changes: 2 additions & 5 deletions src/features/hyperlinks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down Expand Up @@ -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(_) => {
Expand Down
5 changes: 3 additions & 2 deletions src/features/line_numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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())
}

Expand Down
10 changes: 5 additions & 5 deletions src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(()),
}
Expand All @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/blame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>()
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/diff_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(""),
Expand Down
10 changes: 5 additions & 5 deletions src/options/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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();
}
Expand Down
18 changes: 9 additions & 9 deletions src/options/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand All @@ -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");
Expand Down
12 changes: 8 additions & 4 deletions src/parse_styles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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())),
Expand Down
1 change: 1 addition & 0 deletions src/tests/ansi_test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#[cfg(test)]
#[allow(clippy::module_inception)]
pub mod ansi_test_utils {
use ansi_term;

Expand Down
1 change: 1 addition & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
8 changes: 4 additions & 4 deletions src/tests/test_example_diffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
] {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
22 changes: 2 additions & 20 deletions src/utils/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,24 +746,14 @@ 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,
start_time: u64,
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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/regex_replacement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
2 changes: 1 addition & 1 deletion src/wrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading