1
0
mirror of https://github.com/sharkdp/bat synced 2026-08-02 18:41:42 +00:00

Fix some clippy lints

Some might actually improve perf
This commit is contained in:
Lzu Tao
2020-04-24 13:46:01 +07:00
committed by David Peter
parent a4828387c1
commit e37e9c1214
12 changed files with 30 additions and 33 deletions
+6 -4
View File
@@ -80,6 +80,7 @@ impl App {
let paging_mode = match self.matches.value_of("paging") {
Some("always") => PagingMode::Always,
Some("never") => PagingMode::Never,
// FIXME: `_` will always cover in or patterns
Some("auto") | _ => {
if self.matches.occurrences_of("plain") > 1 {
// If we have -pp as an option when in auto mode, the pager should be disabled.
@@ -147,6 +148,7 @@ impl App {
match self.matches.value_of("wrap") {
Some("character") => WrappingMode::Character,
Some("never") => WrappingMode::NoWrapping,
// FIXME: `_` will always cover in or patterns
Some("auto") | _ => {
if style_components.plain() {
WrappingMode::NoWrapping
@@ -249,18 +251,18 @@ impl App {
let mut filenames_or_none: Box<dyn Iterator<Item = _>> = match filenames {
Some(ref filenames) => {
Box::new(filenames.into_iter().map(|name| Some(OsStr::new(*name))))
Box::new(filenames.iter().map(|name| Some(OsStr::new(*name))))
}
None => Box::new(std::iter::repeat(None)),
};
let files: Option<Vec<&OsStr>> = self.matches.values_of_os("FILE").map(|vs| vs.collect());
if files.is_none() {
let input = Input::stdin().with_name(filenames_or_none.nth(0).unwrap_or(None));
let input = Input::stdin().with_name(filenames_or_none.next().unwrap_or(None));
return Ok(vec![input]);
}
let files_or_none: Box<dyn Iterator<Item = _>> = match files {
Some(ref files) => Box::new(files.into_iter().map(|name| Some(*name))),
Some(ref files) => Box::new(files.iter().map(|name| Some(*name))),
None => Box::new(std::iter::repeat(None)),
};
@@ -274,7 +276,7 @@ impl App {
}
}
}
return Ok(file_input);
Ok(file_input)
}
fn style_components(&self) -> Result<StyleComponents> {
+1 -1
View File
@@ -53,5 +53,5 @@ pub fn assets_from_cache_or_binary() -> Result<HighlightingAssets> {
}
}
Ok(HighlightingAssets::from_cache(&cache_dir).unwrap_or(HighlightingAssets::from_binary()))
Ok(HighlightingAssets::from_cache(&cache_dir).unwrap_or_else(|_| HighlightingAssets::from_binary()))
}
+1 -1
View File
@@ -180,7 +180,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
t.parse::<i32>()
.map_err(|_e| "must be an offset or number")
.and_then(|v| if v == 0 && !is_offset {
Err("terminal width cannot be zero".into())
Err("terminal width cannot be zero")
} else {
Ok(())
})
+3 -3
View File
@@ -35,10 +35,10 @@ pub fn generate_config_file() -> bat::error::Result<()> {
match config_dir {
Some(path) => fs::create_dir_all(path)?,
None => {
return Ok(Err(format!(
return Err(format!(
"Unable to write config file to: {}",
config_file.to_string_lossy()
))?)
).into());
}
}
}
@@ -77,7 +77,7 @@ pub fn generate_config_file() -> bat::error::Result<()> {
config_file.to_string_lossy()
);
return Ok(());
Ok(())
}
pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseError> {
+1 -1
View File
@@ -70,7 +70,7 @@ pub fn list_languages(config: &Config) -> Result<()> {
if config.loop_through {
for lang in languages {
write!(stdout, "{}:{}\n", lang.name, lang.file_extensions.join(","))?;
writeln!(stdout, "{}:{}", lang.name, lang.file_extensions.join(","))?;
}
} else {
let longest = languages