Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address more lints #639

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/disk_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ fn disk_usage(path: &Path) -> Result<DiskUsage> {

#[cfg(test)]
mod tests {
#![allow(clippy::assertions_on_result_states)]

use super::*;

const EXCESSIVE_VALUE_F64: f64 = 4_000_000_000_000_000_000.0;
Expand Down
10 changes: 2 additions & 8 deletions src/iomem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
// Licensed under the MIT License.

use core::{num::ParseIntError, ops::Range};
use std::{
fs::OpenOptions,
io::{Error as IoError, Read},
path::Path,
};
use std::{fs::read_to_string, io::Error as IoError, path::Path};

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand All @@ -29,9 +25,7 @@ pub fn parse() -> Result<Vec<Range<u64>>, Error> {
}

fn parse_file(path: &Path) -> Result<Vec<Range<u64>>, Error> {
let mut f = OpenOptions::new().read(true).open(path)?;
let mut buffer = String::new();
f.read_to_string(&mut buffer)?;
let buffer = read_to_string(path)?;

let mut ranges = Vec::new();
for line in buffer.split_terminator('\n') {
Expand Down
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@
#![deny(clippy::if_then_some_else_none)]
#![deny(clippy::shadow_unrelated)]
#![deny(clippy::std_instead_of_core)]
#![warn(clippy::assertions_on_result_states)]
#![warn(clippy::if_then_some_else_none)]
#![warn(clippy::needless_continue)]
#![warn(clippy::redundant_pub_crate)]
#![warn(clippy::shadow_unrelated)]
#![warn(clippy::std_instead_of_core)]
#![warn(clippy::undocumented_unsafe_blocks)]
#![warn(clippy::unused_trait_names)]
#![warn(clippy::verbose_file_reads)]
// #![warn(clippy::arithmetic_side_effects)]
// #![warn(clippy::as_conversions)]
// #![warn(clippy::missing_errors_doc)]
// #![warn(clippy::pattern_type_mismatch)]
// #![warn(clippy::std_instead_of_alloc)]

#[cfg(target_family = "unix")]
mod disk_usage;
Expand Down
12 changes: 7 additions & 5 deletions src/write_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,20 @@ mod tests {
use std::io::Cursor;

#[test]
fn encode_header() {
fn encode_header() -> Result<()> {
let data = "hello world".as_bytes();

let buf = Cursor::new(vec![]);
let mut counter = Counter::new(buf);

assert!(counter.write_all(data).is_ok());
counter.write_all(data)?;
assert_eq!(counter.count(), data.len());
assert_eq!(counter.into_inner().into_inner(), data);
Ok(())
}

#[test]
fn encode_snap() {
fn encode_snap() -> Result<()> {
let size = 1000;
let many_a = "A".repeat(size).into_bytes();

Expand All @@ -66,7 +67,7 @@ mod tests {
let mut counter = Counter::new(cursor);
{
let mut snap = FrameEncoder::new(&mut counter);
assert!(snap.write_all(&many_a).is_ok());
snap.write_all(&many_a)?;
}
// verify we had some compression here...
assert!(counter.count() < size);
Expand All @@ -79,11 +80,12 @@ mod tests {
let mut counter = Counter::new(decoded);
{
let mut snap = FrameDecoder::new(&mut compressed);
assert!(std::io::copy(&mut snap, &mut counter).is_ok());
std::io::copy(&mut snap, &mut counter)?;
}
assert_eq!(counter.count(), size, "verify decoded size");
counter.into_inner().into_inner()
};
assert_eq!(many_a, result, "verify decoded byte are equal");
Ok(())
}
}