Skip to content

Commit 6c541bd

Browse files
authored
Minor lints and CI updates (#9)
1 parent f217b8f commit 6c541bd

13 files changed

+119
-59
lines changed

.cargo-husky/hooks/pre-push

+2-12
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,10 @@
55

66
echo "-------------------------------------------------------------------------------"
77
echo "Run CI steps"
8-
echo "The following steps are also ran during git push command."
8+
echo "The following steps are ran during git push command."
99
echo "If you want to push your changes without running CI, use git push --no-verify"
1010
echo "-------------------------------------------------------------------------------"
1111

1212
set -ex
1313

14-
rustc --version
15-
cargo --version
16-
cargo fmt --all -- --check
17-
cargo build
18-
cargo build --no-default-features --features with-uds
19-
cargo test
20-
cargo test --no-default-features --features with-uds
21-
cargo test --no-default-features
22-
cargo test --doc
23-
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps
24-
cargo clippy -- -D warnings
14+
just ci-test

.github/workflows/ci.yml

+58-6
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,70 @@ name: CI
22

33
on:
44
push:
5-
branches: [main]
5+
branches: [ main ]
66
pull_request:
7-
branches: [main]
7+
branches: [ main ]
88
release:
9-
types: [published]
9+
types: [ published ]
1010
workflow_dispatch:
1111

1212
jobs:
13-
build:
14-
name: Build
13+
test:
14+
name: Test
1515
runs-on: ubuntu-latest
1616
steps:
17+
- uses: taiki-e/install-action@v2
18+
with: { tool: just }
1719
- uses: actions/checkout@v4
1820
- uses: Swatinem/rust-cache@v2
19-
- run: source .cargo-husky/hooks/pre-push
21+
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
22+
- run: just ci-test
23+
- name: Check semver
24+
uses: obi1kenobi/cargo-semver-checks-action@v2
25+
- name: Get local and published versions
26+
id: get-versions
27+
run: |
28+
echo "local_version=$(grep '^version =' Cargo.toml | sed -E 's/version = "([^"]*)".*/\1/')" >> $GITHUB_OUTPUT
29+
CRATE_NAME=$(grep '^name =' Cargo.toml | head -1 | sed -E 's/name = "(.*)"/\1/')
30+
PUBLISHED_VERSION=$(cargo search ${CRATE_NAME} | grep "^${CRATE_NAME} =" | sed -E 's/.* = "(.*)".*/\1/')
31+
echo "published_version=${PUBLISHED_VERSION}" >> $GITHUB_OUTPUT
32+
- name: Test that we haven't published current version yet
33+
run: |
34+
LOCAL_VERSION=${{ steps.get-versions.outputs.local_version }}
35+
PUBLISHED_VERSION=${{ steps.get-versions.outputs.published_version }}
36+
if [ "$LOCAL_VERSION" = "$PUBLISHED_VERSION" ]; then
37+
echo "The current crate version ($LOCAL_VERSION) has already been published."
38+
exit 1
39+
else
40+
echo "The current crate version ($LOCAL_VERSION) has not been published yet."
41+
fi
42+
43+
msrv:
44+
name: Test MSRV
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: taiki-e/install-action@v2
48+
with: { tool: just }
49+
- uses: actions/checkout@v4
50+
- uses: Swatinem/rust-cache@v2
51+
if: github.event_name != 'release' && github.event_name != 'workflow_dispatch'
52+
- name: Read crate metadata
53+
id: metadata
54+
run: echo "rust-version=$(sed -ne 's/rust-version *= *\"\(.*\)\"/\1/p' Cargo.toml)" >> $GITHUB_OUTPUT
55+
- name: Install Rust
56+
uses: dtolnay/rust-toolchain@stable
57+
with:
58+
toolchain: ${{ steps.metadata.outputs.rust-version }}
59+
- run: just ci-test-msrv
60+
61+
publish:
62+
name: Publish to crates.io
63+
if: startsWith(github.ref, 'refs/tags/')
64+
needs: [ test, msrv ]
65+
runs-on: ubuntu-latest
66+
steps:
67+
- uses: actions/checkout@v4
68+
- name: Publish to crates.io
69+
run: cargo publish
70+
env:
71+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

Cargo.toml

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "automotive_diag"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
description = "Core definitions for various Automotive ECU Diagnostics such as UDS ISO-14229, KWP2000, OBD-II, etc."
55
authors = ["Yuri Astrakhan <[email protected]>", "Ashcon Mohseninia <[email protected]>"]
66
repository = "https://github.com/nyurik/automotive_diag"
@@ -29,3 +29,12 @@ displaydoc = { version = "0.2", optional = true }
2929

3030
[dev-dependencies]
3131
cargo-husky = { version = "1", features = ["user-hooks"], default-features = false }
32+
33+
[lints.rust]
34+
unsafe_code = "forbid"
35+
unused_qualifications = "warn"
36+
37+
[lints.clippy]
38+
pedantic = { level = "warn", priority = -1 }
39+
missing_errors_doc = "allow"
40+
module_name_repetitions = "allow"

LICENSE-MIT

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MIT License
22

33
Copyright (c) 2021 Ashcon Mohseninia
4-
Copyright (c) 2023 Yuri Astrakhan
4+
Copyright (c) 2023-2024 Yuri Astrakhan
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal

README.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# automotive_diag
1+
# Automotive diagnostics in Rust
22

33
[![GitHub](https://img.shields.io/badge/github-nyurik/automotive_diag-8da0cb?logo=github)](https://github.com/nyurik/automotive_diag)
44
[![crates.io version](https://img.shields.io/crates/v/automotive_diag.svg)](https://crates.io/crates/automotive_diag)
55
[![docs.rs docs](https://docs.rs/automotive_diag/badge.svg)](https://docs.rs/automotive_diag)
66
[![crates.io version](https://img.shields.io/crates/l/automotive_diag.svg)](https://github.com/nyurik/automotive_diag/blob/main/LICENSE-APACHE)
77
[![CI build](https://github.com/nyurik/automotive_diag/actions/workflows/ci.yml/badge.svg)](https://github.com/nyurik/automotive_diag/actions)
88

9-
This crate provides low-level no_std structs and enums of
9+
This crate provides low-level `no_std` structs and enums of
1010
the [Unified Diagnostic Services](https://en.wikipedia.org/wiki/Unified_Diagnostic_Services) (ISO-14229-1),
1111
[KWP2000](https://en.wikipedia.org/wiki/Keyword_Protocol_2000) (ISO-142330) and
1212
[OBD-II](https://en.wikipedia.org/wiki/On-board_diagnostics) (ISO-9141)
@@ -29,20 +29,20 @@ use automotive_diag::uds::UdsCommandByte;
2929

3030
/// Handle a single command byte on the ECU side
3131
fn handle_cmd_byte(cmd: u8) {
32-
match UdsCommandByte::from(cmd) {
33-
Standard(DiagnosticSessionControl) => {
34-
// handle_diag_session()
32+
match UdsCommandByte::from(cmd) {
33+
Standard(DiagnosticSessionControl) => {
34+
// handle_diag_session()
35+
}
36+
Standard(ECUReset) => {
37+
// handle_ecu_reset()
38+
}
39+
Extended(0x42) => {
40+
// handle_custom_cmd_42()
41+
}
42+
_ => {
43+
// handle all other commands
44+
}
3545
}
36-
Standard(ECUReset) => {
37-
// handle_ecu_reset()
38-
}
39-
Extended(0x42) => {
40-
// handle_custom_cmd_42()
41-
}
42-
_ => {
43-
// handle all other commands
44-
}
45-
}
4646
}
4747
```
4848

justfile

+28-7
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,46 @@ clean:
88
cargo clean
99
rm -f Cargo.lock
1010

11-
# Run cargo fmt and cargo clippy
12-
lint: fmt clippy
11+
# Run cargo clippy
12+
clippy:
13+
cargo clippy --bins --tests --lib --benches --examples -- -D warnings
14+
cargo clippy --no-default-features -- -D warnings
15+
16+
# Test code formatting
17+
test-fmt:
18+
cargo fmt --all -- --check
1319

1420
# Run cargo fmt
1521
fmt:
1622
cargo +nightly fmt -- --config imports_granularity=Module,group_imports=StdExternalCrate
1723

18-
# Run cargo clippy
19-
clippy:
20-
cargo clippy --workspace --all-targets --bins --tests --lib --benches -- -D warnings
21-
2224
# Build and open code documentation
2325
docs:
2426
cargo doc --no-deps --open
2527

28+
# Quick compile
29+
check:
30+
RUSTFLAGS='-D warnings' cargo check
31+
RUSTFLAGS='-D warnings' cargo check --no-default-features --features with-uds
32+
33+
2634
# Run all tests
2735
test:
28-
./.cargo-husky/hooks/pre-push
36+
RUSTFLAGS='-D warnings' cargo test
37+
RUSTFLAGS='-D warnings' cargo test --no-default-features --features with-uds
38+
RUSTFLAGS='-D warnings' cargo test --no-default-features
2939

3040
# Test documentation
3141
test-doc:
3242
cargo test --doc
43+
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps
44+
45+
# Run all tests as expected by CI
46+
ci-test: && test-fmt clippy check test test-doc
47+
rustc --version
48+
cargo --version
49+
50+
# Run minimal subset of tests to ensure compatibility with MSRV
51+
ci-test-msrv: && check test
52+
rustc --version
53+
cargo --version

src/kwp2000/commands.rs

-11
Original file line numberDiff line numberDiff line change
@@ -35,34 +35,23 @@ pub enum KwpCommand {
3535
DisableNormalMessageTransmission = 0x28,
3636
/// Enables normal CAN message transmission from an ECU.
3737
EnableNormalMessageTransmission = 0x29,
38-
///
3938
DynamicallyDefineLocalIdentifier = 0x2C,
40-
///
4139
WriteDataByIdentifier = 0x2E,
42-
///
4340
InputOutputControlByLocalIdentifier = 0x30,
4441
/// Starts a ECU routine given a local identifier.
4542
StartRoutineByLocalIdentifier = 0x31,
4643
/// Stops a ECU routine given a local identifier.
4744
StopRoutineByLocalIdentifier = 0x32,
4845
/// requests results of an executed routine given a local identifier.
4946
RequestRoutineResultsByLocalIdentifier = 0x33,
50-
///
5147
RequestDownload = 0x34,
52-
///
5348
RequestUpload = 0x35,
54-
///
5549
TransferData = 0x36,
56-
///
5750
RequestTransferExit = 0x37,
58-
///
5951
WriteDataByLocalIdentifier = 0x3B,
60-
///
6152
WriteMemoryByAddress = 0x3D,
6253
/// Tester present message.
6354
TesterPresent = 0x3E,
64-
///
6555
ControlDTCSettings = 0x85,
66-
///
6756
ResponseOnEvent = 0x86,
6857
}

src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#![cfg_attr(feature = "default", doc = include_str!("../README.md"))]
22
#![cfg_attr(not(feature = "std"), no_std)]
3-
#![forbid(unsafe_code)]
4-
#![deny(clippy::all, clippy::pedantic)]
5-
#![allow(clippy::missing_errors_doc, clippy::module_name_repetitions)]
63

74
#[cfg(feature = "with-kwp2000")]
85
pub mod kwp2000;

src/obd2/obd_standard.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ enum_wrapper!(obd2, ObdStandard, ObdStandardByte);
99
#[repr(u8)]
1010
#[derive(EnumRepr, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
1111
#[cfg_attr(feature = "display", derive(displaydoc::Display))]
12+
#[allow(clippy::doc_markdown)]
1213
pub enum ObdStandard {
1314
/// OBD-II as defined by the CARB
1415
OBD_II_CARB = 1,

src/uds/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub enum UdsError {
4646
/// The client has tried to obtain security access to the ECU too many times with
4747
/// incorrect keys
4848
ExceedNumberOfAttempts = 0x36,
49-
/// The client has tried to request seed_key's too quickly, before the ECU timeout's period
49+
/// The client has tried to request `seed_key`'s too quickly, before the ECU timeout's period
5050
/// has expired
5151
RequiredTimeDelayNotExpired = 0x37,
5252
/// The ECU cannot accept the requested upload/download request due to a fault condition

src/uds/read_dtc_information.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ enum_wrapper!(uds, DtcSubFunction, DtcSubFunctionByte);
1010
#[repr(u8)]
1111
#[derive(EnumRepr, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
1212
#[cfg_attr(feature = "display", derive(displaydoc::Display))]
13+
#[allow(clippy::doc_markdown)]
1314
pub enum DtcSubFunction {
1415
/// This function takes a 1 byte DTCStatusMask
1516
ReportNumberOfDtcByStatusMask = 0x01,

src/uds/reset_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub enum ResetType {
3030
/// Enables a rapid power shutdown on the ECU during a key-off cycle.
3131
///
3232
/// IMPORTANT: Once this has been used, the diagnostic server **cannot** send
33-
/// any other messages other than ECUReset in order to not disturb the rapid power
33+
/// any other messages other than `ECUReset` in order to not disturb the rapid power
3434
/// shutdown function.
3535
EnableRapidPowerShutDown = 0x04,
3636

src/uds/session_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ enum_wrapper!(uds, UdsSessionType, UdsSessionTypeByte);
99
#[derive(EnumRepr, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
1010
pub enum UdsSessionType {
1111
/// Default diagnostic session mode (ECU is normally in this mode on startup)
12-
/// This session type does not require the diagnostic server to sent TesterPresent messages
12+
/// This session type does not require the diagnostic server to sent `TesterPresent` messages
1313
Default = 0x01,
1414

1515
/// This diagnostic session mode enables all diagnostic services related to flashing or programming

0 commit comments

Comments
 (0)