From d477ed78185e7f6ba38f3ef040168b19e48d1800 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Fri, 2 Oct 2020 06:35:43 -0700 Subject: [PATCH] Address lints Summary: Just going through all the lints that have popped up. Reviewed By: jknoxville Differential Revision: D24078571 fbshipit-source-id: 06504aafa969eea92ee934ac607d3daf51e47914 --- packer/Cargo.toml | 5 +++++ packer/src/error.rs | 4 ++-- packer/src/main.rs | 34 ++++++++++++++++++---------------- packer/src/types.rs | 5 ++--- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/packer/Cargo.toml b/packer/Cargo.toml index 7fcd7e3a5..3f98f715e 100644 --- a/packer/Cargo.toml +++ b/packer/Cargo.toml @@ -1,5 +1,10 @@ [package] name = "flipper-packer" +description = "Helper tool that breaks down a Flipper release into smaller artifacts." +license = "MIT" +repository = "https://github.com/facebook/flipper.git" +keywords = ["flipper", "cli"] +categories = ["development-tools"] version = "0.1.0" authors = ["Facebook, Inc."] edition = "2018" diff --git a/packer/src/error.rs b/packer/src/error.rs index c9b911075..d61680239 100644 --- a/packer/src/error.rs +++ b/packer/src/error.rs @@ -20,14 +20,14 @@ impl std::error::Error for Error {} impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Error::MissingPackFile(platform, pack_type, path) => write!( + Self::MissingPackFile(platform, pack_type, path) => write!( f, "Couldn't open file to pack for platform {:?} and type {:?}: {}", platform, pack_type, path.to_string_lossy() ), - Error::MissingPlatformDefinition(platform) => write!( + Self::MissingPlatformDefinition(platform) => write!( f, "Platform {} is not defined in the given packlist.", platform diff --git a/packer/src/main.rs b/packer/src/main.rs index 0cc9d70e8..7598d11df 100644 --- a/packer/src/main.rs +++ b/packer/src/main.rs @@ -6,6 +6,8 @@ */ #![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)] +// This doesn't seem to cause any issues and nobody I know can read \u{1234} by heart. +#![allow(clippy::non_ascii_literal)] mod error; mod tarsum; @@ -53,7 +55,7 @@ fn default_progress_bar(len: u64) -> indicatif::ProgressBar { } fn pack( - platform: &Platform, + platform: Platform, dist_dir: &std::path::PathBuf, pack_list: &PackList, output_directory: &std::path::PathBuf, @@ -66,11 +68,11 @@ fn pack( )); let packtype_paths = pack_list .0 - .get(platform) - .ok_or_else(|| error::Error::MissingPlatformDefinition(*platform))?; + .get(&platform) + .ok_or_else(|| error::Error::MissingPlatformDefinition(platform))?; let res = packtype_paths .into_par_iter() - .map(|(pack_type, pack_files)| { + .map(|(&pack_type, pack_files)| { let output_path = path::Path::new(output_directory).join(format!("{}.tar", pack_type)); let mut tar = tar::Builder::new(File::create(&output_path).with_context(|| { format!( @@ -86,7 +88,7 @@ fn pack( tar.finish()?; pb.inc(1); - Ok((*pack_type, output_path)) + Ok((pack_type, output_path)) }) .collect(); @@ -95,10 +97,10 @@ fn pack( } fn pack_platform( - platform: &Platform, + platform: Platform, dist_dir: &std::path::PathBuf, pack_files: &[path::PathBuf], - pack_type: &PackType, + pack_type: PackType, tar_builder: &mut tar::Builder, ) -> Result<()> { let base_dir = match platform { @@ -112,7 +114,7 @@ fn pack_platform( let full_path = path::Path::new(&base_dir).join(f); if !full_path.exists() { bail!(error::Error::MissingPackFile( - *platform, *pack_type, full_path, + platform, pack_type, full_path, )); } if full_path.is_file() { @@ -169,13 +171,13 @@ fn main() -> Result<(), anyhow::Error> { shellexpand::tilde(args.value_of("dist").expect("argument has default")).to_string(), ); let compress = !args.is_present("no-compression"); - let pack_list_str = args - .value_of("packlist") - .map(|f| { + let pack_list_str = args.value_of("packlist").map_or_else( + || DEFAULT_PACKLIST.to_string(), + |f| { std::fs::read_to_string(f) .unwrap_or_else(|e| panic!("Failed to open packfile {}: {}", f, e)) - }) - .unwrap_or_else(|| DEFAULT_PACKLIST.to_string()); + }, + ); let pack_list: PackList = serde_yaml::from_str(&pack_list_str).expect("Failed to deserialize YAML packlist."); let output_directory = @@ -186,13 +188,13 @@ fn main() -> Result<(), anyhow::Error> { output_directory.to_string_lossy() ) })?; - let archive_paths = pack(&platform, &dist_dir, &pack_list, output_directory)?; + let archive_paths = pack(platform, &dist_dir, &pack_list, output_directory)?; let compressed_archive_paths = if compress { Some(compress_paths(&archive_paths)?) } else { None }; - manifest(&archive_paths, &compressed_archive_paths, &output_directory)?; + manifest(&archive_paths, &compressed_archive_paths, output_directory)?; Ok(()) } @@ -252,7 +254,7 @@ fn write_manifest( let path = path::PathBuf::from(output_directory).join("manifest.json"); let mut file = File::create(&path) .with_context(|| format!("Failed to write manifest to {}", &path.to_string_lossy()))?; - file.write_all(&serde_json::to_string_pretty(archive_manifest)?.as_bytes())?; + file.write_all(serde_json::to_string_pretty(archive_manifest)?.as_bytes())?; Ok(path) } diff --git a/packer/src/types.rs b/packer/src/types.rs index c86f6c054..c20c3d632 100644 --- a/packer/src/types.rs +++ b/packer/src/types.rs @@ -37,10 +37,9 @@ pub enum PackType { impl Display for PackType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - use PackType::*; match *self { - Frameworks => write!(f, "frameworks"), - Core => write!(f, "core"), + Self::Frameworks => write!(f, "frameworks"), + Self::Core => write!(f, "core"), } } }