diff --git a/.github/workflows/clippy_check.yml b/.github/workflows/clippy_check.yml new file mode 100644 index 0000000..9f184f4 --- /dev/null +++ b/.github/workflows/clippy_check.yml @@ -0,0 +1,18 @@ +on: [push, pull_request] + +name: Clippy check + +jobs: + clippy_check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup Rust toolchain and cache + uses: actions-rust-lang/setup-rust-toolchain@v1.4.4 + + - name: cargo fmt + run: cargo fmt --all -- --check + + - name: Clippy + run: cargo clippy --no-deps diff --git a/src/config.rs b/src/config.rs index 9764579..38cc864 100644 --- a/src/config.rs +++ b/src/config.rs @@ -26,9 +26,9 @@ impl Config { /// You cannot skip any field yet. pub fn new(tab_spaces: usize, max_width: usize, margin: usize) -> Self { Config { - tab_spaces: tab_spaces, - max_width: max_width, - margin: margin, + tab_spaces, + max_width, + margin, } } } diff --git a/src/lib.rs b/src/lib.rs index db7b0e9..020904b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,8 +20,8 @@ pub struct Session<'b, T: Write> { impl<'b, T: Write + 'b> Session<'b, T> { pub fn new(config: config::Config, out: Option<&'b mut T>) -> Self { Self { - config: config, - out: out, + config, + out, has_operational_errors: false, } } @@ -62,9 +62,9 @@ impl Input { fn contents(&self) -> Vec { match self { - Input::File(path) => std::fs::read(path).expect( - format!("something went wrong reading the file {}", path.display()).as_str(), - ), + Input::File(path) => std::fs::read(path).unwrap_or_else(|_| { + panic!("something went wrong reading the file {}", path.display()) + }), Input::Text(string) => string.as_bytes().to_vec(), } } diff --git a/src/main.rs b/src/main.rs index 5df7e41..5035ef9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,6 @@ #[allow(unused_import_braces)] use anyhow::Result; use clap::Parser; -use env_logger; use nufmt::config::Config; use nufmt::{Input, Session}; use std::error::Error; @@ -108,9 +107,7 @@ fn execute(files: Vec, options: Config) -> Result { } fn format_and_emit_report(session: &mut Session<'_, T>, input: Input) { - match session.format(input) { - _ => {} // _ => todo!("Here `nufmt` gives you a FormatReport"), - } + session.format(input); } #[cfg(test)]