mirror of
https://github.com/sharkdp/bat.git
synced 2025-02-15 01:18:31 +00:00
Merge pull request #3197 from einfachIrgendwer0815/style/fix_lints
Fix clippy lint warnings
This commit is contained in:
commit
a95e65eea1
@ -370,7 +370,7 @@ mod tests {
|
|||||||
pub temp_dir: TempDir,
|
pub temp_dir: TempDir,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> SyntaxDetectionTest<'a> {
|
impl SyntaxDetectionTest<'_> {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
SyntaxDetectionTest {
|
SyntaxDetectionTest {
|
||||||
assets: HighlightingAssets::from_binary(),
|
assets: HighlightingAssets::from_binary(),
|
||||||
|
@ -60,7 +60,7 @@ fn to_path_and_stem(source_dir: &Path, entry: DirEntry) -> Option<PathAndStem> {
|
|||||||
fn handle_file(path_and_stem: &PathAndStem) -> Result<Option<String>> {
|
fn handle_file(path_and_stem: &PathAndStem) -> Result<Option<String>> {
|
||||||
if path_and_stem.stem == "NOTICE" {
|
if path_and_stem.stem == "NOTICE" {
|
||||||
handle_notice(&path_and_stem.path)
|
handle_notice(&path_and_stem.path)
|
||||||
} else if path_and_stem.stem.to_ascii_uppercase() == "LICENSE" {
|
} else if path_and_stem.stem.eq_ignore_ascii_case("LICENSE") {
|
||||||
handle_license(&path_and_stem.path)
|
handle_license(&path_and_stem.path)
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
|
@ -425,7 +425,7 @@ impl App {
|
|||||||
None => StyleComponents(HashSet::from_iter(
|
None => StyleComponents(HashSet::from_iter(
|
||||||
StyleComponent::Default
|
StyleComponent::Default
|
||||||
.components(self.interactive_output)
|
.components(self.interactive_output)
|
||||||
.into_iter()
|
.iter()
|
||||||
.cloned(),
|
.cloned(),
|
||||||
)),
|
)),
|
||||||
};
|
};
|
||||||
|
@ -25,7 +25,7 @@ pub struct Controller<'a> {
|
|||||||
preprocessor: Option<LessOpenPreprocessor>,
|
preprocessor: Option<LessOpenPreprocessor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'b> Controller<'b> {
|
impl Controller<'_> {
|
||||||
pub fn new<'a>(config: &'a Config, assets: &'a HighlightingAssets) -> Controller<'a> {
|
pub fn new<'a>(config: &'a Config, assets: &'a HighlightingAssets) -> Controller<'a> {
|
||||||
Controller {
|
Controller {
|
||||||
config,
|
config,
|
||||||
|
@ -75,7 +75,7 @@ pub(crate) enum InputKind<'a> {
|
|||||||
CustomReader(Box<dyn Read + 'a>),
|
CustomReader(Box<dyn Read + 'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> InputKind<'a> {
|
impl InputKind<'_> {
|
||||||
pub fn description(&self) -> InputDescription {
|
pub fn description(&self) -> InputDescription {
|
||||||
match self {
|
match self {
|
||||||
InputKind::OrdinaryFile(ref path) => InputDescription::new(path.to_string_lossy()),
|
InputKind::OrdinaryFile(ref path) => InputDescription::new(path.to_string_lossy()),
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#![cfg(feature = "lessopen")]
|
|
||||||
|
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
@ -200,7 +198,7 @@ impl LessOpenPreprocessor {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fall_back_to_original_file(&self, lessopen_stdout: &Vec<u8>, exit_code: ExitStatus) -> bool {
|
fn fall_back_to_original_file(&self, lessopen_stdout: &[u8], exit_code: ExitStatus) -> bool {
|
||||||
lessopen_stdout.is_empty()
|
lessopen_stdout.is_empty()
|
||||||
&& (!exit_code.success() || matches!(self.kind, LessOpenKind::PipedIgnoreExitCode))
|
&& (!exit_code.success() || matches!(self.kind, LessOpenKind::PipedIgnoreExitCode))
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,8 @@ pub struct LineRange {
|
|||||||
impl Default for LineRange {
|
impl Default for LineRange {
|
||||||
fn default() -> LineRange {
|
fn default() -> LineRange {
|
||||||
LineRange {
|
LineRange {
|
||||||
lower: usize::min_value(),
|
lower: usize::MIN,
|
||||||
upper: usize::max_value(),
|
upper: usize::MAX,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ fn test_parse_full() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_parse_partial_min() {
|
fn test_parse_partial_min() {
|
||||||
let range = LineRange::from(":50").expect("Shouldn't fail on test!");
|
let range = LineRange::from(":50").expect("Shouldn't fail on test!");
|
||||||
assert_eq!(usize::min_value(), range.lower);
|
assert_eq!(usize::MIN, range.lower);
|
||||||
assert_eq!(50, range.upper);
|
assert_eq!(50, range.upper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ fn test_parse_partial_min() {
|
|||||||
fn test_parse_partial_max() {
|
fn test_parse_partial_max() {
|
||||||
let range = LineRange::from("40:").expect("Shouldn't fail on test!");
|
let range = LineRange::from("40:").expect("Shouldn't fail on test!");
|
||||||
assert_eq!(40, range.lower);
|
assert_eq!(40, range.lower);
|
||||||
assert_eq!(usize::max_value(), range.upper);
|
assert_eq!(usize::MAX, range.upper);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -203,11 +203,7 @@ impl LineRanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn from(ranges: Vec<LineRange>) -> LineRanges {
|
pub fn from(ranges: Vec<LineRange>) -> LineRanges {
|
||||||
let largest_upper_bound = ranges
|
let largest_upper_bound = ranges.iter().map(|r| r.upper).max().unwrap_or(usize::MAX);
|
||||||
.iter()
|
|
||||||
.map(|r| r.upper)
|
|
||||||
.max()
|
|
||||||
.unwrap_or(usize::max_value());
|
|
||||||
LineRanges {
|
LineRanges {
|
||||||
ranges,
|
ranges,
|
||||||
largest_upper_bound,
|
largest_upper_bound,
|
||||||
|
@ -73,7 +73,7 @@ pub enum OutputHandle<'a> {
|
|||||||
FmtWrite(&'a mut dyn fmt::Write),
|
FmtWrite(&'a mut dyn fmt::Write),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> OutputHandle<'a> {
|
impl OutputHandle<'_> {
|
||||||
fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> Result<()> {
|
fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> Result<()> {
|
||||||
match self {
|
match self {
|
||||||
Self::IoWrite(handle) => handle.write_fmt(args).map_err(Into::into),
|
Self::IoWrite(handle) => handle.write_fmt(args).map_err(Into::into),
|
||||||
@ -116,7 +116,7 @@ impl<'a> SimplePrinter<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Printer for SimplePrinter<'a> {
|
impl Printer for SimplePrinter<'_> {
|
||||||
fn print_header(
|
fn print_header(
|
||||||
&mut self,
|
&mut self,
|
||||||
_handle: &mut OutputHandle,
|
_handle: &mut OutputHandle,
|
||||||
@ -144,7 +144,7 @@ impl<'a> Printer for SimplePrinter<'a> {
|
|||||||
// Skip squeezed lines.
|
// Skip squeezed lines.
|
||||||
if let Some(squeeze_limit) = self.config.squeeze_lines {
|
if let Some(squeeze_limit) = self.config.squeeze_lines {
|
||||||
if String::from_utf8_lossy(line_buffer)
|
if String::from_utf8_lossy(line_buffer)
|
||||||
.trim_end_matches(|c| c == '\r' || c == '\n')
|
.trim_end_matches(['\r', '\n'])
|
||||||
.is_empty()
|
.is_empty()
|
||||||
{
|
{
|
||||||
self.consecutive_empty_lines += 1;
|
self.consecutive_empty_lines += 1;
|
||||||
@ -267,7 +267,7 @@ impl<'a> InteractivePrinter<'a> {
|
|||||||
let is_printing_binary = input
|
let is_printing_binary = input
|
||||||
.reader
|
.reader
|
||||||
.content_type
|
.content_type
|
||||||
.map_or(false, |c| c.is_binary() && !config.show_nonprintable);
|
.is_some_and(|c| c.is_binary() && !config.show_nonprintable);
|
||||||
|
|
||||||
let needs_to_match_syntax = (!is_printing_binary
|
let needs_to_match_syntax = (!is_printing_binary
|
||||||
|| matches!(config.binary, BinaryBehavior::AsText))
|
|| matches!(config.binary, BinaryBehavior::AsText))
|
||||||
@ -432,7 +432,7 @@ impl<'a> InteractivePrinter<'a> {
|
|||||||
.highlight_line(for_highlighting, highlighter_from_set.syntax_set)?;
|
.highlight_line(for_highlighting, highlighter_from_set.syntax_set)?;
|
||||||
|
|
||||||
if too_long {
|
if too_long {
|
||||||
highlighted_line[0].1 = &line;
|
highlighted_line[0].1 = line;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(highlighted_line)
|
Ok(highlighted_line)
|
||||||
@ -448,7 +448,7 @@ impl<'a> InteractivePrinter<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Printer for InteractivePrinter<'a> {
|
impl Printer for InteractivePrinter<'_> {
|
||||||
fn print_header(
|
fn print_header(
|
||||||
&mut self,
|
&mut self,
|
||||||
handle: &mut OutputHandle,
|
handle: &mut OutputHandle,
|
||||||
@ -544,7 +544,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
if self.config.style_components.grid() {
|
if self.config.style_components.grid() {
|
||||||
if self.content_type.map_or(false, |c| c.is_text())
|
if self.content_type.is_some_and(|c| c.is_text())
|
||||||
|| self.config.show_nonprintable
|
|| self.config.show_nonprintable
|
||||||
|| matches!(self.config.binary, BinaryBehavior::AsText)
|
|| matches!(self.config.binary, BinaryBehavior::AsText)
|
||||||
{
|
{
|
||||||
@ -559,7 +559,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
|||||||
|
|
||||||
fn print_footer(&mut self, handle: &mut OutputHandle, _input: &OpenedInput) -> Result<()> {
|
fn print_footer(&mut self, handle: &mut OutputHandle, _input: &OpenedInput) -> Result<()> {
|
||||||
if self.config.style_components.grid()
|
if self.config.style_components.grid()
|
||||||
&& (self.content_type.map_or(false, |c| c.is_text())
|
&& (self.content_type.is_some_and(|c| c.is_text())
|
||||||
|| self.config.show_nonprintable
|
|| self.config.show_nonprintable
|
||||||
|| matches!(self.config.binary, BinaryBehavior::AsText))
|
|| matches!(self.config.binary, BinaryBehavior::AsText))
|
||||||
{
|
{
|
||||||
@ -644,7 +644,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
|||||||
|
|
||||||
// Skip squeezed lines.
|
// Skip squeezed lines.
|
||||||
if let Some(squeeze_limit) = self.config.squeeze_lines {
|
if let Some(squeeze_limit) = self.config.squeeze_lines {
|
||||||
if line.trim_end_matches(|c| c == '\r' || c == '\n').is_empty() {
|
if line.trim_end_matches(['\r', '\n']).is_empty() {
|
||||||
self.consecutive_empty_lines += 1;
|
self.consecutive_empty_lines += 1;
|
||||||
if self.consecutive_empty_lines > squeeze_limit {
|
if self.consecutive_empty_lines > squeeze_limit {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@ -697,7 +697,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
|||||||
// Regular text.
|
// Regular text.
|
||||||
EscapeSequence::Text(text) => {
|
EscapeSequence::Text(text) => {
|
||||||
let text = self.preprocess(text, &mut cursor_total);
|
let text = self.preprocess(text, &mut cursor_total);
|
||||||
let text_trimmed = text.trim_end_matches(|c| c == '\r' || c == '\n');
|
let text_trimmed = text.trim_end_matches(['\r', '\n']);
|
||||||
|
|
||||||
write!(
|
write!(
|
||||||
handle,
|
handle,
|
||||||
@ -751,10 +751,8 @@ impl<'a> Printer for InteractivePrinter<'a> {
|
|||||||
match chunk {
|
match chunk {
|
||||||
// Regular text.
|
// Regular text.
|
||||||
EscapeSequence::Text(text) => {
|
EscapeSequence::Text(text) => {
|
||||||
let text = self.preprocess(
|
let text = self
|
||||||
text.trim_end_matches(|c| c == '\r' || c == '\n'),
|
.preprocess(text.trim_end_matches(['\r', '\n']), &mut cursor_total);
|
||||||
&mut cursor_total,
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut max_width = cursor_max - cursor;
|
let mut max_width = cursor_max - cursor;
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ impl FromStr for StyleComponentList {
|
|||||||
fn from_str(s: &str) -> Result<Self> {
|
fn from_str(s: &str) -> Result<Self> {
|
||||||
Ok(StyleComponentList(
|
Ok(StyleComponentList(
|
||||||
s.split(",")
|
s.split(",")
|
||||||
.map(|s| ComponentAction::extract_from_str(s)) // If the component starts with "-", it's meant to be removed
|
.map(ComponentAction::extract_from_str) // If the component starts with "-", it's meant to be removed
|
||||||
.map(|(a, s)| Ok((a, StyleComponent::from_str(s)?)))
|
.map(|(a, s)| Ok((a, StyleComponent::from_str(s)?)))
|
||||||
.collect::<Result<Vec<(ComponentAction, StyleComponent)>>>()?,
|
.collect::<Result<Vec<(ComponentAction, StyleComponent)>>>()?,
|
||||||
))
|
))
|
||||||
|
@ -61,7 +61,7 @@ pub struct SyntaxMapping<'a> {
|
|||||||
halt_glob_build: Arc<AtomicBool>,
|
halt_glob_build: Arc<AtomicBool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Drop for SyntaxMapping<'a> {
|
impl Drop for SyntaxMapping<'_> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// signal the offload thread to halt early
|
// signal the offload thread to halt early
|
||||||
self.halt_glob_build.store(true, Ordering::Relaxed);
|
self.halt_glob_build.store(true, Ordering::Relaxed);
|
||||||
@ -153,7 +153,7 @@ impl<'a> SyntaxMapping<'a> {
|
|||||||
if glob.is_match_candidate(&candidate)
|
if glob.is_match_candidate(&candidate)
|
||||||
|| candidate_filename
|
|| candidate_filename
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(false, |filename| glob.is_match_candidate(filename))
|
.is_some_and(|filename| glob.is_match_candidate(filename))
|
||||||
{
|
{
|
||||||
return Some(*syntax);
|
return Some(*syntax);
|
||||||
}
|
}
|
||||||
|
@ -383,7 +383,6 @@ mod tests {
|
|||||||
theme: ThemePreference::Fixed(ThemeName::Named("Theme".to_string())),
|
theme: ThemePreference::Fixed(ThemeName::Named("Theme".to_string())),
|
||||||
theme_dark: Some(ThemeName::Named("Dark Theme".to_string())),
|
theme_dark: Some(ThemeName::Named("Dark Theme".to_string())),
|
||||||
theme_light: Some(ThemeName::Named("Light Theme".to_string())),
|
theme_light: Some(ThemeName::Named("Light Theme".to_string())),
|
||||||
..Default::default()
|
|
||||||
},
|
},
|
||||||
] {
|
] {
|
||||||
let detector = ConstantDetector(color_scheme);
|
let detector = ConstantDetector(color_scheme);
|
||||||
@ -509,7 +508,7 @@ mod tests {
|
|||||||
ThemePreference::Light,
|
ThemePreference::Light,
|
||||||
];
|
];
|
||||||
for pref in prefs {
|
for pref in prefs {
|
||||||
assert_eq!(pref, ThemePreference::new(&pref.to_string()));
|
assert_eq!(pref, ThemePreference::new(pref.to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -360,10 +360,10 @@ pub struct EscapeSequenceOffsetsIterator<'a> {
|
|||||||
|
|
||||||
impl<'a> EscapeSequenceOffsetsIterator<'a> {
|
impl<'a> EscapeSequenceOffsetsIterator<'a> {
|
||||||
pub fn new(text: &'a str) -> EscapeSequenceOffsetsIterator<'a> {
|
pub fn new(text: &'a str) -> EscapeSequenceOffsetsIterator<'a> {
|
||||||
return EscapeSequenceOffsetsIterator {
|
EscapeSequenceOffsetsIterator {
|
||||||
text,
|
text,
|
||||||
chars: text.char_indices().peekable(),
|
chars: text.char_indices().peekable(),
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Takes values from the iterator while the predicate returns true.
|
/// Takes values from the iterator while the predicate returns true.
|
||||||
@ -539,7 +539,7 @@ impl<'a> EscapeSequenceOffsetsIterator<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for EscapeSequenceOffsetsIterator<'a> {
|
impl Iterator for EscapeSequenceOffsetsIterator<'_> {
|
||||||
type Item = EscapeSequenceOffsets;
|
type Item = EscapeSequenceOffsets;
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
match self.chars.peek() {
|
match self.chars.peek() {
|
||||||
@ -564,10 +564,10 @@ pub struct EscapeSequenceIterator<'a> {
|
|||||||
|
|
||||||
impl<'a> EscapeSequenceIterator<'a> {
|
impl<'a> EscapeSequenceIterator<'a> {
|
||||||
pub fn new(text: &'a str) -> EscapeSequenceIterator<'a> {
|
pub fn new(text: &'a str) -> EscapeSequenceIterator<'a> {
|
||||||
return EscapeSequenceIterator {
|
EscapeSequenceIterator {
|
||||||
text,
|
text,
|
||||||
offset_iter: EscapeSequenceOffsetsIterator::new(text),
|
offset_iter: EscapeSequenceOffsetsIterator::new(text),
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,13 +35,7 @@ fn all_jobs_not_missing_any_jobs() {
|
|||||||
.as_mapping()
|
.as_mapping()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.keys()
|
.keys()
|
||||||
.filter_map(|k| {
|
.filter(|k| !exceptions.contains(&k.as_str().unwrap_or_default()))
|
||||||
if exceptions.contains(&k.as_str().unwrap_or_default()) {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(k)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.map(ToOwned::to_owned)
|
.map(ToOwned::to_owned)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
@ -1832,7 +1832,7 @@ fn do_not_panic_regression_tests() {
|
|||||||
] {
|
] {
|
||||||
bat()
|
bat()
|
||||||
.arg("--color=always")
|
.arg("--color=always")
|
||||||
.arg(&format!("regression_tests/{filename}"))
|
.arg(format!("regression_tests/{filename}"))
|
||||||
.assert()
|
.assert()
|
||||||
.success();
|
.success();
|
||||||
}
|
}
|
||||||
@ -1845,7 +1845,7 @@ fn do_not_detect_different_syntax_for_stdin_and_files() {
|
|||||||
let cmd_for_file = bat()
|
let cmd_for_file = bat()
|
||||||
.arg("--color=always")
|
.arg("--color=always")
|
||||||
.arg("--map-syntax=*.js:Markdown")
|
.arg("--map-syntax=*.js:Markdown")
|
||||||
.arg(&format!("--file-name={file}"))
|
.arg(format!("--file-name={file}"))
|
||||||
.arg("--style=plain")
|
.arg("--style=plain")
|
||||||
.arg(file)
|
.arg(file)
|
||||||
.assert()
|
.assert()
|
||||||
@ -1855,7 +1855,7 @@ fn do_not_detect_different_syntax_for_stdin_and_files() {
|
|||||||
.arg("--color=always")
|
.arg("--color=always")
|
||||||
.arg("--map-syntax=*.js:Markdown")
|
.arg("--map-syntax=*.js:Markdown")
|
||||||
.arg("--style=plain")
|
.arg("--style=plain")
|
||||||
.arg(&format!("--file-name={file}"))
|
.arg(format!("--file-name={file}"))
|
||||||
.pipe_stdin(Path::new(EXAMPLES_DIR).join(file))
|
.pipe_stdin(Path::new(EXAMPLES_DIR).join(file))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.assert()
|
.assert()
|
||||||
@ -1874,7 +1874,7 @@ fn no_first_line_fallback_when_mapping_to_invalid_syntax() {
|
|||||||
bat()
|
bat()
|
||||||
.arg("--color=always")
|
.arg("--color=always")
|
||||||
.arg("--map-syntax=*.invalid-syntax:InvalidSyntax")
|
.arg("--map-syntax=*.invalid-syntax:InvalidSyntax")
|
||||||
.arg(&format!("--file-name={file}"))
|
.arg(format!("--file-name={file}"))
|
||||||
.arg("--style=plain")
|
.arg("--style=plain")
|
||||||
.arg(file)
|
.arg(file)
|
||||||
.assert()
|
.assert()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user