Applied linter fixes

This commit is contained in:
Daniele Esposti 2019-03-08 10:46:49 +00:00 committed by David Peter
parent a21ae614e6
commit 82f14121bd
12 changed files with 37 additions and 44 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@ -120,7 +120,7 @@ impl App {
// Read arguments from bats config file
let mut args = get_args_from_env_var()
.unwrap_or_else(|| get_args_from_config_file())
.unwrap_or_else(get_args_from_config_file)
.chain_err(|| "Could not parse configuration file")?;
// Put the zero-th CLI argument (program name) first
@ -152,12 +152,10 @@ impl App {
} else {
PagingMode::Never
}
} else if self.interactive_output {
PagingMode::QuitIfOneScreen
} else {
if self.interactive_output {
PagingMode::QuitIfOneScreen
} else {
PagingMode::Never
}
PagingMode::Never
}
}
};
@ -166,7 +164,7 @@ impl App {
if let Some(values) = self.matches.values_of("map-syntax") {
for from_to in values {
let parts: Vec<_> = from_to.split(":").collect();
let parts: Vec<_> = from_to.split(':').collect();
if parts.len() != 2 {
return Err("Invalid syntax mapping. The format of the -m/--map-syntax option is 'from:to'.".into());
@ -213,11 +211,11 @@ impl App {
.matches
.value_of("terminal-width")
.and_then(|w| {
if w.starts_with("+") || w.starts_with("-") {
if w.starts_with('+') || w.starts_with('-') {
// Treat argument as a delta to the current terminal width
w.parse().ok().map(|delta: i16| {
let old_width: u16 = Term::stdout().size().1;
let new_width: i32 = old_width as i32 + delta as i32;
let new_width: i32 = i32::from(old_width) + i32::from(delta);
if new_width <= 0 {
old_width as usize
@ -252,14 +250,14 @@ impl App {
.value_of("theme")
.map(String::from)
.or_else(|| env::var("BAT_THEME").ok())
.unwrap_or(String::from(BAT_THEME_DEFAULT)),
.unwrap_or_else(|| String::from(BAT_THEME_DEFAULT)),
line_ranges: LineRanges::from(
transpose(
self.matches
.values_of("line-range")
.map(|vs| vs.map(LineRange::from).collect()),
)?
.unwrap_or(vec![]),
.unwrap_or_else(|| vec![]),
),
output_components,
syntax_mapping,
@ -306,7 +304,7 @@ impl App {
let env_style_components: Option<Vec<OutputComponent>> =
transpose(env::var("BAT_STYLE").ok().map(|style_str| {
style_str
.split(",")
.split(',')
.map(|x| OutputComponent::from_str(&x))
.collect::<Result<Vec<OutputComponent>>>()
}))?;
@ -315,13 +313,13 @@ impl App {
.value_of("style")
.map(|styles| {
styles
.split(",")
.split(',')
.map(|style| style.parse::<OutputComponent>())
.filter_map(|style| style.ok())
.collect::<Vec<_>>()
})
.or(env_style_components)
.unwrap_or(vec![OutputComponent::Full])
.unwrap_or_else(|| vec![OutputComponent::Full])
.into_iter()
.map(|style| style.components(self.interactive_output))
.fold(HashSet::new(), |mut acc, components| {

View File

@ -40,7 +40,7 @@ impl HighlightingAssets {
let theme_dir = source_dir.join("themes");
let res = theme_set.add_from_folder(&theme_dir);
if !res.is_ok() {
if res.is_err() {
println!(
"No themes were found in '{}', using the default set",
theme_dir.to_string_lossy()
@ -191,8 +191,8 @@ impl HighlightingAssets {
} else {
None
};
let syntax = ext_syntax.or(line_syntax);
syntax
ext_syntax.or(line_syntax)
}
(None, InputFile::StdIn) => String::from_utf8(reader.first_line.clone())
.ok()

View File

@ -109,7 +109,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
.overrides_with("number")
// Cannot use clap's built in validation because we have to turn off clap's delimiters
.validator(|val| {
let mut invalid_vals = val.split(",").filter(|style| {
let mut invalid_vals = val.split(',').filter(|style| {
!&[
"auto", "full", "plain", "changes", "header", "grid", "numbers",
]

View File

@ -13,7 +13,7 @@ pub fn config_file() -> PathBuf {
.ok()
.map(PathBuf::from)
.filter(|config_path| config_path.is_file())
.unwrap_or(PROJECT_DIRS.config_dir().join("config"))
.unwrap_or_else(|| PROJECT_DIRS.config_dir().join("config"))
}
pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseError> {
@ -22,19 +22,19 @@ pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseEr
.ok()
.map(|content| get_args_from_str(&content)),
)?
.unwrap_or(vec![]))
.unwrap_or_else(|| vec![]))
}
pub fn get_args_from_env_var() -> Option<Result<Vec<OsString>, shell_words::ParseError>> {
env::var("BAT_OPTS").ok().map(|s| get_args_from_str(&s))
}
fn get_args_from_str<'a>(content: &'a str) -> Result<Vec<OsString>, shell_words::ParseError> {
fn get_args_from_str(content: &str) -> Result<Vec<OsString>, shell_words::ParseError> {
let args_per_line = content
.split('\n')
.map(|line| line.trim())
.filter(|line| !line.is_empty())
.filter(|line| !line.starts_with("#"))
.filter(|line| !line.starts_with('#'))
.map(|line| shell_words::split(line))
.collect::<Result<Vec<_>, _>>()?;

View File

@ -88,7 +88,7 @@ impl<'b> Controller<'b> {
Ok(())
}
fn print_file_ranges<'a, P: Printer>(
fn print_file_ranges<P: Printer>(
&self,
printer: &mut P,
writer: &mut Write,

View File

@ -109,18 +109,12 @@ impl LineRanges {
}
pub fn check(&self, line: usize) -> RangeCheckResult {
if self.ranges.is_empty() {
if self.ranges.is_empty() | self.ranges.iter().any(|r| r.is_inside(line)) {
RangeCheckResult::InRange
} else if line < self.largest_upper_bound {
RangeCheckResult::OutsideRange
} else {
if self.ranges.iter().any(|r| r.is_inside(line)) {
RangeCheckResult::InRange
} else {
if line < self.largest_upper_bound {
RangeCheckResult::OutsideRange
} else {
RangeCheckResult::AfterLastRange
}
}
RangeCheckResult::AfterLastRange
}
}
}

View File

@ -67,7 +67,7 @@ mod errors {
pub fn handle_error(error: &Error) {
match error {
&Error(ErrorKind::Io(ref io_error), _)
Error(ErrorKind::Io(ref io_error), _)
if io_error.kind() == super::io::ErrorKind::BrokenPipe =>
{
super::process::exit(0);

View File

@ -51,7 +51,7 @@ impl OutputType {
let pager = pager_from_config
.or(pager_from_env)
.unwrap_or(String::from("less"));
.unwrap_or_else(|| String::from("less"));
let pagerflags =
shell_words::split(&pager).chain_err(|| "Could not parse pager command.")?;

View File

@ -64,7 +64,7 @@ impl Printer for SimplePrinter {
line_buffer: &[u8],
) -> Result<()> {
if !out_of_range {
handle.write(line_buffer)?;
handle.write_all(line_buffer)?;
}
Ok(())
}
@ -270,7 +270,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
};
if self.config.show_nonprintable {
line = replace_nonprintable(&mut line, self.config.tab_width);
line = replace_nonprintable(&line, self.config.tab_width);
}
let regions = {
@ -355,11 +355,11 @@ impl<'a> Printer for InteractivePrinter<'a> {
}
if line.bytes().next_back() != Some(b'\n') {
write!(handle, "\n")?;
writeln!(handle)?;
}
} else {
for &(style, region) in regions.iter() {
let mut ansi_iterator = AnsiCodeIterator::new(region);
let ansi_iterator = AnsiCodeIterator::new(region);
let mut ansi_prefix: String = String::new();
for chunk in ansi_iterator {
match chunk {
@ -472,7 +472,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
ansi_style.paint(" ".repeat(cursor_max - cursor))
)?;
}
write!(handle, "\n")?;
writeln!(handle)?;
}
Ok(())

View File

@ -21,8 +21,8 @@ pub enum OutputWrap {
}
impl OutputComponent {
pub fn components(&self, interactive_terminal: bool) -> &'static [OutputComponent] {
match *self {
pub fn components(self, interactive_terminal: bool) -> &'static [OutputComponent] {
match self {
OutputComponent::Auto => {
if interactive_terminal {
OutputComponent::Full.components(interactive_terminal)

View File

@ -1,14 +1,15 @@
use std::borrow::Cow;
use std::collections::HashMap;
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct SyntaxMapping(HashMap<String, String>);
impl SyntaxMapping {
pub fn new() -> SyntaxMapping {
SyntaxMapping(HashMap::new())
Default::default()
}
pub fn insert(&mut self, from: impl Into<String>, to: impl Into<String>) -> Option<String> {
self.0.insert(from.into(), to.into())
}