Skip to content

Commit

Permalink
feat: lint and format scripts (#615)
Browse files Browse the repository at this point in the history
- Closes #544
  • Loading branch information
gadomski authored Jan 31, 2025
1 parent ee7a499 commit 03739a3
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 11 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ jobs:
run: |
wget https://github.com/duckdb/duckdb/releases/download/v1.1.3/libduckdb-linux-amd64.zip
unzip libduckdb-linux-amd64.zip -d /opt/duckdb
- name: Fmt
run: cargo fmt
- name: Clippy
run: cargo clippy --workspace --all-features
- name: Lint
run: scripts/lint
- name: Build # need to build first to get the executable for CLI tests
run: cargo build --all-features
- name: Test
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Draft pull requests with a failing test to demonstrate a bug are much appreciate

Please open a [pull request](https://docs.github.com/en/pull-requests) with your changes -- make sure to include unit tests.
Please follow standard git commit formatting (subject line 50 characters max, wrap the body at 72 characters).
Run `scripts/lint` to make sure your changes are nice, and use `scripts/format` to fix things that can be fixed.

We use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/).
Your commits do not have to but if you'd like to format them this way, we would be grateful.
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl Stacrs {
} else {
serde_json::to_writer_pretty(std::io::stdout(), &value)?;
}
println!("");
println!();
} else {
return Err(anyhow!("invalid output format: {}", format));
}
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub enum Error {
Parquet(#[from] parquet::errors::ParquetError),

/// [reqwest::Error]
#[cfg(any(feature = "reqwest"))]
#[cfg(feature = "reqwest")]
#[error(transparent)]
Reqwest(#[from] reqwest::Error),

Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ mod tests {
]))))
.unwrap();
assert!(item
.intersects(&crate::geo::bbox(&vec![-106.0, 41.0, -105.0, 42.0]).unwrap())
.intersects(&crate::geo::bbox(&[-106.0, 41.0, -105.0, 42.0]).unwrap())
.unwrap());
}

Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/item_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ mod tests {
#[test]
fn item_collection_from_iter() {
let items = vec![Item::new("a"), Item::new("b")];
let _ = ItemCollection::from_iter(items.into_iter());
let _ = ItemCollection::from_iter(items);
}

#[test]
Expand Down
7 changes: 4 additions & 3 deletions crates/pgstac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,13 @@ pub(crate) mod tests {
use stac_api::{Fields, Filter, Search, Sortby};
use std::{
ops::Deref,
sync::{atomic::AtomicU16, Mutex},
sync::{atomic::AtomicU16, LazyLock},
};
use tokio::sync::Mutex;
use tokio_postgres::{Client, Config, NoTls};
use tokio_test as _;

static MUTEX: Mutex<()> = Mutex::new(());
static MUTEX: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));

struct TestClient {
client: Client,
Expand All @@ -359,7 +360,7 @@ pub(crate) mod tests {
let dbname = format!("pgstac_test_{}", id);
let config = config();
{
let _mutex = MUTEX.lock().unwrap();
let _mutex = MUTEX.lock().await;
let (client, connection) = config.connect(NoTls).await.unwrap();
let _handle = tokio::spawn(async move { connection.await.unwrap() });
let _ = client
Expand Down
6 changes: 6 additions & 0 deletions scripts/format
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh

set -e

cargo fmt
cargo clippy --workspace --all-features --fix
6 changes: 6 additions & 0 deletions scripts/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh

set -e

cargo fmt --check
cargo clippy --workspace --all-features -- -D warnings

0 comments on commit 03739a3

Please sign in to comment.