Skip to content

Commit 62a241c

Browse files
authored
chore: Add clippy and fix some lint warnings (#25)
This adds a lint action for GHA. Also fixes some warnings turned up by clippy, and disables dead code warnings for this crate.
1 parent 31b6e9e commit 62a241c

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

.github/workflows/test.yml

+12
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@ jobs:
1616
run: cargo update
1717
- name: Run Cargo Tests
1818
run: cargo test
19+
lint:
20+
timeout-minutes: 5
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
24+
- name: Install Rust Toolchain
25+
run: rustup toolchain install stable --profile minimal --no-self-update
26+
- name: Update cargo
27+
run: cargo update
28+
- name: Lint
29+
run: cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings
30+

src/checker.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use reqwest::{Response, StatusCode};
44

55
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
66
pub enum CheckResult {
7-
SUCCESS,
8-
FAILURE(FailureReason),
9-
MISSED,
7+
Success,
8+
Failure(FailureReason),
9+
Missed,
1010
}
1111

1212
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
@@ -34,10 +34,10 @@ pub async fn do_request(
3434
/// Up is defined as returning a 2xx within a specific timeframe.
3535
pub async fn check_url(client: &reqwest::Client, url: String) -> CheckResult {
3636
match do_request(client, url).await {
37-
Ok(_) => CheckResult::SUCCESS,
37+
Ok(_) => CheckResult::Success,
3838
Err(e) => {
3939
if e.is_timeout() {
40-
return CheckResult::FAILURE(FailureReason::Timeout);
40+
return CheckResult::Failure(FailureReason::Timeout);
4141
}
4242
// TODO: More reasons
4343
let mut inner = &e as &dyn Error;
@@ -48,13 +48,13 @@ pub async fn check_url(client: &reqwest::Client, url: String) -> CheckResult {
4848
// Not sure if there's a better way
4949
let inner_message = inner.to_string();
5050
if inner_message.contains("dns error") {
51-
return CheckResult::FAILURE(FailureReason::DnsError(
51+
return CheckResult::Failure(FailureReason::DnsError(
5252
inner.source().unwrap().to_string(),
5353
));
5454
}
5555
}
5656
// TODO: Should incorporate status code somehow
57-
CheckResult::FAILURE(FailureReason::Error(format!("{:?}", e)))
57+
CheckResult::Failure(FailureReason::Error(format!("{:?}", e)))
5858
}
5959
}
6060
}
@@ -93,15 +93,15 @@ mod tests {
9393

9494
assert_eq!(
9595
check_url(&client, server.url("/head")).await,
96-
CheckResult::SUCCESS
96+
CheckResult::Success
9797
);
9898
assert_eq!(
9999
check_url(&client, server.url("/no-head")).await,
100-
CheckResult::SUCCESS
100+
CheckResult::Success
101101
);
102102
assert_eq!(
103103
check_url(&client, server.url("/timeout")).await,
104-
CheckResult::FAILURE(FailureReason::Timeout)
104+
CheckResult::Failure(FailureReason::Timeout)
105105
);
106106
head_mock.assert();
107107
head_disallowed_mock.assert();

src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// TODO: We might want to remove this once more stable, but it's just noisy for now.
2+
#![allow(dead_code)]
13
mod checker;
24
mod cli;
35
mod cliapp;

0 commit comments

Comments
 (0)