mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-12-13 20:35:47 +01:00
style: apply rustfmt
Maybe 2024 changes? Note that we now set `edition = "2024"` explicitly in `rustfmt.toml`. Without this, it seems like it's possible in some cases for rustfmt to run under an older edition's style. Not sure how though.
This commit is contained in:
@@ -16,7 +16,7 @@ use std::{ffi::OsString, io};
|
||||
pub fn hostname() -> io::Result<OsString> {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
use winapi_util::sysinfo::{get_computer_name, ComputerNameKind};
|
||||
use winapi_util::sysinfo::{ComputerNameKind, get_computer_name};
|
||||
get_computer_name(ComputerNameKind::PhysicalDnsHostname)
|
||||
}
|
||||
#[cfg(unix)]
|
||||
|
||||
@@ -133,19 +133,19 @@ mod wtr;
|
||||
|
||||
pub use crate::{
|
||||
decompress::{
|
||||
resolve_binary, DecompressionMatcher, DecompressionMatcherBuilder,
|
||||
DecompressionReader, DecompressionReaderBuilder,
|
||||
DecompressionMatcher, DecompressionMatcherBuilder,
|
||||
DecompressionReader, DecompressionReaderBuilder, resolve_binary,
|
||||
},
|
||||
escape::{escape, escape_os, unescape, unescape_os},
|
||||
hostname::hostname,
|
||||
human::{parse_human_readable_size, ParseSizeError},
|
||||
human::{ParseSizeError, parse_human_readable_size},
|
||||
pattern::{
|
||||
pattern_from_bytes, pattern_from_os, patterns_from_path,
|
||||
patterns_from_reader, patterns_from_stdin, InvalidPatternError,
|
||||
InvalidPatternError, pattern_from_bytes, pattern_from_os,
|
||||
patterns_from_path, patterns_from_reader, patterns_from_stdin,
|
||||
},
|
||||
process::{CommandError, CommandReader, CommandReaderBuilder},
|
||||
wtr::{
|
||||
stdout, stdout_buffered_block, stdout_buffered_line, StandardStream,
|
||||
StandardStream, stdout, stdout_buffered_block, stdout_buffered_line,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
Provides completions for ripgrep's CLI for the fish shell.
|
||||
*/
|
||||
|
||||
use crate::flags::{defs::FLAGS, CompletionType};
|
||||
use crate::flags::{CompletionType, defs::FLAGS};
|
||||
|
||||
const TEMPLATE: &'static str = "complete -c rg !SHORT! -l !LONG! -d '!DOC!'";
|
||||
const TEMPLATE_NEGATED: &'static str =
|
||||
"complete -c rg -l !NEGATED! -n '__rg_contains_opt !LONG! !SHORT!' -d '!DOC!'\n";
|
||||
const TEMPLATE_NEGATED: &'static str = "complete -c rg -l !NEGATED! -n '__rg_contains_opt !LONG! !SHORT!' -d '!DOC!'\n";
|
||||
|
||||
/// Generate completions for Fish.
|
||||
///
|
||||
|
||||
@@ -34,8 +34,7 @@ Register-ArgumentCompleter -Native -CommandName 'rg' -ScriptBlock {
|
||||
}
|
||||
";
|
||||
|
||||
const TEMPLATE_FLAG: &'static str =
|
||||
"[CompletionResult]::new('!DASH_NAME!', '!NAME!', [CompletionResultType]::ParameterName, '!DOC!')";
|
||||
const TEMPLATE_FLAG: &'static str = "[CompletionResult]::new('!DASH_NAME!', '!NAME!', [CompletionResultType]::ParameterName, '!DOC!')";
|
||||
|
||||
/// Generate completions for PowerShell.
|
||||
///
|
||||
|
||||
@@ -10,7 +10,7 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use bstr::{io::BufReadExt, ByteSlice};
|
||||
use bstr::{ByteSlice, io::BufReadExt};
|
||||
|
||||
/// Return a sequence of arguments derived from ripgrep rc configuration files.
|
||||
pub fn args() -> Vec<OsString> {
|
||||
|
||||
@@ -22,13 +22,13 @@ use std::{path::PathBuf, sync::LazyLock};
|
||||
use {anyhow::Context as AnyhowContext, bstr::ByteVec};
|
||||
|
||||
use crate::flags::{
|
||||
Category, Flag, FlagValue,
|
||||
lowargs::{
|
||||
BinaryMode, BoundaryMode, BufferMode, CaseMode, ColorChoice,
|
||||
ContextMode, EncodingMode, EngineChoice, GenerateMode, LoggingMode,
|
||||
LowArgs, MmapMode, Mode, PatternSource, SearchMode, SortMode,
|
||||
SortModeKind, SpecialMode, TypeChange,
|
||||
},
|
||||
Category, Flag, FlagValue,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -8,7 +8,7 @@ is used when the `--help` flag is given.
|
||||
|
||||
use std::{collections::BTreeMap, fmt::Write};
|
||||
|
||||
use crate::flags::{defs::FLAGS, doc::version, Category, Flag};
|
||||
use crate::flags::{Category, Flag, defs::FLAGS, doc::version};
|
||||
|
||||
const TEMPLATE_SHORT: &'static str = include_str!("template.short.help");
|
||||
const TEMPLATE_LONG: &'static str = include_str!("template.long.help");
|
||||
|
||||
@@ -4,7 +4,7 @@ Provides routines for generating ripgrep's man page in `roff` format.
|
||||
|
||||
use std::{collections::BTreeMap, fmt::Write};
|
||||
|
||||
use crate::flags::{defs::FLAGS, doc::version, Flag};
|
||||
use crate::flags::{Flag, defs::FLAGS, doc::version};
|
||||
|
||||
const TEMPLATE: &'static str = include_str!("template.rg.1");
|
||||
|
||||
|
||||
@@ -169,9 +169,5 @@ fn features() -> Vec<String> {
|
||||
|
||||
/// Returns `+` when `enabled` is `true` and `-` otherwise.
|
||||
fn sign(enabled: bool) -> &'static str {
|
||||
if enabled {
|
||||
"+"
|
||||
} else {
|
||||
"-"
|
||||
}
|
||||
if enabled { "+" } else { "-" }
|
||||
}
|
||||
|
||||
@@ -579,10 +579,10 @@ impl HiArgs {
|
||||
SearchMode::Count => SummaryKind::Count,
|
||||
SearchMode::CountMatches => SummaryKind::CountMatches,
|
||||
SearchMode::JSON => {
|
||||
return Printer::JSON(self.printer_json(wtr))
|
||||
return Printer::JSON(self.printer_json(wtr));
|
||||
}
|
||||
SearchMode::Standard => {
|
||||
return Printer::Standard(self.printer_standard(wtr))
|
||||
return Printer::Standard(self.printer_standard(wtr));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -809,11 +809,7 @@ impl HiArgs {
|
||||
// When both error, we can't distinguish, so treat as equal.
|
||||
(None, None) => Ordering::Equal,
|
||||
};
|
||||
if sort.reverse {
|
||||
ordering.reverse()
|
||||
} else {
|
||||
ordering
|
||||
}
|
||||
if sort.reverse { ordering.reverse() } else { ordering }
|
||||
});
|
||||
Box::new(with_timestamps.into_iter().map(|(s, _)| s))
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ pub(crate) use crate::flags::{
|
||||
},
|
||||
hiargs::HiArgs,
|
||||
lowargs::{GenerateMode, Mode, SearchMode, SpecialMode},
|
||||
parse::{parse, ParseResult},
|
||||
parse::{ParseResult, parse},
|
||||
};
|
||||
|
||||
mod complete;
|
||||
|
||||
@@ -7,10 +7,10 @@ use std::{borrow::Cow, collections::BTreeSet, ffi::OsString};
|
||||
use anyhow::Context;
|
||||
|
||||
use crate::flags::{
|
||||
Flag, FlagValue,
|
||||
defs::FLAGS,
|
||||
hiargs::HiArgs,
|
||||
lowargs::{LoggingMode, LowArgs, SpecialMode},
|
||||
Flag, FlagValue,
|
||||
};
|
||||
|
||||
/// The result of parsing CLI arguments.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use std::fmt::Write;
|
||||
use std::path::{is_separator, Path};
|
||||
use std::path::{Path, is_separator};
|
||||
|
||||
use regex_automata::meta::Regex;
|
||||
|
||||
use crate::{new_regex, Candidate, Error, ErrorKind};
|
||||
use crate::{Candidate, Error, ErrorKind, new_regex};
|
||||
|
||||
/// Describes a matching strategy for a particular pattern.
|
||||
///
|
||||
@@ -340,11 +340,7 @@ impl Glob {
|
||||
let Token::Literal(c) = *t else { return None };
|
||||
lit.push(c);
|
||||
}
|
||||
if lit.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(lit)
|
||||
}
|
||||
if lit.is_empty() { None } else { Some(lit) }
|
||||
}
|
||||
|
||||
/// Returns an extension if this pattern matches a file path if and only
|
||||
@@ -385,11 +381,7 @@ impl Glob {
|
||||
_ => return None,
|
||||
}
|
||||
}
|
||||
if lit.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(lit)
|
||||
}
|
||||
if lit.is_empty() { None } else { Some(lit) }
|
||||
}
|
||||
|
||||
/// This is like `ext`, but returns an extension even if it isn't sufficient
|
||||
@@ -452,11 +444,7 @@ impl Glob {
|
||||
if need_sep {
|
||||
lit.push('/');
|
||||
}
|
||||
if lit.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(lit)
|
||||
}
|
||||
if lit.is_empty() { None } else { Some(lit) }
|
||||
}
|
||||
|
||||
/// Returns a literal suffix of this pattern if the entire pattern matches
|
||||
@@ -505,11 +493,7 @@ impl Glob {
|
||||
let Token::Literal(c) = *t else { return None };
|
||||
lit.push(c);
|
||||
}
|
||||
if lit.is_empty() || lit == "/" {
|
||||
None
|
||||
} else {
|
||||
Some((lit, entire))
|
||||
}
|
||||
if lit.is_empty() || lit == "/" { None } else { Some((lit, entire)) }
|
||||
}
|
||||
|
||||
/// If this pattern only needs to inspect the basename of a file path,
|
||||
|
||||
@@ -120,11 +120,11 @@ use std::{
|
||||
|
||||
use {
|
||||
aho_corasick::AhoCorasick,
|
||||
bstr::{ByteSlice, ByteVec, B},
|
||||
bstr::{B, ByteSlice, ByteVec},
|
||||
regex_automata::{
|
||||
PatternSet,
|
||||
meta::Regex,
|
||||
util::pool::{Pool, PoolGuard},
|
||||
PatternSet,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -634,11 +634,7 @@ impl<'a> Candidate<'a> {
|
||||
}
|
||||
|
||||
fn path_prefix(&self, max: usize) -> &[u8] {
|
||||
if self.path.len() <= max {
|
||||
&*self.path
|
||||
} else {
|
||||
&self.path[..max]
|
||||
}
|
||||
if self.path.len() <= max { &*self.path } else { &self.path[..max] }
|
||||
}
|
||||
|
||||
fn path_suffix(&self, max: usize) -> &[u8] {
|
||||
|
||||
@@ -88,7 +88,7 @@ pub(crate) fn normalize_path(mut path: Cow<[u8]>) -> Cow<[u8]> {
|
||||
mod tests {
|
||||
use std::borrow::Cow;
|
||||
|
||||
use bstr::{ByteVec, B};
|
||||
use bstr::{B, ByteVec};
|
||||
|
||||
use super::{file_name_ext, normalize_path};
|
||||
|
||||
|
||||
@@ -891,7 +891,7 @@ mod tests {
|
||||
use std::{io::Write, path::Path};
|
||||
|
||||
use crate::{
|
||||
dir::IgnoreBuilder, gitignore::Gitignore, tests::TempDir, Error,
|
||||
Error, dir::IgnoreBuilder, gitignore::Gitignore, tests::TempDir,
|
||||
};
|
||||
|
||||
fn wfile<P: AsRef<Path>>(path: P, contents: &str) {
|
||||
|
||||
@@ -20,8 +20,8 @@ use {
|
||||
};
|
||||
|
||||
use crate::{
|
||||
pathutil::{is_file_name, strip_prefix},
|
||||
Error, Match, PartialErrorBuilder,
|
||||
pathutil::{is_file_name, strip_prefix},
|
||||
};
|
||||
|
||||
/// Glob represents a single glob in a gitignore file.
|
||||
|
||||
@@ -477,11 +477,7 @@ impl<T> Match<T> {
|
||||
|
||||
/// Return the match if it is not none. Otherwise, return other.
|
||||
pub fn or(self, other: Self) -> Self {
|
||||
if self.is_none() {
|
||||
other
|
||||
} else {
|
||||
self
|
||||
}
|
||||
if self.is_none() { other } else { self }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ line tools.
|
||||
use std::path::Path;
|
||||
|
||||
use crate::{
|
||||
gitignore::{self, Gitignore, GitignoreBuilder},
|
||||
Error, Match,
|
||||
gitignore::{self, Gitignore, GitignoreBuilder},
|
||||
};
|
||||
|
||||
/// Glob represents a single glob in an override matcher.
|
||||
|
||||
@@ -91,7 +91,7 @@ use {
|
||||
regex_automata::util::pool::Pool,
|
||||
};
|
||||
|
||||
use crate::{default_types::DEFAULT_TYPES, pathutil::file_name, Error, Match};
|
||||
use crate::{Error, Match, default_types::DEFAULT_TYPES, pathutil::file_name};
|
||||
|
||||
/// Glob represents a single glob in a set of file type definitions.
|
||||
///
|
||||
|
||||
@@ -4,8 +4,8 @@ use std::{
|
||||
fs::{self, FileType, Metadata},
|
||||
io,
|
||||
path::{Path, PathBuf},
|
||||
sync::atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrdering},
|
||||
sync::Arc,
|
||||
sync::atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrdering},
|
||||
};
|
||||
|
||||
use {
|
||||
@@ -15,11 +15,11 @@ use {
|
||||
};
|
||||
|
||||
use crate::{
|
||||
Error, PartialErrorBuilder,
|
||||
dir::{Ignore, IgnoreBuilder},
|
||||
gitignore::GitignoreBuilder,
|
||||
overrides::Override,
|
||||
types::Types,
|
||||
Error, PartialErrorBuilder,
|
||||
};
|
||||
|
||||
/// A directory entry with a possible error attached.
|
||||
@@ -1894,7 +1894,7 @@ fn device_num<P: AsRef<Path>>(path: P) -> io::Result<u64> {
|
||||
|
||||
#[cfg(windows)]
|
||||
fn device_num<P: AsRef<Path>>(path: P) -> io::Result<u64> {
|
||||
use winapi_util::{file, Handle};
|
||||
use winapi_util::{Handle, file};
|
||||
|
||||
let h = Handle::from_path_any(path)?;
|
||||
file::information(h).map(|info| info.volume_serial_number())
|
||||
@@ -1940,11 +1940,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn normal_path(unix: &str) -> String {
|
||||
if cfg!(windows) {
|
||||
unix.replace("\\", "/")
|
||||
} else {
|
||||
unix.to_string()
|
||||
}
|
||||
if cfg!(windows) { unix.replace("\\", "/") } else { unix.to_string() }
|
||||
}
|
||||
|
||||
fn walk_collect(prefix: &Path, builder: &WalkBuilder) -> Vec<String> {
|
||||
|
||||
@@ -200,13 +200,17 @@ fn test_dirs_in_deep() {
|
||||
assert!(m("ROOT/parent_dir/dir_deep_00", true).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_00/file", false).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_00/child_dir", true).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_00/child_dir/file", false).is_ignore());
|
||||
assert!(
|
||||
m("ROOT/parent_dir/dir_deep_00/child_dir/file", false).is_ignore()
|
||||
);
|
||||
|
||||
// 01
|
||||
assert!(m("ROOT/parent_dir/dir_deep_01", true).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_01/file", false).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_01/child_dir", true).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_01/child_dir/file", false).is_ignore());
|
||||
assert!(
|
||||
m("ROOT/parent_dir/dir_deep_01/child_dir/file", false).is_ignore()
|
||||
);
|
||||
|
||||
// 02
|
||||
assert!(m("ROOT/parent_dir/dir_deep_02", true).is_none());
|
||||
@@ -248,51 +252,67 @@ fn test_dirs_in_deep() {
|
||||
assert!(m("ROOT/parent_dir/dir_deep_20", true).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_20/file", false).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_20/child_dir", true).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_20/child_dir/file", false).is_ignore());
|
||||
assert!(
|
||||
m("ROOT/parent_dir/dir_deep_20/child_dir/file", false).is_ignore()
|
||||
);
|
||||
|
||||
// 21
|
||||
assert!(m("ROOT/parent_dir/dir_deep_21", true).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_21/file", false).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_21/child_dir", true).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_21/child_dir/file", false).is_ignore());
|
||||
assert!(
|
||||
m("ROOT/parent_dir/dir_deep_21/child_dir/file", false).is_ignore()
|
||||
);
|
||||
|
||||
// 22
|
||||
// dir itself doesn't match
|
||||
assert!(m("ROOT/parent_dir/dir_deep_22", true).is_none());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_22/file", false).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_22/child_dir", true).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_22/child_dir/file", false).is_ignore());
|
||||
assert!(
|
||||
m("ROOT/parent_dir/dir_deep_22/child_dir/file", false).is_ignore()
|
||||
);
|
||||
|
||||
// 23
|
||||
// dir itself doesn't match
|
||||
assert!(m("ROOT/parent_dir/dir_deep_23", true).is_none());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_23/file", false).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_23/child_dir", true).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_23/child_dir/file", false).is_ignore());
|
||||
assert!(
|
||||
m("ROOT/parent_dir/dir_deep_23/child_dir/file", false).is_ignore()
|
||||
);
|
||||
|
||||
// 30
|
||||
assert!(m("ROOT/parent_dir/dir_deep_30", true).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_30/file", false).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_30/child_dir", true).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_30/child_dir/file", false).is_ignore());
|
||||
assert!(
|
||||
m("ROOT/parent_dir/dir_deep_30/child_dir/file", false).is_ignore()
|
||||
);
|
||||
|
||||
// 31
|
||||
assert!(m("ROOT/parent_dir/dir_deep_31", true).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_31/file", false).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_31/child_dir", true).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_31/child_dir/file", false).is_ignore());
|
||||
assert!(
|
||||
m("ROOT/parent_dir/dir_deep_31/child_dir/file", false).is_ignore()
|
||||
);
|
||||
|
||||
// 32
|
||||
// dir itself doesn't match
|
||||
assert!(m("ROOT/parent_dir/dir_deep_32", true).is_none());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_32/file", false).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_32/child_dir", true).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_32/child_dir/file", false).is_ignore());
|
||||
assert!(
|
||||
m("ROOT/parent_dir/dir_deep_32/child_dir/file", false).is_ignore()
|
||||
);
|
||||
|
||||
// 33
|
||||
// dir itself doesn't match
|
||||
assert!(m("ROOT/parent_dir/dir_deep_33", true).is_none());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_33/file", false).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_33/child_dir", true).is_ignore());
|
||||
assert!(m("ROOT/parent_dir/dir_deep_33/child_dir/file", false).is_ignore());
|
||||
assert!(
|
||||
m("ROOT/parent_dir/dir_deep_33/child_dir/file", false).is_ignore()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ fn is_valid_cap_letter(b: &u8) -> bool {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{find_cap_ref, interpolate, CaptureRef};
|
||||
use super::{CaptureRef, find_cap_ref, interpolate};
|
||||
|
||||
macro_rules! find {
|
||||
($name:ident, $text:expr) => {
|
||||
|
||||
@@ -14,8 +14,8 @@ use {
|
||||
};
|
||||
|
||||
use crate::{
|
||||
counter::CounterWriter, jsont, stats::Stats,
|
||||
util::find_iter_at_in_context, util::Replacer,
|
||||
counter::CounterWriter, jsont, stats::Stats, util::Replacer,
|
||||
util::find_iter_at_in_context,
|
||||
};
|
||||
|
||||
/// The configuration for the JSON printer.
|
||||
@@ -969,7 +969,7 @@ mod tests {
|
||||
use grep_regex::{RegexMatcher, RegexMatcherBuilder};
|
||||
use grep_searcher::SearcherBuilder;
|
||||
|
||||
use super::{JSONBuilder, JSON};
|
||||
use super::{JSON, JSONBuilder};
|
||||
|
||||
const SHERLOCK: &'static [u8] = b"\
|
||||
For the Doctor Watsons of this world, as opposed to the Sherlock
|
||||
|
||||
@@ -61,10 +61,10 @@ assert_eq!(output, expected);
|
||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||
|
||||
pub use crate::{
|
||||
color::{default_color_specs, ColorError, ColorSpecs, UserColorSpec},
|
||||
color::{ColorError, ColorSpecs, UserColorSpec, default_color_specs},
|
||||
hyperlink::{
|
||||
hyperlink_aliases, HyperlinkAlias, HyperlinkConfig,
|
||||
HyperlinkEnvironment, HyperlinkFormat, HyperlinkFormatError,
|
||||
HyperlinkAlias, HyperlinkConfig, HyperlinkEnvironment,
|
||||
HyperlinkFormat, HyperlinkFormatError, hyperlink_aliases,
|
||||
},
|
||||
path::{PathPrinter, PathPrinterBuilder},
|
||||
standard::{Standard, StandardBuilder, StandardSink},
|
||||
@@ -73,7 +73,7 @@ pub use crate::{
|
||||
};
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
pub use crate::json::{JSONBuilder, JSONSink, JSON};
|
||||
pub use crate::json::{JSON, JSONBuilder, JSONSink};
|
||||
|
||||
// The maximum number of bytes to execute a search to account for look-ahead.
|
||||
//
|
||||
|
||||
@@ -22,8 +22,8 @@ use crate::{
|
||||
hyperlink::{self, HyperlinkConfig},
|
||||
stats::Stats,
|
||||
util::{
|
||||
find_iter_at_in_context, trim_ascii_prefix, trim_line_terminator,
|
||||
DecimalFormatter, PrinterPath, Replacer, Sunk,
|
||||
find_iter_at_in_context, trim_ascii_prefix, trim_line_terminator,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ use crate::{
|
||||
counter::CounterWriter,
|
||||
hyperlink::{self, HyperlinkConfig},
|
||||
stats::Stats,
|
||||
util::{find_iter_at_in_context, PrinterPath},
|
||||
util::{PrinterPath, find_iter_at_in_context},
|
||||
};
|
||||
|
||||
/// The configuration for the summary printer.
|
||||
|
||||
@@ -8,7 +8,7 @@ use {
|
||||
},
|
||||
};
|
||||
|
||||
use crate::{hyperlink::HyperlinkPath, MAX_LOOK_AHEAD};
|
||||
use crate::{MAX_LOOK_AHEAD, hyperlink::HyperlinkPath};
|
||||
|
||||
/// A type for handling replacements while amortizing allocation.
|
||||
pub(crate) struct Replacer<M: Matcher> {
|
||||
|
||||
@@ -341,11 +341,7 @@ impl ConfiguredHIR {
|
||||
|
||||
/// Returns the "end line" anchor for this configuration.
|
||||
fn line_anchor_end(&self) -> hir::Look {
|
||||
if self.config.crlf {
|
||||
hir::Look::EndCRLF
|
||||
} else {
|
||||
hir::Look::EndLF
|
||||
}
|
||||
if self.config.crlf { hir::Look::EndCRLF } else { hir::Look::EndLF }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use {
|
||||
regex_automata::meta::Regex,
|
||||
regex_syntax::hir::{
|
||||
self,
|
||||
self, Hir,
|
||||
literal::{Literal, Seq},
|
||||
Hir,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -223,11 +222,7 @@ impl Extractor {
|
||||
// extracting prefixes or suffixes.
|
||||
seq = self.cross(seq, self.extract(hir));
|
||||
}
|
||||
if let Some(prev) = prev {
|
||||
prev.choose(seq)
|
||||
} else {
|
||||
seq
|
||||
}
|
||||
if let Some(prev) = prev { prev.choose(seq) } else { seq }
|
||||
}
|
||||
|
||||
/// Extract a sequence from the given alternation.
|
||||
|
||||
@@ -4,8 +4,8 @@ use {
|
||||
NoError,
|
||||
},
|
||||
regex_automata::{
|
||||
meta::Regex, util::captures::Captures as AutomataCaptures, Input,
|
||||
PatternID,
|
||||
Input, PatternID, meta::Regex,
|
||||
util::captures::Captures as AutomataCaptures,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -587,10 +587,12 @@ mod tests {
|
||||
// and the regex could not be modified to remove a line terminator.
|
||||
#[test]
|
||||
fn line_terminator_error() {
|
||||
assert!(RegexMatcherBuilder::new()
|
||||
.line_terminator(Some(b'\n'))
|
||||
.build(r"a\nz")
|
||||
.is_err())
|
||||
assert!(
|
||||
RegexMatcherBuilder::new()
|
||||
.line_terminator(Some(b'\n'))
|
||||
.build(r"a\nz")
|
||||
.is_err()
|
||||
)
|
||||
}
|
||||
|
||||
// Test that enabling CRLF permits `$` to match at the end of a line.
|
||||
|
||||
@@ -122,7 +122,7 @@ fn strip_from_match_ascii(expr: Hir, byte: u8) -> Result<Hir, Error> {
|
||||
mod tests {
|
||||
use regex_syntax::Parser;
|
||||
|
||||
use super::{strip_from_match, LineTerminator};
|
||||
use super::{LineTerminator, strip_from_match};
|
||||
use crate::error::Error;
|
||||
|
||||
fn roundtrip(pattern: &str, byte: u8) -> String {
|
||||
|
||||
@@ -4,8 +4,8 @@ use std::io;
|
||||
use std::process;
|
||||
|
||||
use grep_regex::RegexMatcher;
|
||||
use grep_searcher::sinks::UTF8;
|
||||
use grep_searcher::Searcher;
|
||||
use grep_searcher::sinks::UTF8;
|
||||
|
||||
fn main() {
|
||||
if let Err(err) = example() {
|
||||
@@ -18,7 +18,7 @@ fn example() -> Result<(), Box<dyn Error>> {
|
||||
let pattern = match env::args().nth(1) {
|
||||
Some(pattern) => pattern,
|
||||
None => {
|
||||
return Err(From::from(format!("Usage: search-stdin <pattern>")))
|
||||
return Err(From::from(format!("Usage: search-stdin <pattern>")));
|
||||
}
|
||||
};
|
||||
let matcher = RegexMatcher::new(&pattern)?;
|
||||
|
||||
@@ -90,8 +90,8 @@ pub use crate::{
|
||||
SearcherBuilder,
|
||||
},
|
||||
sink::{
|
||||
sinks, Sink, SinkContext, SinkContextKind, SinkError, SinkFinish,
|
||||
SinkMatch,
|
||||
Sink, SinkContext, SinkContextKind, SinkError, SinkFinish, SinkMatch,
|
||||
sinks,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use grep_matcher::Matcher;
|
||||
|
||||
use crate::{
|
||||
line_buffer::{LineBufferReader, DEFAULT_BUFFER_CAPACITY},
|
||||
line_buffer::{DEFAULT_BUFFER_CAPACITY, LineBufferReader},
|
||||
lines::{self, LineStep},
|
||||
searcher::{core::Core, Config, Range, Searcher},
|
||||
searcher::{Config, Range, Searcher, core::Core},
|
||||
sink::{Sink, SinkError},
|
||||
};
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ use {
|
||||
|
||||
use crate::{
|
||||
line_buffer::{
|
||||
self, alloc_error, BufferAllocation, LineBuffer, LineBufferBuilder,
|
||||
LineBufferReader, DEFAULT_BUFFER_CAPACITY,
|
||||
self, BufferAllocation, DEFAULT_BUFFER_CAPACITY, LineBuffer,
|
||||
LineBufferBuilder, LineBufferReader, alloc_error,
|
||||
},
|
||||
searcher::glue::{MultiLine, ReadByLine, SliceByLine},
|
||||
sink::{Sink, SinkError},
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
max_width = 79
|
||||
use_small_heuristics = "max"
|
||||
edition = "2024"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::hay::{SHERLOCK, SHERLOCK_CRLF};
|
||||
use crate::util::{sort_lines, Dir, TestCommand};
|
||||
use crate::util::{Dir, TestCommand, sort_lines};
|
||||
|
||||
// See: https://github.com/BurntSushi/ripgrep/issues/1
|
||||
rgtest!(f1_sjis, |dir: Dir, mut cmd: TestCommand| {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::hay::SHERLOCK;
|
||||
use crate::util::{cmd_exists, sort_lines, Dir, TestCommand};
|
||||
use crate::util::{Dir, TestCommand, cmd_exists, sort_lines};
|
||||
|
||||
// This file contains "miscellaneous" tests that were either written before
|
||||
// features were tracked more explicitly, or were simply written without
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::hay::SHERLOCK;
|
||||
use crate::util::{sort_lines, Dir, TestCommand};
|
||||
use crate::util::{Dir, TestCommand, sort_lines};
|
||||
|
||||
// See: https://github.com/BurntSushi/ripgrep/issues/16
|
||||
rgtest!(r16, |dir: Dir, mut cmd: TestCommand| {
|
||||
|
||||
Reference in New Issue
Block a user