Skip to content

Commit

Permalink
[rust] Fix Clippy warnings
Browse files Browse the repository at this point in the history
Summary:
Fixed all remaining Clippy warnings for the workspace

Depends on D12178

Test Plan: No more Clippy warnings when running `cargo check` or `cargo clippy`

Reviewers: varun

Reviewed By: varun

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D12179
  • Loading branch information
barthap committed May 28, 2024
1 parent 4d5d38f commit d6d4e0d
Show file tree
Hide file tree
Showing 18 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use tracing::debug;

#[napi]
#[instrument(skip_all)]
#[allow(clippy::too_many_arguments)]
pub async fn login_user(
username: String,
password: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ mod tests {
use super::CODE_VERSION;

#[test]
#[allow(clippy::assertions_on_constants)]
fn test_code_version_exists() {
assert!(CODE_VERSION > 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use tracing::{debug, warn};

#[napi]
#[instrument(skip_all)]
#[allow(clippy::too_many_arguments)]
pub async fn register_user(
username: String,
password: String,
Expand Down
4 changes: 2 additions & 2 deletions native/native_rust_library/src/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,10 @@ pub async fn create_userkeys_compaction(
}

pub async fn create_siwe_backup_msg_compaction(
backup_id: &String,
backup_id: &str,
siwe_backup_msg: String,
) -> Result<(), Box<dyn Error>> {
let siwe_backup_msg_file = get_siwe_backup_message_path(&backup_id)?;
let siwe_backup_msg_file = get_siwe_backup_message_path(backup_id)?;
tokio::fs::write(siwe_backup_msg_file, siwe_backup_msg).await?;

Ok(())
Expand Down
1 change: 1 addition & 0 deletions native/native_rust_library/src/identity/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use super::{IdentityAuthResult, LogInPasswordUserInfo, LogInWalletUserInfo};
use crate::utils::jsi_callbacks::handle_string_result_as_callback;
use crate::{Error, CODE_VERSION, DEVICE_TYPE, IDENTITY_SOCKET_ADDR, RUNTIME};

#[allow(clippy::too_many_arguments)]
pub mod ffi {
use crate::identity::{
DeviceKeys, LogInPasswordUserInfo, LogInWalletUserInfo,
Expand Down
1 change: 1 addition & 0 deletions native/native_rust_library/src/identity/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use super::{
RegisterReservedWalletUserInfo, RegisterWalletUserInfo,
};

#[allow(clippy::too_many_arguments)]
pub mod ffi {
use crate::identity::{
DeviceKeys, RegisterPasswordUserInfo, RegisterReservedPasswordUserInfo,
Expand Down
1 change: 1 addition & 0 deletions native/native_rust_library/src/identity/x3dh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub mod ffi {
});
}

#[allow(clippy::too_many_arguments)]
pub fn refresh_user_prekeys(
auth_user_id: String,
auth_device_id: String,
Expand Down
1 change: 1 addition & 0 deletions native/native_rust_library/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use backup::ffi::*;
use identity::ffi::*;
use utils::future_manager::ffi::*;

#[allow(clippy::too_many_arguments)]
#[cxx::bridge]
mod ffi {

Expand Down
2 changes: 1 addition & 1 deletion services/blob/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl BlobService {
if let Some(invite_secret) =
blob_hash.strip_prefix(INVITE_LINK_BLOB_HASH_PREFIX)
{
Self::validate_invite_link_blob_hash(&invite_secret)?;
Self::validate_invite_link_blob_hash(invite_secret)?;
}

let mut upload_session =
Expand Down
2 changes: 1 addition & 1 deletion services/commtest/src/identity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl SigningCapableAccount {
}

/// signs message, returns signature
pub fn sign_message(&mut self, message: &str) -> String {
pub fn sign_message(&self, message: &str) -> String {
let signature: Signature = self.signing_key.sign(message.as_bytes());
base64::engine::general_purpose::STANDARD_NO_PAD
.encode(signature.to_bytes())
Expand Down
2 changes: 1 addition & 1 deletion services/commtest/tests/identity_access_tokens_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async fn refresh_token_test() {
.await
.expect("Couldn't connect to identity service");

let mut account = SigningCapableAccount::new();
let account = SigningCapableAccount::new();
let client_keys = account.public_keys();
let user = register_user_device(Some(&client_keys), None).await;

Expand Down
4 changes: 2 additions & 2 deletions services/commtest/tests/identity_one_time_key_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ async fn max_hundred_keys_in_ddb() {
(0..20).map(|_| generate_random_olm_key()).collect();

if request_num == 0 {
expected_first_retrieved_content_key = content_keys.get(0).cloned();
expected_first_retrieved_notif_key = notif_keys.get(0).cloned();
expected_first_retrieved_content_key = content_keys.first().cloned();
expected_first_retrieved_notif_key = notif_keys.first().cloned();
expected_second_retrieved_content_key = content_keys.get(5).cloned();
expected_second_retrieved_notif_key = notif_keys.get(5).cloned();
}
Expand Down
1 change: 1 addition & 0 deletions services/identity/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ impl DatabaseClient {
Ok(user_id)
}

#[allow(clippy::too_many_arguments)]
pub async fn add_wallet_user_to_users_table(
&self,
flattened_device_key_upload: FlattenedDeviceKeyUpload,
Expand Down
1 change: 1 addition & 0 deletions services/identity/src/grpc_services/authenticated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ impl IdentityClientService for AuthenticatedService {
}
}

#[allow(dead_code)]
enum DeviceListItemKind {
Any,
Primary,
Expand Down
4 changes: 2 additions & 2 deletions services/identity/src/grpc_services/shared.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use grpc_clients::error::unsupported_version;
use tonic::{IntoRequest, Request, Status};
use tracing::{trace, Instrument};
use tonic::{Request, Status};
use tracing::trace;

use crate::constants::{request_metadata, MIN_SUPPORTED_NATIVE_VERSION};

Expand Down
4 changes: 4 additions & 0 deletions services/identity/src/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ mod tests {
));
}

#[allow(clippy::bool_assert_comparison)]
#[test]
fn test_invalid_username_too_short() {
assert_eq!(is_valid_username(""), false);
}

#[allow(clippy::bool_assert_comparison)]
#[test]
fn test_invalid_username_too_long() {
assert_eq!(
Expand All @@ -42,11 +44,13 @@ mod tests {
);
}

#[allow(clippy::bool_assert_comparison)]
#[test]
fn test_invalid_username_first_char_non_alphanumeric() {
assert_eq!(is_valid_username("-asdf"), false);
}

#[allow(clippy::bool_assert_comparison)]
#[test]
fn test_invalid_username_invalid_symbol() {
assert_eq!(is_valid_username("asdf$"), false);
Expand Down
1 change: 1 addition & 0 deletions services/identity/src/siwe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ mod tests {
));
}

#[allow(clippy::bool_assert_comparison)]
#[test]
fn test_invalid_ethereum_address() {
// Shorter than 42 characters
Expand Down
3 changes: 3 additions & 0 deletions shared/comm-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod http;
pub mod shared;
pub mod tools;

#[allow(unused_imports)]
mod reexports {
#[cfg(feature = "blob-client")]
pub use {bytes, reqwest};
Expand All @@ -30,4 +31,6 @@ mod reexports {
pub use ddb::Error as DynamoDBError;
}
}

#[allow(unused_imports)]
pub use reexports::*;

0 comments on commit d6d4e0d

Please sign in to comment.