Skip to content

Commit

Permalink
Clear some clippy::pedantic pings (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
philiptaron authored Oct 28, 2024
2 parents 6a56d99 + f68244b commit 02db8e4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
5 changes: 2 additions & 3 deletions src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::{env, fs, process};
use anyhow::Context;
use relative_path::RelativePathBuf;
use serde::Deserialize;
use tempfile::Builder;

use crate::nix_file::CallPackageArgumentInfo;
use crate::problem::{
Expand Down Expand Up @@ -155,9 +154,9 @@ fn mutate_nix_instatiate_arguments_based_on_cfg(
pub fn check_values(
nixpkgs_path: &Path,
nix_file_store: &mut NixFileStore,
package_names: Vec<String>,
package_names: &[String],
) -> validation::Result<ratchet::Nixpkgs> {
let work_dir = Builder::new()
let work_dir = tempfile::Builder::new()
.prefix("nixpkgs-vet")
.tempdir()
.with_context(|| "Failed to create a working directory")?;
Expand Down
3 changes: 1 addition & 2 deletions src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ impl LineIndex {
pub fn line(&self, index: usize) -> usize {
match self.newlines.binary_search(&index) {
// +1 because lines are 1-indexed
Ok(x) => x + 1,
Err(x) => x + 1,
Ok(x) | Err(x) => x + 1,
}
}

Expand Down
22 changes: 14 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// #![warn(clippy::pedantic)]
// #![allow(clippy::uninlined_format_args)]
// #![allow(clippy::enum_glob_use)]
// #![allow(clippy::module_name_repetitions)]
// #![allow(clippy::doc_markdown)]
// #![allow(clippy::if_not_else)]
// #![allow(clippy::ignored_unit_patterns)]
mod eval;
mod location;
mod nix_file;
Expand Down Expand Up @@ -112,7 +119,7 @@ fn check_nixpkgs(nixpkgs_path: &Path) -> validation::Result<ratchet::Nixpkgs> {

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

Ok(result)
Expand Down Expand Up @@ -209,7 +216,7 @@ mod tests {
"symlinked_tmpdir",
Path::new("tests/success"),
"Validated successfully\n",
)
);
});
Ok(())
}
Expand Down Expand Up @@ -245,12 +252,11 @@ mod tests {

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

if !expected_errors_regex.is_match(&actual_errors) {
panic!(
"Failed test case {name}: {}",
StrComparison::new(expected_errors, &actual_errors)
);
}
assert!(
expected_errors_regex.is_match(&actual_errors),
"Failed test case {name}: {}",
StrComparison::new(expected_errors, &actual_errors)
);
}

/// Check whether a path is in a case-insensitive filesystem
Expand Down
6 changes: 3 additions & 3 deletions src/nix_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ mod tests {
(
Position { line, column },
result
.map(|node| node.to_string())
.map(ToString::to_string)
.map_right(|node| node.to_string()),
)
}));
Expand All @@ -589,7 +589,7 @@ mod tests {
fn detects_call_package() -> anyhow::Result<()> {
let temp_dir = tests::tempdir()?;
let file = temp_dir.path().join("file.nix");
let contents = indoc! {r#"
let contents = indoc! {r"
self: with self; {
a.sub = null;
b = null;
Expand All @@ -601,7 +601,7 @@ mod tests {
h = callPackage ./file.nix { x = 0; };
i = callPackage ({ }: { }) (let in { });
}
"#};
"};

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

Expand Down
2 changes: 1 addition & 1 deletion src/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn read_dir_sorted(base_dir: &Path) -> anyhow::Result<Vec<DirEntry>> {

process_results(listing, |listing| {
use itertools::Itertools;
Itertools::collect_vec(listing.sorted_by_key(|entry| entry.file_name()))
Itertools::collect_vec(listing.sorted_by_key(DirEntry::file_name))
})
.with_context(ctx)
}
Expand Down
3 changes: 1 addition & 2 deletions src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ impl Validation<()> {
pub fn and<A>(self, other: Validation<A>) -> Validation<A> {
match (self, other) {
(Success(_), Success(right_value)) => Success(right_value),
(Failure(errors), Success(_)) => Failure(errors),
(Success(_), Failure(errors)) => Failure(errors),
(Failure(errors_l), Failure(errors_r)) => Failure(concat([errors_l, errors_r])),
(Failure(errors), Success(_)) | (Success(_), Failure(errors)) => Failure(errors),
}
}
}
Expand Down

0 comments on commit 02db8e4

Please sign in to comment.