Refactor: fix clippy warnings

master
Mason Stallmo 6 years ago
parent c8410f2de7
commit d84aae3b64
  1. 1
      clippy.toml
  2. 13
      src/child.rs
  3. 2
      src/command/build.rs
  4. 8
      src/command/login.rs
  5. 9
      src/command/mod.rs
  6. 2
      src/command/publish/mod.rs
  7. 2
      src/command/utils.rs
  8. 2
      src/installer.rs
  9. 2
      src/lockfile.rs
  10. 14
      src/manifest/mod.rs
  11. 4
      src/npm.rs
  12. 8
      src/progressbar.rs
  13. 4
      src/readme.rs

@ -0,0 +1 @@
too-many-arguments-threshold = 8

@ -41,7 +41,7 @@ pub fn new_command(program: &str) -> Command {
/// given sender. /// given sender.
fn read_and_send<R, F>( fn read_and_send<R, F>(
mut reader: R, mut reader: R,
sender: mpsc::Sender<OutputFragment>, sender: &mpsc::Sender<OutputFragment>,
mut map: F, mut map: F,
) -> io::Result<()> ) -> io::Result<()>
where where
@ -104,10 +104,7 @@ where
.rev() .rev()
.find(|(_, ch)| *ch == b'\n') .find(|(_, ch)| *ch == b'\n')
{ {
let next_in_progress: Vec<u8> = self.in_progress[last_newline + 1..] let next_in_progress: Vec<u8> = self.in_progress[last_newline + 1..].to_vec();
.iter()
.cloned()
.collect();
let mut these_lines = mem::replace(&mut self.in_progress, next_in_progress); let mut these_lines = mem::replace(&mut self.in_progress, next_in_progress);
these_lines.truncate(last_newline + 1); these_lines.truncate(last_newline + 1);
let these_lines = String::from_utf8(these_lines)?; let these_lines = String::from_utf8(these_lines)?;
@ -153,9 +150,9 @@ pub fn run(mut command: Command, command_name: &str) -> Result<String, Error> {
// waiting on the child process. // waiting on the child process.
let stdout_handle = let stdout_handle =
thread::spawn(move || read_and_send(stdout, stdout_send, OutputFragment::Stdout)); thread::spawn(move || read_and_send(stdout, &stdout_send, OutputFragment::Stdout));
let stderr_handle = let stderr_handle =
thread::spawn(move || read_and_send(stderr, stderr_send, OutputFragment::Stderr)); thread::spawn(move || read_and_send(stderr, &stderr_send, OutputFragment::Stderr));
let mut stdout = OutputAccumulator::new(|line| { let mut stdout = OutputAccumulator::new(|line| {
info!("{} (stdout): {}", command_name, line); info!("{} (stdout): {}", command_name, line);
@ -182,7 +179,7 @@ pub fn run(mut command: Command, command_name: &str) -> Result<String, Error> {
let exit = child.wait()?; let exit = child.wait()?;
if exit.success() { if exit.success() {
return Ok(stdout); Ok(stdout)
} else { } else {
drop((stdout, stderr)); drop((stdout, stderr));
bail!("failed to execute `{}`: exited with {}", command_name, exit) bail!("failed to execute `{}`: exited with {}", command_name, exit)

@ -220,7 +220,7 @@ impl Build {
Ok(()) Ok(())
} }
fn get_process_steps(mode: &BuildMode) -> Vec<(&'static str, BuildStep)> { fn get_process_steps(mode: BuildMode) -> Vec<(&'static str, BuildStep)> {
macro_rules! steps { macro_rules! steps {
($($name:ident),+) => { ($($name:ident),+) => {
{ {

@ -5,11 +5,11 @@ use PBAR;
pub fn login( pub fn login(
registry: Option<String>, registry: Option<String>,
scope: Option<String>, scope: &Option<String>,
always_auth: bool, always_auth: bool,
auth_type: Option<String>, auth_type: &Option<String>,
) -> result::Result<(), failure::Error> { ) -> result::Result<(), failure::Error> {
let registry = registry.unwrap_or(npm::DEFAULT_NPM_REGISTRY.to_string()); let registry = registry.unwrap_or_else(|| npm::DEFAULT_NPM_REGISTRY.to_string());
info!("Logging in to npm..."); info!("Logging in to npm...");
info!( info!(
@ -20,6 +20,6 @@ pub fn login(
npm::npm_login(&registry, &scope, always_auth, &auth_type)?; npm::npm_login(&registry, &scope, always_auth, &auth_type)?;
info!("Logged you in!"); info!("Logged you in!");
PBAR.message(&format!("👋 logged you in!")); PBAR.message(&"👋 logged you in!".to_string());
Ok(()) Ok(())
} }

@ -90,7 +90,7 @@ pub enum Command {
pub fn run_wasm_pack(command: Command) -> result::Result<(), Error> { pub fn run_wasm_pack(command: Command) -> result::Result<(), Error> {
// Run the correct command based off input and store the result of it so that we can clear // Run the correct command based off input and store the result of it so that we can clear
// the progress bar then return it // the progress bar then return it
let status = match command { match command {
Command::Build(build_opts) => { Command::Build(build_opts) => {
info!("Running build command..."); info!("Running build command...");
Build::try_from_opts(build_opts).and_then(|mut b| b.run()) Build::try_from_opts(build_opts).and_then(|mut b| b.run())
@ -120,14 +120,11 @@ pub fn run_wasm_pack(command: Command) -> result::Result<(), Error> {
"Registry: {:?}, Scope: {:?}, Always Auth: {}, Auth Type: {:?}", "Registry: {:?}, Scope: {:?}, Always Auth: {}, Auth Type: {:?}",
&registry, &scope, &always_auth, &auth_type &registry, &scope, &always_auth, &auth_type
); );
login(registry, scope, always_auth, auth_type) login(registry, &scope, always_auth, &auth_type)
} }
Command::Test(test_opts) => { Command::Test(test_opts) => {
info!("Running test command..."); info!("Running test command...");
Test::try_from_opts(test_opts).and_then(|t| t.run()) Test::try_from_opts(test_opts).and_then(|t| t.run())
} }
}; }
// Return the actual status of the program to the main function
status
} }

@ -15,7 +15,7 @@ use PBAR;
/// Creates a tarball from a 'pkg' directory /// Creates a tarball from a 'pkg' directory
/// and publishes it to the NPM registry /// and publishes it to the NPM registry
pub fn publish( pub fn publish(
_target: String, _target: &str,
path: Option<PathBuf>, path: Option<PathBuf>,
access: Option<Access>, access: Option<Access>,
) -> result::Result<(), Error> { ) -> result::Result<(), Error> {

@ -11,7 +11,7 @@ use PBAR;
/// If an explicit path is given, then use it, otherwise assume the current /// If an explicit path is given, then use it, otherwise assume the current
/// directory is the crate path. /// directory is the crate path.
pub fn set_crate_path(path: Option<PathBuf>) -> Result<PathBuf, failure::Error> { pub fn set_crate_path(path: Option<PathBuf>) -> Result<PathBuf, failure::Error> {
Ok(path.unwrap_or(PathBuf::from("."))) Ok(path.unwrap_or_else(|| PathBuf::from(".")))
} }
/// Construct our `pkg` directory in the crate. /// Construct our `pkg` directory in the crate.

@ -114,7 +114,7 @@ fn confirm_can_overwrite(dst: &Path) -> Result<(), failure::Error> {
.read_line(&mut line) .read_line(&mut line)
.with_context(|_| "failed to read stdin")?; .with_context(|_| "failed to read stdin")?;
if line.starts_with("y") || line.starts_with("Y") { if line.starts_with('y') || line.starts_with('Y') {
return Ok(()); return Ok(());
} }

@ -1,5 +1,7 @@
//! Reading Cargo.lock lock file. //! Reading Cargo.lock lock file.
#![allow(clippy::new_ret_no_self)]
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::PathBuf;

@ -1,5 +1,7 @@
//! Reading and writing Cargo.toml and package.json manifests. //! Reading and writing Cargo.toml and package.json manifests.
#![allow(clippy::new_ret_no_self, clippy::needless_pass_by_value)]
mod npm; mod npm;
use std::fs; use std::fs;
@ -20,7 +22,7 @@ use strsim::levenshtein;
use toml; use toml;
use PBAR; use PBAR;
const WASM_PACK_METADATA_KEY: &'static str = "package.metadata.wasm-pack"; const WASM_PACK_METADATA_KEY: &str = "package.metadata.wasm-pack";
/// Store for metadata learned about a crate /// Store for metadata learned about a crate
pub struct CrateData { pub struct CrateData {
@ -145,7 +147,7 @@ impl CargoWasmPackProfile {
D: serde::Deserializer<'de>, D: serde::Deserializer<'de>,
{ {
let mut profile = <Option<Self>>::deserialize(deserializer)?.unwrap_or_default(); let mut profile = <Option<Self>>::deserialize(deserializer)?.unwrap_or_default();
profile.update_with_defaults(Self::default_dev()); profile.update_with_defaults(&Self::default_dev());
Ok(profile) Ok(profile)
} }
@ -154,7 +156,7 @@ impl CargoWasmPackProfile {
D: serde::Deserializer<'de>, D: serde::Deserializer<'de>,
{ {
let mut profile = <Option<Self>>::deserialize(deserializer)?.unwrap_or_default(); let mut profile = <Option<Self>>::deserialize(deserializer)?.unwrap_or_default();
profile.update_with_defaults(Self::default_release()); profile.update_with_defaults(&Self::default_release());
Ok(profile) Ok(profile)
} }
@ -163,11 +165,11 @@ impl CargoWasmPackProfile {
D: serde::Deserializer<'de>, D: serde::Deserializer<'de>,
{ {
let mut profile = <Option<Self>>::deserialize(deserializer)?.unwrap_or_default(); let mut profile = <Option<Self>>::deserialize(deserializer)?.unwrap_or_default();
profile.update_with_defaults(Self::default_profiling()); profile.update_with_defaults(&Self::default_profiling());
Ok(profile) Ok(profile)
} }
fn update_with_defaults(&mut self, defaults: Self) { fn update_with_defaults(&mut self, defaults: &Self) {
macro_rules! d { macro_rules! d {
( $( $path:ident ).* ) => { ( $( $path:ident ).* ) => {
self. $( $path ).* .get_or_insert(defaults. $( $path ).* .unwrap()); self. $( $path ).* .get_or_insert(defaults. $( $path ).* .unwrap());
@ -248,7 +250,7 @@ impl CrateData {
for e in errors[..errors.len() - 1].iter().rev() { for e in errors[..errors.len() - 1].iter().rev() {
err = err.context(e.to_string()).into(); err = err.context(e.to_string()).into();
} }
return err; err
} }
} }

@ -6,7 +6,7 @@ use failure::{self, ResultExt};
use log::info; use log::info;
/// The default npm registry used when we aren't working with a custom registry. /// The default npm registry used when we aren't working with a custom registry.
pub const DEFAULT_NPM_REGISTRY: &'static str = "https://registry.npmjs.org/"; pub const DEFAULT_NPM_REGISTRY: &str = "https://registry.npmjs.org/";
/// Run the `npm pack` command. /// Run the `npm pack` command.
pub fn npm_pack(path: &str) -> Result<(), failure::Error> { pub fn npm_pack(path: &str) -> Result<(), failure::Error> {
@ -33,7 +33,7 @@ pub fn npm_publish(path: &str, access: Option<Access>) -> Result<(), failure::Er
/// Run the `npm login` command. /// Run the `npm login` command.
pub fn npm_login( pub fn npm_login(
registry: &String, registry: &str,
scope: &Option<String>, scope: &Option<String>,
always_auth: bool, always_auth: bool,
auth_type: &Option<String>, auth_type: &Option<String>,

@ -75,7 +75,7 @@ impl ProgressOutput {
} }
/// Add an error message. /// Add an error message.
pub fn error(&self, message: String) { pub fn error(&self, message: &str) {
let err = format!( let err = format!(
"{} {}: {}", "{} {}: {}",
emoji::ERROR, emoji::ERROR,
@ -135,3 +135,9 @@ impl Drop for ProgressOutput {
self.done(); self.done();
} }
} }
impl Default for ProgressOutput {
fn default() -> Self {
Self::new()
}
}

@ -23,8 +23,8 @@ pub fn copy_from_crate(path: &Path, out_dir: &Path, step: &Step) -> Result<(), f
PBAR.step(step, &msg); PBAR.step(step, &msg);
let crate_readme_path = path.join("README.md"); let crate_readme_path = path.join("README.md");
let new_readme_path = out_dir.join("README.md"); let new_readme_path = out_dir.join("README.md");
if let Err(_) = fs::copy(&crate_readme_path, &new_readme_path) { if fs::copy(&crate_readme_path, &new_readme_path).is_err() {
PBAR.warn("origin crate has no README"); PBAR.warn("origin crate has no README");
}; }
Ok(()) Ok(())
} }

Loading…
Cancel
Save