summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2020-02-17 18:08:47 -0500
committerAndrew Gallant <jamslam@gmail.com>2020-02-17 19:24:53 -0500
commit0bc4f0447b05468f043e06278a3ca2b1c5646f9b (patch)
tree8a7e03399262af04a47ad1397fca74f654bfea5b
parentc95f29e3ba46ef622481995ab01fd9f4e931345c (diff)
style: rustfmt everything
This is why I was so intent on clearing the PR queue. This will effectively invalidate all existing patches, so I wanted to start from a clean slate. We do make one little tweak: we put the default type definitions in their own file and tell rustfmt to keep its grubby mits off of it. We also sort it lexicographically and hopefully will enforce that from here on.
-rw-r--r--build.rs18
-rw-r--r--globset/src/glob.rs231
-rw-r--r--globset/src/lib.rs71
-rw-r--r--globset/src/pathutil.rs2
-rw-r--r--grep-cli/src/decompress.rs30
-rw-r--r--grep-cli/src/escape.rs92
-rw-r--r--grep-cli/src/human.rs50
-rw-r--r--grep-cli/src/lib.rs16
-rw-r--r--grep-cli/src/pattern.rs32
-rw-r--r--grep-cli/src/process.rs31
-rw-r--r--grep-matcher/src/interpolate.rs8
-rw-r--r--grep-matcher/src/lib.rs69
-rw-r--r--grep-matcher/tests/test_matcher.rs172
-rw-r--r--grep-matcher/tests/util.rs23
-rw-r--r--grep-pcre2/src/matcher.rs58
-rw-r--r--grep-printer/src/color.rs105
-rw-r--r--grep-printer/src/json.rs105
-rw-r--r--grep-printer/src/jsont.rs34
-rw-r--r--grep-printer/src/lib.rs4
-rw-r--r--grep-printer/src/standard.rs251
-rw-r--r--grep-printer/src/stats.rs4
-rw-r--r--grep-printer/src/summary.rs167
-rw-r--r--grep-printer/src/util.rs61
-rw-r--r--grep-regex/src/ast.rs2
-rw-r--r--grep-regex/src/config.rs16
-rw-r--r--grep-regex/src/crlf.rs7
-rw-r--r--grep-regex/src/literal.rs60
-rw-r--r--grep-regex/src/matcher.rs93
-rw-r--r--grep-regex/src/multi.rs18
-rw-r--r--grep-regex/src/non_matching.rs32
-rw-r--r--grep-regex/src/strip.rs13
-rw-r--r--grep-regex/src/util.rs2
-rw-r--r--grep-regex/src/word.rs26
-rw-r--r--grep-searcher/examples/search-stdin.rs20
-rw-r--r--grep-searcher/src/lib.rs9
-rw-r--r--grep-searcher/src/line_buffer.rs28
-rw-r--r--grep-searcher/src/lines.rs39
-rw-r--r--grep-searcher/src/searcher/core.rs64
-rw-r--r--grep-searcher/src/searcher/glue.rs97
-rw-r--r--grep-searcher/src/searcher/mod.rs104
-rw-r--r--grep-searcher/src/sink.rs35
-rw-r--r--grep-searcher/src/testutil.rs50
-rw-r--r--grep/examples/simplegrep.rs12
-rw-r--r--ignore/src/default_types.rs244
-rw-r--r--ignore/src/dir.rs77
-rw-r--r--ignore/src/gitignore.rs55
-rw-r--r--ignore/src/lib.rs98
-rw-r--r--ignore/src/overrides.rs18
-rw-r--r--ignore/src/pathutil.rs4
-rw-r--r--ignore/src/types.rs288
-rw-r--r--ignore/src/walk.rs161
-rw-r--r--ignore/tests/gitignore_matched_path_or_any_parents_tests.rs43
-rw-r--r--rustfmt.toml3
-rw-r--r--src/app.rs1092
-rw-r--r--src/args.rs234
-rw-r--r--src/config.rs47
-rw-r--r--src/path_printer.rs5
-rw-r--r--src/search.rs81
-rw-r--r--src/subject.rs10
-rw-r--r--tests/binary.rs111
-rw-r--r--tests/feature.rs140
-rw-r--r--tests/json.rs70
-rw-r--r--tests/macros.rs2
-rw-r--r--tests/misc.rs41
-rw-r--r--tests/multiline.rs36
-rw-r--r--tests/regression.rs102
-rw-r--r--tests/util.rs67
67 files changed, 2711 insertions, 2679 deletions
diff --git a/build.rs b/build.rs
index 43f667ca..53f7259e 100644
--- a/build.rs
+++ b/build.rs
@@ -21,7 +21,8 @@ fn main() {
eprintln!(
"OUT_DIR environment variable not defined. \
Please file a bug: \
- https://github.com/BurntSushi/ripgrep/issues/new");
+ https://github.com/BurntSushi/ripgrep/issues/new"
+ );
process::exit(1);
}
};
@@ -90,8 +91,10 @@ fn generate_man_page<P: AsRef<Path>>(outdir: P) -> io::Result<()> {
File::create(&txt_path)?.write_all(tpl.as_bytes())?;
let result = process::Command::new("a2x")
.arg("--no-xmllint")
- .arg("--doctype").arg("manpage")
- .arg("--format").arg("manpage")
+ .arg("--doctype")
+ .arg("manpage")
+ .arg("--format")
+ .arg("manpage")
.arg(&txt_path)
.spawn()?
.wait()?;
@@ -114,7 +117,7 @@ fn formatted_options() -> io::Result<String> {
// ripgrep only has two positional arguments, and probably will only
// ever have two positional arguments, so we just hardcode them into
// the template.
- if let app::RGArgKind::Positional{..} = arg.kind {
+ if let app::RGArgKind::Positional { .. } = arg.kind {
continue;
}
formatted.push(formatted_arg(&arg)?);
@@ -124,7 +127,9 @@ fn formatted_options() -> io::Result<String> {
fn formatted_arg(arg: &RGArg) -> io::Result<String> {
match arg.kind {
- RGArgKind::Positional{..} => panic!("unexpected positional argument"),
+ RGArgKind::Positional { .. } => {
+ panic!("unexpected positional argument")
+ }
RGArgKind::Switch { long, short, multiple } => {
let mut out = vec![];
@@ -163,7 +168,8 @@ fn formatted_arg(arg: &RGArg) -> io::Result<String> {
}
fn formatted_doc_txt(arg: &RGArg) -> io::Result<String> {
- let paragraphs: Vec<String> = arg.doc_long
+ let paragraphs: Vec<String> = arg
+ .doc_long
.replace("{", "&#123;")
.replace("}", r"&#125;")
.split("\n\n")
diff --git a/globset/src/glob.rs b/globset/src/glob.rs
index c8dedba2..50502b96 100644
--- a/globset/src/glob.rs
+++ b/globset/src/glob.rs
@@ -2,13 +2,13 @@ use std::fmt;
use std::hash;
use std::iter;
use std::ops::{Deref, DerefMut};
-use std::path::{Path, is_separator};
+use std::path::{is_separator, Path};
use std::str;
use regex;
use regex::bytes::Regex;
-use {Candidate, Error, ErrorKind, new_regex};
+use {new_regex, Candidate, Error, ErrorKind};
/// Describes a matching strategy for a particular pattern.
///
@@ -85,16 +85,16 @@ pub struct Glob {
}
impl PartialEq for Glob {
- fn eq(&self, other: &Glob) -> bool {
- self.glob == other.glob && self.opts == other.opts
- }
+ fn eq(&self, other: &Glob) -> bool {
+ self.glob == other.glob && self.opts == other.opts
+ }
}
impl hash::Hash for Glob {
- fn hash<H: hash::Hasher>(&self, state: &mut H) {
- self.glob.hash(state);
- self.opts.hash(state);
- }
+ fn hash<H: hash::Hasher>(&self, state: &mut H) {
+ self.glob.hash(state);
+ self.opts.hash(state);
+ }
}
impl fmt::Display for Glob {
@@ -227,11 +227,15 @@ struct Tokens(Vec<Token>);
impl Deref for Tokens {
type Target = Vec<Token>;
- fn deref(&self) -> &Vec<Token> { &self.0 }
+ fn deref(&self) -> &Vec<Token> {
+ &self.0
+ }
}
impl DerefMut for Tokens {
- fn deref_mut(&mut self) -> &mut Vec<Token> { &mut self.0 }
+ fn deref_mut(&mut self) -> &mut Vec<Token> {
+ &mut self.0
+ }
}
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -242,10 +246,7 @@ enum Token {
RecursivePrefix,
RecursiveSuffix,
RecursiveZeroOrMore,
- Class {
- negated: bool,
- ranges: Vec<(char, char)>,
- },
+ Class { negated: bool, ranges: Vec<(char, char)> },
Alternates(Vec<Tokens>),
}
@@ -257,12 +258,9 @@ impl Glob {
/// Returns a matcher for this pattern.
pub fn compile_matcher(&self) -> GlobMatcher {
- let re = new_regex(&self.re)
- .expect("regex compilation shouldn't fail");
- GlobMatcher {
- pat: self.clone(),
- re: re,
- }
+ let re =
+ new_regex(&self.re).expect("regex compilation shouldn't fail");
+ GlobMatcher { pat: self.clone(), re: re }
}
/// Returns a strategic matcher.
@@ -273,13 +271,9 @@ impl Glob {
#[cfg(test)]
fn compile_strategic_matcher(&self) -> GlobStrategic {
let strategy = MatchStrategy::new(self);
- let re = new_regex(&self.re)
- .expect("regex compilation shouldn't fail");
- GlobStrategic {
- strategy: strategy,
- pat: self.clone(),
- re: re,
- }
+ let re =
+ new_regex(&self.re).expect("regex compilation shouldn't fail");
+ GlobStrategic { strategy: strategy, pat: self.clone(), re: re }
}
/// Returns the original glob pattern used to build this pattern.
@@ -537,7 +531,7 @@ impl Glob {
| Token::RecursiveZeroOrMore => {
return None;
}
- Token::Class{..} | Token::Alternates(..) => {
+ Token::Class { .. } | Token::Alternates(..) => {
// We *could* be a little smarter here, but either one
// of these is going to prevent our literal optimizations
// anyway, so give up.
@@ -574,10 +568,7 @@ impl<'a> GlobBuilder<'a> {
///
/// The pattern is not compiled until `build` is called.
pub fn new(glob: &'a str) -> GlobBuilder<'a> {
- GlobBuilder {
- glob: glob,
- opts: GlobOptions::default(),
- }
+ GlobBuilder { glob: glob, opts: GlobOptions::default() }
}
/// Parses and builds the pattern.
@@ -875,25 +866,22 @@ impl<'a> Parser<'a> {
return Ok(());
}
}
- let is_suffix =
- match self.peek() {
- None => {
- assert!(self.bump().is_none());
- true
- }
- Some(',') | Some('}') if self.stack.len() >= 2 => {
- true
- }
- Some(c) if is_separator(c) => {
- assert!(self.bump().map(is_separator).unwrap_or(false));
- false
- }
- _ => {
- self.push_token(Token::ZeroOrMore)?;
- self.push_token(Token::ZeroOrMore)?;
- return Ok(());
- }
- };
+ let is_suffix = match self.peek() {
+ None => {
+ assert!(self.bump().is_none());
+ true
+ }
+ Some(',') | Some('}') if self.stack.len() >= 2 => true,
+ Some(c) if is_separator(c) => {
+ assert!(self.bump().map(is_separator).unwrap_or(false));
+ false
+ }
+ _ => {
+ self.push_token(Token::ZeroOrMore)?;
+ self.push_token(Token::ZeroOrMore)?;
+ return Ok(());
+ }
+ };
match self.pop_token()? {
Token::RecursivePrefix => {
self.push_token(Token::RecursivePrefix)?;
@@ -973,7 +961,10 @@ impl<'a> Parser<'a> {
// invariant: in_range is only set when there is
// already at least one character seen.
add_to_last_range(
- &self.glob, ranges.last_mut().unwrap(), c)?;
+ &self.glob,
+ ranges.last_mut().unwrap(),
+ c,
+ )?;
} else {
ranges.push((c, c));
}
@@ -987,10 +978,7 @@ impl<'a> Parser<'a> {
// it as a literal.
ranges.push(('-', '-'));
}
- self.push_token(Token::Class {
- negated: negated,
- ranges: ranges,
- })
+ self.push_token(Token::Class { negated: negated, ranges: ranges })
}
fn bump(&mut self) -> Option<char> {
@@ -1019,9 +1007,9 @@ fn ends_with(needle: &[u8], haystack: &[u8]) -> bool {
#[cfg(test)]
mod tests {
- use {GlobSetBuilder, ErrorKind};
- use super::{Glob, GlobBuilder, Token};
use super::Token::*;
+ use super::{Glob, GlobBuilder, Token};
+ use {ErrorKind, GlobSetBuilder};
#[derive(Clone, Copy, Debug, Default)]
struct Options {
@@ -1037,7 +1025,7 @@ mod tests {
let pat = Glob::new($pat).unwrap();
assert_eq!($tokens, pat.tokens.0);
}
- }
+ };
}
macro_rules! syntaxerr {
@@ -1047,7 +1035,7 @@ mod tests {
let err = Glob::new($pat).unwrap_err();
assert_eq!(&$err, err.kind());
}
- }
+ };
}
macro_rules! toregex {
@@ -1129,7 +1117,9 @@ mod tests {
};
}
- fn s(string: &str) -> String { string.to_string() }
+ fn s(string: &str) -> String {
+ string.to_string()
+ }
fn class(s: char, e: char) -> Token {
Class { negated: false, ranges: vec![(s, e)] }
@@ -1153,16 +1143,20 @@ mod tests {
syntax!(any2, "a?b", vec![Literal('a'), Any, Literal('b')]);
syntax!(seq1, "*", vec![ZeroOrMore]);
syntax!(seq2, "a*b", vec![Literal('a'), ZeroOrMore, Literal('b')]);
- syntax!(seq3, "*a*b*", vec![
- ZeroOrMore, Literal('a'), ZeroOrMore, Literal('b'), ZeroOrMore,
- ]);
+ syntax!(
+ seq3,
+ "*a*b*",
+ vec![ZeroOrMore, Literal('a'), ZeroOrMore, Literal('b'), ZeroOrMore,]
+ );
syntax!(rseq1, "**", vec![RecursivePrefix]);
syntax!(rseq2, "**/", vec![RecursivePrefix]);
syntax!(rseq3, "/**", vec![RecursiveSuffix]);
syntax!(rseq4, "/**/", vec![RecursiveZeroOrMore]);
- syntax!(rseq5, "a/**/b", vec![
- Literal('a'), RecursiveZeroOrMore, Literal('b'),
- ]);
+ syntax!(
+ rseq5,
+ "a/**/b",
+ vec![Literal('a'), RecursiveZeroOrMore, Literal('b'),]
+ );
syntax!(cls1, "[a]", vec![class('a', 'a')]);
syntax!(cls2, "[!a]", vec![classn('a', 'a')]);
syntax!(cls3, "[a-z]", vec![class('a', 'z')]);
@@ -1174,9 +1168,11 @@ mod tests {
syntax!(cls9, "[a-]", vec![rclass(&[('a', 'a'), ('-', '-')])]);
syntax!(cls10, "[-a-z]", vec![rclass(&[('-', '-'), ('a', 'z')])]);
syntax!(cls11, "[a-z-]", vec![rclass(&[('a', 'z'), ('-', '-')])]);
- syntax!(cls12, "[-a-z-]", vec![
- rclass(&[('-', '-'), ('a', 'z'), ('-', '-')]),
- ]);
+ syntax!(
+ cls12,
+ "[-a-z-]",
+ vec![rclass(&[('-', '-'), ('a', 'z'), ('-', '-')]),]
+ );
syntax!(cls13, "[]-z]", vec![class(']', 'z')]);
syntax!(cls14, "[--z]", vec![class('-', 'z')]);
syntax!(cls15, "[ --]", vec![class(' ', '-')]);
@@ -1194,26 +1190,14 @@ mod tests {
syntaxerr!(err_range1, "[z-a]", ErrorKind::InvalidRange('z', 'a'));
syntaxerr!(err_range2, "[z--]", ErrorKind::InvalidRange('z', '-'));
- const CASEI: Options = Options {
- casei: Some(true),
- litsep: None,
- bsesc: None,
- };
- const SLASHLIT: Options = Options {
- casei: None,
- litsep: Some(true),
- bsesc: None,
- };
- const NOBSESC: Options = Options {
- casei: None,
- litsep: None,
- bsesc: Some(false),
- };
- const BSESC: Options = Options {
- casei: None,
- litsep: None,
- bsesc: Some(true),
- };
+ const CASEI: Options =
+ Options { casei: Some(true), litsep: None, bsesc: None };
+ const SLASHLIT: Options =
+ Options { casei: None, litsep: Some(true), bsesc: None };
+ const NOBSESC: Options =
+ Options { casei: None, litsep: None, bsesc: Some(false) };
+ const BSESC: Options =
+ Options { casei: None, litsep: None, bsesc: Some(true) };
toregex!(re_casei, "a", "(?i)^a$", &CASEI);
@@ -1311,8 +1295,11 @@ mod tests {
matches!(matchpat4, "*hello.txt", "some\\path\\to\\hello.txt");
matches!(matchpat5, "*hello.txt", "/an/absolute/path/to/hello.txt");
matches!(matchpat6, "*some/path/to/hello.txt", "some/path/to/hello.txt");
- matches!(matchpat7, "*some/path/to/hello.txt",
- "a/bigger/some/path/to/hello.txt");
+ matches!(
+ matchpat7,
+ "*some/path/to/hello.txt",
+ "a/bigger/some/path/to/hello.txt"
+ );
matches!(matchescape, "_[[]_[]]_[?]_[*]_!_", "_[_]_?_*_!_");
@@ -1375,28 +1362,44 @@ mod tests {
nmatches!(matchnot15, "[!-]", "-");
nmatches!(matchnot16, "*hello.txt", "hello.txt-and-then-some");
nmatches!(matchnot17, "*hello.txt", "goodbye.txt");
- nmatches!(matchnot18, "*some/path/to/hello.txt",
- "some/path/to/hello.txt-and-then-some");
- nmatches!(matchnot19, "*some/path/to/hello.txt",
- "some/other/path/to/hello.txt");
+ nmatches!(
+ matchnot18,
+ "*some/path/to/hello.txt",
+ "some/path/to/hello.txt-and-then-some"
+ );
+ nmatches!(
+ matchnot19,
+ "*some/path/to/hello.txt",
+ "some/other/path/to/hello.txt"
+ );
nmatches!(matchnot20, "a", "foo/a");
nmatches!(matchnot21, "./foo", "foo");
nmatches!(matchnot22, "**/foo", "foofoo");
nmatches!(matchnot23, "**/foo/bar", "foofoo/bar");
nmatches!(matchnot24, "/*.c", "mozilla-sha1/sha1.c");
nmatches!(matchnot25, "*.c", "mozilla-sha1/sha1.c", SLASHLIT);
- nmatches!(matchnot26, "**/m4/ltoptions.m4",
- "csharp/src/packages/repositories.config", SLASHLIT);
+ nmatches!(
+ matchnot26,
+ "**/m4/ltoptions.m4",
+ "csharp/src/packages/repositories.config",
+ SLASHLIT
+ );
nmatches!(matchnot27, "a[^0-9]b", "a0b");
nmatches!(matchnot28, "a[^0-9]b", "a9b");
nmatches!(matchnot29, "[^-]", "-");
nmatches!(matchnot30, "some/*/needle.txt", "some/needle.txt");
nmatches!(
matchrec31,
- "some/*/needle.txt", "some/one/two/needle.txt", SLASHLIT);
+ "some/*/needle.txt",
+ "some/one/two/needle.txt",
+ SLASHLIT
+ );
nmatches!(
matchrec32,
- "some/*/needle.txt", "some/one/two/three/needle.txt", SLASHLIT);
+ "some/*/needle.txt",
+ "some/one/two/three/needle.txt",
+ SLASHLIT
+ );
macro_rules! extract {
($which:ident, $name:ident, $pat:expr, $expect:expr) => {
@@ -1458,19 +1461,27 @@ mod tests {
literal!(extract_lit7, "foo/bar", Some(s("foo/bar")));
literal!(extract_lit8, "**/foo/bar", None);
- basetokens!(extract_basetoks1, "**/foo", Some(&*vec![
- Literal('f'), Literal('o'), Literal('o'),
- ]));
+ basetokens!(
+ extract_basetoks1,
+ "**/foo",
+ Some(&*vec![Literal('f'), Literal('o'), Literal('o'),])
+ );
basetokens!(extract_basetoks2, "**/foo", None, CASEI);
- basetokens!(extract_basetoks3, "**/foo", Some(&*vec![
- Literal('f'), Literal('o'), Literal('o'),
- ]), SLASHLIT);
+ basetokens!(
+ extract_basetoks3,
+ "**/foo",
+ Some(&*vec![Literal('f'), Literal('o'), Literal('o'),]),
+ SLASHLIT
+ );
basetokens!(extract_basetoks4, "*foo", None, SLASHLIT);
basetokens!(extract_basetoks5, "*foo", None);
basetokens!(extract_basetoks6, "**/fo*o", None);
- basetokens!(extract_basetoks7, "**/fo*o", Some(&*vec![
- Literal('f'), Literal('o'), ZeroOrMore, Literal('o'),
- ]), SLASHLIT);
+ basetokens!(
+ extract_basetoks7,
+ "**/fo*o",
+ Some(&*vec![Literal('f'), Literal('o'), ZeroOrMore, Literal('o'),]),
+ SLASHLIT
+ );
ext!(extract_ext1, "**/*.rs", Some(s(".rs")));
ext!(extract_ext2, "**/*.rs.bak", None);
diff --git a/globset/src/lib.rs b/globset/src/lib.rs
index 0b3b7b6c..862be689 100644
--- a/globset/src/lib.rs
+++ b/globset/src/lib.rs
@@ -119,12 +119,12 @@ use std::path::Path;
use std::str;
use aho_corasick::AhoCorasick;
-use bstr::{B, ByteSlice, ByteVec};
+use bstr::{ByteSlice, ByteVec, B};
use regex::bytes::{Regex, RegexBuilder, RegexSet};
-use pathutil::{file_name, file_name_ext, normalize_path};
use glob::MatchStrategy;
pub use glob::{Glob, GlobBuilder, GlobMatcher};
+use pathutil::{file_name, file_name_ext, normalize_path};
mod glob;
mod pathutil;
@@ -202,9 +202,7 @@ impl ErrorKind {
ErrorKind::UnclosedClass => {
"unclosed character class; missing ']'"
}
- ErrorKind::InvalidRange(_, _) => {
- "invalid character range"
- }
+ ErrorKind::InvalidRange(_, _) => "invalid character range",
ErrorKind::UnopenedAlternates => {
"unopened alternate group; missing '{' \
(maybe escape '}' with '[}]'?)"
@@ -216,9 +214,7 @@ impl ErrorKind {
ErrorKind::NestedAlternates => {
"nested alternate groups are not allowed"
}
- ErrorKind::DanglingEscape => {
- "dangling '\\'"
- }
+ ErrorKind::DanglingEscape => "dangling '\\'",
ErrorKind::Regex(ref err) => err,
ErrorKind::__Nonexhaustive => unreachable!(),
}