diff --git a/copperd/Cargo.toml b/copperd/Cargo.toml index 98240988..f9612b78 100644 --- a/copperd/Cargo.toml +++ b/copperd/Cargo.toml @@ -61,6 +61,40 @@ needless_return = "allow" new_without_default = "allow" tabs_in_doc_comments = "allow" + +# Extra +expect_used = "deny" +#unwrap_used = "deny" +#panic = "deny" +dbg_macro = "deny" +allow_attributes = "deny" +create_dir = "deny" +filetype_is_file = "deny" +integer_division = "deny" +lossy_float_literal = "deny" +map_err_ignore = "deny" +mutex_atomic = "deny" +needless_raw_strings = "deny" +print_stderr = "deny" +print_stdout = "deny" +str_to_string = "deny" +string_add = "deny" +string_to_string = "deny" +unimplemented = "deny" +use_debug = "deny" +verbose_file_reads = "deny" +#wildcard_enum_match_arm = "deny" + +# Pedantic +large_types_passed_by_value = "deny" +match_on_vec_items = "deny" + +# Cargo +wildcard_dependencies = "deny" +negative_feature_names = "deny" +redundant_feature_names = "deny" +#multiple_crate_versions = "deny" + [workspace.dependencies] # Shared libraries copper-util = { path = "lib/util" } diff --git a/copperd/bin/edged/src/api/storage/upload_part.rs b/copperd/bin/edged/src/api/storage/upload_part.rs index 9a3c0b3c..3d4de834 100644 --- a/copperd/bin/edged/src/api/storage/upload_part.rs +++ b/copperd/bin/edged/src/api/storage/upload_part.rs @@ -42,7 +42,7 @@ pub(super) async fn upload_part( // Parse multipart data let mut data: Option = None; while let Some(field) = multipart.next_field().await.unwrap() { - let name = field.name().unwrap().to_string(); + let name = field.name().unwrap().to_owned(); match &name[..] { "part_data" => { diff --git a/copperd/bin/edged/src/main.rs b/copperd/bin/edged/src/main.rs index b631bbe7..2bca0d83 100644 --- a/copperd/bin/edged/src/main.rs +++ b/copperd/bin/edged/src/main.rs @@ -135,6 +135,8 @@ async fn make_app(config: Arc, s3_client: Arc) -> Router async fn main() { let config_res = match load_env::() { Ok(x) => x, + + #[expect(clippy::print_stdout)] Err(err) => { println!("Error while loading .env: {err}"); std::process::exit(1); diff --git a/copperd/bin/piper/src/main.rs b/copperd/bin/piper/src/main.rs index 9cd96aa5..dd550099 100644 --- a/copperd/bin/piper/src/main.rs +++ b/copperd/bin/piper/src/main.rs @@ -35,6 +35,8 @@ mod pipeline; async fn main() { let config_res = match load_env::() { Ok(x) => x, + + #[expect(clippy::print_stdout)] Err(err) => { println!("Error while loading .env: {err}"); std::process::exit(1); diff --git a/copperd/lib/migrate/src/lib.rs b/copperd/lib/migrate/src/lib.rs index 163428ed..b0e8de54 100644 --- a/copperd/lib/migrate/src/lib.rs +++ b/copperd/lib/migrate/src/lib.rs @@ -40,7 +40,7 @@ pub enum MigrationError { /// We could not deserialize a migration record #[error("could not deserialize migration")] - MalformedMigrationRecord, + MalformedMigrationRecord(#[from] serde_json::Error), } /// A migration entry in the database, @@ -105,8 +105,7 @@ impl<'a> Migrator<'a> { let mut ap_migs: BTreeMap, MigrationRecord> = BTreeMap::new(); for row in res { - let r: MigrationRecord = serde_json::from_str(row.get("val")) - .map_err(|_| MigrationError::MalformedMigrationRecord)?; + let r: MigrationRecord = serde_json::from_str(row.get("val"))?; ap_migs.insert(r.name.clone(), r); } diff --git a/copperd/lib/util/src/env.rs b/copperd/lib/util/src/env.rs index aeb32985..54162342 100644 --- a/copperd/lib/util/src/env.rs +++ b/copperd/lib/util/src/env.rs @@ -43,6 +43,7 @@ impl LoadedEnv { /// Load the configuration type `T` from the current environment, /// including the `.env` if it exists. +#[expect(clippy::wildcard_enum_match_arm)] pub fn load_env() -> Result, EnvLoadError> { let env_path = match dotenvy::dotenv() { Ok(path) => Some(path), diff --git a/copperd/nodes/audiofile/src/common/vorbiscomment.rs b/copperd/nodes/audiofile/src/common/vorbiscomment.rs index 065e9c96..d3bb04a3 100644 --- a/copperd/nodes/audiofile/src/common/vorbiscomment.rs +++ b/copperd/nodes/audiofile/src/common/vorbiscomment.rs @@ -132,18 +132,21 @@ impl VorbisComment { let mut block = [0u8; 4]; let vendor = { + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block) .map_err(|_| VorbisCommentDecodeError::MalformedData)?; let length = u32::from_le_bytes(block); let mut text = vec![0u8; length.try_into().unwrap()]; + #[expect(clippy::map_err_ignore)] d.read_exact(&mut text) .map_err(|_| VorbisCommentDecodeError::MalformedData)?; String::from_utf8(text)? }; + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block) .map_err(|_| VorbisCommentDecodeError::MalformedData)?; let n_comments: usize = u32::from_le_bytes(block).try_into().unwrap(); @@ -152,12 +155,14 @@ impl VorbisComment { let mut pictures = Vec::new(); for _ in 0..n_comments { let comment = { + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block) .map_err(|_| VorbisCommentDecodeError::MalformedData)?; let length = u32::from_le_bytes(block); let mut text = vec![0u8; length.try_into().unwrap()]; + #[expect(clippy::map_err_ignore)] d.read_exact(&mut text) .map_err(|_| VorbisCommentDecodeError::MalformedData)?; @@ -172,6 +177,7 @@ impl VorbisComment { if !val.is_empty() { if var.to_uppercase() == "METADATA_BLOCK_PICTURE" { + #[expect(clippy::map_err_ignore)] pictures.push( FlacPictureBlock::decode( &base64::prelude::BASE64_STANDARD @@ -248,7 +254,11 @@ impl VorbisComment { x -= x % 3; x += 3; } - sum += 4 * (x / 3); + + #[expect(clippy::integer_division)] + { + sum += 4 * (x / 3); + } // Add "METADATA_BLOCK_PICTURE=" sum += 23; @@ -298,8 +308,11 @@ impl VorbisComment { for p in &self.pictures { let mut pic_data = Vec::new(); + + #[expect(clippy::map_err_ignore)] p.encode(false, false, &mut pic_data) .map_err(|_| VorbisCommentEncodeError::PictureEncodeError)?; + let pic_string = format!( "METADATA_BLOCK_PICTURE={}", &base64::prelude::BASE64_STANDARD.encode(&pic_data) diff --git a/copperd/nodes/audiofile/src/flac/blocks/application.rs b/copperd/nodes/audiofile/src/flac/blocks/application.rs index b23333c3..cd2f3784 100644 --- a/copperd/nodes/audiofile/src/flac/blocks/application.rs +++ b/copperd/nodes/audiofile/src/flac/blocks/application.rs @@ -29,8 +29,11 @@ impl FlacMetablockDecode for FlacApplicationBlock { let mut d = Cursor::new(data); let mut block = [0u8; 4]; + + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block) .map_err(|_| FlacDecodeError::MalformedBlock)?; + let application_id = u32::from_be_bytes(block); let data = { diff --git a/copperd/nodes/audiofile/src/flac/blocks/picture.rs b/copperd/nodes/audiofile/src/flac/blocks/picture.rs index 14a4179b..f872cd3b 100644 --- a/copperd/nodes/audiofile/src/flac/blocks/picture.rs +++ b/copperd/nodes/audiofile/src/flac/blocks/picture.rs @@ -55,18 +55,21 @@ impl FlacMetablockDecode for FlacPictureBlock { // This is re-used whenever we need to read four bytes let mut block = [0u8; 4]; + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block) .map_err(|_| FlacDecodeError::MalformedBlock)?; let picture_type = PictureType::from_idx(u32::from_be_bytes(block))?; // Image format let mime = { + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block) .map_err(|_| FlacDecodeError::MalformedBlock)?; let mime_length = u32::from_be_bytes(block).try_into().unwrap(); let mut mime = vec![0u8; mime_length]; + #[expect(clippy::map_err_ignore)] d.read_exact(&mut mime) .map_err(|_| FlacDecodeError::MalformedBlock)?; @@ -75,12 +78,14 @@ impl FlacMetablockDecode for FlacPictureBlock { // Image description let description = { + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block) .map_err(|_| FlacDecodeError::MalformedBlock)?; let desc_length = u32::from_be_bytes(block).try_into().unwrap(); let mut desc = vec![0u8; desc_length]; + #[expect(clippy::map_err_ignore)] d.read_exact(&mut desc) .map_err(|_| FlacDecodeError::MalformedBlock)?; @@ -88,33 +93,39 @@ impl FlacMetablockDecode for FlacPictureBlock { }; // Image width + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block) .map_err(|_| FlacDecodeError::MalformedBlock)?; let width = u32::from_be_bytes(block); // Image height + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block) .map_err(|_| FlacDecodeError::MalformedBlock)?; let height = u32::from_be_bytes(block); // Image bit depth + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block) .map_err(|_| FlacDecodeError::MalformedBlock)?; let depth = u32::from_be_bytes(block); // Color count for indexed images + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block) .map_err(|_| FlacDecodeError::MalformedBlock)?; let color_count = u32::from_be_bytes(block); // Image data length let img_data = { + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block) .map_err(|_| FlacDecodeError::MalformedBlock)?; let data_length = u32::from_be_bytes(block).try_into().unwrap(); let mut img_data = vec![0u8; data_length]; + #[expect(clippy::map_err_ignore)] d.read_exact(&mut img_data) .map_err(|_| FlacDecodeError::MalformedBlock)?; @@ -138,8 +149,8 @@ impl FlacMetablockEncode for FlacPictureBlock { fn get_len(&self) -> u32 { (4 + (4 + self.mime.to_string().len()) + (4 + self.description.len()) - + 4 + 4 + 4 + 4 - + (4 + self.img_data.len())) + + 4 + 4 + 4 + + 4 + (4 + self.img_data.len())) .try_into() .unwrap() } @@ -167,7 +178,7 @@ impl FlacMetablockEncode for FlacPictureBlock { drop(mime); target.write_all(&u32::try_from(self.description.len()).unwrap().to_be_bytes())?; - target.write_all(self.description.to_string().as_bytes())?; + target.write_all(self.description.as_bytes())?; target.write_all(&self.width.to_be_bytes())?; target.write_all(&self.height.to_be_bytes())?; diff --git a/copperd/nodes/audiofile/src/flac/blocks/streaminfo.rs b/copperd/nodes/audiofile/src/flac/blocks/streaminfo.rs index ff0fcf1d..ddaac9ba 100644 --- a/copperd/nodes/audiofile/src/flac/blocks/streaminfo.rs +++ b/copperd/nodes/audiofile/src/flac/blocks/streaminfo.rs @@ -46,34 +46,48 @@ impl FlacMetablockDecode for FlacStreaminfoBlock { let min_block_size = { let mut block = [0u8; 4]; + + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block[2..]) .map_err(|_| FlacDecodeError::MalformedBlock)?; + u32::from_be_bytes(block) }; let max_block_size = { let mut block = [0u8; 4]; + + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block[2..]) .map_err(|_| FlacDecodeError::MalformedBlock)?; + u32::from_be_bytes(block) }; let min_frame_size = { let mut block = [0u8; 4]; + + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block[1..]) .map_err(|_| FlacDecodeError::MalformedBlock)?; + u32::from_be_bytes(block) }; let max_frame_size = { let mut block = [0u8; 4]; + + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block[1..]) .map_err(|_| FlacDecodeError::MalformedBlock)?; + u32::from_be_bytes(block) }; let (sample_rate, channels, bits_per_sample, total_samples) = { let mut block = [0u8; 8]; + + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block) .map_err(|_| FlacDecodeError::MalformedBlock)?; @@ -117,6 +131,7 @@ impl FlacMetablockDecode for FlacStreaminfoBlock { let md5_signature = { let mut block = [0u8; 16]; + #[expect(clippy::map_err_ignore)] d.read_exact(&mut block) .map_err(|_| FlacDecodeError::MalformedBlock)?; block