summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Ieni <11428655+MarcoIeni@users.noreply.github.com>2020-11-06 00:12:27 +0100
committerGitHub <noreply@github.com>2020-11-05 18:12:27 -0500
commit3dac4f7fa6451c446902583d2d2aa1358960fe7c (patch)
treeaa56fafc017bcea4346516400079234ee4a2bdae
parent8c8ddc8a815997250419594dd506bca6313433a6 (diff)
fix some clippy warnings (#380)
-rw-r--r--src/ansi/mod.rs4
-rw-r--r--src/color.rs2
-rw-r--r--src/config.rs23
-rw-r--r--src/delta.rs17
-rw-r--r--src/env.rs2
-rw-r--r--src/features/hyperlinks.rs6
-rw-r--r--src/features/line_numbers.rs2
-rw-r--r--src/features/side_by_side.rs20
-rw-r--r--src/main.rs14
-rw-r--r--src/options/rewrite.rs8
-rw-r--r--src/options/set.rs10
-rw-r--r--src/paint.rs27
-rw-r--r--src/parse.rs4
-rw-r--r--src/style.rs14
14 files changed, 67 insertions, 86 deletions
diff --git a/src/ansi/mod.rs b/src/ansi/mod.rs
index e2fdaf7f..fc28fc9c 100644
--- a/src/ansi/mod.rs
+++ b/src/ansi/mod.rs
@@ -60,7 +60,7 @@ pub fn truncate_str<'a, 'b>(s: &'a str, display_width: usize, tail: &'b str) ->
}
}
- return Cow::from(format!("{}{}", result, result_tail));
+ Cow::from(format!("{}{}", result, result_tail))
}
pub fn parse_first_style(s: &str) -> Option<ansi_term::Style> {
@@ -72,7 +72,7 @@ pub fn parse_first_style(s: &str) -> Option<ansi_term::Style> {
pub fn string_starts_with_ansi_style_sequence(s: &str) -> bool {
AnsiElementIterator::new(s)
- .nth(0)
+ .next()
.map(|el| matches!(el, Element::CSI(_, _, _)))
.unwrap_or(false)
}
diff --git a/src/color.rs b/src/color.rs
index ed0f4f75..a34628d6 100644
--- a/src/color.rs
+++ b/src/color.rs
@@ -17,7 +17,7 @@ pub fn parse_color(s: &str, true_color: bool) -> Option<Color> {
eprintln!("Invalid color or style attribute: {}", s);
process::exit(1);
};
- let syntect_color = if s.starts_with("#") {
+ let syntect_color = if s.starts_with('#') {
SyntectColor::from_str(s).unwrap_or_else(|_| die())
} else {
s.parse::<u8>()
diff --git a/src/config.rs b/src/config.rs
index b383784a..2d4ee766 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -161,20 +161,17 @@ impl From<cli::Opt> for Config {
hyperlinks_file_link_format: opt.hyperlinks_file_link_format,
inspect_raw_lines: opt.computed.inspect_raw_lines,
keep_plus_minus_markers: opt.keep_plus_minus_markers,
- line_numbers: match opt.computed.line_numbers_mode {
- cli::LineNumbersMode::Full => true,
- _ => false,
- },
+ line_numbers: matches!(opt.computed.line_numbers_mode, cli::LineNumbersMode::Full),
line_numbers_left_format: opt.line_numbers_left_format,
line_numbers_left_style,
line_numbers_minus_style,
line_numbers_plus_style,
line_numbers_right_format: opt.line_numbers_right_format,
line_numbers_right_style,
- line_numbers_show_first_line_number: match opt.computed.line_numbers_mode {
- cli::LineNumbersMode::First => true,
- _ => false,
- },
+ line_numbers_show_first_line_number: matches!(
+ opt.computed.line_numbers_mode,
+ cli::LineNumbersMode::First
+ ),
line_numbers_zero_style,
max_buffered_lines: 32,
max_line_distance: opt.max_line_distance,
@@ -182,7 +179,7 @@ impl From<cli::Opt> for Config {
max_line_length: opt.max_line_length,
minus_emph_style,
minus_empty_line_marker_style,
- minus_file: opt.minus_file.map(|s| s.clone()),
+ minus_file: opt.minus_file,
minus_non_emph_style,
minus_style,
navigate: opt.navigate,
@@ -191,7 +188,7 @@ impl From<cli::Opt> for Config {
paging_mode: opt.computed.paging_mode,
plus_emph_style,
plus_empty_line_marker_style,
- plus_file: opt.plus_file.map(|s| s.clone()),
+ plus_file: opt.plus_file,
plus_non_emph_style,
plus_style,
git_minus_style,
@@ -211,8 +208,8 @@ impl From<cli::Opt> for Config {
}
}
-fn make_hunk_styles<'a>(
- opt: &'a cli::Opt,
+fn make_hunk_styles(
+ opt: &cli::Opt,
) -> (
Style,
Style,
@@ -350,7 +347,7 @@ fn make_hunk_styles<'a>(
)
}
-fn make_line_number_styles<'a>(opt: &'a cli::Opt) -> (Style, Style, Style, Style, Style) {
+fn make_line_number_styles(opt: &cli::Opt) -> (Style, Style, Style, Style, Style) {
let true_color = opt.computed.true_color;
let line_numbers_left_style =
Style::from_str(&opt.line_numbers_left_style, None, None, true_color, false);
diff --git a/src/delta.rs b/src/delta.rs
index c0ad1ed3..2607d1c3 100644
--- a/src/delta.rs
+++ b/src/delta.rs
@@ -35,10 +35,7 @@ pub enum Source {
impl State {
fn is_in_hunk(&self) -> bool {
- match *self {
- State::HunkHeader | State::HunkZero | State::HunkMinus(_) | State::HunkPlus(_) => true,
- _ => false,
- }
+ matches!(*self, State::HunkHeader | State::HunkZero | State::HunkMinus(_) | State::HunkPlus(_))
}
}
@@ -267,14 +264,8 @@ fn handle_commit_meta_header_line(
};
let (formatted_line, formatted_raw_line) = if config.hyperlinks {
(
- Cow::from(
- features::hyperlinks::format_commit_line_with_osc8_commit_hyperlink(line, config),
- ),
- Cow::from(
- features::hyperlinks::format_commit_line_with_osc8_commit_hyperlink(
- raw_line, config,
- ),
- ),
+ features::hyperlinks::format_commit_line_with_osc8_commit_hyperlink(line, config),
+ features::hyperlinks::format_commit_line_with_osc8_commit_hyperlink(raw_line, config),
)
} else {
(Cow::from(line), Cow::from(raw_line))
@@ -433,7 +424,7 @@ fn handle_hunk_header_line(
writeln!(painter.writer)?;
} else {
let line = match painter.prepare(&raw_code_fragment, false) {
- s if s.len() > 0 => format!("{} ", s),
+ s if !s.is_empty() => format!("{} ", s),
s => s,
};
writeln!(painter.writer)?;
diff --git a/src/env.rs b/src/env.rs
index 0a988f9a..9792355b 100644
--- a/src/env.rs
+++ b/src/env.rs
@@ -3,7 +3,7 @@ use std::env;
/// If `name` is set and, after trimming whitespace, is not empty string, then return that trimmed
/// string. Else None.
pub fn get_env_var(name: &str) -> Option<String> {
- match env::var(name).unwrap_or("".to_string()).trim() {
+ match env::var(name).unwrap_or_else(|_| "".to_string()).trim() {
"" => None,
non_empty_string => Some(non_empty_string.to_string()),
}
diff --git a/src/features/hyperlinks.rs b/src/features/hyperlinks.rs
index 8fc58e9f..3bb5e70c 100644
--- a/src/features/hyperlinks.rs
+++ b/src/features/hyperlinks.rs
@@ -67,9 +67,9 @@ lazy_static! {
static ref COMMIT_LINE_REGEX: Regex = Regex::new("(.* )([0-9a-f]{40})(.*)").unwrap();
}
-fn format_commit_line_captures_with_osc8_commit_hyperlink<'a, 'b>(
- captures: &'a Captures,
- github_repo: &'b str,
+fn format_commit_line_captures_with_osc8_commit_hyperlink(
+ captures: &Captures,
+ github_repo: &str,
) -> String {
let commit = captures.get(2).unwrap().as_str();
format!(
diff --git a/src/features/line_numbers.rs b/src/features/line_numbers.rs
index e03da5f9..19c35d40 100644
--- a/src/features/line_numbers.rs
+++ b/src/features/line_numbers.rs
@@ -234,7 +234,7 @@ fn parse_line_number_format<'a>(format_string: &'a str) -> LineNumberFormatData<
}
fn format_and_paint_line_number_field<'a>(
- format_data: &Vec<LineNumberPlaceholderData<'a>>,
+ format_data: &[LineNumberPlaceholderData<'a>],
style: &Style,
minus_number: Option<usize>,
plus_number: Option<usize>,
diff --git a/src/features/side_by_side.rs b/src/features/side_by_side.rs
index e3837455..04380461 100644
--- a/src/features/side_by_side.rs
+++ b/src/features/side_by_side.rs
@@ -177,8 +177,8 @@ pub fn paint_zero_lines_side_by_side(
fn paint_left_panel_minus_line<'a>(
line_index: Option<usize>,
- syntax_style_sections: &Vec<Vec<(SyntectStyle, &str)>>,
- diff_style_sections: &Vec<Vec<(Style, &str)>>,
+ syntax_style_sections: &[Vec<(SyntectStyle, &str)>],
+ diff_style_sections: &[Vec<(Style, &str)>],
state: &'a State,
line_numbers_data: &mut Option<&mut line_numbers::LineNumbersData>,
prefix: &str,
@@ -210,8 +210,8 @@ fn paint_left_panel_minus_line<'a>(
fn paint_right_panel_plus_line<'a>(
line_index: Option<usize>,
- syntax_style_sections: &Vec<Vec<(SyntectStyle, &str)>>,
- diff_style_sections: &Vec<Vec<(Style, &str)>>,
+ syntax_style_sections: &[Vec<(SyntectStyle, &str)>],
+ diff_style_sections: &[Vec<(Style, &str)>],
state: &'a State,
line_numbers_data: &mut Option<&mut line_numbers::LineNumbersData>,
prefix: &str,
@@ -243,7 +243,7 @@ fn paint_right_panel_plus_line<'a>(
fn get_right_fill_style_for_left_panel(
line_is_empty: bool,
line_index: Option<usize>,
- diff_style_sections: &Vec<Vec<(Style, &str)>>,
+ diff_style_sections: &[Vec<(Style, &str)>],
state: &State,
background_color_extends_to_terminal_width: Option<bool>,
config: &Config,
@@ -289,10 +289,10 @@ fn get_right_fill_style_for_left_panel(
// what this will do is set the line number pair in that function to `(Some(minus_number), None)`,
// and then only emit the right field (which has a None number, i.e. blank). However, it will also
// increment the minus line number, so we need to knock that back down.
-fn paint_minus_or_plus_panel_line<'a>(
+fn paint_minus_or_plus_panel_line(
line_index: Option<usize>,
- syntax_style_sections: &Vec<Vec<(SyntectStyle, &str)>>,
- diff_style_sections: &Vec<Vec<(Style, &str)>>,
+ syntax_style_sections: &[Vec<(SyntectStyle, &str)>],
+ diff_style_sections: &[Vec<(Style, &str)>],
state: &State,
line_numbers_data: &mut Option<&mut line_numbers::LineNumbersData>,
panel_side: PanelSide,
@@ -355,7 +355,7 @@ fn right_pad_left_panel_line(
panel_line: &mut String,
panel_line_is_empty: bool,
line_index: Option<usize>,
- diff_style_sections: &Vec<Vec<(Style, &str)>>,
+ diff_style_sections: &[Vec<(Style, &str)>],
state: &State,
background_color_extends_to_terminal_width: Option<bool>,
config: &Config,
@@ -408,7 +408,7 @@ fn right_fill_right_panel_line(
panel_line: &mut String,
panel_line_is_empty: bool,
line_index: Option<usize>,
- diff_style_sections: &Vec<Vec<(Style, &str)>>,
+ diff_style_sections: &[Vec<(Style, &str)>],
state: &State,
background_color_extends_to_terminal_width: Option<bool>,
config: &Config,
diff --git a/src/main.rs b/src/main.rs
index a691c331..bd65956d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -29,8 +29,6 @@ use std::io::{self, ErrorKind, Read, Write};
use std::path::PathBuf;
use std::process;
-use ansi_term;
-use atty;
use bytelines::ByteLinesReader;
use itertools::Itertools;
use structopt::StructOpt;
@@ -237,8 +235,8 @@ fn show_config(config: &config::Config) {
syntax_theme = config
.syntax_theme
.clone()
- .map(|t| t.name.unwrap_or("none".to_string()))
- .unwrap_or("none".to_string()),
+ .map(|t| t.name.unwrap_or_else(|| "none".to_string()))
+ .unwrap_or_else(|| "none".to_string()),
width = match config.decorations_width {
cli::Width::Fixed(width) => width.to_string(),
cli::Width::Variable => "variable".to_string(),
@@ -255,8 +253,8 @@ where
S: AsRef<str>,
{
let s = s.as_ref();
- if s.ends_with(" ")
- || s.starts_with(" ")
+ if s.ends_with(' ')
+ || s.starts_with(' ')
|| s.contains(&['\\', '{', '}', ':'][..])
|| s.is_empty()
{
@@ -345,9 +343,9 @@ index f38589a..0f1bb83 100644
pub fn list_syntax_themes() -> std::io::Result<()> {
if atty::is(atty::Stream::Stdout) {
- return _list_syntax_themes_for_humans();
+ _list_syntax_themes_for_humans()
} else {
- return _list_syntax_themes_for_machines();
+ _list_syntax_themes_for_machines()
}
}
diff --git a/src/options/rewrite.rs b/src/options/rewrite.rs
index c1f349d7..12597756 100644
--- a/src/options/rewrite.rs
+++ b/src/options/rewrite.rs
@@ -49,7 +49,7 @@ fn rewrite_style_strings_to_honor_deprecated_minus_plus_options(opt: &mut cli::O
),
"minus",
) {
- opt.minus_style = rewritten.to_string();
+ opt.minus_style = rewritten;
}
if let Some(rewritten) = _get_rewritten_minus_plus_style_string(
&opt.minus_emph_style,
@@ -60,7 +60,7 @@ fn rewrite_style_strings_to_honor_deprecated_minus_plus_options(opt: &mut cli::O
),
"minus-emph",
) {
- opt.minus_emph_style = rewritten.to_string();
+ opt.minus_emph_style = rewritten;
}
if let Some(rewritten) = _get_rewritten_minus_plus_style_string(
&opt.plus_style,
@@ -68,7 +68,7 @@ fn rewrite_style_strings_to_honor_deprecated_minus_plus_options(opt: &mut cli::O
(None, opt.deprecated_plus_background_color.as_deref()),
"plus",
) {
- opt.plus_style = rewritten.to_string();
+ opt.plus_style = rewritten;
}
if let Some(rewritten) = _get_rewritten_minus_plus_style_string(
&opt.plus_emph_style,
@@ -76,7 +76,7 @@ fn rewrite_style_strings_to_honor_deprecated_minus_plus_options(opt: &mut cli::O
(None, opt.deprecated_plus_emph_background_color.as_deref()),
"plus-emph",
) {
- opt.plus_emph_style = rewritten.to_string();
+ opt.plus_emph_style = rewritten;
}
}
diff --git a/src/options/set.rs b/src/options/set.rs
index a9ca6be7..3683c657 100644
--- a/src/options/set.rs
+++ b/src/options/set.rs
@@ -311,7 +311,7 @@ fn set__light__dark__syntax_theme__options(
///
/// [delta "d"]
/// features = f e
-fn gather_features<'a>(
+fn gather_features(
opt: &cli::Opt,
builtin_features: &HashMap<String, features::BuiltinFeature>,
git_config: &Option<git_config::GitConfig>,
@@ -364,7 +364,7 @@ fn gather_features<'a>(
if let Some(git_config) = git_config {
// Gather features from [delta] section if --features was not passed.
if opt.features.is_empty() {
- if let Some(feature_string) = git_config.get::<String>(&format!("delta.features")) {
+ if let Some(feature_string) = git_config.get::<String>("delta.features") {
for feature in split_feature_string(&feature_string.to_lowercase()) {
gather_features_recursively(
feature,
@@ -390,7 +390,7 @@ fn gather_features<'a>(
}
/// Add to feature list `features` all features in the tree rooted at `feature`.
-fn gather_features_recursively<'a>(
+fn gather_features_recursively(
feature: &str,
features: &mut VecDeque<String>,
builtin_features: &HashMap<String, features::BuiltinFeature>,
@@ -426,7 +426,7 @@ fn gather_features_recursively<'a>(
/// Look for builtin features requested via boolean feature flags (as opposed to via a "features"
/// list) in a custom feature section in git config and add them to the features list.
-fn gather_builtin_features_from_flags_in_gitconfig<'a>(
+fn gather_builtin_features_from_flags_in_gitconfig(
git_config_key: &str,
features: &mut VecDeque<String>,
builtin_features: &HashMap<String, features::BuiltinFeature>,
@@ -450,7 +450,7 @@ fn gather_builtin_features_from_flags_in_gitconfig<'a>(
/// children of a node in the tree are features in (a) and (b). (In both cases the features
/// referenced will be other builtin features, since a builtin feature is determined at compile
/// time and therefore cannot know of the existence of a non-builtin custom features in gitconfig).
-fn gather_builtin_features_recursively<'a>(
+fn gather_builtin_features_recursively(
feature: &str,
features: &mut VecDeque<String>,
builtin_features: &HashMap<String, features::BuiltinFeature>,
diff --git a/src/paint.rs b/src/paint.rs
index e69ebeee..c35ba5a5 100644
--- a/src/paint.rs
+++ b/src/paint.rs
@@ -2,7 +2,6 @@ use lazy_static::lazy_static;
use regex::Regex;
use std::io::Write;
-use ansi_term;
use itertools::Itertools;
use syntect::easy::HighlightLines;
use syntect::highlighting::Style as SyntectStyle;
@@ -65,11 +64,9 @@ impl<'a> Painter<'a> {
return syntax;
}
}
- return syntax_set
+ syntax_set
.find_syntax_by_extension("txt")
- .unwrap_or_else(|| {
- delta_unreachable("Failed to find any language syntax definitions.")
- });
+ .unwrap_or_else(|| delta_unreachable("Failed to find any language syntax definitions."))
}
pub fn set_highlighter(&mut self) {
@@ -302,7 +299,7 @@ impl<'a> Painter<'a> {
/// Determine whether the terminal should fill the line rightwards with a background color, and
/// the style for doing so.
pub fn get_should_right_fill_background_color_and_fill_style(
- diff_sections: &Vec<(Style, &str)>,
+ diff_sections: &[(Style, &str)],
state: &State,
background_color_extends_to_terminal_width: Option<bool>,
config: &config::Config,
@@ -379,8 +376,8 @@ impl<'a> Painter<'a> {
/// Return painted line (maybe prefixed with line numbers field) and an is_empty? boolean.
pub fn paint_line(
- syntax_sections: &Vec<(SyntectStyle, &str)>,
- diff_sections: &Vec<(Style, &str)>,
+ syntax_sections: &[(SyntectStyle, &str)],
+ diff_sections: &[(Style, &str)],
state: &State,
line_numbers_data: &mut Option<&mut line_numbers::LineNumbersData>,
side_by_side_panel: Option<side_by_side::PanelSide>,
@@ -424,7 +421,7 @@ impl<'a> Painter<'a> {
if prefix != "" {
ansi_strings.push(section_style.paint(prefix));
}
- if text.len() > 0 {
+ if !text.is_empty() {
text.remove(0);
}
handled_prefix = true;
@@ -468,7 +465,7 @@ impl<'a> Painter<'a> {
}
pub fn get_syntax_style_sections_for_lines<'s>(
- lines: &'s Vec<(String, State)>,
+ lines: &'s [(String, State)],
state: &State,
highlighter: &mut HighlightLines,
config: &config::Config,
@@ -491,8 +488,8 @@ impl<'a> Painter<'a> {
/// Set background styles to represent diff for minus and plus lines in buffer.
fn get_diff_style_sections<'b>(
- minus_lines: &'b Vec<(String, State)>,
- plus_lines: &'b Vec<(String, State)>,
+ minus_lines: &'b [(String, State)],
+ plus_lines: &'b [(String, State)],
config: &config::Config,
) -> (
Vec<Vec<(Style, &'b str)>>,
@@ -578,7 +575,7 @@ impl<'a> Painter<'a> {
// edits::annotate doesn't return "coalesced" annotations (see comment there), so we can't assume
// that `sections.len() > 1 <=> (multiple styles)`.
-fn style_sections_contain_more_than_one_style(sections: &Vec<(Style, &str)>) -> bool {
+fn style_sections_contain_more_than_one_style(sections: &[(Style, &str)]) -> bool {
if sections.len() > 1 {
let (first_style, _) = sections[0];
sections
@@ -599,7 +596,7 @@ lazy_static! {
// TODO: Git recognizes blank lines at end of file (blank-at-eof) as a whitespace error but delta
// does not yet.
// https://git-scm.com/docs/git-config#Documentation/git-config.txt-corewhitespace
-fn is_whitespace_error(sections: &Vec<(Style, &str)>) -> bool {
+fn is_whitespace_error(sections: &[(Style, &str)]) -> bool {
!sections
.iter()
.any(|(_, s)| NON_WHITESPACE_REGEX.is_match(s))
@@ -692,7 +689,7 @@ mod superimpose_style_sections {
}
// TODO: This is not the ideal location for the following code.
- if current_string.ends_with("\n") {
+ if current_string.ends_with('\n') {
// Remove the terminating newline whose presence was necessary for the syntax
// highlighter to work correctly.
current_string.truncate(current_string.len() - 1);
diff --git a/src/parse.rs b/src/parse.rs
index cc259e37..6188117d 100644
--- a/src/parse.rs
+++ b/src/parse.rs
@@ -63,7 +63,7 @@ pub fn get_file_change_description_from_file_paths(
format!("comparing: {} ⟶ {}", minus_file, plus_file)
} else {
let format_label = |label: &str| {
- if label.len() > 0 {
+ if !label.is_empty() {
format!("{} ", label)
} else {
"".to_string()
@@ -143,7 +143,7 @@ pub fn parse_hunk_header(line: &str) -> (String, Vec<(usize, usize)>) {
})
.collect();
let code_fragment = &caps[2];
- return (code_fragment.to_string(), line_numbers_and_hunk_lengths);
+ (code_fragment.to_string(), line_numbers_and_hunk_lengths)
}
/// Attempt to parse input as a file path and return extension as a &str.
diff --git a/src/style.rs b/src/style.rs
index 7bf56c71..d25fc2f7 100644
--- a/src/style.rs
+++ b/src/style.rs
@@ -1,7 +1,6 @@
use std::borrow::Cow;
use std::fmt;
-use ansi_term;
use lazy_static::lazy_static;
use crate::ansi;
@@ -135,9 +134,8 @@ impl Style {
}
(false, None) => words.push("normal".to_string()),
}
- match self.ansi_term_style.background {
- Some(color) => words.push(color::color_to_string(color)),
- None => {}
+ if let Some(color) = self.ansi_term_style.background {
+ words.push(color::color_to_string(color))
}
words.join(" ")
}
@@ -155,10 +153,10 @@ pub fn ansi_term_style_equality(a: ansi_term::Style, b: ansi_term::Style) -> boo
..b
};
if a_attrs != b_attrs {
- return false;
+ false
} else {
- return ansi_term_color_equality(a.foreground, b.foreground)
- & ansi_term_color_equality(a.background, b.background);
+ ansi_term_color_equality(a.foreground, b.foreground)
+ & ansi_term_color_equality(a.background, b.background)
}
}
@@ -211,7 +209,7 @@ pub fn line_has_style_other_than<'a>(line: &str, styles: impl Iterator<Item = &'
return false;
}
}
- return true;
+ true
}
#[cfg(test)]