diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 517d7d8..b9352ae 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -8,14 +8,32 @@ env: CARGO_TERM_COLOR: always jobs: - build_and_test: + test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: toolchain: stable - - uses: actions-rs/cargo@v1 + - name: Run cargo test + uses: actions-rs/cargo@v1 with: - command: build - args: --release --all-features + command: test + lints: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: clippy + - name: Run cargo fmt (check if all code is rustfmt-ed) + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + - name: Run cargo clippy (deny warnings) + uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings diff --git a/src/checker.rs b/src/checker.rs index 3206891..b725be9 100644 --- a/src/checker.rs +++ b/src/checker.rs @@ -43,10 +43,8 @@ impl Status { if accepted.contains(&statuscode) { return Status::Ok(statuscode); } - } else { - if statuscode.is_success() { - return Status::Ok(statuscode); - } + } else if statuscode.is_success() { + return Status::Ok(statuscode); }; if statuscode.is_redirection() { Status::Redirected @@ -119,6 +117,9 @@ pub(crate) struct Checker<'a> { impl<'a> Checker<'a> { /// Creates a new link checker + // we should consider adding a config struct for this, so that the list + // of arguments is short + #[allow(clippy::too_many_arguments)] pub fn try_new( token: String, excludes: Excludes, @@ -215,7 +216,7 @@ impl<'a> Checker<'a> { status } - pub async fn valid_mail(&self, address: &String) -> bool { + pub async fn valid_mail(&self, address: &str) -> bool { let input = CheckEmailInput::new(vec![address.to_string()]); let results = check_email(&input).await; let result = results.get(0); @@ -334,10 +335,8 @@ impl<'a> Checker<'a> { if let Some(message) = self.status_message(&ret, uri) { pb.println(message); } - } else { - if let Some(message) = self.status_message(&ret, uri) { - println!("{}", message); - } + } else if let Some(message) = self.status_message(&ret, uri) { + println!("{}", message); } ret diff --git a/src/main.rs b/src/main.rs index 6402fe0..1f7f44b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ use checker::{Checker, Excludes, Status}; use extract::Uri; use options::LycheeOptions; -fn print_summary(found: &HashSet, results: &Vec) { +fn print_summary(found: &HashSet, results: &[Status]) { let found = found.len(); let excluded: usize = results .iter()