Skip to content

Commit 03739a3

Browse files
authored
feat: lint and format scripts (#615)
- Closes #544
1 parent ee7a499 commit 03739a3

File tree

9 files changed

+23
-11
lines changed

9 files changed

+23
-11
lines changed

.github/workflows/ci.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ jobs:
5858
run: |
5959
wget https://github.com/duckdb/duckdb/releases/download/v1.1.3/libduckdb-linux-amd64.zip
6060
unzip libduckdb-linux-amd64.zip -d /opt/duckdb
61-
- name: Fmt
62-
run: cargo fmt
63-
- name: Clippy
64-
run: cargo clippy --workspace --all-features
61+
- name: Lint
62+
run: scripts/lint
6563
- name: Build # need to build first to get the executable for CLI tests
6664
run: cargo build --all-features
6765
- name: Test

CONTRIBUTING.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Draft pull requests with a failing test to demonstrate a bug are much appreciate
1313

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

1718
We use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/).
1819
Your commits do not have to but if you'd like to format them this way, we would be grateful.

crates/cli/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl Stacrs {
365365
} else {
366366
serde_json::to_writer_pretty(std::io::stdout(), &value)?;
367367
}
368-
println!("");
368+
println!();
369369
} else {
370370
return Err(anyhow!("invalid output format: {}", format));
371371
}

crates/core/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub enum Error {
102102
Parquet(#[from] parquet::errors::ParquetError),
103103

104104
/// [reqwest::Error]
105-
#[cfg(any(feature = "reqwest"))]
105+
#[cfg(feature = "reqwest")]
106106
#[error(transparent)]
107107
Reqwest(#[from] reqwest::Error),
108108

crates/core/src/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ mod tests {
738738
]))))
739739
.unwrap();
740740
assert!(item
741-
.intersects(&crate::geo::bbox(&vec![-106.0, 41.0, -105.0, 42.0]).unwrap())
741+
.intersects(&crate::geo::bbox(&[-106.0, 41.0, -105.0, 42.0]).unwrap())
742742
.unwrap());
743743
}
744744

crates/core/src/item_collection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ mod tests {
136136
#[test]
137137
fn item_collection_from_iter() {
138138
let items = vec![Item::new("a"), Item::new("b")];
139-
let _ = ItemCollection::from_iter(items.into_iter());
139+
let _ = ItemCollection::from_iter(items);
140140
}
141141

142142
#[test]

crates/pgstac/src/lib.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,13 @@ pub(crate) mod tests {
334334
use stac_api::{Fields, Filter, Search, Sortby};
335335
use std::{
336336
ops::Deref,
337-
sync::{atomic::AtomicU16, Mutex},
337+
sync::{atomic::AtomicU16, LazyLock},
338338
};
339+
use tokio::sync::Mutex;
339340
use tokio_postgres::{Client, Config, NoTls};
340341
use tokio_test as _;
341342

342-
static MUTEX: Mutex<()> = Mutex::new(());
343+
static MUTEX: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
343344

344345
struct TestClient {
345346
client: Client,
@@ -359,7 +360,7 @@ pub(crate) mod tests {
359360
let dbname = format!("pgstac_test_{}", id);
360361
let config = config();
361362
{
362-
let _mutex = MUTEX.lock().unwrap();
363+
let _mutex = MUTEX.lock().await;
363364
let (client, connection) = config.connect(NoTls).await.unwrap();
364365
let _handle = tokio::spawn(async move { connection.await.unwrap() });
365366
let _ = client

scripts/format

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env sh
2+
3+
set -e
4+
5+
cargo fmt
6+
cargo clippy --workspace --all-features --fix

scripts/lint

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env sh
2+
3+
set -e
4+
5+
cargo fmt --check
6+
cargo clippy --workspace --all-features -- -D warnings

0 commit comments

Comments
 (0)