mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-06-25 14:22:54 +02:00
fix some clippy lints (#288)
This commit is contained in:
committed by
Andrew Gallant
parent
cbacf4f19e
commit
dd5ded2f78
10
src/args.rs
10
src/args.rs
@ -26,7 +26,7 @@ use worker::{Worker, WorkerBuilder};
|
|||||||
|
|
||||||
use {Result, version};
|
use {Result, version};
|
||||||
|
|
||||||
/// Args are transformed/normalized from ArgMatches.
|
/// `Args` are transformed/normalized from `ArgMatches`.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
paths: Vec<PathBuf>,
|
paths: Vec<PathBuf>,
|
||||||
@ -80,12 +80,12 @@ impl Args {
|
|||||||
let matches = app::app_short().get_matches();
|
let matches = app::app_short().get_matches();
|
||||||
if matches.is_present("help-short") {
|
if matches.is_present("help-short") {
|
||||||
let _ = ::app::app_short().print_help();
|
let _ = ::app::app_short().print_help();
|
||||||
let _ = println!("");
|
println!("");
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
}
|
}
|
||||||
if matches.is_present("help") {
|
if matches.is_present("help") {
|
||||||
let _ = ::app::app_long().print_help();
|
let _ = ::app::app_long().print_help();
|
||||||
let _ = println!("");
|
println!("");
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
}
|
}
|
||||||
if matches.is_present("version") {
|
if matches.is_present("version") {
|
||||||
@ -264,7 +264,7 @@ impl Args {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ArgMatches wraps clap::ArgMatches and provides semantic meaning to several
|
/// `ArgMatches` wraps `clap::ArgMatches` and provides semantic meaning to several
|
||||||
/// options/flags.
|
/// options/flags.
|
||||||
struct ArgMatches<'a>(clap::ArgMatches<'a>);
|
struct ArgMatches<'a>(clap::ArgMatches<'a>);
|
||||||
|
|
||||||
@ -723,7 +723,7 @@ impl<'a> ArgMatches<'a> {
|
|||||||
/// Like values_of_lossy, but returns an empty vec if the flag is not
|
/// Like values_of_lossy, but returns an empty vec if the flag is not
|
||||||
/// present.
|
/// present.
|
||||||
fn values_of_lossy_vec(&self, name: &str) -> Vec<String> {
|
fn values_of_lossy_vec(&self, name: &str) -> Vec<String> {
|
||||||
self.values_of_lossy(name).unwrap_or(vec![])
|
self.values_of_lossy(name).unwrap_or_else(Vec::new)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Safely reads an arg value with the given name, and if it's present,
|
/// Safely reads an arg value with the given name, and if it's present,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*!
|
/*!
|
||||||
The pathutil module provides platform specific operations on paths that are
|
The pathutil module provides platform specific operations on paths that are
|
||||||
typically faster than the same operations as provided in std::path. In
|
typically faster than the same operations as provided in `std::path`. In
|
||||||
particular, we really want to avoid the costly operation of parsing the path
|
particular, we really want to avoid the costly operation of parsing the path
|
||||||
into its constituent components. We give up on Windows, but on Unix, we deal
|
into its constituent components. We give up on Windows, but on Unix, we deal
|
||||||
with the raw bytes directly.
|
with the raw bytes directly.
|
||||||
@ -26,7 +26,7 @@ pub fn strip_prefix<'a, P: AsRef<Path> + ?Sized>(
|
|||||||
if prefix.len() > path.len() || prefix != &path[0..prefix.len()] {
|
if prefix.len() > path.len() || prefix != &path[0..prefix.len()] {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(&Path::new(OsStr::from_bytes(&path[prefix.len()..])))
|
Some(Path::new(OsStr::from_bytes(&path[prefix.len()..])))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,7 +579,7 @@ impl FromStr for Spec {
|
|||||||
type Err = Error;
|
type Err = Error;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Spec, Error> {
|
fn from_str(s: &str) -> Result<Spec, Error> {
|
||||||
let pieces: Vec<&str> = s.split(":").collect();
|
let pieces: Vec<&str> = s.split(':').collect();
|
||||||
if pieces.len() <= 1 || pieces.len() > 3 {
|
if pieces.len() <= 1 || pieces.len() > 3 {
|
||||||
return Err(Error::InvalidFormat(s.to_string()));
|
return Err(Error::InvalidFormat(s.to_string()));
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
/*!
|
/*!
|
||||||
The search_buffer module is responsible for searching a single file all in a
|
The `search_buffer` module is responsible for searching a single file all in a
|
||||||
single buffer. Typically, the source of the buffer is a memory map. This can
|
single buffer. Typically, the source of the buffer is a memory map. This can
|
||||||
be useful for when memory maps are faster than streaming search.
|
be useful for when memory maps are faster than streaming search.
|
||||||
|
|
||||||
Note that this module doesn't quite support everything that search_stream does.
|
Note that this module doesn't quite support everything that `search_stream` does.
|
||||||
Notably, showing contexts.
|
Notably, showing contexts.
|
||||||
*/
|
*/
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*!
|
/*!
|
||||||
The search_stream module is responsible for searching a single file and
|
The `search_stream` module is responsible for searching a single file and
|
||||||
printing matches. In particular, it searches the file in a streaming fashion
|
printing matches. In particular, it searches the file in a streaming fashion
|
||||||
using `read` calls and a (roughly) fixed size buffer.
|
using `read` calls and a (roughly) fixed size buffer.
|
||||||
*/
|
*/
|
||||||
@ -272,7 +272,7 @@ impl<'a, R: io::Read, W: WriteColor> Searcher<'a, R, W> {
|
|||||||
while !self.terminate() && self.inp.pos < self.inp.lastnl {
|
while !self.terminate() && self.inp.pos < self.inp.lastnl {
|
||||||
let matched = self.grep.read_match(
|
let matched = self.grep.read_match(
|
||||||
&mut self.last_match,
|
&mut self.last_match,
|
||||||
&mut self.inp.buf[..self.inp.lastnl],
|
&self.inp.buf[..self.inp.lastnl],
|
||||||
self.inp.pos);
|
self.inp.pos);
|
||||||
if self.opts.invert_match {
|
if self.opts.invert_match {
|
||||||
let upto =
|
let upto =
|
||||||
@ -331,12 +331,12 @@ impl<'a, R: io::Read, W: WriteColor> Searcher<'a, R, W> {
|
|||||||
lines);
|
lines);
|
||||||
}
|
}
|
||||||
if keep < self.last_printed {
|
if keep < self.last_printed {
|
||||||
self.last_printed = self.last_printed - keep;
|
self.last_printed -= keep;
|
||||||
} else {
|
} else {
|
||||||
self.last_printed = 0;
|
self.last_printed = 0;
|
||||||
}
|
}
|
||||||
if keep <= self.last_line {
|
if keep <= self.last_line {
|
||||||
self.last_line = self.last_line - keep;
|
self.last_line -= keep;
|
||||||
} else {
|
} else {
|
||||||
self.count_lines(keep);
|
self.count_lines(keep);
|
||||||
self.last_line = 0;
|
self.last_line = 0;
|
||||||
@ -457,7 +457,7 @@ impl<'a, R: io::Read, W: WriteColor> Searcher<'a, R, W> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// InputBuffer encapsulates the logic of maintaining a ~fixed sized buffer
|
/// `InputBuffer` encapsulates the logic of maintaining a ~fixed sized buffer
|
||||||
/// on which to search. There are three key pieces of complexity:
|
/// on which to search. There are three key pieces of complexity:
|
||||||
///
|
///
|
||||||
/// 1. We must be able to handle lines that are longer than the size of the
|
/// 1. We must be able to handle lines that are longer than the size of the
|
||||||
@ -473,7 +473,7 @@ impl<'a, R: io::Read, W: WriteColor> Searcher<'a, R, W> {
|
|||||||
/// may occur at the beginning of a buffer, in which case, lines at the end
|
/// may occur at the beginning of a buffer, in which case, lines at the end
|
||||||
/// of the previous contents of the buffer need to be printed.
|
/// of the previous contents of the buffer need to be printed.
|
||||||
///
|
///
|
||||||
/// An InputBuffer is designed to be reused and isn't tied to any particular
|
/// An `InputBuffer` is designed to be reused and isn't tied to any particular
|
||||||
/// reader.
|
/// reader.
|
||||||
pub struct InputBuffer {
|
pub struct InputBuffer {
|
||||||
/// The number of bytes to attempt to read at a time. Once set, this is
|
/// The number of bytes to attempt to read at a time. Once set, this is
|
||||||
|
@ -30,7 +30,7 @@ pub fn unescape(s: &str) -> Vec<u8> {
|
|||||||
't' => { bytes.push(b'\t'); state = Literal; }
|
't' => { bytes.push(b'\t'); state = Literal; }
|
||||||
'x' => { state = HexFirst; }
|
'x' => { state = HexFirst; }
|
||||||
c => {
|
c => {
|
||||||
bytes.extend(&format!(r"\{}", c).into_bytes());
|
bytes.extend(format!(r"\{}", c).into_bytes());
|
||||||
state = Literal;
|
state = Literal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ pub fn unescape(s: &str) -> Vec<u8> {
|
|||||||
state = HexSecond(c);
|
state = HexSecond(c);
|
||||||
}
|
}
|
||||||
c => {
|
c => {
|
||||||
bytes.extend(&format!(r"\x{}", c).into_bytes());
|
bytes.extend(format!(r"\x{}", c).into_bytes());
|
||||||
state = Literal;
|
state = Literal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ pub fn unescape(s: &str) -> Vec<u8> {
|
|||||||
}
|
}
|
||||||
c => {
|
c => {
|
||||||
let original = format!(r"\x{}{}", first, c);
|
let original = format!(r"\x{}{}", first, c);
|
||||||
bytes.extend(&original.into_bytes());
|
bytes.extend(original.into_bytes());
|
||||||
state = Literal;
|
state = Literal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ pub fn unescape(s: &str) -> Vec<u8> {
|
|||||||
match state {
|
match state {
|
||||||
Escape => bytes.push(b'\\'),
|
Escape => bytes.push(b'\\'),
|
||||||
HexFirst => bytes.extend(b"\\x"),
|
HexFirst => bytes.extend(b"\\x"),
|
||||||
HexSecond(c) => bytes.extend(&format!("\\x{}", c).into_bytes()),
|
HexSecond(c) => bytes.extend(format!("\\x{}", c).into_bytes()),
|
||||||
Literal => {}
|
Literal => {}
|
||||||
}
|
}
|
||||||
bytes
|
bytes
|
||||||
|
@ -199,7 +199,7 @@ impl Worker {
|
|||||||
Work::Stdin => {
|
Work::Stdin => {
|
||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
let stdin = stdin.lock();
|
let stdin = stdin.lock();
|
||||||
self.search(printer, &Path::new("<stdin>"), stdin)
|
self.search(printer, Path::new("<stdin>"), stdin)
|
||||||
}
|
}
|
||||||
Work::DirEntry(dent) => {
|
Work::DirEntry(dent) => {
|
||||||
let mut path = dent.path();
|
let mut path = dent.path();
|
||||||
|
Reference in New Issue
Block a user