From 31efa794291617522cee67ff85158f538cc87940 Mon Sep 17 00:00:00 2001 From: vincent-herlemont Date: Sun, 6 Jul 2025 17:49:25 +0200 Subject: [PATCH] ci: add comprehensive formatting and linting setup - Add formatting commands to justfile (format, fmt_check, clippy_check, fc) - Create GitHub Actions workflows for automated fmt and clippy checks - Fix existing clippy warnings in macro code - Ensure CI enforcement of code quality standards This brings native_model in line with native_db's robust formatting and linting approach. --- .../.github/workflows/clippy_check.yml | 30 +++++++++++++++++++ .../.github/workflows/fmt_check.yml | 30 +++++++++++++++++++ libraries/native_model/benches/overhead.rs | 2 +- libraries/native_model/justfile | 17 +++++++++++ .../native_model_macro/src/lib.rs | 7 ++--- .../src/method/decode_body.rs | 2 +- .../src/method/encode_body.rs | 2 +- libraries/native_model/src/wrapper.rs | 2 +- 8 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 libraries/native_model/.github/workflows/clippy_check.yml create mode 100644 libraries/native_model/.github/workflows/fmt_check.yml diff --git a/libraries/native_model/.github/workflows/clippy_check.yml b/libraries/native_model/.github/workflows/clippy_check.yml new file mode 100644 index 00000000..ad268eca --- /dev/null +++ b/libraries/native_model/.github/workflows/clippy_check.yml @@ -0,0 +1,30 @@ +name: Clippy Check + +on: + push: + branches: [ main ] + pull_request: + branches: [ main, next ] + schedule: + - cron: '0 23 * * 4' + +env: + RUST_BACKTRACE: full + +jobs: + clippy_check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + - uses: extractions/setup-just@v3 + - uses: hustcer/setup-nu@v3.19 + with: + version: '0.105.1' + env: + GITHUB_TOKEN: ${{ secrets.PAT_GLOBAL }} + - name: Just version + run: just --version + - name: Clippy Check + run: just clippy_check \ No newline at end of file diff --git a/libraries/native_model/.github/workflows/fmt_check.yml b/libraries/native_model/.github/workflows/fmt_check.yml new file mode 100644 index 00000000..4fff2d18 --- /dev/null +++ b/libraries/native_model/.github/workflows/fmt_check.yml @@ -0,0 +1,30 @@ +name: Fmt Check + +on: + push: + branches: [ main ] + pull_request: + branches: [ main, next ] + schedule: + - cron: '0 23 * * 4' + +env: + RUST_BACKTRACE: full + +jobs: + fmt_check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + - uses: extractions/setup-just@v3 + - uses: hustcer/setup-nu@v3.19 + with: + version: '0.105.1' + env: + GITHUB_TOKEN: ${{ secrets.PAT_GLOBAL }} + - name: Just version + run: just --version + - name: Fmt Check + run: just fmt_check \ No newline at end of file diff --git a/libraries/native_model/benches/overhead.rs b/libraries/native_model/benches/overhead.rs index 80d88628..75ea7d0e 100644 --- a/libraries/native_model/benches/overhead.rs +++ b/libraries/native_model/benches/overhead.rs @@ -1,7 +1,7 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; +use native_model::Model; use native_model_macro::native_model; use serde::{Deserialize, Serialize}; -use native_model::Model; #[derive(Serialize, Deserialize)] #[native_model(id = 1, version = 1)] struct Data(Vec); diff --git a/libraries/native_model/justfile b/libraries/native_model/justfile index 286b5723..78f7fa93 100644 --- a/libraries/native_model/justfile +++ b/libraries/native_model/justfile @@ -60,3 +60,20 @@ bench_overhead: cargo bench --bench overhead bench_all: bench_overhead + +format: + cargo clippy; \ + cargo fmt --all + +fmt_check: + cargo fmt --all -- --check + +clippy_check: + rustc --version; \ + cargo clippy --version; \ + cargo clippy -- -D warnings + +# Format check +fc: + just fmt_check; \ + just clippy_check diff --git a/libraries/native_model/native_model_macro/src/lib.rs b/libraries/native_model/native_model_macro/src/lib.rs index e11c9f10..2193d4de 100644 --- a/libraries/native_model/native_model_macro/src/lib.rs +++ b/libraries/native_model/native_model_macro/src/lib.rs @@ -27,7 +27,7 @@ pub(crate) struct ModelAttributes { pub(crate) try_from: Option<(Path, Path)>, } -impl Default for ModelAttributes { +impl Default for ModelAttributes { fn default() -> Self { ModelAttributes { id: None, @@ -57,10 +57,7 @@ impl ModelAttributes { fields.next().unwrap().clone(), )); } else { - panic!( - "Unknown attribute: {}", - meta.path.get_ident().unwrap().to_string() - ); + panic!("Unknown attribute: {}", meta.path.get_ident().unwrap()); } Ok(()) } diff --git a/libraries/native_model/native_model_macro/src/method/decode_body.rs b/libraries/native_model/native_model_macro/src/method/decode_body.rs index 474ca77d..e1a1195e 100644 --- a/libraries/native_model/native_model_macro/src/method/decode_body.rs +++ b/libraries/native_model/native_model_macro/src/method/decode_body.rs @@ -19,5 +19,5 @@ pub(crate) fn generate_native_model_decode_body(attrs: &ModelAttributes) -> Toke } }; - gen.into() + gen } diff --git a/libraries/native_model/native_model_macro/src/method/encode_body.rs b/libraries/native_model/native_model_macro/src/method/encode_body.rs index 36571369..6cff9ee7 100644 --- a/libraries/native_model/native_model_macro/src/method/encode_body.rs +++ b/libraries/native_model/native_model_macro/src/method/encode_body.rs @@ -14,5 +14,5 @@ pub(crate) fn generate_native_model_encode_body(attrs: &ModelAttributes) -> Toke } }; - gen.into() + gen } diff --git a/libraries/native_model/src/wrapper.rs b/libraries/native_model/src/wrapper.rs index 8d07ac68..dd42a262 100644 --- a/libraries/native_model/src/wrapper.rs +++ b/libraries/native_model/src/wrapper.rs @@ -1,6 +1,6 @@ use crate::header::Header; use zerocopy::little_endian::U32; -use zerocopy::{SplitByteSlice, SplitByteSliceMut, Ref, IntoBytes}; +use zerocopy::{IntoBytes, Ref, SplitByteSlice, SplitByteSliceMut}; pub struct Wrapper { header: Ref,