From b2ada4746c207fa6873d6b18228474776cb7e584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Romanowski?= Date: Fri, 16 Oct 2020 14:35:38 +0200 Subject: [PATCH 1/3] Introduce cargo fmt and clippy checks, fix all clippy warnings --- .github/workflows/rust.yml | 18 ++++++++++++++++++ src/checker.rs | 17 ++++++++--------- src/main.rs | 4 ++-- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 517d7d8..6d1ec81 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -19,3 +19,21 @@ jobs: with: command: build args: --release --all-features + 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 c2f4ec5..e3c8f29 100644 --- a/src/checker.rs +++ b/src/checker.rs @@ -41,10 +41,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 @@ -83,6 +81,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: Option, @@ -179,7 +180,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); @@ -271,10 +272,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 d306026..c5ae903 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,7 @@ use checker::{Checker, 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() @@ -31,7 +31,7 @@ fn print_summary(found: &HashSet, results: &Vec) { .count(); let errors: usize = found - excluded - success; - println!(""); + println!(); println!("📝Summary"); println!("-------------------"); println!("🔍Found: {}", found); From 7bcf2de400dae53913bf3655df6fef21c349c033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Romanowski?= Date: Fri, 16 Oct 2020 14:38:05 +0200 Subject: [PATCH 2/3] Actually run tests in GitHub actions --- .github/workflows/rust.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6d1ec81..36821fe 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -8,7 +8,7 @@ env: CARGO_TERM_COLOR: always jobs: - build_and_test: + test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -17,8 +17,7 @@ jobs: toolchain: stable - uses: actions-rs/cargo@v1 with: - command: build - args: --release --all-features + command: test lints: runs-on: ubuntu-latest steps: From 96a92deffd989bb89e8d64ff60e279b72a1c3479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Romanowski?= Date: Fri, 16 Oct 2020 14:47:54 +0200 Subject: [PATCH 3/3] Use more descriptive name for cargo test action --- .github/workflows/rust.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 36821fe..b9352ae 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -15,7 +15,8 @@ jobs: - uses: actions-rs/toolchain@v1 with: toolchain: stable - - uses: actions-rs/cargo@v1 + - name: Run cargo test + uses: actions-rs/cargo@v1 with: command: test lints: