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.
This commit is contained in:
vincent-herlemont
2025-07-06 17:49:25 +02:00
committed by Vincent Herlemont
parent 64b1d15dd1
commit 31efa79429
8 changed files with 83 additions and 9 deletions
@@ -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
+30
View File
@@ -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
+1 -1
View File
@@ -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<u8>);
+17
View File
@@ -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
@@ -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(())
}
@@ -19,5 +19,5 @@ pub(crate) fn generate_native_model_decode_body(attrs: &ModelAttributes) -> Toke
}
};
gen.into()
gen
}
@@ -14,5 +14,5 @@ pub(crate) fn generate_native_model_encode_body(attrs: &ModelAttributes) -> Toke
}
};
gen.into()
gen
}
+1 -1
View File
@@ -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<T: SplitByteSlice> {
header: Ref<T, Header>,