Skip to content

Commit f06d8cb

Browse files
committed
feat: achieve full clippy compliance and enhance CI/CD
- Fix all 54 clippy warnings to pass cargo clippy -- -D warnings - Modernize format strings throughout codebase - Fix version display to use CARGO_PKG_VERSION instead of hardcoded '1.0' - Add comprehensive GitHub Actions workflows (CI, release, security) - Improve error handling and code quality following Rust best practices - Add strategic allow attributes for complex cases (too many arguments, needless range loops) - Enhance type safety and maintainability across parser implementation
1 parent 8b47185 commit f06d8cb

7 files changed

Lines changed: 272 additions & 81 deletions

File tree

.github/workflows/ci.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: Build and Test
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
RUST_BACKTRACE: 1
12+
13+
jobs:
14+
check:
15+
name: Check and Lint
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Install Rust toolchain
22+
uses: actions-rust-lang/setup-rust-toolchain@v1
23+
with:
24+
toolchain: stable
25+
components: rustfmt, clippy
26+
27+
- name: Cache cargo dependencies
28+
uses: actions/cache@v4
29+
with:
30+
path: |
31+
~/.cargo/bin/
32+
~/.cargo/registry/index/
33+
~/.cargo/registry/cache/
34+
~/.cargo/git/db/
35+
target/
36+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
37+
38+
- name: Check formatting
39+
run: cargo fmt --all -- --check
40+
41+
- name: Run clippy
42+
run: cargo clippy --all-targets --all-features -- -D warnings
43+
44+
- name: Check documentation
45+
run: cargo doc --no-deps --all-features
46+
47+
test:
48+
name: Test
49+
runs-on: ${{ matrix.os }}
50+
needs: check
51+
strategy:
52+
matrix:
53+
os: [ubuntu-latest, windows-latest, macos-latest]
54+
steps:
55+
- name: Checkout repository
56+
uses: actions/checkout@v4
57+
58+
- name: Install Rust toolchain
59+
uses: actions-rust-lang/setup-rust-toolchain@v1
60+
with:
61+
toolchain: stable
62+
63+
- name: Cache cargo dependencies
64+
uses: actions/cache@v4
65+
with:
66+
path: |
67+
~/.cargo/bin/
68+
~/.cargo/registry/index/
69+
~/.cargo/registry/cache/
70+
~/.cargo/git/db/
71+
target/
72+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
73+
74+
- name: Run tests (library)
75+
run: cargo test --lib --verbose
76+
77+
- name: Run tests (CLI)
78+
run: cargo test --features=cli --verbose
79+
80+
- name: Run doc tests
81+
run: cargo test --doc --verbose
82+
83+
build:
84+
name: Build Release Binaries
85+
runs-on: ${{ matrix.os }}
86+
needs: test
87+
strategy:
88+
matrix:
89+
include:
90+
- os: ubuntu-latest
91+
artifact_name: bbl_parser-linux
92+
binary_path: target/release/bbl_parser
93+
- os: windows-latest
94+
artifact_name: bbl_parser-windows
95+
binary_path: target/release/bbl_parser.exe
96+
- os: macos-latest
97+
artifact_name: bbl_parser-macos
98+
binary_path: target/release/bbl_parser
99+
100+
steps:
101+
- name: Checkout repository
102+
uses: actions/checkout@v4
103+
104+
- name: Install Rust toolchain
105+
uses: actions-rust-lang/setup-rust-toolchain@v1
106+
with:
107+
toolchain: stable
108+
109+
- name: Cache cargo dependencies
110+
uses: actions/cache@v4
111+
with:
112+
path: |
113+
~/.cargo/bin/
114+
~/.cargo/registry/index/
115+
~/.cargo/registry/cache/
116+
~/.cargo/git/db/
117+
target/
118+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
119+
120+
- name: Build release binary
121+
run: cargo build --release --features=cli
122+
123+
- name: Upload binary artifact
124+
uses: actions/upload-artifact@v4
125+
with:
126+
name: ${{ matrix.artifact_name }}
127+
path: ${{ matrix.binary_path }}
128+
overwrite: true
129+
if-no-files-found: error

