diff --git a/.cargo/config b/.cargo/config index d43b6746..331d3b33 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,5 +1,27 @@ [alias] xtask = "run --package xtask --" +ruma-clippy = """\ + clippy --workspace --all-targets --all-features --quiet -- \ + -W rust_2018_idioms \ + -W semicolon_in_expressions_from_macros \ + -W unused_import_braces \ + -W unused_qualifications \ + -W clippy::branches_sharing_code \ + -W clippy::cloned_instead_of_copied \ + -W clippy::dbg_macro \ + -W clippy::empty_line_after_outer_attr \ + -W clippy::inefficient_to_string \ + -W clippy::macro_use_imports \ + -W clippy::map_flatten \ + -W clippy::mut_mut \ + -W clippy::needless_borrow \ + -A clippy::new_without_default \ + -W clippy::todo \ + -W clippy::unreadable_literal \ + -W clippy::unseparated_literal_suffix \ + -W clippy::useless_let_if_seq \ + -W clippy::wildcard_imports \ +""" [doc.extern-map.registries] crates-io = "https://docs.rs/" diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 00000000..1cf14c6d --- /dev/null +++ b/.clippy.toml @@ -0,0 +1 @@ +msrv = "1.45" diff --git a/contrib/ide/vscode/settings.json b/contrib/ide/vscode/settings.json index e0975d87..eed0a506 100644 --- a/contrib/ide/vscode/settings.json +++ b/contrib/ide/vscode/settings.json @@ -1,3 +1,4 @@ { - "rust-analyzer.cargo.allFeatures": true + "rust-analyzer.cargo.allFeatures": true, + "rust-analyzer.checkOnSave.command": "ruma-clippy" } diff --git a/crates/ruma-api/tests/conversions.rs b/crates/ruma-api/tests/conversions.rs index b521279e..fc21e0e2 100644 --- a/crates/ruma-api/tests/conversions.rs +++ b/crates/ruma-api/tests/conversions.rs @@ -1,5 +1,5 @@ use ruma_api::{ - ruma_api, IncomingRequest as _, OutgoingRequest as _, OutgoingRequestAppserviceExt as _, + ruma_api, IncomingRequest as _, OutgoingRequest as _, OutgoingRequestAppserviceExt, SendAccessToken, }; use ruma_identifiers::{user_id, UserId}; @@ -91,7 +91,7 @@ fn request_with_user_id_serde() { } mod without_query { - use super::*; + use super::{ruma_api, user_id, OutgoingRequestAppserviceExt, SendAccessToken, UserId}; ruma_api! { metadata: { diff --git a/crates/ruma-appservice-api/src/event/push_events/v1.rs b/crates/ruma-appservice-api/src/event/push_events/v1.rs index f0a3742b..9b94c5e5 100644 --- a/crates/ruma-appservice-api/src/event/push_events/v1.rs +++ b/crates/ruma-appservice-api/src/event/push_events/v1.rs @@ -170,7 +170,7 @@ mod tests { SendAccessToken::IfRequired("auth_tok"), ) .unwrap(); - let json_body: serde_json::Value = serde_json::from_slice(&req.body()).unwrap(); + let json_body: serde_json::Value = serde_json::from_slice(req.body()).unwrap(); assert_eq!( 1, diff --git a/crates/ruma-appservice-api/tests/appservice_registration.rs b/crates/ruma-appservice-api/tests/appservice_registration.rs index 26ef9800..7f00588f 100644 --- a/crates/ruma-appservice-api/tests/appservice_registration.rs +++ b/crates/ruma-appservice-api/tests/appservice_registration.rs @@ -18,7 +18,7 @@ fn registration_deserialization() { regex: "#_irc_bridge_.*" rooms: [] "##; - let observed = serde_yaml::from_str(®istration_config).unwrap(); + let observed = serde_yaml::from_str(registration_config).unwrap(); assert_matches!( observed, Registration { @@ -59,7 +59,7 @@ fn config_with_optional_url() { rooms: [] "#; assert_matches!( - serde_yaml::from_str(®istration_config).unwrap(), + serde_yaml::from_str(registration_config).unwrap(), Registration { url, .. } if url == "null" ); } diff --git a/crates/ruma-client-api/src/r0/contact/get_contacts.rs b/crates/ruma-client-api/src/r0/contact/get_contacts.rs index f21ad585..569e29d7 100644 --- a/crates/ruma-client-api/src/r0/contact/get_contacts.rs +++ b/crates/ruma-client-api/src/r0/contact/get_contacts.rs @@ -112,8 +112,8 @@ mod tests { let third_party_id_serialized = json!({ "medium": "email", "address": "monkey@banana.island", - "validated_at": 1_535_176_800_000u64, - "added_at": 1_535_336_848_756u64 + "validated_at": 1_535_176_800_000_u64, + "added_at": 1_535_336_848_756_u64 }); assert_eq!(to_json_value(third_party_id.clone()).unwrap(), third_party_id_serialized); diff --git a/crates/ruma-common/src/push.rs b/crates/ruma-common/src/push.rs index d45daffe..956f8d02 100644 --- a/crates/ruma-common/src/push.rs +++ b/crates/ruma-common/src/push.rs @@ -926,7 +926,7 @@ mod tests { let context_one_to_one = &PushConditionRoomCtx { room_id: room_id!("!dm:server.name"), - member_count: 2u32.into(), + member_count: 2_u32.into(), user_display_name: "Jolly Jumper".into(), users_power_levels: BTreeMap::new(), default_power_level: 50.into(), @@ -935,7 +935,7 @@ mod tests { let context_public_room = &PushConditionRoomCtx { room_id: room_id!("!far_west:server.name"), - member_count: 100u32.into(), + member_count: 100_u32.into(), user_display_name: "Jolly Jumper".into(), users_power_levels: BTreeMap::new(), default_power_level: 50.into(), @@ -1025,7 +1025,7 @@ mod tests { fn custom_ruleset_applies() { let context_one_to_one = &PushConditionRoomCtx { room_id: room_id!("!dm:server.name"), - member_count: 2u32.into(), + member_count: 2_u32.into(), user_display_name: "Jolly Jumper".into(), users_power_levels: BTreeMap::new(), default_power_level: 50.into(), diff --git a/crates/ruma-common/src/push/condition.rs b/crates/ruma-common/src/push/condition.rs index ff79c8a5..507e404f 100644 --- a/crates/ruma-common/src/push/condition.rs +++ b/crates/ruma-common/src/push/condition.rs @@ -484,7 +484,7 @@ mod tests { let context = PushConditionRoomCtx { room_id: room_id!("!room:server.name"), - member_count: 3u8.into(), + member_count: 3_u8.into(), user_display_name: "Groovy Gorilla".into(), users_power_levels, default_power_level: 50.into(), diff --git a/crates/ruma-common/src/push/condition/room_member_count_is.rs b/crates/ruma-common/src/push/condition/room_member_count_is.rs index b03439f9..770478a1 100644 --- a/crates/ruma-common/src/push/condition/room_member_count_is.rs +++ b/crates/ruma-common/src/push/condition/room_member_count_is.rs @@ -190,7 +190,7 @@ mod tests { #[test] fn eq_range_contains_its_own_count() { - let count = 2u32.into(); + let count = 2_u32.into(); let range = RoomMemberCountIs::from(count); assert!(range.contains(&count)); @@ -199,7 +199,7 @@ mod tests { #[test] fn ge_range_contains_large_number() { let range = RoomMemberCountIs::from(uint!(2)..); - let large_number = 9001u32.into(); + let large_number = 9001_u32.into(); assert!(range.contains(&large_number)); } diff --git a/crates/ruma-events/src/policy/rule/room.rs b/crates/ruma-events/src/policy/rule/room.rs index 4ec2699d..78863cb3 100644 --- a/crates/ruma-events/src/policy/rule/room.rs +++ b/crates/ruma-events/src/policy/rule/room.rs @@ -56,7 +56,7 @@ mod tests { "recommendation": "m.ban" }, "event_id": "$143273582443PhrSn:example.org", - "origin_server_ts": 1432735824653u64, + "origin_server_ts": 1_432_735_824_653_u64, "room_id": "!jEsUZKDJdhlrceRyVU:example.org", "sender": "@example:example.org", "state_key": "rule:#*:example.org", @@ -78,7 +78,7 @@ mod tests { "recommendation": "m.ban" }, "event_id": "$143273582443PhrSn:example.org", - "origin_server_ts": 1432735824653u64, + "origin_server_ts": 1_432_735_824_653_u64, "room_id": "!jEsUZKDJdhlrceRyVU:example.org", "sender": "@example:example.org", "state_key": "rule:#*:example.org", diff --git a/crates/ruma-events/src/room/encrypted.rs b/crates/ruma-events/src/room/encrypted.rs index fce099ee..bdcb2aa6 100644 --- a/crates/ruma-events/src/room/encrypted.rs +++ b/crates/ruma-events/src/room/encrypted.rs @@ -191,7 +191,9 @@ mod tests { .deserialize() .unwrap(); - assert_matches!(content.scheme, EncryptedEventScheme::MegolmV1AesSha2(MegolmV1AesSha2Content { + assert_matches!( + content.scheme, + EncryptedEventScheme::MegolmV1AesSha2(MegolmV1AesSha2Content { ciphertext, sender_key, device_id, @@ -204,7 +206,7 @@ mod tests { assert_matches!( content.relates_to, - Option::::Some(Relation::Reply { in_reply_to }) + Some(Relation::Reply { in_reply_to }) if in_reply_to.event_id == event_id!("$h29iv0s8:example.com") ); } @@ -231,7 +233,7 @@ mod tests { assert_eq!(c.sender_key, "test_key"); assert_eq!(c.ciphertext.len(), 1); assert_eq!(c.ciphertext["test_curve_key"].body, "encrypted_body"); - assert_eq!(c.ciphertext["test_curve_key"].message_type, 1u16.into()); + assert_eq!(c.ciphertext["test_curve_key"].message_type, 1_u16.into()); } _ => panic!("Wrong content type, expected a OlmV1 content"), } diff --git a/crates/ruma-events/src/room/pinned_events.rs b/crates/ruma-events/src/room/pinned_events.rs index 8ec4d16a..cbb32e54 100644 --- a/crates/ruma-events/src/room/pinned_events.rs +++ b/crates/ruma-events/src/room/pinned_events.rs @@ -49,7 +49,7 @@ mod tests { let event = StateEvent { content: content.clone(), event_id: EventId::new(server_name), - origin_server_ts: UNIX_EPOCH + Duration::from_millis(1_432_804_485_886u64), + origin_server_ts: UNIX_EPOCH + Duration::from_millis(1_432_804_485_886_u64), prev_content: None, room_id: RoomId::new(server_name), sender: UserId::new(server_name), diff --git a/crates/ruma-federation-api/src/transactions/edu.rs b/crates/ruma-federation-api/src/transactions/edu.rs index 4eaf52a0..16f2236a 100644 --- a/crates/ruma-federation-api/src/transactions/edu.rs +++ b/crates/ruma-federation-api/src/transactions/edu.rs @@ -341,7 +341,7 @@ mod test { "m.read": { "@john:matrix.org": { "data": { - "ts": 1533358 + "ts": 1_533_358 }, "event_ids": [ "$read_this_event:matrix.org" diff --git a/crates/ruma-serde/src/time/ms_since_unix_epoch.rs b/crates/ruma-serde/src/time/ms_since_unix_epoch.rs index 500c4bfb..70532343 100644 --- a/crates/ruma-serde/src/time/ms_since_unix_epoch.rs +++ b/crates/ruma-serde/src/time/ms_since_unix_epoch.rs @@ -67,12 +67,12 @@ mod tests { #[test] fn issue_446() { - let json = json!({ "timestamp": 15159743990000u64 }); + let json = json!({ "timestamp": 15_159_743_990_000_u64 }); assert_matches!( serde_json::from_value::(json), Ok(SystemTimeTest { timestamp }) - if timestamp == UNIX_EPOCH + Duration::from_millis(15159743990000) + if timestamp == UNIX_EPOCH + Duration::from_millis(15_159_743_990_000) ); } diff --git a/crates/ruma-serde/tests/url_serialize.rs b/crates/ruma-serde/tests/url_serialize.rs index 3813bac0..5ae71a26 100644 --- a/crates/ruma-serde/tests/url_serialize.rs +++ b/crates/ruma-serde/tests/url_serialize.rs @@ -88,7 +88,7 @@ fn serialize_multiple_lists() { #[test] fn serialize_nested_list() { - let params = &[("list", vec![vec![0u8]])]; + let params = &[("list", vec![vec![0_u8]])]; assert_matches!( urlencoded::to_string(params), Err(Error::Custom(s)) if s.contains("unsupported") diff --git a/crates/ruma-signatures/src/lib.rs b/crates/ruma-signatures/src/lib.rs index 3de041cf..3109b3f4 100644 --- a/crates/ruma-signatures/src/lib.rs +++ b/crates/ruma-signatures/src/lib.rs @@ -170,7 +170,7 @@ fn split_id(id: &str) -> Result<(Algorithm, String), SplitError<'_>> { mod tests { use std::collections::BTreeMap; - use base64::{decode_config, STANDARD_NO_PAD}; + use base64::{decode_config, encode_config, STANDARD_NO_PAD}; use ring::signature::{Ed25519KeyPair as RingEd25519KeyPair, KeyPair as _}; use ruma_identifiers::RoomVersionId; use serde_json::{from_str as from_json_str, to_string as to_json_string}; @@ -186,12 +186,10 @@ mod tests { /// Convenience method for getting the public key as a string fn public_key_string() -> String { - base64::encode_config( - &RingEd25519KeyPair::from_pkcs8( - &base64::decode_config(PKCS8, STANDARD_NO_PAD).unwrap(), - ) - .unwrap() - .public_key(), + encode_config( + &RingEd25519KeyPair::from_pkcs8(&decode_config(PKCS8, STANDARD_NO_PAD).unwrap()) + .unwrap() + .public_key(), STANDARD_NO_PAD, ) } diff --git a/xtask/src/ci.rs b/xtask/src/ci.rs index 7741d5bf..378fbefe 100644 --- a/xtask/src/ci.rs +++ b/xtask/src/ci.rs @@ -60,11 +60,7 @@ impl CiTask { fn build_nightly(&self) -> xshell::Result<()> { vec![ cmd!("rustup run nightly cargo fmt -- --check").run(), - cmd!( - "rustup run nightly cargo clippy -p ruma - --all-targets --all-features --quiet -- -D warnings" - ) - .run(), + cmd!("rustup run nightly cargo ruma-clippy -D warnings").run(), cmd!( "rustup run nightly cargo clippy -p ruma-client --all-targets --quiet -- -D warnings"