summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorebroto <ebroto@tutanota.com>2019-12-18 20:19:44 +0100
committerGitHub <noreply@github.com>2019-12-18 20:19:44 +0100
commitd62bf8a8eb11935767fbb9442c5955e0879a1801 (patch)
tree089b711721a9c4aac2e461a2fa7211d7ba5de266
parenta9d72f358fca4dbe7cedd07f02e7ea20b9b5bdc1 (diff)
parent9e6f390c1f34de0d0b413f4704fc2d1f655c47bc (diff)
Merge pull request #22 from ebroto/clippy-in-ci
Run clippy and rustfmt in the CI
-rw-r--r--.travis.yml15
-rw-r--r--rustfmt.toml1
-rw-r--r--src/display/components/table.rs2
-rw-r--r--src/display/ui.rs2
-rw-r--r--src/main.rs8
-rw-r--r--src/network/connection.rs4
-rw-r--r--src/network/sniffer.rs2
-rw-r--r--src/os/lsof_utils.rs2
-rw-r--r--src/os/shared.rs5
-rw-r--r--src/tests/cases/raw_mode.rs2
-rw-r--r--src/tests/fakes/fake_input.rs11
11 files changed, 38 insertions, 16 deletions
diff --git a/.travis.yml b/.travis.yml
index 8c91a74..df70939 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,7 +2,20 @@ language: rust
rust:
- stable
- beta
- - nightly
+before_script:
+ - rustup component add rustfmt clippy
+script:
+ - set -e # Abort on failure, see https://github.com/travis-ci/travis-ci/issues/1066
+ - cargo fmt -- --check
+ - cargo build --verbose
+ - cargo test --verbose
+ - cargo clippy --all-targets --all-features -- -D warnings
matrix:
+ include:
+ - rust: nightly
+ before_script:
+ - rustup component add rustfmt
+ # Fallback to git in case clippy is not available in the current nightly
+ - rustup component add clippy --toolchain=nightly || cargo install --git https://github.com/rust-lang/rust-clippy/ --force clippy
allow_failures:
- rust: nightly
diff --git a/rustfmt.toml b/rustfmt.toml
new file mode 100644
index 0000000..32a9786
--- /dev/null
+++ b/rustfmt.toml
@@ -0,0 +1 @@
+edition = "2018"
diff --git a/src/display/components/table.rs b/src/display/components/table.rs
index f59536e..74e207a 100644
--- a/src/display/components/table.rs
+++ b/src/display/components/table.rs
@@ -85,7 +85,7 @@ impl<'a> Table<'a> {
.iter()
.map(|(process_name, data_for_process)| {
vec![
- process_name.to_string(),
+ (*process_name).to_string(),
data_for_process.connection_count.to_string(),
display_upload_and_download(*data_for_process),
]
diff --git a/src/display/ui.rs b/src/display/ui.rs
index f2e3f25..3fcb092 100644
--- a/src/display/ui.rs
+++ b/src/display/ui.rs
@@ -34,7 +34,7 @@ where
ip_to_host: Default::default(),
}
}
- pub fn output_text(&mut self, write_to_stdout: &mut Box<dyn FnMut(String) + Send>) {
+ pub fn output_text(&mut self, write_to_stdout: &mut (dyn FnMut(String) + Send)) {
let state = &self.state;
let ip_to_host = &self.ip_to_host;
let local_time: DateTime<Local> = Local::now();
diff --git a/src/main.rs b/src/main.rs
index d499432..9022cfa 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,5 @@
+#![deny(clippy::all)]
+
mod display;
mod network;
mod os;
@@ -9,6 +11,7 @@ use network::{
dns::{self, IpTable},
Connection, Sniffer, Utilization,
};
+use os::OnSigWinch;
use ::pnet::datalink::{DataLinkReceiver, NetworkInterface};
use ::std::collections::HashMap;
@@ -80,12 +83,12 @@ pub struct OsInputOutput {
pub get_open_sockets: fn() -> HashMap<Connection, String>,
pub keyboard_events: Box<dyn Iterator<Item = Event> + Send>,
pub dns_client: Option<dns::Client>,
- pub on_winch: Box<dyn Fn(Box<dyn Fn()>) + Send>,
+ pub on_winch: Box<OnSigWinch>,
pub cleanup: Box<dyn Fn() + Send>,
pub write_to_stdout: Box<dyn FnMut(String) + Send>,
}
-pub fn start<'a, B>(terminal_backend: B, os_input: OsInputOutput, opts: Opt)
+pub fn start<B>(terminal_backend: B, os_input: OsInputOutput, opts: Opt)
where
B: Backend + Send + 'static,
{
@@ -130,7 +133,6 @@ where
.spawn({
let running = running.clone();
let network_utilization = network_utilization.clone();
- let ui = ui.clone();
move || {
while running.load(Ordering::Acquire) {
let render_start_time = Instant::now();
diff --git a/src/network/connection.rs b/src/network/connection.rs
index 75edf86..f931d54 100644
--- a/src/network/connection.rs
+++ b/src/network/connection.rs
@@ -11,8 +11,8 @@ pub enum Protocol {
}
impl Protocol {
- pub fn from_string(string: &String) -> Option<Self> {
- match string.as_str() {
+ pub fn from_str(string: &str) -> Option<Self> {
+ match string {
"TCP" => Some(Protocol::Tcp),
"UDP" => Some(Protocol::Udp),
_ => None,
diff --git a/src/network/sniffer.rs b/src/network/sniffer.rs
index 0d68a20..3ec6886 100644
--- a/src/network/sniffer.rs
+++ b/src/network/sniffer.rs
@@ -26,7 +26,7 @@ pub enum Direction {
}
impl Direction {
- pub fn new(network_interface_ips: &Vec<IpNetwork>, ip_packet: &Ipv4Packet) -> Self {
+ pub fn new(network_interface_ips: &[IpNetwork], ip_packet: &Ipv4Packet) -> Self {
if network_interface_ips
.iter()
.any(|ip_network| ip_network.ip() == ip_packet.get_source())
diff --git a/src/os/lsof_utils.rs b/src/os/lsof_utils.rs
index 9f6b479..93d68fe 100644
--- a/src/os/lsof_utils.rs
+++ b/src/os/lsof_utils.rs
@@ -45,7 +45,7 @@ impl RawConnection {
}
pub fn get_protocol(&self) -> Protocol {
- return Protocol::from_string(&self.protocol).unwrap();
+ return Protocol::from_str(&self.protocol).unwrap();
}
pub fn get_ip_address(&self) -> IpAddr {
diff --git a/src/os/shared.rs b/src/os/shared.rs
index 313b941..8947ecb 100644
--- a/src/os/shared.rs
+++ b/src/os/shared.rs
@@ -15,6 +15,9 @@ use crate::os::linux::get_open_sockets;
use crate::os::macos::get_open_sockets;
use crate::{network::dns, OsInputOutput};
+pub type OnSigWinch = dyn Fn(Box<dyn Fn()>) + Send;
+pub type SigCleanup = dyn Fn() + Send;
+
pub struct KeyboardEvents;
impl Iterator for KeyboardEvents {
@@ -45,7 +48,7 @@ fn get_interface(interface_name: &str) -> Option<NetworkInterface> {
.find(|iface| iface.name == interface_name)
}
-fn sigwinch() -> (Box<dyn Fn(Box<dyn Fn()>) + Send>, Box<dyn Fn() + Send>) {
+fn sigwinch() -> (Box<OnSigWinch>, Box<SigCleanup>) {
let signals = Signals::new(&[signal_hook::SIGWINCH]).unwrap();
let on_winch = {
let signals = signals.clone();
diff --git a/src/tests/cases/raw_mode.rs b/src/tests/cases/raw_mode.rs
index 26a1801..f0989ca 100644
--- a/src/tests/cases/raw_mode.rs
+++ b/src/tests/cases/raw_mode.rs
@@ -37,7 +37,7 @@ fn build_tcp_packet(
pkt.packet().to_vec()
}
-fn format_raw_output<'t>(output: Vec<u8>) -> String {
+fn format_raw_output(output: Vec<u8>) -> String {
let stdout_utf8 = String::from_utf8(output).unwrap();
use regex::Regex;
let timestamp = Regex::new(r"<\d+>").unwrap();
diff --git a/src/tests/fakes/fake_input.rs b/src/tests/fakes/fake_input.rs
index 889e708..b3b089b 100644
--- a/src/tests/fakes/fake_input.rs
+++ b/src/tests/fakes/fake_input.rs
@@ -10,9 +10,12 @@ use ::std::task::{Context, Poll};
use ::std::{thread, time};
use ::termion::event::Event;
-use crate::network::{
- dns::{self, Lookup},
- Connection, Protocol,
+use crate::{
+ network::{
+ dns::{self, Lookup},
+ Connection, Protocol,
+ },
+ os::OnSigWinch,
};
pub struct KeyboardEvents {
@@ -142,7 +145,7 @@ pub fn get_interface() -> NetworkInterface {
}
}
-pub fn create_fake_on_winch(should_send_winch_event: bool) -> Box<dyn Fn(Box<dyn Fn()>) + Send> {
+pub fn create_fake_on_winch(should_send_winch_event: bool) -> Box<OnSigWinch> {
Box::new(move |cb| {
if should_send_winch_event {
thread::sleep(time::Duration::from_millis(900));