From b50f26cf0bef742f26776444c0d0ce54b2d9da80 Mon Sep 17 00:00:00 2001 From: Auca Maillot Date: Sat, 10 Jun 2023 08:28:00 -0300 Subject: [PATCH] :boom: make clippy break CI --- src/config.rs | 3 +++ src/formatting.rs | 5 ++++- src/lib.rs | 7 +++++-- src/main.rs | 30 ++++++++++++++---------------- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/config.rs b/src/config.rs index 38cc864..c00aca6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,3 +1,6 @@ +// set clippy to pedantic lint +#![warn(clippy::all, clippy::pedantic, clippy::cargo)] + use anyhow::Result; #[derive(Debug)] diff --git a/src/formatting.rs b/src/formatting.rs index ea61295..d14adeb 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -1,3 +1,6 @@ +// set clippy to pedantic lint +#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)] + use crate::config::Config; use log::trace; use nu_parser::{flatten_block, parse, FlatShape}; @@ -80,7 +83,7 @@ pub fn format_inner(contents: &[u8], _config: &Config) -> Vec { // The pipe is just a pipe `|`. // // return the pipe AND a space after that - out.extend("| ".to_string().bytes()) + out.extend("| ".to_string().bytes()); } FlatShape::External => { // External are some key commands diff --git a/src/lib.rs b/src/lib.rs index 081ca3d..d537e56 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,9 @@ //! //! It does not do anything more than that, which makes it so fast. +// set clippy to pedantic lint +#![warn(clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo)] + use config::Config; use formatting::format_inner; use log::{debug, trace}; @@ -24,7 +27,7 @@ pub fn format_single_file(file: &PathBuf, config: &Config) { // compare the contents if formatted_bytes == contents { - debug!("File is formatted correctly.") + debug!("File is formatted correctly."); } // write down the file to path @@ -33,7 +36,7 @@ pub fn format_single_file(file: &PathBuf, config: &Config) { writer .write_all(file_bites) .expect("something went wrong writing"); - trace!("written") + trace!("written"); } pub fn format_string(input_string: &String, config: &Config) -> String { diff --git a/src/main.rs b/src/main.rs index 89a5970..9c3f456 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,6 +36,8 @@ //! //! - `-v` or `--version` prints the version and exit +// set clippy to pedantic lint +#![warn(clippy::all, clippy::pedantic, clippy::cargo)] // throw error if finds a broken link in doc #![deny(rustdoc::broken_intra_doc_links)] // or docs are missing for public members @@ -81,15 +83,12 @@ fn main() -> Result<(), Box> { trace!("recieved cli.stdin: {:?}", cli.stdin); trace!("recieved cli.config: {:?}", cli.config); - let cli_config = match cli.config { - None => Config::default(), - Some(input_cli) => { - todo!( - "cannot read from {:?} Reading a config from file not implemented!", - input_cli - ) - } - }; + let cli_config = cli.config.map_or_else(Config::default, |input_cli| { + todo!( + "cannot read from {:?} Reading a config from file not implemented!", + input_cli + ) + }); // Note the deref and reborrow here to obtain a slice // so rust doesnt complain for the [] arm @@ -123,21 +122,20 @@ fn execute_string(string: Option, options: &Config) -> Result { /// Sends the files to format in lib.rs fn execute_files(files: Vec, options: &Config) -> Result { // walk the files in the vec of files - for file in files.iter() { + for file in &files { if !file.exists() { eprintln!("Error: {} not found!", file.to_str().unwrap()); return Ok(FAILED_EXIT); } else if file.is_dir() { eprintln!( - "Error: {} is a directory. Please pass files only.", - file.to_str().unwrap() + "Error: {:?} is a directory. Please pass files only.", + file.to_str() ); return Ok(FAILED_EXIT); - } else { - // send the file to lib.rs - println!("formatting file: {:?}", file); - format_single_file(file, options); } + // send the file to lib.rs + println!("formatting file: {file:?}"); + format_single_file(file, options); } Ok(SUCCESSFUL_EXIT)