Skip to content

Commit eb8fc7a

Browse files
committed
Fix clippy warnings and enforce clippy in CI
1 parent 584f458 commit eb8fc7a

15 files changed

Lines changed: 48 additions & 50 deletions

File tree

.github/workflows/rust-clippy.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ jobs:
4848
fi
4949
5050
- name: Run rust-clippy
51-
run: cargo clippy --all-features --message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
52-
continue-on-error: true
51+
run: cargo clippy -p rustiflow --all-targets --message-format=json -- -D warnings | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt
5352

5453
- name: Upload analysis results to GitHub
5554
uses: github/codeql-action/upload-sarif@v3

.github/workflows/rust.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ jobs:
3737
- name: Build userspace program
3838
run: cargo build --verbose
3939

40+
- name: Run Clippy
41+
run: cargo clippy -p rustiflow --all-targets -- -D warnings
42+
4043
- name: Fetch gh-pages branch
4144
run: git fetch origin gh-pages:gh-pages
4245

common/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct EbpfEventIpv4 {
2525
}
2626

2727
impl EbpfEventIpv4 {
28+
#[allow(clippy::too_many_arguments)]
2829
pub fn new(
2930
timestamp_ns: u64,
3031
ipv4_destination: u32,
@@ -89,6 +90,7 @@ pub struct EbpfEventIpv6 {
8990
}
9091

9192
impl EbpfEventIpv6 {
93+
#[allow(clippy::too_many_arguments)]
9294
pub fn new(
9395
timestamp_ns: u64,
9496
ipv6_destination: u128,
@@ -150,10 +152,10 @@ impl NetworkHeader for TcpHdr {
150152
self.dest
151153
}
152154
fn window_size(&self) -> u16 {
153-
self.window as u16
155+
self.window
154156
}
155157
fn combined_flags(&self) -> u8 {
156-
((self.fin() as u8) << 0)
158+
(self.fin() as u8)
157159
| ((self.syn() as u8) << 1)
158160
| ((self.rst() as u8) << 2)
159161
| ((self.psh() as u8) << 3)

rustiflow/src/args.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use clap::{ArgGroup, Args, Parser, Subcommand};
22
use serde::{Deserialize, Serialize};
3+
use std::fmt;
34
use strum_macros::{EnumString, VariantNames};
45

56
#[derive(Debug, Parser)]
@@ -79,17 +80,18 @@ pub enum Commands {
7980
},
8081
}
8182

82-
impl ToString for Commands {
83-
fn to_string(&self) -> String {
83+
impl fmt::Display for Commands {
84+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8485
match self {
8586
Commands::Realtime {
8687
interface,
8788
ingress_only,
88-
} => format!(
89+
} => write!(
90+
f,
8991
"Realtime/Interface: {}/Ingress only: {}",
9092
interface, ingress_only
9193
),
92-
Commands::Pcap { path } => format!("Pcap/Path: {}", path),
94+
Commands::Pcap { path } => write!(f, "Pcap/Path: {}", path),
9395
}
9496
}
9597
}
@@ -155,6 +157,7 @@ pub enum ExportMethodType {
155157
Csv,
156158
}
157159

160+
#[allow(clippy::upper_case_acronyms)]
158161
#[derive(Serialize, Deserialize, clap::ValueEnum, Clone, Debug, EnumString, VariantNames)]
159162
#[strum(serialize_all = "kebab_case")]
160163
pub enum FlowType {

rustiflow/src/flow_table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ where
200200
async fn check_and_export_expired_flows(&mut self, current_time_us: i64) {
201201
if self
202202
.next_check_time_us
203-
.map_or(true, |next_check| current_time_us >= next_check)
203+
.is_none_or(|next_check| current_time_us >= next_check)
204204
{
205205
self.export_expired_flows(current_time_us).await;
206206
self.next_check_time_us = Some(current_time_us + self.expiration_check_interval_us);

rustiflow/src/flow_tui.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,14 @@ async fn run_app<B: Backend>(
8080
tokio::select! {
8181
Ok(_) = packet_rx.changed() => {
8282
let counts = packet_rx.borrow();
83-
app.update_packet_data(&*counts);
83+
app.update_packet_data(&counts);
8484
}
8585

8686
poll_result = task::spawn_blocking(|| crossterm::event::poll(Duration::from_millis(100))) => {
8787
if poll_result?? {
8888
if let Event::Key(key) = event::read()? {
89-
match key.code {
90-
KeyCode::Char('q') => return Ok(()),
91-
_ => {}
89+
if let KeyCode::Char('q') = key.code {
90+
return Ok(());
9291
}
9392
}
9493
}

rustiflow/src/flows/basic_flow.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl Flow for BasicFlow {
300300
false
301301
}
302302

303-
fn close_flow(&mut self, _timestamp_us: i64, cause: FlowExpireCause) -> () {
303+
fn close_flow(&mut self, _timestamp_us: i64, cause: FlowExpireCause) {
304304
self.flow_expire_cause = cause;
305305
self.update_tcp_close_style(cause);
306306
}
@@ -322,10 +322,9 @@ impl Flow for BasicFlow {
322322
}
323323

324324
fn get_features() -> String {
325-
format!(
326-
"flow_id,source_ip,source_port,destination_ip,destination_port,protocol,\
325+
"flow_id,source_ip,source_port,destination_ip,destination_port,protocol,\
327326
first_timestamp,last_timestamp,duration,flow_expire_cause"
328-
)
327+
.to_string()
329328
}
330329

331330
fn dump_without_contamination(&self) -> String {
@@ -340,7 +339,7 @@ impl Flow for BasicFlow {
340339
}
341340

342341
fn get_features_without_contamination() -> String {
343-
format!("src_port_iana,dst_port_iana,protocol,duration,flow_expire_cause")
342+
"src_port_iana,dst_port_iana,protocol,duration,flow_expire_cause".to_string()
344343
}
345344

346345
fn get_first_timestamp_us(&self) -> i64 {

rustiflow/src/flows/custom_flow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl Flow for CustomFlow {
8181

8282
fn get_features() -> String {
8383
// Add here the features of the custom flow.
84-
format!("flow_id,icmp_type,icmp_code,icmp_echo_request_count,icmp_echo_reply_count,icmp_error_count,icmp_destination_unreachable_count")
84+
"flow_id,icmp_type,icmp_code,icmp_echo_request_count,icmp_echo_reply_count,icmp_error_count,icmp_destination_unreachable_count".to_string()
8585
}
8686

8787
fn dump_without_contamination(&self) -> String {
@@ -99,7 +99,7 @@ impl Flow for CustomFlow {
9999

100100
fn get_features_without_contamination() -> String {
101101
// Add here the features of the custom flow without contaminant features.
102-
format!("icmp_type,icmp_code,icmp_echo_request_count,icmp_echo_reply_count,icmp_error_count,icmp_destination_unreachable_count")
102+
"icmp_type,icmp_code,icmp_echo_request_count,icmp_echo_reply_count,icmp_error_count,icmp_destination_unreachable_count".to_string()
103103
}
104104

105105
fn get_first_timestamp_us(&self) -> i64 {

rustiflow/src/flows/features/bulk_stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl FlowFeature for BulkStats {
116116
let current_ts = packet.timestamp_us / 1000;
117117
// 1. Skip zero-length packets
118118
let packet_len = packet.length;
119-
if packet_len <= 0 {
119+
if packet_len == 0 {
120120
return;
121121
}
122122

rustiflow/src/flows/features/icmp_stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl IcmpStats {
5454
self.error_count += 1;
5555
self.destination_unreachable_count += 1;
5656
}
57-
Some(2 | 3 | 4) => self.error_count += 1,
57+
Some(2..=4) => self.error_count += 1,
5858
_ => {}
5959
},
6060
_ => {}

0 commit comments

Comments
 (0)