Skip to content

Commit 02db8e4

Browse files
authored
Clear some clippy::pedantic pings (#120)
2 parents 6a56d99 + f68244b commit 02db8e4

File tree

6 files changed

+22
-19
lines changed

6 files changed

+22
-19
lines changed

src/eval.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::{env, fs, process};
44
use anyhow::Context;
55
use relative_path::RelativePathBuf;
66
use serde::Deserialize;
7-
use tempfile::Builder;
87

98
use crate::nix_file::CallPackageArgumentInfo;
109
use crate::problem::{
@@ -155,9 +154,9 @@ fn mutate_nix_instatiate_arguments_based_on_cfg(
155154
pub fn check_values(
156155
nixpkgs_path: &Path,
157156
nix_file_store: &mut NixFileStore,
158-
package_names: Vec<String>,
157+
package_names: &[String],
159158
) -> validation::Result<ratchet::Nixpkgs> {
160-
let work_dir = Builder::new()
159+
let work_dir = tempfile::Builder::new()
161160
.prefix("nixpkgs-vet")
162161
.tempdir()
163162
.with_context(|| "Failed to create a working directory")?;

src/location.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ impl LineIndex {
4545
pub fn line(&self, index: usize) -> usize {
4646
match self.newlines.binary_search(&index) {
4747
// +1 because lines are 1-indexed
48-
Ok(x) => x + 1,
49-
Err(x) => x + 1,
48+
Ok(x) | Err(x) => x + 1,
5049
}
5150
}
5251

src/main.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// #![warn(clippy::pedantic)]
2+
// #![allow(clippy::uninlined_format_args)]
3+
// #![allow(clippy::enum_glob_use)]
4+
// #![allow(clippy::module_name_repetitions)]
5+
// #![allow(clippy::doc_markdown)]
6+
// #![allow(clippy::if_not_else)]
7+
// #![allow(clippy::ignored_unit_patterns)]
18
mod eval;
29
mod location;
310
mod nix_file;
@@ -112,7 +119,7 @@ fn check_nixpkgs(nixpkgs_path: &Path) -> validation::Result<ratchet::Nixpkgs> {
112119

113120
// Only if we could successfully parse the structure, we do the evaluation checks
114121
let result = structure.result_map(|package_names| {
115-
eval::check_values(&nixpkgs_path, &mut nix_file_store, package_names)
122+
eval::check_values(&nixpkgs_path, &mut nix_file_store, package_names.as_slice())
116123
})?;
117124

118125
Ok(result)
@@ -209,7 +216,7 @@ mod tests {
209216
"symlinked_tmpdir",
210217
Path::new("tests/success"),
211218
"Validated successfully\n",
212-
)
219+
);
213220
});
214221
Ok(())
215222
}
@@ -245,12 +252,11 @@ mod tests {
245252

246253
let actual_errors = format!("{status}\n");
247254

248-
if !expected_errors_regex.is_match(&actual_errors) {
249-
panic!(
250-
"Failed test case {name}: {}",
251-
StrComparison::new(expected_errors, &actual_errors)
252-
);
253-
}
255+
assert!(
256+
expected_errors_regex.is_match(&actual_errors),
257+
"Failed test case {name}: {}",
258+
StrComparison::new(expected_errors, &actual_errors)
259+
);
254260
}
255261

256262
/// Check whether a path is in a case-insensitive filesystem

src/nix_file.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ mod tests {
566566
(
567567
Position { line, column },
568568
result
569-
.map(|node| node.to_string())
569+
.map(ToString::to_string)
570570
.map_right(|node| node.to_string()),
571571
)
572572
}));
@@ -589,7 +589,7 @@ mod tests {
589589
fn detects_call_package() -> anyhow::Result<()> {
590590
let temp_dir = tests::tempdir()?;
591591
let file = temp_dir.path().join("file.nix");
592-
let contents = indoc! {r#"
592+
let contents = indoc! {r"
593593
self: with self; {
594594
a.sub = null;
595595
b = null;
@@ -601,7 +601,7 @@ mod tests {
601601
h = callPackage ./file.nix { x = 0; };
602602
i = callPackage ({ }: { }) (let in { });
603603
}
604-
"#};
604+
"};
605605

606606
std::fs::write(&file, contents)?;
607607

src/structure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn read_dir_sorted(base_dir: &Path) -> anyhow::Result<Vec<DirEntry>> {
2727

2828
process_results(listing, |listing| {
2929
use itertools::Itertools;
30-
Itertools::collect_vec(listing.sorted_by_key(|entry| entry.file_name()))
30+
Itertools::collect_vec(listing.sorted_by_key(DirEntry::file_name))
3131
})
3232
.with_context(ctx)
3333
}

src/validation.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ impl Validation<()> {
7878
pub fn and<A>(self, other: Validation<A>) -> Validation<A> {
7979
match (self, other) {
8080
(Success(_), Success(right_value)) => Success(right_value),
81-
(Failure(errors), Success(_)) => Failure(errors),
82-
(Success(_), Failure(errors)) => Failure(errors),
8381
(Failure(errors_l), Failure(errors_r)) => Failure(concat([errors_l, errors_r])),
82+
(Failure(errors), Success(_)) | (Success(_), Failure(errors)) => Failure(errors),
8483
}
8584
}
8685
}

0 commit comments

Comments
 (0)