Skip to content

Commit

Permalink
Added more clippy lint rules (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
ywegel authored Aug 7, 2024
1 parent 5eae2a6 commit ba03b34
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ jobs:
override: true
components: clippy
- name: Run Clippy
run: cargo clippy --all-targets --all-features
run: cargo clippy --all-targets --all-features -- -D warnings
5 changes: 1 addition & 4 deletions src/fcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ pub async fn send_fcm_message<T: Serialize>(
project_id: &str,
) -> Result<(), FcmError> {
info!("Sending FCM message to device: {}", device_token);
let url = format!(
"https://fcm.googleapis.com/v1/projects/{}/messages:send",
project_id
);
let url = format!("https://fcm.googleapis.com/v1/projects/{project_id}/messages:send");

send_fcm_message_with_url(
device_token,
Expand Down
21 changes: 18 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
mod error;
mod fcm;
mod token_manager;
#![forbid(unsafe_code)]
#![warn(
clippy::pedantic,
clippy::nursery,
clippy::tests_outside_test_module,
unused_qualifications,
non_ascii_idents
)]
#![allow(
clippy::missing_errors_doc,
clippy::missing_panics_doc,
clippy::module_name_repetitions,
clippy::future_not_send
)]

use std::fmt::Debug;
use std::io::Read;
Expand All @@ -15,6 +26,10 @@ pub use token_manager::TokenManager;
use tracing::info;
use tracing::instrument;

mod error;
mod fcm;
mod token_manager;

/// Creates a new `SharedTokenManager`.
///
/// This function is a helper for creating a `SharedTokenManager` from a given
Expand Down
14 changes: 6 additions & 8 deletions src/token_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl TokenManager {

let service_account_key = serde_json::from_reader(credentials)?;

Ok(TokenManager {
Ok(Self {
token: None,
expires_at: None,
service_account_key,
Expand Down Expand Up @@ -113,13 +113,11 @@ impl TokenManager {
/// needed by users.
#[instrument(level = "debug", skip(self))]
pub fn is_token_expired(&self) -> bool {
self.expires_at
.map(|expires_at| {
let expired = expires_at <= Instant::now();
debug!("Token expired: {}", expired);
expired
})
.unwrap_or(true)
self.expires_at.map_or(true, |expires_at| {
let expired = expires_at <= Instant::now();
debug!("Token expired: {}", expired);
expired
})
}

/// Refreshes the current OAuth token.
Expand Down
5 changes: 1 addition & 4 deletions tests/valid_fcm_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::fs::File;
use std::fs::{
self,
};
use std::sync::Once;

use oauth_fcm::create_shared_token_manager;
Expand Down Expand Up @@ -123,7 +120,7 @@ async fn successful_fcm_test_from_string() {
.with_status(200)
.create();

let creds = fs::read_to_string("tests/mock_credentials.json").unwrap();
let creds = std::fs::read_to_string("tests/mock_credentials.json").unwrap();
let shared_token_manager =
create_shared_token_manager(creds.as_bytes()).expect("Failed to create SharedTokenManager");

Expand Down

0 comments on commit ba03b34

Please sign in to comment.