From 716f44031a39c5e43fb441ecc470db76efc23dd4 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 14 Jun 2026 11:24:36 +0900 Subject: refactor(pcre): drop Result from Preg method return types The Preg methods panic on PCRE failure (per the file header rationale), so their anyhow::Result wrappers never carried an Err. Co-Authored-By: Claude Opus 4.8 --- crates/shirabe/src/json/json_file.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'crates/shirabe/src/json/json_file.rs') diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs index f06a0b9..f04a7a4 100644 --- a/crates/shirabe/src/json/json_file.rs +++ b/crates/shirabe/src/json/json_file.rs @@ -109,7 +109,7 @@ impl JsonFile { http_downloader: Option>>, io: Option>>, ) -> Result { - if http_downloader.is_none() && Preg::is_match(r"{^https?://}i", &path).unwrap_or(false) { + if http_downloader.is_none() && Preg::is_match(r"{^https?://}i", &path) { return Err(InvalidArgumentException { message: "http urls require a HttpDownloader instance to be passed".to_string(), code: 0, @@ -456,8 +456,7 @@ impl JsonFile { str_repeat(&indent_owned, (strlen(whole) / 4) as usize) }, &json, - ) - .unwrap_or(json); + ); } json @@ -512,8 +511,7 @@ impl JsonFile { json, -1, &mut count, - ) - .unwrap_or_else(|_| json.to_string()); + ); if count == 1 { data = json_decode(&replaced, true)?; if !matches!(data, PhpMixed::Null) { @@ -575,8 +573,7 @@ impl JsonFile { pub fn detect_indenting(json: Option<&str>) -> String { let mut m: IndexMap = IndexMap::new(); - if Preg::is_match3(r##"#^([ \t]+)"#m"##, json.unwrap_or(""), Some(&mut m)).unwrap_or(false) - { + if Preg::is_match3(r##"#^([ \t]+)"#m"##, json.unwrap_or(""), Some(&mut m)) { return m.get(&CaptureKey::ByIndex(1)).cloned().unwrap_or_default(); } -- cgit v1.3.1