Skip to content

Commit

Permalink
Merge pull request #19 from pmcgleenon/clippy-ci
Browse files Browse the repository at this point in the history
Clippy warnings
  • Loading branch information
jfernandez authored Feb 29, 2024
2 parents 661aa0b + 12e6c67 commit ec29ec8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
sudo apt-get install -y zlib1g-dev libelf-dev
- name: Test
run: cargo test
- name: clippy
run: cargo clippy --all --tests --all-features --no-deps
- name: Build
run: cargo build --release
- name: Create Release and Upload Artficat
Expand All @@ -33,4 +35,4 @@ jobs:
artifacts: "target/release/bpftop"
draft: true
allowUpdates: true
updateOnlyUnreleased: true
updateOnlyUnreleased: true
11 changes: 4 additions & 7 deletions src/app.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ impl App {
let items = self.items.lock().unwrap();
let state = self.state.lock().unwrap();

match state.selected() {
Some(i) => Some(items[i].clone()),
None => None,
}
state.selected().map(|i| items[i].clone())
}
pub fn next_program(&mut self) {
let items = self.items.lock().unwrap();
Expand Down Expand Up @@ -320,11 +317,11 @@ mod tests {
let mut app = App::new();

// Initially, show_graphs is false
assert_eq!(app.show_graphs, false);
assert!(!app.show_graphs);

// After calling toggle_graphs, show_graphs should be true
app.toggle_graphs();
assert_eq!(app.show_graphs, true);
assert!(app.show_graphs);

// Set max_cpu, max_eps, and max_runtime to non-zero values
app.max_cpu = 10.0;
Expand All @@ -338,7 +335,7 @@ mod tests {

// After calling toggle_graphs, show_graphs should be false again
app.toggle_graphs();
assert_eq!(app.show_graphs, false);
assert!(!app.show_graphs);

// max_cpu, max_eps, and max_runtime should be reset to 0
assert_eq!(app.max_cpu, 0.0);
Expand Down
13 changes: 5 additions & 8 deletions src/main.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ fn main() -> Result<()> {
terminal.show_cursor()?;
terminal.clear()?;

#[allow(clippy::question_mark)]
if res.is_err() {
return res;
}
Expand Down Expand Up @@ -139,9 +140,8 @@ fn run_draw_loop<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> Result
}
_ => {}
}
match (key.modifiers, key.code) {
(KeyModifiers::CONTROL, KeyCode::Char('c')) => return Ok(()),
_ => {}
if let (KeyModifiers::CONTROL, KeyCode::Char('c')) = (key.modifiers, key.code) {
return Ok(())
}
}
}
Expand Down Expand Up @@ -210,7 +210,7 @@ fn render_graphs(f: &mut Frame, app: &mut App, area: Rect) {
total_runtime += val.average_runtime_ns;
}

let max_cpu = moving_max_cpu as f64;
let max_cpu = moving_max_cpu;
let max_eps = moving_max_eps as f64;
let max_runtime = moving_max_runtime as f64;
let avg_cpu = total_cpu / data_buf.len() as f64;
Expand Down Expand Up @@ -417,10 +417,7 @@ fn render_footer(f: &mut Frame, app: &mut App, area: Rect) {
}

fn running_as_root() -> bool {
match nix::unistd::getuid().as_raw() {
0 => true,
_ => false,
}
matches!(nix::unistd::getuid().as_raw(), 0)
}

fn format_percent(num: f64) -> String {
Expand Down

0 comments on commit ec29ec8

Please sign in to comment.