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

Fix Clippy lints #1661

Merged
merged 7 commits into from
May 27, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

## Other

- Fix Clippy lints, see #1661 (@mohamed-abdelnour)


## Syntaxes

Expand Down
2 changes: 1 addition & 1 deletion src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl HighlightingAssets {
bat_warning!("Theme '{}' is deprecated, using 'ansi' instead.", theme);
return self.get_theme("ansi");
}
if theme != "" {
if !theme.is_empty() {
bat_warning!("Unknown theme '{}', using default.", theme)
}
&self.theme_set.themes[self.fallback_theme.unwrap_or_else(|| Self::default_theme())]
Expand Down
22 changes: 11 additions & 11 deletions src/pager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,17 @@ pub(crate) fn get_pager(config_pager: Option<&str>) -> Result<Option<Pager>, Par
Some((bin, args)) => {
let kind = PagerKind::from_bin(bin);

let use_less_instead = match (&source, &kind) {
// 'more' and 'most' do not supports colors; automatically use 'less' instead
// if the problematic pager came from the generic PAGER env var
(PagerSource::EnvVarPager, PagerKind::More) => true,
(PagerSource::EnvVarPager, PagerKind::Most) => true,

// If PAGER=bat, silently use 'less' instead to prevent recursion ...
(PagerSource::EnvVarPager, PagerKind::Bat) => true,

// Never silently use less if BAT_PAGER or --pager has been specified
_ => false,
let use_less_instead = if source == PagerSource::EnvVarPager {
// 'more' and 'most' do not supports colors; automatically use
// 'less' instead if the problematic pager came from the
// generic PAGER env var.
// If PAGER=bat, silently use 'less' instead to prevent
// recursion.
// Never silently use 'less' if BAT_PAGER or --pager has been
// specified.
matches!(kind, PagerKind::More | PagerKind::Most | PagerKind::Bat)
} else {
false
};

Ok(Some(if use_less_instead {
Expand Down
21 changes: 11 additions & 10 deletions src/pretty_printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ pub struct PrettyPrinter<'a> {

impl<'a> PrettyPrinter<'a> {
pub fn new() -> Self {
let mut config = Config::default();

config.colored_output = true;
config.true_color = true;
let config = Config {
colored_output: true,
true_color: true,
..Default::default()
};

PrettyPrinter {
inputs: vec![],
Expand Down Expand Up @@ -335,14 +336,14 @@ impl<'a> Input<'a> {
}
}

impl<'a> Into<Input<'a>> for input::Input<'a> {
fn into(self) -> Input<'a> {
Input { input: self }
impl<'a> From<input::Input<'a>> for Input<'a> {
fn from(input: input::Input<'a>) -> Self {
Self { input }
}
}

impl<'a> Into<input::Input<'a>> for Input<'a> {
fn into(self) -> input::Input<'a> {
self.input
impl<'a> From<Input<'a>> for input::Input<'a> {
fn from(Input { input }: Input<'a>) -> Self {
input
}
}
12 changes: 8 additions & 4 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,10 @@ impl<'a> Printer for InteractivePrinter<'a> {

if text.len() != text_trimmed.len() {
if let Some(background_color) = background_color {
let mut ansi_style = Style::default();
ansi_style.background = to_ansi_color(background_color, true_color);
let ansi_style = Style {
background: to_ansi_color(background_color, true_color),
..Default::default()
};
let width = if cursor_total <= cursor_max {
cursor_max - cursor_total + 1
} else {
Expand Down Expand Up @@ -588,8 +590,10 @@ impl<'a> Printer for InteractivePrinter<'a> {
}

if let Some(background_color) = background_color {
let mut ansi_style = Style::default();
ansi_style.background = to_ansi_color(background_color, self.config.true_color);
let ansi_style = Style {
background: to_ansi_color(background_color, self.config.true_color),
..Default::default()
};

write!(
handle,
Expand Down