fix(style): remove printlns and appease cargo fmt

master
Ashley Williams 7 years ago
parent e607eda95c
commit 354f038a1a
  1. 21
      src/manifest/mod.rs
  2. 12
      tests/all/manifest.rs
  3. 3
      tests/all/utils/manifest.rs

@ -129,7 +129,11 @@ impl CargoManifest {
None => {} None => {}
} }
check_optional_fields(&self.package.description, &self.package.repository, &self.package.license); check_optional_fields(
&self.package.description,
&self.package.repository,
&self.package.license,
);
NpmPackage::CommonJSPackage(CommonJSPackage { NpmPackage::CommonJSPackage(CommonJSPackage {
name: self.package.name, name: self.package.name,
@ -170,7 +174,11 @@ impl CargoManifest {
None => {} None => {}
} }
check_optional_fields(&self.package.description, &self.package.repository, &self.package.license); check_optional_fields(
&self.package.description,
&self.package.repository,
&self.package.license,
);
NpmPackage::ESModulesPackage(ESModulesPackage { NpmPackage::ESModulesPackage(ESModulesPackage {
name: self.package.name, name: self.package.name,
@ -201,7 +209,6 @@ pub fn write_package_json(
) -> Result<(), Error> { ) -> Result<(), Error> {
let msg = format!("{}Writing a package.json...", emoji::MEMO); let msg = format!("{}Writing a package.json...", emoji::MEMO);
PBAR.step(step, &msg); PBAR.step(step, &msg);
let pkg_file_path = out_dir.join("package.json"); let pkg_file_path = out_dir.join("package.json");
let mut pkg_file = File::create(pkg_file_path)?; let mut pkg_file = File::create(pkg_file_path)?;
@ -212,14 +219,17 @@ pub fn write_package_json(
crate_data.into_esmodules(scope, disable_dts) crate_data.into_esmodules(scope, disable_dts)
}; };
let npm_json = serde_json::to_string_pretty(&npm_data)?; let npm_json = serde_json::to_string_pretty(&npm_data)?;
pkg_file.write_all(npm_json.as_bytes())?; pkg_file.write_all(npm_json.as_bytes())?;
Ok(()) Ok(())
} }
/// Check the data for missing fields and warn /// Check the data for missing fields and warn
pub fn check_optional_fields(description: &Option<String>, repository: &Option<String>, license: &Option<String>) { pub fn check_optional_fields(
description: &Option<String>,
repository: &Option<String>,
license: &Option<String>,
) {
let warn_fmt = |field| { let warn_fmt = |field| {
format!( format!(
"Field '{}' is missing from Cargo.toml. It is not necessary, but recommended", "Field '{}' is missing from Cargo.toml. It is not necessary, but recommended",
@ -236,7 +246,6 @@ pub fn check_optional_fields(description: &Option<String>, repository: &Option<S
if license.is_none() { if license.is_none() {
PBAR.warn(&warn_fmt("license")); PBAR.warn(&warn_fmt("license"));
} }
} }
/// Get the crate name for the crate at the given path. /// Get the crate name for the crate at the given path.

@ -94,7 +94,11 @@ fn it_creates_a_package_json_provided_path() {
assert_eq!(pkg.module, "js_hello_world.js"); assert_eq!(pkg.module, "js_hello_world.js");
let actual_files: HashSet<String> = pkg.files.into_iter().collect(); let actual_files: HashSet<String> = pkg.files.into_iter().collect();
let expected_files: HashSet<String> = ["js_hello_world_bg.wasm", "js_hello_world.d.ts", "js_hello_world.js"] let expected_files: HashSet<String> = [
"js_hello_world_bg.wasm",
"js_hello_world.d.ts",
"js_hello_world.js",
]
.iter() .iter()
.map(|&s| String::from(s)) .map(|&s| String::from(s))
.collect(); .collect();
@ -125,7 +129,11 @@ fn it_creates_a_package_json_provided_path_with_scope() {
assert_eq!(pkg.module, "scopes_hello_world.js"); assert_eq!(pkg.module, "scopes_hello_world.js");
let actual_files: HashSet<String> = pkg.files.into_iter().collect(); let actual_files: HashSet<String> = pkg.files.into_iter().collect();
let expected_files: HashSet<String> = ["scopes_hello_world_bg.wasm", "scopes_hello_world.d.ts", "scopes_hello_world.js"] let expected_files: HashSet<String> = [
"scopes_hello_world_bg.wasm",
"scopes_hello_world.d.ts",
"scopes_hello_world.js",
]
.iter() .iter()
.map(|&s| String::from(s)) .map(|&s| String::from(s))
.collect(); .collect();

@ -22,7 +22,7 @@ pub struct NpmPackage {
} }
fn default_none() -> String { fn default_none() -> String {
"".to_string() "".to_string()
} }
#[derive(Deserialize)] #[derive(Deserialize)]
@ -38,6 +38,5 @@ pub fn read_package_json(path: &Path, out_dir: &Path) -> Result<NpmPackage, Erro
let mut pkg_contents = String::new(); let mut pkg_contents = String::new();
pkg_file.read_to_string(&mut pkg_contents)?; pkg_file.read_to_string(&mut pkg_contents)?;
println!("pkg_file: {}", pkg_contents);
Ok(serde_json::from_str(&pkg_contents)?) Ok(serde_json::from_str(&pkg_contents)?)
} }

Loading…
Cancel
Save