Skip to content

Commit bdfda31

Browse files
weiji14kylebarron
andauthored
ci: Add clippy and fmt lints (#132)
* CI: Add clippy and fmt lints Run cargo clippy, and cargo fmt with import sorting. * Format imports * Move lints from test.yml and test-python.yml to lint.yml * Format imports in python/ folder * Apply suggestions from code review * Update .github/workflows/lint.yml * remove rustfmt component installation --------- Co-authored-by: Kyle Barron <[email protected]> Co-authored-by: Kyle Barron <[email protected]>
1 parent fac684f commit bdfda31

File tree

11 files changed

+67
-47
lines changed

11 files changed

+67
-47
lines changed

.github/workflows/lint.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
types: [opened, reopened, synchronize]
8+
branches: ["main"]
9+
10+
permissions: {}
11+
12+
# Make sure CI fails on all warnings, including Clippy lints
13+
env:
14+
CARGO_TERM_COLOR: always
15+
RUSTFLAGS: "-Dwarnings"
16+
17+
jobs:
18+
clippy_check:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v6
24+
with:
25+
persist-credentials: false
26+
27+
- name: Run Clippy
28+
run: |
29+
cargo clippy --all-targets --all-features
30+
cargo clippy --all-targets --all-features --manifest-path python/Cargo.toml
31+
32+
format_check:
33+
runs-on: ubuntu-latest
34+
35+
steps:
36+
- name: Checkout repository
37+
uses: actions/checkout@v6
38+
with:
39+
persist-credentials: false
40+
41+
- name: Run Rustfmt
42+
run: |
43+
cargo fmt --all --check -- --config imports_granularity=Module,group_imports=StdExternalCrate
44+
cargo fmt --all --check --manifest-path python/Cargo.toml -- --config imports_granularity=Module,group_imports=StdExternalCrate

.github/workflows/test-python.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ on:
77
pull_request:
88

99
jobs:
10-
lint-test:
11-
name: Lint and Test
10+
test:
11+
name: Test
1212
runs-on: ubuntu-latest
1313
defaults:
1414
run:
@@ -18,17 +18,9 @@ jobs:
1818

1919
- name: Install Rust
2020
uses: dtolnay/rust-toolchain@stable
21-
with:
22-
components: rustfmt, clippy
2321

2422
- uses: Swatinem/rust-cache@v2
2523

26-
- name: Cargo fmt
27-
run: cargo fmt --all -- --check
28-
29-
- name: "clippy --all"
30-
run: cargo clippy --all --all-features --tests -- -D warnings
31-
3224
- name: "cargo check"
3325
run: cargo check --all --all-features
3426

@@ -47,8 +39,6 @@ jobs:
4739
- uses: actions/checkout@v4
4840
- name: Install Rust
4941
uses: dtolnay/rust-toolchain@stable
50-
with:
51-
components: rustfmt
5242

5343
- uses: Swatinem/rust-cache@v2
5444
- uses: actions/setup-python@v5

.github/workflows/test.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,17 @@ on:
77
pull_request:
88

99
jobs:
10-
lint-test:
11-
name: Lint and Test
10+
test:
11+
name: Test
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v3
1515

1616
- name: Install Rust
1717
uses: dtolnay/rust-toolchain@stable
18-
with:
19-
components: rustfmt, clippy
2018

2119
- uses: Swatinem/rust-cache@v2
2220

23-
- name: Cargo fmt
24-
run: cargo fmt --all -- --check
25-
26-
- name: "clippy --all"
27-
run: cargo clippy --all --all-features --tests -- -D warnings
28-
2921
- run: cargo install cargo-all-features
3022

3123
- name: Check all combinations of features can build

python/src/thread_pool.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::sync::Arc;
22

33
use pyo3::exceptions::PyValueError;
44
use pyo3::prelude::*;
5-
65
use pyo3::sync::PyOnceLock;
76
use rayon::{ThreadPool, ThreadPoolBuilder};
87

src/cog.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ mod test {
2323
use std::io::BufReader;
2424
use std::sync::Arc;
2525

26-
use crate::metadata::{PrefetchBuffer, TiffMetadataReader};
27-
use crate::reader::{AsyncFileReader, ObjectReader};
28-
29-
use super::*;
3026
use object_store::local::LocalFileSystem;
3127
use tiff::decoder::{DecodingResult, Limits};
3228

29+
use super::*;
30+
use crate::metadata::{PrefetchBuffer, TiffMetadataReader};
31+
use crate::reader::{AsyncFileReader, ObjectReader};
32+
3333
#[ignore = "local file"]
3434
#[tokio::test]
3535
async fn tmp() {

src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Error handling.
22
33
use std::fmt::Debug;
4+
45
use thiserror::Error;
56

67
/// Enum with all errors in this crate.

src/geo/geo_key_directory.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use std::collections::HashMap;
55

66
use num_enum::{IntoPrimitive, TryFromPrimitive};
77

8-
use crate::tiff::Value;
9-
use crate::tiff::{TiffError, TiffResult};
8+
use crate::tiff::{TiffError, TiffResult, Value};
109

1110
/// Geospatial TIFF tag variants
1211
#[derive(Clone, Copy, Debug, PartialEq, TryFromPrimitive, IntoPrimitive, Eq, Hash)]

src/metadata/reader.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,14 +623,15 @@ async fn read_tag_value<F: MetadataFetch>(
623623

624624
#[cfg(test)]
625625
mod test {
626-
use crate::{
627-
metadata::{reader::read_tag, MetadataFetch},
628-
reader::Endianness,
629-
tiff::{tags::Tag, Value},
630-
};
631626
use bytes::Bytes;
632627
use futures::FutureExt;
633628

629+
use crate::metadata::reader::read_tag;
630+
use crate::metadata::MetadataFetch;
631+
use crate::reader::Endianness;
632+
use crate::tiff::tags::Tag;
633+
use crate::tiff::Value;
634+
634635
impl MetadataFetch for Bytes {
635636
fn fetch(
636637
&self,

src/predictor.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use std::fmt::Debug;
33

44
use bytes::{Bytes, BytesMut};
55

6-
use crate::error::AsyncTiffError;
6+
use crate::error::{AsyncTiffError, AsyncTiffResult};
7+
use crate::reader::Endianness;
78
use crate::tiff::tags::PlanarConfiguration;
89
use crate::ImageFileDirectory;
9-
use crate::{error::AsyncTiffResult, reader::Endianness};
1010

1111
/// All info that may be used by a predictor
1212
///
@@ -397,12 +397,9 @@ mod test {
397397

398398
use bytes::Bytes;
399399

400-
use crate::{
401-
predictor::{unpredict_float, unpredict_hdiff},
402-
reader::Endianness,
403-
};
404-
405400
use super::*;
401+
use crate::predictor::{unpredict_float, unpredict_hdiff};
402+
use crate::reader::Endianness;
406403

407404
const PRED_INFO: PredictorInfo = PredictorInfo {
408405
endianness: Endianness::LittleEndian,

src/reader.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ impl<T: tokio::io::AsyncRead + tokio::io::AsyncSeek + Unpin + Send + Debug> Toki
108108

109109
async fn make_range_request(&self, range: Range<u64>) -> AsyncTiffResult<Bytes> {
110110
use std::io::SeekFrom;
111+
111112
use tokio::io::{AsyncReadExt, AsyncSeekExt};
112113

113114
use crate::error::AsyncTiffError;

0 commit comments

Comments
 (0)