Skip to content

Commit

Permalink
chore: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Dec 15, 2022
1 parent a02c6c4 commit 0150207
Show file tree
Hide file tree
Showing 54 changed files with 163 additions and 182 deletions.
2 changes: 1 addition & 1 deletion core/config-schema/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
crate_dir.join("../../tooling/cli/schema.json"),
] {
let mut schema_file = BufWriter::new(File::create(&file)?);
write!(schema_file, "{}", schema_str)?;
write!(schema_file, "{schema_str}")?;
}

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions core/tauri-build/src/codegen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl CodegenContext {
pub fn build(self) -> PathBuf {
match self.try_build() {
Ok(out) => out,
Err(error) => panic!("Error found during Codegen::build: {}", error),
Err(error) => panic!("Error found during Codegen::build: {error}"),
}
}

Expand Down Expand Up @@ -161,7 +161,7 @@ impl CodegenContext {
)
})?;

writeln!(file, "{}", code).with_context(|| {
writeln!(file, "{code}").with_context(|| {
format!(
"Unable to write tokenstream to out file during tauri-build {}",
out.display()
Expand Down
12 changes: 6 additions & 6 deletions core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ fn copy_file(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()> {
Ok(())
}

fn copy_binaries<'a>(
binaries: ResourcePaths<'a>,
fn copy_binaries(
binaries: ResourcePaths,
target_triple: &str,
path: &Path,
package_name: Option<&String>,
Expand All @@ -48,7 +48,7 @@ fn copy_binaries<'a>(
.file_name()
.expect("failed to extract external binary filename")
.to_string_lossy()
.replace(&format!("-{}", target_triple), "");
.replace(&format!("-{target_triple}"), "");

if package_name.map_or(false, |n| n == &file_name) {
return Err(anyhow::anyhow!(
Expand Down Expand Up @@ -90,7 +90,7 @@ fn has_feature(feature: &str) -> bool {
// `alias` must be a snake case string.
fn cfg_alias(alias: &str, has_feature: bool) {
if has_feature {
println!("cargo:rustc-cfg={}", alias);
println!("cargo:rustc-cfg={alias}");
}
}

Expand Down Expand Up @@ -227,8 +227,8 @@ impl Attributes {
/// This is typically desirable when running inside a build script; see [`try_build`] for no panics.
pub fn build() {
if let Err(error) = try_build(Attributes::default()) {
let error = format!("{:#}", error);
println!("{}", error);
let error = format!("{error:#}");
println!("{error}");
if error.starts_with("unknown field") {
print!("found an unknown configuration field. This usually means that you are using a CLI version that is newer than `tauri-build` and is incompatible. ");
println!(
Expand Down
5 changes: 2 additions & 3 deletions core/tauri-codegen/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
} else if target.contains("apple-ios") {
Target::Ios
} else {
panic!("unknown codegen target {}", target);
panic!("unknown codegen target {target}");
}
} else if cfg!(target_os = "linux") {
Target::Linux
Expand Down Expand Up @@ -371,8 +371,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
let dir = config_parent.join(dir);
if !dir.exists() {
panic!(
"The isolation application path is set to `{:?}` but it does not exist",
dir
"The isolation application path is set to `{dir:?}` but it does not exist"
)
}

Expand Down
4 changes: 2 additions & 2 deletions core/tauri-codegen/src/embedded_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,14 @@ impl EmbeddedAssets {

let mut hex = String::with_capacity(2 * bytes.len());
for b in bytes {
write!(hex, "{:02x}", b).map_err(EmbeddedAssetsError::Hex)?;
write!(hex, "{b:02x}").map_err(EmbeddedAssetsError::Hex)?;
}
hex
};

// use the content hash to determine filename, keep extensions that exist
let out_path = if let Some(ext) = path.extension().and_then(|e| e.to_str()) {
out_dir.join(format!("{}.{}", hash, ext))
out_dir.join(format!("{hash}.{ext}"))
} else {
out_dir.join(hash)
};
Expand Down
2 changes: 1 addition & 1 deletion core/tauri-runtime-wry/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// `alias` must be a snake case string.
fn alias(alias: &str, has_feature: bool) {
if has_feature {
println!("cargo:rustc-cfg={}", alias);
println!("cargo:rustc-cfg={alias}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/tauri-runtime/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// `alias` must be a snake case string.
fn alias(alias: &str, has_feature: bool) {
if has_feature {
println!("cargo:rustc-cfg={}", alias);
println!("cargo:rustc-cfg={alias}");
}
}

Expand Down
19 changes: 9 additions & 10 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub enum WindowUrl {
impl fmt::Display for WindowUrl {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::External(url) => write!(f, "{}", url),
Self::External(url) => write!(f, "{url}"),
Self::App(path) => write!(f, "{}", path.display()),
}
}
Expand Down Expand Up @@ -125,7 +125,7 @@ impl<'de> Deserialize<'de> for BundleType {
"app" => Ok(Self::App),
"dmg" => Ok(Self::Dmg),
"updater" => Ok(Self::Updater),
_ => Err(DeError::custom(format!("unknown bundle target '{}'", s))),
_ => Err(DeError::custom(format!("unknown bundle target '{s}'"))),
}
}
}
Expand Down Expand Up @@ -223,7 +223,7 @@ impl<'de> Deserialize<'de> for BundleTarget {

match BundleTargetInner::deserialize(deserializer)? {
BundleTargetInner::All(s) if s.to_lowercase() == "all" => Ok(Self::All),
BundleTargetInner::All(t) => Err(DeError::custom(format!("invalid bundle type {}", t))),
BundleTargetInner::All(t) => Err(DeError::custom(format!("invalid bundle type {t}"))),
BundleTargetInner::List(l) => Ok(Self::List(l)),
BundleTargetInner::One(t) => Ok(Self::One(t)),
}
Expand Down Expand Up @@ -994,7 +994,7 @@ impl CspDirectiveSources {
/// Whether the given source is configured on this directive or not.
pub fn contains(&self, source: &str) -> bool {
match self {
Self::Inline(s) => s.contains(&format!("{} ", source)) || s.contains(&format!(" {}", source)),
Self::Inline(s) => s.contains(&format!("{source} ")) || s.contains(&format!(" {source}")),
Self::List(l) => l.contains(&source.into()),
}
}
Expand Down Expand Up @@ -1060,7 +1060,7 @@ impl From<Csp> for HashMap<String, CspDirectiveSources> {
impl Display for Csp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Policy(s) => write!(f, "{}", s),
Self::Policy(s) => write!(f, "{s}"),
Self::DirectiveMap(m) => {
let len = m.len();
let mut i = 0;
Expand Down Expand Up @@ -2365,8 +2365,7 @@ impl<'de> Deserialize<'de> for WindowsUpdateInstallMode {
"quiet" => Ok(Self::Quiet),
"passive" => Ok(Self::Passive),
_ => Err(DeError::custom(format!(
"unknown update install mode '{}'",
s
"unknown update install mode '{s}'"
))),
}
}
Expand Down Expand Up @@ -2510,7 +2509,7 @@ pub enum AppUrl {
impl std::fmt::Display for AppUrl {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Url(url) => write!(f, "{}", url),
Self::Url(url) => write!(f, "{url}"),
Self::Files(files) => write!(f, "{}", serde_json::to_string(files).unwrap()),
}
}
Expand Down Expand Up @@ -2649,9 +2648,9 @@ impl<'d> serde::Deserialize<'d> for PackageVersion {
let path = PathBuf::from(value);
if path.exists() {
let json_str = read_to_string(&path)
.map_err(|e| DeError::custom(format!("failed to read version JSON file: {}", e)))?;
.map_err(|e| DeError::custom(format!("failed to read version JSON file: {e}")))?;
let package_json: serde_json::Value = serde_json::from_str(&json_str)
.map_err(|e| DeError::custom(format!("failed to read version JSON file: {}", e)))?;
.map_err(|e| DeError::custom(format!("failed to read version JSON file: {e}")))?;
if let Some(obj) = package_json.as_object() {
let version = obj
.get("version")
Expand Down
10 changes: 5 additions & 5 deletions core/tauri-utils/src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn serialize_node_ref_internal<S: Serializer>(
traversal_scope: TraversalScope,
) -> crate::Result<()> {
match (traversal_scope, node.data()) {
(ref scope, &NodeData::Element(ref element)) => {
(ref scope, NodeData::Element(element)) => {
if *scope == TraversalScope::IncludeNode {
let attrs = element.attributes.borrow();

Expand Down Expand Up @@ -82,16 +82,16 @@ fn serialize_node_ref_internal<S: Serializer>(

(TraversalScope::ChildrenOnly(_), _) => Ok(()),

(TraversalScope::IncludeNode, &NodeData::Doctype(ref doctype)) => {
(TraversalScope::IncludeNode, NodeData::Doctype(doctype)) => {
serializer.write_doctype(&doctype.name).map_err(Into::into)
}
(TraversalScope::IncludeNode, &NodeData::Text(ref text)) => {
(TraversalScope::IncludeNode, NodeData::Text(text)) => {
serializer.write_text(&text.borrow()).map_err(Into::into)
}
(TraversalScope::IncludeNode, &NodeData::Comment(ref text)) => {
(TraversalScope::IncludeNode, NodeData::Comment(text)) => {
serializer.write_comment(&text.borrow()).map_err(Into::into)
}
(TraversalScope::IncludeNode, &NodeData::ProcessingInstruction(ref contents)) => {
(TraversalScope::IncludeNode, NodeData::ProcessingInstruction(contents)) => {
let contents = contents.borrow();
serializer
.write_processing_instruction(&contents.0, &contents.1)
Expand Down
2 changes: 1 addition & 1 deletion core/tauri-utils/src/mime_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl std::fmt::Display for MimeType {
MimeType::Svg => "image/svg+xml",
MimeType::Mp4 => "video/mp4",
};
write!(f, "{}", mime)
write!(f, "{mime}")
}
}

Expand Down
8 changes: 4 additions & 4 deletions core/tauri-utils/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ pub fn target_triple() -> crate::Result<String> {
return Err(crate::Error::Environment);
};

format!("{}-{}", os, env)
format!("{os}-{env}")
};

Ok(format!("{}-{}", arch, os))
Ok(format!("{arch}-{os}"))
}

/// Computes the resource directory of the current environment.
Expand All @@ -157,8 +157,8 @@ pub fn resource_dir(package_info: &PackageInfo, env: &Env) -> crate::Result<Path
let exe_dir = exe.parent().expect("failed to get exe directory");
let curr_dir = exe_dir.display().to_string();

if curr_dir.ends_with(format!("{S}target{S}debug", S = MAIN_SEPARATOR).as_str())
|| curr_dir.ends_with(format!("{S}target{S}release", S = MAIN_SEPARATOR).as_str())
if curr_dir.ends_with(format!("{MAIN_SEPARATOR}target{MAIN_SEPARATOR}debug").as_str())
|| curr_dir.ends_with(format!("{MAIN_SEPARATOR}target{MAIN_SEPARATOR}release").as_str())
|| cfg!(target_os = "windows")
{
// running from the out dir or windows
Expand Down
10 changes: 5 additions & 5 deletions core/tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn has_feature(feature: &str) -> bool {
// `alias` must be a snake case string.
fn alias(alias: &str, has_feature: bool) {
if has_feature {
println!("cargo:rustc-cfg={}", alias);
println!("cargo:rustc-cfg={alias}");
}
}

Expand Down Expand Up @@ -137,8 +137,8 @@ fn main() {
let checked_features_out_path =
Path::new(&std::env::var("OUT_DIR").unwrap()).join("checked_features");
std::fs::write(
&checked_features_out_path,
&CHECKED_FEATURES.get().unwrap().lock().unwrap().join(","),
checked_features_out_path,
CHECKED_FEATURES.get().unwrap().lock().unwrap().join(","),
)
.expect("failed to write checked_features file");
}
Expand All @@ -153,14 +153,14 @@ fn main() {
//
// Note that both `module` and `apis` strings must be written in kebab case.
fn alias_module(module: &str, apis: &[&str], api_all: bool) {
let all_feature_name = format!("{}-all", module);
let all_feature_name = format!("{module}-all");
let all = has_feature(&all_feature_name) || api_all;
alias(&all_feature_name.to_snake_case(), all);

let mut any = all;

for api in apis {
let has = has_feature(&format!("{}-{}", module, api)) || all;
let has = has_feature(&format!("{module}-{api}")) || all;
alias(
&format!("{}_{}", AsSnakeCase(module), AsSnakeCase(api)),
has,
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/api/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ mod test {
fn check_test_dir() {
// create a callback closure that takes in a TempDir type and prints it.
let callback = |td: &tempfile::TempDir| {
println!("{:?}", td);
println!("{td:?}");
};

// execute the with_temp_dir function on the callback
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/api/file/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl<'a, R: std::fmt::Debug + Read + Seek> std::fmt::Debug for Extract<'a, R> {
impl<'a, R: Read + Seek> Extract<'a, R> {
/// Create archive from reader.
pub fn from_cursor(mut reader: R, archive_format: ArchiveFormat) -> Extract<'a, R> {
if reader.seek(io::SeekFrom::Start(0)).is_err() {
if reader.rewind().is_err() {
#[cfg(debug_assertions)]
eprintln!("Could not seek to start of the file");
}
Expand Down
5 changes: 2 additions & 3 deletions core/tauri/src/api/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl TryFrom<FilePart> for Vec<u8> {
type Error = crate::api::Error;
fn try_from(file: FilePart) -> crate::api::Result<Self> {
let bytes = match file {
FilePart::Path(path) => std::fs::read(&path)?,
FilePart::Path(path) => std::fs::read(path)?,
FilePart::Contents(bytes) => bytes,
};
Ok(bytes)
Expand Down Expand Up @@ -441,8 +441,7 @@ impl<'de> Deserialize<'de> for HeaderMap {
headers.insert(key, value);
} else {
return Err(serde::de::Error::custom(format!(
"invalid header `{}` `{}`",
key, value
"invalid header `{key}` `{value}`"
)));
}
}
Expand Down
8 changes: 4 additions & 4 deletions core/tauri/src/api/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,22 +242,22 @@ mod test {
}

let raw_str = "T".repeat(MIN_JSON_PARSE_LEN);
assert_eq!(serialize_js(&raw_str).unwrap(), format!("\"{}\"", raw_str));
assert_eq!(serialize_js(&raw_str).unwrap(), format!("\"{raw_str}\""));

assert_eq!(
serialize_js(&JsonObj {
value: raw_str.clone()
})
.unwrap(),
format!("JSON.parse('{{\"value\":\"{}\"}}')", raw_str)
format!("JSON.parse('{{\"value\":\"{raw_str}\"}}')")
);

assert_eq!(
serialize_js(&JsonObj {
value: format!("\"{}\"", raw_str)
value: format!("\"{raw_str}\"")
})
.unwrap(),
format!("JSON.parse('{{\"value\":\"\\\\\"{}\\\\\"\"}}')", raw_str)
format!("JSON.parse('{{\"value\":\"\\\\\"{raw_str}\\\\\"\"}}')")
);

let dangerous_json = RawValue::from_string(
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/api/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,5 @@ pub fn open<P: AsRef<str>>(
) -> crate::api::Result<()> {
scope
.open(path.as_ref(), with)
.map_err(|err| crate::api::Error::Shell(format!("failed to open: {}", err)))
.map_err(|err| crate::api::Error::Shell(format!("failed to open: {err}")))
}
3 changes: 1 addition & 2 deletions core/tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,8 +1290,7 @@ impl<R: Runtime> Builder<R> {
let type_name = std::any::type_name::<T>();
assert!(
self.state.set(state),
"state for type '{}' is already being managed",
type_name
"state for type '{type_name}' is already being managed"
);
self
}
Expand Down
3 changes: 1 addition & 2 deletions core/tauri/src/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ pub(crate) fn handle<R: Runtime>(
if let Some(unknown_variant_name) = s.next() {
if unknown_variant_name == module {
return resolver.reject(format!(
"The `{}` module is not enabled. You must enable one of its APIs in the allowlist.",
module
"The `{module}` module is not enabled. You must enable one of its APIs in the allowlist."
));
} else if module == "Window" {
return resolver.reject(window::into_allowlist_error(unknown_variant_name).to_string());
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/endpoints/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl Cmd {
serde_json::to_string(&p)
.map_err(|e| {
#[cfg(debug_assertions)]
eprintln!("{}", e);
eprintln!("{e}");
e
})
.ok()
Expand Down
Loading

0 comments on commit 0150207

Please sign in to comment.