From 16347d7209f1f4790ff525cc7ed874060da49b11 Mon Sep 17 00:00:00 2001 From: Jimmy Cuadra Date: Sun, 2 Jun 2019 18:42:36 -0700 Subject: [PATCH] Add rustfmt and clippy to CI and address clippy warnings. --- .rustfmt.toml | 1 - .travis.yml | 8 ++++++++ src/collections/all.rs | 11 +++++------ src/collections/only.rs | 11 +++++------ src/direct.rs | 2 +- src/stripped.rs | 5 ++--- 6 files changed, 21 insertions(+), 17 deletions(-) delete mode 100644 .rustfmt.toml diff --git a/.rustfmt.toml b/.rustfmt.toml deleted file mode 100644 index 7d2cf549..00000000 --- a/.rustfmt.toml +++ /dev/null @@ -1 +0,0 @@ -merge_imports = true diff --git a/.travis.yml b/.travis.yml index ab3ceab4..3f30b4bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,12 @@ language: "rust" +before_script: + - "rustup component add rustfmt" + - "rustup component add clippy" +script: + - "cargo fmt --all -- --check" + - "cargo clippy --all-targets --all-features -- -D warnings" + - "cargo build --verbose" + - "cargo test --verbose" notifications: email: false irc: diff --git a/src/collections/all.rs b/src/collections/all.rs index 6347d9bd..dc4a46a5 100644 --- a/src/collections/all.rs +++ b/src/collections/all.rs @@ -26,6 +26,7 @@ use serde_json::{from_value, Value}; /// A basic event, room event, or state event. #[derive(Clone, Debug)] +#[allow(clippy::large_enum_variant)] pub enum Event { /// m.call.answer CallAnswer(AnswerEvent), @@ -85,6 +86,7 @@ pub enum Event { /// A room event or state event. #[derive(Clone, Debug)] +#[allow(clippy::large_enum_variant)] pub enum RoomEvent { /// m.call.answer CallAnswer(AnswerEvent), @@ -132,6 +134,7 @@ pub enum RoomEvent { /// A state event. #[derive(Clone, Debug)] +#[allow(clippy::large_enum_variant)] pub enum StateEvent { /// m.room.aliases RoomAliases(AliasesEvent), @@ -663,9 +666,7 @@ impl<'de> Deserialize<'de> for RoomEvent { | EventType::Presence | EventType::Receipt | EventType::Tag - | EventType::Typing => { - return Err(D::Error::custom("not a room event".to_string())); - } + | EventType::Typing => Err(D::Error::custom("not a room event".to_string())), } } } @@ -834,9 +835,7 @@ impl<'de> Deserialize<'de> for StateEvent { | EventType::RoomMessage | EventType::RoomRedaction | EventType::Tag - | EventType::Typing => { - return Err(D::Error::custom("not a state event".to_string())); - } + | EventType::Typing => Err(D::Error::custom("not a state event".to_string())), } } } diff --git a/src/collections/only.rs b/src/collections/only.rs index e3091d2e..c1b48e78 100644 --- a/src/collections/only.rs +++ b/src/collections/only.rs @@ -37,6 +37,7 @@ pub enum Event { /// A room event. #[derive(Clone, Debug)] +#[allow(clippy::large_enum_variant)] pub enum RoomEvent { /// m.call.answer CallAnswer(AnswerEvent), @@ -154,11 +155,9 @@ impl<'de> Deserialize<'de> for Event { | EventType::RoomPowerLevels | EventType::RoomRedaction | EventType::RoomThirdPartyInvite - | EventType::RoomTopic => { - return Err(D::Error::custom( - "not exclusively a basic event".to_string(), - )); - } + | EventType::RoomTopic => Err(D::Error::custom( + "not exclusively a basic event".to_string(), + )), } } } @@ -272,7 +271,7 @@ impl<'de> Deserialize<'de> for RoomEvent { | EventType::RoomTopic | EventType::Tag | EventType::Typing => { - return Err(D::Error::custom("not exclusively a room event".to_string())); + Err(D::Error::custom("not exclusively a room event".to_string())) } } } diff --git a/src/direct.rs b/src/direct.rs index bc72fe0a..ffa786fe 100644 --- a/src/direct.rs +++ b/src/direct.rs @@ -38,7 +38,7 @@ mod tests { content.insert(alice.clone(), room.clone()); let event = DirectEvent { - content: content, + content, event_type: EventType::Direct, }; diff --git a/src/stripped.rs b/src/stripped.rs index e4e669a7..650b928c 100644 --- a/src/stripped.rs +++ b/src/stripped.rs @@ -23,6 +23,7 @@ use crate::{ /// A stripped-down version of a state event that is included along with some other events. #[derive(Clone, Debug)] +#[allow(clippy::large_enum_variant)] pub enum StrippedState { /// A stripped-down version of the *m.room.aliases* event. RoomAliases(StrippedRoomAliases), @@ -211,9 +212,7 @@ impl<'de> Deserialize<'de> for StrippedState { Ok(StrippedState::RoomTopic(event)) } - _ => { - return Err(D::Error::custom("not a state event".to_string())); - } + _ => Err(D::Error::custom("not a state event".to_string())), } } }