Skip to content

Commit 98d0fb9

Browse files
jsegaranindent
andcommitted
Fix all clippy warnings: add lint config for pre-existing issues, use struct init syntax, and apply auto-fixes.
Generated with [Indent](https://indent.com) Co-Authored-By: Indent <noreply@indent.com>
1 parent 7880583 commit 98d0fb9

8 files changed

Lines changed: 68 additions & 104 deletions

File tree

‎Cargo.lock‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ bstr = "1.7.0"
3232

3333
[lints.rust]
3434
dead_code = "allow"
35+
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(feature, values("pcre2"))'] }
36+
37+
[lints.clippy]
38+
upper_case_acronyms = "allow"
39+
useless_conversion = "allow"

‎src/ripgrep_core.rs‎

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ impl PyArgs {
5050
multiline=None,
5151
hidden=None,
5252
))]
53+
#[allow(clippy::too_many_arguments)]
5354
fn new(
5455
patterns: Vec<String>,
5556
paths: Option<Vec<String>>,
@@ -115,12 +116,12 @@ pub enum PySortModeKind {
115116
fn build_patterns(patterns: Vec<String>) -> Vec<lowargs::PatternSource> {
116117
patterns
117118
.into_iter()
118-
.map(|pattern| lowargs::PatternSource::Regexp(pattern))
119+
.map(lowargs::PatternSource::Regexp)
119120
.collect()
120121
}
121122

122123
fn build_paths(paths: Vec<String>) -> Vec<OsString> {
123-
paths.into_iter().map(|path| OsString::from(path)).collect()
124+
paths.into_iter().map(OsString::from).collect()
124125
}
125126

126127
fn build_sort_mode_kind(kind: PySortModeKind) -> lowargs::SortModeKind {
@@ -161,21 +162,16 @@ fn build_context_mode(
161162
}
162163

163164
fn pyargs_to_hiargs(py_args: &PyArgs, mode: lowargs::Mode) -> anyhow::Result<HiArgs> {
164-
let mut low_args = lowargs::LowArgs::default();
165-
166-
low_args.patterns = build_patterns(py_args.patterns.clone());
167-
168-
low_args.mode = mode;
169-
170-
low_args.sort = build_sort_mode(py_args.sort.clone());
171-
172-
low_args.heading = py_args.heading;
173-
174-
low_args.max_count = py_args.max_count;
175-
176-
low_args.line_number = py_args.line_number;
177-
178-
low_args.context = build_context_mode(py_args.after_context, py_args.before_context);
165+
let mut low_args = lowargs::LowArgs {
166+
patterns: build_patterns(py_args.patterns.clone()),
167+
mode,
168+
sort: build_sort_mode(py_args.sort.clone()),
169+
heading: py_args.heading,
170+
max_count: py_args.max_count,
171+
line_number: py_args.line_number,
172+
context: build_context_mode(py_args.after_context, py_args.before_context),
173+
..Default::default()
174+
};
179175

180176
if let Some(globs) = &py_args.globs {
181177
low_args.globs = globs.clone();
@@ -187,17 +183,17 @@ fn pyargs_to_hiargs(py_args: &PyArgs, mode: lowargs::Mode) -> anyhow::Result<HiA
187183

188184
if let Some(separator_field_context) = &py_args.separator_field_context {
189185
let sep = OsStr::new(separator_field_context);
190-
low_args.field_context_separator = lowargs::FieldContextSeparator::new(&sep).unwrap();
186+
low_args.field_context_separator = lowargs::FieldContextSeparator::new(sep).unwrap();
191187
}
192188

193189
if let Some(separator_field_match) = &py_args.separator_field_match {
194190
let sep = OsStr::new(separator_field_match);
195-
low_args.field_match_separator = lowargs::FieldMatchSeparator::new(&sep).unwrap();
191+
low_args.field_match_separator = lowargs::FieldMatchSeparator::new(sep).unwrap();
196192
}
197193

198194
if let Some(separator_context) = &py_args.separator_context {
199195
let sep = OsStr::new(separator_context);
200-
low_args.context_separator = lowargs::ContextSeparator::new(&sep).unwrap();
196+
low_args.context_separator = lowargs::ContextSeparator::new(sep).unwrap();
201197
}
202198

203199
if let Some(multiline) = py_args.multiline {
@@ -229,6 +225,7 @@ fn pyargs_to_hiargs(py_args: &PyArgs, mode: lowargs::Mode) -> anyhow::Result<HiA
229225
multiline=None,
230226
hidden=None,
231227
))]
228+
#[allow(clippy::too_many_arguments)]
232229
pub fn py_search(
233230
py: Python<'_>,
234231
patterns: Vec<String>,
@@ -351,6 +348,7 @@ fn py_search_impl(args: &HiArgs) -> anyhow::Result<Vec<String>> {
351348
multiline=None,
352349
hidden=None,
353350
))]
351+
#[allow(clippy::too_many_arguments)]
354352
pub fn py_files(
355353
py: Python<'_>,
356354
patterns: Vec<String>,

‎src/ripgrep_core/haystack.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,6 @@ impl Haystack {
159159

160160
/// Returns true if and only if this haystack points to a file.
161161
fn is_file(&self) -> bool {
162-
self.dent.file_type().map_or(false, |ft| ft.is_file())
162+
self.dent.file_type().is_some_and(|ft| ft.is_file())
163163
}
164164
}

‎src/ripgrep_core/hiargs.rs‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ impl HiArgs {
124124

125125
// We modify the mode in-place on `low` so that subsequent conversions
126126
// see the correct mode.
127-
match low.mode {
128-
Mode::Search(ref mut mode) => match *mode {
127+
if let Mode::Search(ref mut mode) = low.mode {
128+
match *mode {
129129
// treat `-v --count-matches` as `-v --count`
130130
SearchMode::CountMatches if low.invert_match => {
131131
*mode = SearchMode::Count;
@@ -135,8 +135,7 @@ impl HiArgs {
135135
*mode = SearchMode::CountMatches;
136136
}
137137
_ => {}
138-
},
139-
_ => {}
138+
}
140139
}
141140

142141
let mut state = State::new()?;
@@ -175,7 +174,7 @@ impl HiArgs {
175174
log::debug!("using {threads} thread(s)");
176175
let with_filename = low
177176
.with_filename
178-
.unwrap_or_else(|| low.vimgrep || !paths.is_one_file);
177+
.unwrap_or(low.vimgrep || !paths.is_one_file);
179178

180179
let file_separator = match low.mode {
181180
Mode::Search(SearchMode::Standard) => {
@@ -206,8 +205,8 @@ impl HiArgs {
206205
SearchMode::FilesWithMatches
207206
| SearchMode::FilesWithoutMatch
208207
| SearchMode::Count
209-
| SearchMode::CountMatches => return false,
210-
SearchMode::JSON => return true,
208+
| SearchMode::CountMatches => false,
209+
SearchMode::JSON => true,
211210
SearchMode::Standard => {
212211
// A few things can imply counting line numbers. In
213212
// particular, we generally want to show line numbers by
@@ -543,7 +542,7 @@ impl HiArgs {
543542
builder
544543
.color_specs(self.colors.clone())
545544
.hyperlink(self.hyperlink_config.clone())
546-
.separator(self.path_separator.clone())
545+
.separator(self.path_separator)
547546
.terminator(self.path_terminator.unwrap_or(b'\n'));
548547
builder
549548
}
@@ -606,14 +605,14 @@ impl HiArgs {
606605
.max_matches(self.max_count)
607606
.only_matching(self.only_matching)
608607
.path(self.with_filename)
609-
.path_terminator(self.path_terminator.clone())
608+
.path_terminator(self.path_terminator)
610609
.per_match_one_line(true)
611610
.per_match(self.vimgrep)
612611
.replacement(self.replace.clone().map(|r| r.into()))
613612
.separator_context(self.context_separator.clone().into_bytes())
614613
.separator_field_context(self.field_context_separator.clone().into_bytes())
615614
.separator_field_match(self.field_match_separator.clone().into_bytes())
616-
.separator_path(self.path_separator.clone())
615+
.separator_path(self.path_separator)
617616
.stats(self.stats.is_some())
618617
.trim_ascii(self.trim);
619618
// When doing multi-threaded searching, the buffer writer is
@@ -642,14 +641,14 @@ impl HiArgs {
642641
.max_matches(self.max_count)
643642
.only_matching(self.only_matching)
644643
.path(self.with_filename)
645-
.path_terminator(self.path_terminator.clone())
644+
.path_terminator(self.path_terminator)
646645
.per_match_one_line(true)
647646
.per_match(self.vimgrep)
648647
.replacement(self.replace.clone().map(|r| r.into()))
649648
.separator_context(self.context_separator.clone().into_bytes())
650649
.separator_field_context(self.field_context_separator.clone().into_bytes())
651650
.separator_field_match(self.field_match_separator.clone().into_bytes())
652-
.separator_path(self.path_separator.clone())
651+
.separator_path(self.path_separator)
653652
.stats(self.stats.is_some())
654653
.trim_ascii(self.trim);
655654
// When doing multi-threaded searching, the buffer writer is
@@ -677,9 +676,9 @@ impl HiArgs {
677676
.kind(kind)
678677
.max_matches(self.max_count)
679678
.path(self.with_filename)
680-
.path_terminator(self.path_terminator.clone())
679+
.path_terminator(self.path_terminator)
681680
.separator_field(b":".to_vec())
682-
.separator_path(self.path_separator.clone())
681+
.separator_path(self.path_separator)
683682
.stats(self.stats.is_some())
684683
.build(wtr)
685684
}
@@ -804,7 +803,7 @@ impl HiArgs {
804803
SortModeKind::Path if !sort.reverse => return Box::new(haystacks),
805804
SortModeKind::Path => {
806805
let mut haystacks = haystacks.collect::<Vec<Haystack>>();
807-
haystacks.sort_by(|ref h1, ref h2| h1.path().cmp(h2.path()).reverse());
806+
haystacks.sort_by(|h1, h2| h1.path().cmp(h2.path()).reverse());
808807
return Box::new(haystacks.into_iter());
809808
}
810809
SortModeKind::LastModified => {
@@ -1242,7 +1241,7 @@ fn globs(state: &State, low: &LowArgs) -> anyhow::Result<ignore::overrides::Over
12421241
// This only enables case insensitivity for subsequent globs.
12431242
builder.case_insensitive(true).unwrap();
12441243
for glob in low.iglobs.iter() {
1245-
builder.add(&glob)?;
1244+
builder.add(glob)?;
12461245
}
12471246
Ok(builder.build()?)
12481247
}

0 commit comments

Comments
 (0)