From 3dc71b2f5160ef9bd46143eed0edb5d2557b58e6 Mon Sep 17 00:00:00 2001 From: aur-build Date: Sun, 22 Nov 2026 10:36:24 +0000 Subject: rustfmt,lints: pin the formatting, adopt the idiom lints, pay them off rustfmt.toml fixes the shape the tree is written in (120 columns, small items kept on one line) and one canonical pass makes it the truth. [lints.clippy] names the idiom lints worth enforcing and leaves out the two that would add doc-comment boilerplate rather than remove it. The tree pays them off here: write!/writeln! instead of push_str(&format!()), let-else instead of match-on-Option, borrows where a thread entry point only reads what it owns, no `&self` on a Copy state and no `self` nobody reads. ops::to_prometheus gains one gauge helper: a metric's HELP, TYPE and value are now emitted by the same call instead of three. --- src/config.rs | 79 +++++++++++++++++------------------------------------------ 1 file changed, 23 insertions(+), 56 deletions(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index 7818e4b..1b9f26a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -204,10 +204,7 @@ impl Default for Config { impl Config { pub fn sandbox_image(&self) -> String { - self.sandbox - .image() - .unwrap_or(DEFAULT_SANDBOX_IMAGE) - .to_string() + self.sandbox.image().unwrap_or(DEFAULT_SANDBOX_IMAGE).to_string() } pub fn validate(&self) -> crate::error::Result<()> { @@ -259,10 +256,7 @@ impl Config { let dir = absolute(root)?; let p = dir.join("config.json"); if !p.exists() { - return Err(crate::error::Error::not_found(format!( - "no config at {}; run `aur-build init`", - p.display() - ))); + return Err(crate::error::Error::not_found(format!("no config at {}; run `aur-build init`", p.display()))); } let s = std::fs::read_to_string(&p)?; let v: serde_json::Value = serde_json::from_str(&s)?; @@ -276,10 +270,7 @@ impl Config { std::fs::create_dir_all(&self.root)?; let mut out = self.clone(); out.root = absolute(&self.root)?; - std::fs::write( - self.root.join("config.json"), - serde_json::to_string_pretty(&out)? + "\n", - )?; + std::fs::write(self.root.join("config.json"), serde_json::to_string_pretty(&out)? + "\n")?; Ok(()) } @@ -396,10 +387,7 @@ impl Config { self.root.join("repo") } pub fn repo_arch_dir(&self) -> PathBuf { - self.repo_dir() - .join(&self.repo_name) - .join("os") - .join(&self.arch) + self.repo_dir().join(&self.repo_name).join("os").join(&self.arch) } pub fn repo_db_name(&self) -> String { format!("{}.db", self.repo_name) @@ -419,12 +407,12 @@ fn check_retired_sandbox_keys(v: &serde_json::Value) -> crate::error::Result<()> let named: Vec = RETIRED .iter() .filter(|k| { - let key: &str = k; - match v.get(key) { - None => false, - Some(serde_json::Value::String(s)) => !retired_key_is_inert(key, s), - Some(_) => true, - } + let key: &str = k; + match v.get(key) { + None => false, + Some(serde_json::Value::String(s)) => !retired_key_is_inert(key, s), + Some(_) => true, + } }) .map(|k| format!("\"{k}\"")) .collect(); @@ -437,10 +425,7 @@ fn check_retired_sandbox_keys(v: &serde_json::Value) -> crate::error::Result<()> "{\"kind\":\"remote\",\"listen\":…,\"token\":…}, or ", "{\"kind\":\"agent-sandbox\",\"api\":…,\"namespace\":…,\"bearer\":…,\"image\":…,\"listen\":…,\"token\":…}" ); - Err(crate::error::Error::invalid(format!( - "{} are retired sandbox keys; {example}", - named.join(", ") - ))) + Err(crate::error::Error::invalid(format!("{} are retired sandbox keys; {example}", named.join(", ")))) } fn absolute(p: &Path) -> crate::error::Result { @@ -449,13 +434,7 @@ fn absolute(p: &Path) -> crate::error::Result { fn slug(url: &str) -> String { url.chars() - .map(|c| { - if c.is_ascii_alphanumeric() { - c.to_ascii_lowercase() - } else { - '-' - } - }) + .map(|c| if c.is_ascii_alphanumeric() { c.to_ascii_lowercase() } else { '-' }) .collect::() .trim_matches('-') .chars() @@ -472,11 +451,7 @@ mod tests { // fixture corpus, or a subprocess. fn load_sandbox(sandbox: &str) -> Result { let tmp = tempfile::tempdir().unwrap(); - std::fs::write( - tmp.path().join("config.json"), - format!("{{\n \"sandbox\": {sandbox}\n}}\n"), - ) - .unwrap(); + std::fs::write(tmp.path().join("config.json"), format!("{{\n \"sandbox\": {sandbox}\n}}\n")).unwrap(); Config::load(tmp.path()).map_err(|e| e.to_string()) } @@ -496,10 +471,7 @@ mod tests { other => panic!("expected loopback, got {other:?}"), } - let remote = load_sandbox( - r#"{"kind":"remote","listen":"127.0.0.1:8787","token":"s3cr3t"}"#, - ) - .unwrap(); + let remote = load_sandbox(r#"{"kind":"remote","listen":"127.0.0.1:8787","token":"s3cr3t"}"#).unwrap(); match &remote.sandbox { Sandbox::Remote { listen, token, shared_workspace } => { assert_eq!(listen, "127.0.0.1:8787"); @@ -545,8 +517,7 @@ mod tests { r#""token":"t""#.to_string(), ]; fields.retain(|f| !f.starts_with(&format!("\"{missing}\""))); - let err = load_sandbox(&format!("{{\"kind\":\"agent-sandbox\",{}}}", fields.join(","))) - .unwrap_err(); + let err = load_sandbox(&format!("{{\"kind\":\"agent-sandbox\",{}}}", fields.join(","))).unwrap_err(); assert!(err.contains(missing), "dropping {missing} must name it: {err}"); } } @@ -637,13 +608,12 @@ mod tests { #[test] fn a_field_that_is_present_but_empty_is_refused() { - let cfg = load_sandbox(r#"{"kind":"remote","listen":"","token":"t","shared_workspace":true}"#) - .unwrap(); + let cfg = load_sandbox(r#"{"kind":"remote","listen":"","token":"t","shared_workspace":true}"#).unwrap(); let err = cfg.validate().unwrap_err().to_string(); assert!(err.contains("listen"), "must name the empty field: {err}"); - let cfg = load_sandbox(r#"{"kind":"remote","listen":"127.0.0.1:1","token":" ","shared_workspace":true}"#) - .unwrap(); + let cfg = + load_sandbox(r#"{"kind":"remote","listen":"127.0.0.1:1","token":" ","shared_workspace":true}"#).unwrap(); let err = cfg.validate().unwrap_err().to_string(); assert!(err.contains("token"), "whitespace is not a token: {err}"); @@ -657,8 +627,7 @@ mod tests { ("token", "t"), ]); fields.insert(blank, ""); - let body: Vec = - fields.iter().map(|(k, v)| format!("\"{k}\":\"{v}\"")).collect(); + let body: Vec = fields.iter().map(|(k, v)| format!("\"{k}\":\"{v}\"")).collect(); let cfg = load_sandbox(&format!("{{\"kind\":\"agent-sandbox\",{}}}", body.join(","))).unwrap(); let err = cfg.validate().unwrap_err().to_string(); assert!(err.contains(blank), "blank {blank} must be named: {err}"); @@ -682,12 +651,10 @@ mod tests { assert!(err.contains("shared_workspace"), "{err}"); assert!(err.contains("agent-sandbox"), "{err}"); - assert!(load_sandbox( - r#"{"kind":"remote","listen":"127.0.0.1:1","token":"t","shared_workspace":true}"# - ) - .unwrap() - .validate() - .is_ok()); + assert!(load_sandbox(r#"{"kind":"remote","listen":"127.0.0.1:1","token":"t","shared_workspace":true}"#) + .unwrap() + .validate() + .is_ok()); } #[test] -- cgit v1.2.3