style: simplify string formatting (#10259)

* style: simplfiy string formatting

* fix: file formatting in `core/`
This commit is contained in:
Hamir Mahal 2024-07-12 03:33:14 -07:00 committed by GitHub
parent 2b1ceb40d3
commit 1a88fc1a9b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 20 additions and 34 deletions

View File

@ -156,7 +156,7 @@ fn copy_dir(from: &Path, to: &Path) -> Result<()> {
// Copies the framework under `{src_dir}/{framework}.framework` to `{dest_dir}/{framework}.framework`.
fn copy_framework_from(src_dir: &Path, framework: &str, dest_dir: &Path) -> Result<bool> {
let src_name = format!("{}.framework", framework);
let src_name = format!("{framework}.framework");
let src_path = src_dir.join(&src_name);
if src_path.exists() {
copy_dir(&src_path, &dest_dir.join(&src_name))?;
@ -168,12 +168,8 @@ fn copy_framework_from(src_dir: &Path, framework: &str, dest_dir: &Path) -> Resu
// Copies the macOS application bundle frameworks to the target folder
fn copy_frameworks(dest_dir: &Path, frameworks: &[String]) -> Result<()> {
std::fs::create_dir_all(dest_dir).with_context(|| {
format!(
"Failed to create frameworks output directory at {:?}",
dest_dir
)
})?;
std::fs::create_dir_all(dest_dir)
.with_context(|| format!("Failed to create frameworks output directory at {dest_dir:?}"))?;
for framework in frameworks.iter() {
if framework.ends_with(".framework") {
let src_path = PathBuf::from(framework);
@ -469,7 +465,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
let mut android_package_prefix = String::new();
for (i, w) in s.enumerate() {
if i == last {
println!("cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_APP_NAME={}", w);
println!("cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_APP_NAME={w}");
} else {
android_package_prefix.push_str(w);
android_package_prefix.push('_');

View File

@ -55,9 +55,9 @@ dependencies {"
app_build_gradle.push_str("\n}");
if let Some(version) = config.version.as_ref() {
app_tauri_properties.push(format!("tauri.android.versionName={}", version));
app_tauri_properties.push(format!("tauri.android.versionName={version}"));
if let Some(version_code) = config.bundle.android.version_code.as_ref() {
app_tauri_properties.push(format!("tauri.android.versionCode={}", version_code));
app_tauri_properties.push(format!("tauri.android.versionCode={version_code}"));
} else if let Ok(version) = Version::parse(version) {
let mut version_code = version.major * 1000000 + version.minor * 1000 + version.patch;
@ -76,7 +76,7 @@ dependencies {"
));
}
app_tauri_properties.push(format!("tauri.android.versionCode={}", version_code));
app_tauri_properties.push(format!("tauri.android.versionCode={version_code}"));
}
}

View File

@ -183,8 +183,7 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult<TokenStream> {
let assets_path = config_parent.join(path);
if !assets_path.exists() {
panic!(
"The `frontendDist` configuration is set to `{:?}` but this path doesn't exist",
path
"The `frontendDist` configuration is set to `{path:?}` but this path doesn't exist"
)
}
EmbeddedAssets::new(assets_path, &options, map_core_assets(&options))?

View File

@ -435,8 +435,6 @@ identifier = "deny-{slugified_command}"
description = "Denies the {command} command without any pre-configured scope."
commands.deny = ["{command}"]
"###,
command = command,
slugified_command = slugified_command,
);
let out_path = path.join(format!("{command}.toml"));

View File

@ -229,7 +229,7 @@ fn main() {
alias("custom_protocol", custom_protocol);
alias("dev", dev);
println!("cargo:dev={}", dev);
println!("cargo:dev={dev}");
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let mobile = target_os == "ios" || target_os == "android";
@ -257,10 +257,7 @@ fn main() {
if let Ok(kotlin_out_dir) = std::env::var("WRY_ANDROID_KOTLIN_FILES_OUT_DIR") {
fn env_var(var: &str) -> String {
std::env::var(var).unwrap_or_else(|_| {
panic!(
"`{}` is not set, which is needed to generate the kotlin files for android.",
var
)
panic!("`{var}` is not set, which is needed to generate the kotlin files for android.")
})
}
@ -346,7 +343,7 @@ fn define_permissions(out_dir: &Path) {
.filter(|(_cmd, default)| *default)
.map(|(cmd, _)| {
let slugified_command = cmd.replace('_', "-");
format!("\"allow-{}\"", slugified_command)
format!("\"allow-{slugified_command}\"")
})
.collect::<Vec<_>>()
.join(", ");

View File

@ -175,22 +175,20 @@ pub fn listen_js_script(
) -> String {
format!(
"(function () {{
if (window['{listeners}'] === void 0) {{
Object.defineProperty(window, '{listeners}', {{ value: Object.create(null) }});
if (window['{listeners_object_name}'] === void 0) {{
Object.defineProperty(window, '{listeners_object_name}', {{ value: Object.create(null) }});
}}
if (window['{listeners}']['{event}'] === void 0) {{
Object.defineProperty(window['{listeners}'], '{event}', {{ value: Object.create(null) }});
if (window['{listeners_object_name}']['{event}'] === void 0) {{
Object.defineProperty(window['{listeners_object_name}'], '{event}', {{ value: Object.create(null) }});
}}
const eventListeners = window['{listeners}']['{event}']
const eventListeners = window['{listeners_object_name}']['{event}']
const listener = {{
target: {target},
target: {serialized_target},
handler: {handler}
}};
Object.defineProperty(eventListeners, '{event_id}', {{ value: listener, configurable: true }});
}})()
",
listeners = listeners_object_name,
target = serialized_target,
)
}

View File

@ -759,9 +759,7 @@ mod test {
assert_eq!(
received.len(),
expected.len(),
"received {:?} `{kind}` events but expected {:?}",
received,
expected
"received {received:?} `{kind}` events but expected {expected:?}"
);
}

View File

@ -314,7 +314,7 @@ mod tests {
});
app.run(|_app, event| {
println!("{:?}", event);
println!("{event:?}");
});
}
}

View File

@ -219,7 +219,7 @@ fn borrow_cmd_async(the_argument: &str) -> &str {
#[command]
fn raw_request(request: Request<'_>) -> Response {
println!("{:?}", request);
println!("{request:?}");
Response::new(include_bytes!("./README.md").to_vec())
}