FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
refactor: clear S9045 and S107 new-code issues (#3336)
Dylan M. Taylor7725f4867369
diff --git a/crates/engine/src/proxies.rs b/crates/engine/src/proxies.rsindex ad84893c6..e6e7f203c 100644--- a/crates/engine/src/proxies.rs+++ b/crates/engine/src/proxies.rs@@ -97,7 +97,13 @@ pub fn transcode(preset: &Preset,progress: &Progress,) -> std::result::Result<Report, String> {- transcode_with_file(clip, name, src, range, out, None, preset, progress)+ transcode_with_file(clip, name, src, range, Dest { path: out, file: None }, preset, progress)+}++/// Output path, plus the already-open file to write into when the caller holds one.+struct Dest<'a> {+ path: &'a str,+ file: Option<Arc<std::fs::File>>,}fn transcode_with_file(@@ -105,11 +111,11 @@ fn transcode_with_file(name: &str,src: SharedSource,range: Option<TimeRange>,- out: &str,- output_file: Option<Arc<std::fs::File>>,+ dest: Dest<'_>,preset: &Preset,progress: &Progress,) -> std::result::Result<Report, String> {+ let Dest { path: out, file: output_file } = dest;let info = &clip.info;let rate = clip.frame_rate();let mut st = SequenceSettings::default();@@ -280,7 +286,7 @@ fn start_job(s: &mut Session, label: String, work: Vec<(ItemId, ReservedOutput,}*prog.status.lock().unwrap_or_else(|e| e.into_inner()) = format!("{name} ({} of {n})", k + 1);let out = output.path().to_string_lossy().into_owned();- match transcode_with_file(&clip, &name, src, None, &out, output.file(), pr, &prog) {+ match transcode_with_file(&clip, &name, src, None, Dest { path: &out, file: output.file() }, pr, &prog) {Ok(r) => {bytes += r.bytes;output.preserve();diff --git a/crates/export/src/pipeline.rs b/crates/export/src/pipeline.rsindex 814b85c4d..c4c6f73ea 100644--- a/crates/export/src/pipeline.rs+++ b/crates/export/src/pipeline.rs@@ -26,18 +26,6 @@ fn bounded_overlay_dimensions(w: usize, h: usize) -> Result<()> {Ok(())}-#[cfg(test)]-mod overlay_budget_tests {- use super::*;-- #[test]- fn overlay_pixel_budget_is_checked_without_overflow() {- assert!(bounded_overlay_dimensions(4096, 4096).is_ok());- assert!(bounded_overlay_dimensions(4097, 4096).is_err());- assert!(bounded_overlay_dimensions(usize::MAX, 2).is_err());- }-}-/// Where the rendered picture lands in the output frame.#[derive(Clone, Copy, Debug, PartialEq)]pub(crate) struct Geometry {@@ -534,3 +522,15 @@ fn limit_px(c: &mut [f32; 3], lo: f32, hi: f32) {}c.iter_mut().for_each(|v| *v = v.clamp(0.0, hi.max(lo)));}++#[cfg(test)]+mod overlay_budget_tests {+ use super::*;++ #[test]+ fn overlay_pixel_budget_is_checked_without_overflow() {+ assert!(bounded_overlay_dimensions(4096, 4096).is_ok());+ assert!(bounded_overlay_dimensions(4097, 4096).is_err());+ assert!(bounded_overlay_dimensions(usize::MAX, 2).is_err());+ }+}diff --git a/crates/speech/src/whisper/tokenizer.rs b/crates/speech/src/whisper/tokenizer.rsindex aaaa93b9c..e9eba3328 100644--- a/crates/speech/src/whisper/tokenizer.rs+++ b/crates/speech/src/whisper/tokenizer.rs@@ -125,21 +125,6 @@ impl Tokenizer {}}-#[cfg(test)]-mod tests {- use super::*;-- #[test]- fn sparse_huge_vocab_id_is_rejected_before_allocation() {- let json = format!(r#"{{"model":{{"vocab":{{"x":{}}}}},"added_tokens":[]}}"#, MAX_VOCAB_ID + 1);- let error = match Tokenizer::from_json(&json) {- Err(error) => error,- Ok(_) => panic!("huge sparse vocabulary was accepted"),- };- assert!(error.to_string().contains("vocab id is too large"));- }-}-/// Group text tokens into words: a token whose text starts with a space starts a new word;/// punctuation-only tokens join the word before them (opening quotes/brackets the word after)./// Returns (word text, token index range).@@ -186,3 +171,18 @@ pub fn group_words(tok: &Tokenizer, ids: &[u32]) -> Vec<(String, std::ops::Range}groups.into_iter().map(|(b, r)| (String::from_utf8_lossy(&b).trim().to_string(), r)).filter(|(t, _)| !t.is_empty()).collect()}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn sparse_huge_vocab_id_is_rejected_before_allocation() {+ let json = format!(r#"{{"model":{{"vocab":{{"x":{}}}}},"added_tokens":[]}}"#, MAX_VOCAB_ID + 1);+ let error = match Tokenizer::from_json(&json) {+ Err(error) => error,+ Ok(_) => panic!("huge sparse vocabulary was accepted"),+ };+ assert!(error.to_string().contains("vocab id is too large"));+ }+}