code style fixes and nesting fixes
All checks were successful
Version Check / check-version (pull_request) Successful in 3s

This commit is contained in:
2026-03-18 17:15:24 +01:00
parent b3651aa5dd
commit 5056f8dd0a
9 changed files with 46 additions and 66 deletions

View File

@@ -135,7 +135,7 @@ fn json_to_xml(value: &Value) -> String {
let mut s = String::new();
for (k, v) in map {
if k == "$text" {
s.push_str(&v.as_str().unwrap_or(""));
s.push_str(v.as_str().unwrap_or(""));
} else if let Some(arr) = v.as_array() {
for item in arr {
s.push_str(&format!("<{}>", k));
@@ -437,8 +437,8 @@ mod tests {
"port_str": "8080",
"is_enabled": true,
"is_enabled_str": "true",
"float_num": 3.14,
"float_str": "3.14"
"float_num": 42.42,
"float_str": "42.42"
});
flatten(&json, "", 0, "", &mut vars);
@@ -466,10 +466,10 @@ mod tests {
assert_eq!(unflattened["is_enabled_str"].as_str(), Some("true"));
assert!(unflattened["float_num"].is_number(), "float_num should be a number");
assert_eq!(unflattened["float_num"].as_f64(), Some(3.14));
assert_eq!(unflattened["float_num"].as_f64(), Some(42.42));
assert!(unflattened["float_str"].is_string(), "float_str should be a string");
assert_eq!(unflattened["float_str"].as_str(), Some("3.14"));
assert_eq!(unflattened["float_str"].as_str(), Some("42.42"));
}
#[test]

View File

@@ -68,7 +68,7 @@ impl FormatHandler for IniHandler {
}
}
conf.write_to_file(path)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))
.map_err(io::Error::other)
}
}

View File

@@ -99,21 +99,15 @@ pub fn detect_format(path: &Path, override_format: Option<String>) -> FormatType
}
}
let file_name = path.file_name().unwrap_or_default().to_string_lossy();
if file_name.ends_with(".json") {
FormatType::Json
} else if file_name.ends_with(".yaml") || file_name.ends_with(".yml") {
FormatType::Yaml
} else if file_name.ends_with(".toml") {
FormatType::Toml
} else if file_name.ends_with(".xml") {
FormatType::Xml
} else if file_name.ends_with(".ini") {
FormatType::Ini
} else if file_name.ends_with(".properties") {
FormatType::Properties
} else {
FormatType::Env
let ext = path.extension().and_then(|s| s.to_str()).unwrap_or_default();
match ext {
"json" => FormatType::Json,
"yaml" | "yml" => FormatType::Yaml,
"toml" => FormatType::Toml,
"xml" => FormatType::Xml,
"ini" => FormatType::Ini,
"properties" => FormatType::Properties,
_ => FormatType::Env,
}
}

View File

@@ -23,15 +23,15 @@ impl FormatHandler for PropertiesHandler {
let parts: Vec<&str> = path.split('.').collect();
let mut current_path = String::new();
for i in 0..parts.len().saturating_sub(1) {
for (i, part) in parts.iter().enumerate().take(parts.len().saturating_sub(1)) {
if !current_path.is_empty() {
current_path.push('.');
}
current_path.push_str(parts[i]);
current_path.push_str(part);
if groups.insert(current_path.clone()) {
vars.push(ConfigItem {
key: parts[i].to_string(),
key: part.to_string(),
path: current_path.clone(),
value: None,
template_value: None,
@@ -73,11 +73,11 @@ impl FormatHandler for PropertiesHandler {
.or(var.template_value.as_deref())
.unwrap_or("");
prop_writer.write(&var.path, val)
.map_err(|e| io::Error::other(e))?;
.map_err(io::Error::other)?;
}
}
prop_writer.finish().map_err(|e| io::Error::other(e))
prop_writer.finish().map_err(io::Error::other)
}
}