Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
chore: improve linting (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
xvello authored Apr 24, 2024
1 parent 55292bd commit 60debad
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 25 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
push:
branches: [main]
pull_request:
branches: [main]

env:
CARGO_TERM_COLOR: always
Expand Down Expand Up @@ -71,7 +70,7 @@ jobs:
- name: Run cargo check
run: cargo check --all-features

clippy:
linting:
runs-on: depot-ubuntu-22.04-4

steps:
Expand All @@ -81,7 +80,7 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: clippy
components: clippy,rustfmt

- uses: actions/cache@v3
with:
Expand All @@ -94,17 +93,18 @@ jobs:
- name: Run clippy
run: cargo clippy -- -D warnings

format:
runs-on: depot-ubuntu-22.04-4
- name: Check format
run: cargo fmt -- --check

shear:
runs-on: depot-ubuntu-22.04-4
steps:
- uses: actions/checkout@v3

- name: Install latest rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: rustfmt
- name: Install cargo-binstall
uses: cargo-bins/cargo-binstall@main

- name: Format
run: cargo fmt -- --check
- name: Install cargo-shear
run: cargo binstall --no-confirm cargo-shear

- run: cargo shear
15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ members = [
"hook-worker",
]

[workspace.lints.rust]
# See https://doc.rust-lang.org/stable/rustc/lints/listing/allowed-by-default.html
unsafe_code = "forbid" # forbid cannot be ignored with an annotation
unstable_features = "forbid"
macro_use_extern_crate = "forbid"
let_underscore_drop = "deny"
non_ascii_idents = "deny"
trivial_casts = "deny"
trivial_numeric_casts = "deny"
unit_bindings = "deny"

[workspace.lints.clippy]
# See https://rust-lang.github.io/rust-clippy/, we might want to add more
enum_glob_use = "deny"

[workspace.dependencies]
anyhow = "1.0"
assert-json-diff = "2.0.2"
Expand Down
3 changes: 3 additions & 0 deletions capture-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name = "capture-server"
version = "0.1.0"
edition = "2021"

[lints]
workspace = true

[dependencies]
capture = { path = "../capture" }
envconfig = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion capture/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ name = "capture"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lints]
workspace = true

[dependencies]
anyhow = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions capture/src/sinks/kafka.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ impl KafkaSink {
client_config.create_with_context(KafkaContext { liveness })?;

// Ping the cluster to make sure we can reach brokers, fail after 10 seconds
_ = producer.client().fetch_metadata(
drop(producer.client().fetch_metadata(
Some("__consumer_offsets"),
Timeout::After(Duration::new(10, 0)),
)?;
)?);
info!("connected to Kafka brokers");

Ok(KafkaSink {
Expand Down
3 changes: 2 additions & 1 deletion common/health/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ name = "health"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lints]
workspace = true

[dependencies]
axum = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion hook-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ name = "hook-api"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lints]
workspace = true

[dependencies]
axum = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion hook-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ name = "hook-common"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lints]
workspace = true

[dependencies]
async-trait = { workspace = true }
Expand Down
14 changes: 8 additions & 6 deletions hook-common/src/pgqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,14 +827,15 @@ mod tests {

let retry_interval = retry_policy.retry_interval(job.job.attempt as u32, None);
let retry_queue = retry_policy.retry_queue(&job.job.queue).to_owned();
let _ = job
.retry(
drop(
job.retry(
"a very reasonable failure reason",
retry_interval,
&retry_queue,
)
.await
.expect("failed to retry job");
.expect("failed to retry job"),
);
batch.commit().await.expect("failed to commit transaction");

let retried_job: PgTransactionJob<JobParameters, JobMetadata> = queue
Expand Down Expand Up @@ -883,14 +884,15 @@ mod tests {

let retry_interval = retry_policy.retry_interval(job.job.attempt as u32, None);
let retry_queue = retry_policy.retry_queue(&job.job.queue).to_owned();
let _ = job
.retry(
drop(
job.retry(
"a very reasonable failure reason",
retry_interval,
&retry_queue,
)
.await
.expect("failed to retry job");
.expect("failed to retry job"),
);
batch.commit().await.expect("failed to commit transaction");

let retried_job_not_found: Option<PgTransactionBatch<JobParameters, JobMetadata>> = queue
Expand Down
3 changes: 2 additions & 1 deletion hook-janitor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ name = "hook-janitor"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lints]
workspace = true

[dependencies]
async-trait = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions hook-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name = "hook-worker"
version = "0.1.0"
edition = "2021"

[lints]
workspace = true

[dependencies]
axum = { workspace = true }
chrono = { workspace = true }
Expand Down

0 comments on commit 60debad

Please sign in to comment.