.github/workflows/release.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
env:
8+
CARGO_TERM_COLOR: always
9+
10+
jobs:
11+
publish:
12+
name: Publish to crates.io
13+
runs-on: ubuntu-latest
14+
if: startsWith(github.ref, 'refs/tags/')
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Install Rust toolchain
20+
uses: actions-rust-lang/setup-rust-toolchain@v1
21+
with:
22+
toolchain: stable
23+
24+
- name: Cache cargo dependencies
25+
uses: actions/cache@v4
26+
with:
27+
path: |
28+
~/.cargo/bin/
29+
~/.cargo/registry/index/
30+
~/.cargo/registry/cache/
31+
~/.cargo/git/db/
32+
target/
33+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
34+
35+
- name: Verify version matches tag
36+
run: |
37+
CARGO_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
38+
TAG_VERSION=${GITHUB_REF#refs/tags/v}
39+
if [[ "$CARGO_VERSION" != "$TAG_VERSION" ]]; then
40+
echo "Version mismatch: Cargo.toml has $CARGO_VERSION, tag is v$TAG_VERSION"
41+
exit 1
42+
fi
43+
44+
- name: Run tests
45+
run: cargo test --all-features
46+
47+
- name: Publish to crates.io
48+
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}

.github/workflows/security.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Security Audit
2+
3+
on:
4+
schedule:
5+
# Run every Monday at 9 AM UTC
6+
- cron: '0 9 * * 1'
7+
push:
8+
branches: [main, master]
9+
pull_request:
10+
branches: [main, master]
11+
12+
jobs:
13+
security_audit:
14+
name: Security Audit
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Install Rust toolchain
21+
uses: actions-rust-lang/setup-rust-toolchain@v1
22+
with:
23+
toolchain: stable
24+
25+
- name: Install cargo-audit
26+
run: cargo install cargo-audit
27+
28+
- name: Run security audit
29+
run: cargo audit

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
[package]
22
name = "bbl_parser"
3-
version = "0.1.0"
3+
version = "0.9.0"
44
edition = "2021"
5+
authors = ["nerdCopter"]
6+
license = "AGPL-3.0"
57
description = "Parser for Betaflight/EmuFlight/INAV blackbox log files"
68
keywords = ["betaflight", "blackbox", "drone", "flight-log", "parser"]
79
categories = ["parsing", "aerospace"]
10+
rust-version = "1.70.0"
811

912
[dependencies]
1013
anyhow = "1.0"

src/bbl_format.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ impl<'a> BBLDataStream<'a> {
107107
let mut nibble_index = 0;
108108
let mut buffer = 0u8;
109109

110+
#[allow(clippy::needless_range_loop)]
110111
for i in 0..4 {
111112
let field_type = (selector >> (i * 2)) & 0x03;
112113

@@ -126,7 +127,7 @@ impl<'a> BBLDataStream<'a> {
126127
if nibble_index == 0 {
127128
values[i] = sign_extend_8bit(self.read_byte()?);
128129
} else {
129-
let mut char1 = ((buffer & 0x0f) << 4) as u8;
130+
let mut char1 = (buffer & 0x0f) << 4;
130131
buffer = self.read_byte()?;
131132
char1 |= buffer >> 4;
132133
values[i] = sign_extend_8bit(char1);
@@ -180,6 +181,7 @@ impl<'a> BBLDataStream<'a> {
180181
}
181182
3 => { // 8, 16 or 24 bit fields
182183
let mut selector = lead_byte;
184+
#[allow(clippy::needless_range_loop)]
183185
for i in 0..3 {
184186
match selector & 0x03 {
185187
0 => { // 8-bit
@@ -224,6 +226,7 @@ impl<'a> BBLDataStream<'a> {
224226
values[0] = self.read_signed_vb()?;
225227
} else {
226228
let mut header = self.read_byte()?;
229+
#[allow(clippy::needless_range_loop)]
227230
for i in 0..8.min(value_count) {
228231
values[i] = if header & 0x01 != 0 {
229232
self.read_signed_vb()?
@@ -289,6 +292,7 @@ pub fn sign_extend_14bit(value: u16) -> i32 {
289292
}
290293
}
291294

295+
#[allow(clippy::too_many_arguments)]
292296
pub fn apply_predictor(
293297
field_index: usize,
294298
predictor: u8,
@@ -341,7 +345,7 @@ pub fn apply_predictor(
341345

342346
PREDICT_MINTHROTTLE => {
343347
let minthrottle = sysconfig.get("minthrottle").copied().unwrap_or(1150);
344-
(raw_value | 0) + minthrottle
348+
raw_value + minthrottle
345349
}
346350

347351
PREDICT_MOTOR_0 => {
@@ -415,6 +419,7 @@ pub fn decode_frame_field(
415419
}
416420
}
417421

422+
#[allow(clippy::too_many_arguments)]
418423
pub fn parse_frame_data(
419424
stream: &mut BBLDataStream,
420425
frame_def: &crate::FrameDefinition,

0 commit comments

Comments
 (0)