From ad45dcd6dbf4c4eb3b40ae2f692804906e7a7af1 Mon Sep 17 00:00:00 2001 From: Marcel Schneider Date: Thu, 5 Mar 2020 11:34:13 +0100 Subject: [PATCH] fixing clippy warnings --- src/app.rs | 6 +++--- src/cache.rs | 1 + src/gitignore.rs | 1 + src/helpers.rs | 20 +------------------- src/main.rs | 15 ++++++++++----- src/template.rs | 8 +------- 6 files changed, 17 insertions(+), 34 deletions(-) diff --git a/src/app.rs b/src/app.rs index 9661b19..0728351 100644 --- a/src/app.rs +++ b/src/app.rs @@ -8,10 +8,10 @@ use std::path::PathBuf; use directories::ProjectDirs; use structopt::StructOpt; -use log::{debug, error, info, trace, warn}; +use log::{info, trace}; // Local Imports -use crate::cache::{Cache, File as FileCache}; +use crate::cache::File as FileCache; use crate::errors::*; use crate::gitignore::Gitignore; use crate::helpers::{git_dir, BoilerplateOpts, HELP_TEMPLATE}; @@ -94,6 +94,7 @@ fn run_add(glob: &str) -> Result<()> { /// Runs the command `get` fn run_get(lang: &str) -> Result<()> { + trace!("Run command `get` with lang {}", &lang); unimplemented!(); } @@ -136,7 +137,6 @@ pub fn main(opts: CliOpts) -> Result<()> { // Tests go below the code where they'll be out of the way when not the target of attention #[cfg(test)] mod tests { - use super::CliOpts; // TODO: Unit test to verify that the doc comment on `CliOpts` isn't overriding the intended // about string. diff --git a/src/cache.rs b/src/cache.rs index 753ddeb..379077b 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -1,3 +1,4 @@ +//! Module to implement a simple cache use crate::errors::*; use crate::template::GithubTemplates; use core::time::Duration; diff --git a/src/gitignore.rs b/src/gitignore.rs index 6e3d8ec..97e2acf 100644 --- a/src/gitignore.rs +++ b/src/gitignore.rs @@ -1,3 +1,4 @@ +//! This module contains an abstraction for gitignore files use crate::errors::*; use std::fs::OpenOptions; use std::path::PathBuf; diff --git a/src/helpers.rs b/src/helpers.rs index 1a6786e..51a06d8 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -6,12 +6,9 @@ // `#![...]` it onto the entire module. #![allow(clippy::result_unwrap_used)] use log::{info, trace}; -use std::fs::File; use crate::errors::*; -use std::fs::DirEntry; -use std::fs::ReadDir; -use std::path::Path; + use std::path::PathBuf; use structopt::{clap, StructOpt}; @@ -100,18 +97,3 @@ pub fn git_dir() -> Result> { info!("Arrived at filesystem root while checking for git folder"); Ok(None) } - -/// Returns the path to the cache dir -/// -/// If env `XDG_CACHE_HOME` is not set it uses `$HOME/.cache` and appends `gitig`. If dir does not -/// exists it will be created -pub fn cache_dir() -> PathBuf { - let root = std::env::var("XDG_CACHE_HOME").unwrap_or_else(|_| "$HOME/.cache/".to_string()); - let mut root = PathBuf::from(root); - root.push("gitig"); - if !root.exists() && std::fs::create_dir_all(&root).is_err() { - // should not happen, but as a fallback we can use /tmp/ - root = PathBuf::from("/tmp"); - } - root -} diff --git a/src/main.rs b/src/main.rs index d031d11..359274d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,6 @@ -/*! TODO: Application description here +/*! Gitig is a small cli program to handle gitignore files + +It helps adding new entries to ignore and start a new project with templates from [Github](https://github.com/github/gitignore). This project used [rust-cli-boilerplate](https://github.com/ssokolow/rust-cli-boilerplate) */ @@ -20,12 +22,15 @@ This project used [rust-cli-boilerplate](https://github.com/ssokolow/rust-cli-bo clippy::restriction )] // Opt out of the lints I've seen and don't want -#![allow(clippy::float_arithmetic, clippy::implicit_return, clippy::filter_map)] +#![allow( + clippy::float_arithmetic, + clippy::implicit_return, + clippy::filter_map, + clippy::wildcard_imports +)] #[macro_use] extern crate error_chain; -extern crate reqwest; -extern crate serde; // stdlib imports use std::convert::TryInto; @@ -33,7 +38,6 @@ use std::io; // 3rd-party imports mod errors; -use log::error; use structopt::{clap, StructOpt}; // Local imports @@ -52,6 +56,7 @@ mod template; /// /// **TODO:** Consider switching to Failure and look into `impl Termination` as a way to avoid /// having to put the error message pretty-printing inside main() +#[allow(clippy::result_expect_used, clippy::exit, clippy::use_debug)] fn main() { // Parse command-line arguments (exiting on parse error, --version, or --help) let opts = app::CliOpts::from_args(); diff --git a/src/template.rs b/src/template.rs index f61d1e1..6987a2f 100644 --- a/src/template.rs +++ b/src/template.rs @@ -1,6 +1,5 @@ //! This module contains structs for working with the github templates -use crate::cache::Cache; use log::{debug, trace}; use reqwest::blocking::Client; use reqwest::header::{ACCEPT, CONTENT_TYPE, USER_AGENT}; @@ -8,13 +7,8 @@ use serde::{Deserialize, Serialize}; use crate::errors::*; -type CacheContents = Vec