Enable non-default clippy lints

This commit is contained in:
Devin Ragotzy 2021-05-06 07:07:31 -04:00 committed by GitHub
parent c6aa2e0428
commit 5090c11843
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 56 additions and 36 deletions

View File

@ -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/"

1
.clippy.toml Normal file
View File

@ -0,0 +1 @@
msrv = "1.45"

View File

@ -1,3 +1,4 @@
{
"rust-analyzer.cargo.allFeatures": true
"rust-analyzer.cargo.allFeatures": true,
"rust-analyzer.checkOnSave.command": "ruma-clippy"
}

View File

@ -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: {

View File

@ -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,

View File

@ -18,7 +18,7 @@ fn registration_deserialization() {
regex: "#_irc_bridge_.*"
rooms: []
"##;
let observed = serde_yaml::from_str(&registration_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(&registration_config).unwrap(),
serde_yaml::from_str(registration_config).unwrap(),
Registration { url, .. } if url == "null"
);
}

View File

@ -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);

View File

@ -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(),

View File

@ -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(),

View File

@ -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));
}

View File

@ -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",

View File

@ -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::<Relation>::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"),
}

View File

@ -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),

View File

@ -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"

View File

@ -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::<SystemTimeTest>(json),
Ok(SystemTimeTest { timestamp })
if timestamp == UNIX_EPOCH + Duration::from_millis(15159743990000)
if timestamp == UNIX_EPOCH + Duration::from_millis(15_159_743_990_000)
);
}

View File

@ -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")

View File

@ -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,
)
}

View File

@ -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"