diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..2c22b1dc --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,16 @@ +name: Linters + +on: [pull_request] + +jobs: + rustfmt: + name: Formatter + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Check Formatting + run: cargo fmt --all -- --check + + - name: Check for idiomatic code + run: cargo clippy --all --all-features -- -D warnings diff --git a/cloudflare-e2e-test/src/main.rs b/cloudflare-e2e-test/src/main.rs index 52bacab2..9905da23 100644 --- a/cloudflare-e2e-test/src/main.rs +++ b/cloudflare-e2e-test/src/main.rs @@ -9,7 +9,7 @@ async fn tests( api_client: &ApiClientType, account_id: &str, ) -> anyhow::Result<()> { - test_lb_pool(api_client, &account_id).await?; + test_lb_pool(api_client, account_id).await?; println!("Tests passed"); Ok(()) } @@ -137,18 +137,18 @@ async fn main() -> anyhow::Result<()> { Environment::Production, )?; - tests(&api_client, &account_id).await + tests(&api_client, account_id).await } pub trait ResultExt { /// Convenience function for logging errors inside results. /// Basically just `map_err` except the closure argument doesn't return anything, /// and `.log_err` always returns `self`. - fn log_err ()>(self, log: L) -> Self; + fn log_err(self, log: L) -> Self; } impl ResultExt for Result { - fn log_err ()>(self, log: L) -> Self { + fn log_err(self, log: L) -> Self { if let Err(e) = &self { log(e) } diff --git a/cloudflare-examples/src/main.rs b/cloudflare-examples/src/main.rs index fcca03b3..06f4db8f 100644 --- a/cloudflare-examples/src/main.rs +++ b/cloudflare-examples/src/main.rs @@ -317,7 +317,7 @@ fn main() -> Result<(), Box> { for (section_name, section) in matched_sections { (section.function)( - &matches.subcommand_matches(section_name).unwrap(), + matches.subcommand_matches(section_name).unwrap(), &api_client, ); } diff --git a/cloudflare/src/endpoints/account/list_accounts.rs b/cloudflare/src/endpoints/account/list_accounts.rs index f814c55f..9a9d1512 100644 --- a/cloudflare/src/endpoints/account/list_accounts.rs +++ b/cloudflare/src/endpoints/account/list_accounts.rs @@ -16,7 +16,7 @@ impl Endpoint, ListAccountsParams> for ListAccounts { Method::Get } fn path(&self) -> String { - format!("accounts") + "accounts".to_string() } fn query(&self) -> Option { self.params.clone() diff --git a/cloudflare/src/endpoints/argo_tunnel/delete_tunnel.rs b/cloudflare/src/endpoints/argo_tunnel/delete_tunnel.rs index 0b50c42b..40149665 100644 --- a/cloudflare/src/endpoints/argo_tunnel/delete_tunnel.rs +++ b/cloudflare/src/endpoints/argo_tunnel/delete_tunnel.rs @@ -15,6 +15,9 @@ impl<'a> Endpoint for DeleteTunnel<'a> { Method::Delete } fn path(&self) -> String { - format!("accounts/{}/tunnels/{}", self.account_identifier, self.tunnel_id) + format!( + "accounts/{}/tunnels/{}", + self.account_identifier, self.tunnel_id + ) } } diff --git a/cloudflare/src/endpoints/dns.rs b/cloudflare/src/endpoints/dns.rs index f9eca221..42d1cfa7 100644 --- a/cloudflare/src/endpoints/dns.rs +++ b/cloudflare/src/endpoints/dns.rs @@ -157,6 +157,7 @@ pub struct Meta { /// here as an associated, strongly typed value. #[derive(Deserialize, Serialize, Clone, Debug)] #[serde(tag = "type")] +#[allow(clippy::upper_case_acronyms)] pub enum DnsContent { A { content: Ipv4Addr }, AAAA { content: Ipv6Addr }, diff --git a/cloudflare/src/endpoints/load_balancing/create_lb.rs b/cloudflare/src/endpoints/load_balancing/create_lb.rs index 66ea1199..73600c66 100644 --- a/cloudflare/src/endpoints/load_balancing/create_lb.rs +++ b/cloudflare/src/endpoints/load_balancing/create_lb.rs @@ -1,4 +1,7 @@ -use crate::endpoints::load_balancing::{LbPoolId, SteeringPolicy, SessionAffinityAttributes, LbPoolMapping, SessionAffinity, LoadBalancer}; +use crate::endpoints::load_balancing::{ + LbPoolId, LbPoolMapping, LoadBalancer, SessionAffinity, SessionAffinityAttributes, + SteeringPolicy, +}; use crate::framework::endpoint::{Endpoint, Method}; /// Create Load Balancer diff --git a/cloudflare/src/endpoints/load_balancing/mod.rs b/cloudflare/src/endpoints/load_balancing/mod.rs index 08c7bad4..53f6747d 100644 --- a/cloudflare/src/endpoints/load_balancing/mod.rs +++ b/cloudflare/src/endpoints/load_balancing/mod.rs @@ -8,7 +8,7 @@ pub mod pool_details; use crate::framework::response::ApiResult; use chrono::offset::Utc; use chrono::DateTime; -use std::collections::{HashSet, HashMap}; +use std::collections::{HashMap, HashSet}; use std::hash::{Hash, Hasher}; use std::net::IpAddr; @@ -80,7 +80,7 @@ pub enum SessionAffinity { Nil, None, Cookie, - IpCookie + IpCookie, } #[derive(Eq, PartialEq, Deserialize, Serialize, Clone, Debug)] @@ -104,12 +104,11 @@ pub enum Secure { /// `Auto` maps to `Always` if Always Use HTTPS is set, or `Never` otherwise. Auto, Always, - Never + Never, } impl ApiResult for LoadBalancer {} - /// A pool is a set of origins that requests could be routed to (e.g. each of your data centers or /// regions have its own pool). /// Requests will be routed to particular pools according to your steering policy, and then balanced diff --git a/cloudflare/src/endpoints/workers/delete_do.rs b/cloudflare/src/endpoints/workers/delete_do.rs index 3c7ed571..6fc090f6 100644 --- a/cloudflare/src/endpoints/workers/delete_do.rs +++ b/cloudflare/src/endpoints/workers/delete_do.rs @@ -21,4 +21,3 @@ impl<'a> Endpoint<(), (), ()> for DeleteDurableObject<'a> { ) } } - diff --git a/cloudflare/src/endpoints/workers/delete_script.rs b/cloudflare/src/endpoints/workers/delete_script.rs index accf53f1..7f3b9215 100644 --- a/cloudflare/src/endpoints/workers/delete_script.rs +++ b/cloudflare/src/endpoints/workers/delete_script.rs @@ -2,7 +2,7 @@ use crate::framework::endpoint::{Endpoint, Method}; use crate::framework::response::ApiResult; /// Delete Workers script -/// https://api.cloudflare.com/#worker-script-delete-worker +/// https://api.cloudflare.com/#worker-script-delete-worker #[derive(Debug)] pub struct DeleteScript<'a> { /// account id of owner of the script diff --git a/cloudflare/src/endpoints/workers/list_bindings.rs b/cloudflare/src/endpoints/workers/list_bindings.rs index e6192594..c85e256d 100644 --- a/cloudflare/src/endpoints/workers/list_bindings.rs +++ b/cloudflare/src/endpoints/workers/list_bindings.rs @@ -1,5 +1,5 @@ +use super::WorkersBinding; use crate::framework::endpoint::{Endpoint, Method}; -use super::WorkersBinding; /// List Bindings /// Lists all bindings for a given script @@ -19,8 +19,7 @@ impl<'a> Endpoint> for ListBindings<'a> { fn path(&self) -> String { format!( "accounts/{}/workers/scripts/{}/bindings", - self.account_id, - self.script_name + self.account_id, self.script_name ) } } diff --git a/cloudflare/src/endpoints/workers/mod.rs b/cloudflare/src/endpoints/workers/mod.rs index 47909e9c..87538af4 100644 --- a/cloudflare/src/endpoints/workers/mod.rs +++ b/cloudflare/src/endpoints/workers/mod.rs @@ -93,5 +93,4 @@ pub struct WorkersBinding { } impl ApiResult for WorkersBinding {} -impl ApiResult for Vec{} - +impl ApiResult for Vec {} diff --git a/cloudflare/src/endpoints/workerskv/mod.rs b/cloudflare/src/endpoints/workerskv/mod.rs index 15a6eb29..63a86aae 100644 --- a/cloudflare/src/endpoints/workerskv/mod.rs +++ b/cloudflare/src/endpoints/workerskv/mod.rs @@ -40,8 +40,8 @@ pub struct Key { pub fn deserialize_option_timestamp<'de, D>( deserializer: D, ) -> Result>, D::Error> - where - D: Deserializer<'de>, +where + D: Deserializer<'de>, { let s: Option = Option::deserialize(deserializer)?; if let Some(s) = s { diff --git a/cloudflare/src/framework/async_api.rs b/cloudflare/src/framework/async_api.rs index 55c0a9f6..9ef334dd 100644 --- a/cloudflare/src/framework/async_api.rs +++ b/cloudflare/src/framework/async_api.rs @@ -8,9 +8,8 @@ use crate::framework::{ Environment, HttpApiClientConfig, }; use async_trait::async_trait; -use reqwest; -use serde::Serialize; use cfg_if::cfg_if; +use serde::Serialize; #[async_trait] pub trait ApiClient { @@ -47,8 +46,7 @@ impl Client { environment: Environment, ) -> anyhow::Result { #[allow(unused_mut)] - let mut builder = reqwest::Client::builder() - .default_headers(config.default_headers); + let mut builder = reqwest::Client::builder().default_headers(config.default_headers); cfg_if! { // There are no timeouts in wasm. The property is documented as no-op in wasm32. @@ -104,10 +102,10 @@ impl ApiClient for Client { &self, endpoint: &(dyn Endpoint + Send + Sync), ) -> ApiResponse - where - ResultType: ApiResult, - QueryType: Serialize, - BodyType: Serialize, + where + ResultType: ApiResult, + QueryType: Serialize, + BodyType: Serialize, { self.request_handle(endpoint).await } diff --git a/cloudflare/src/framework/mock.rs b/cloudflare/src/framework/mock.rs index 9192f215..a1deecdb 100644 --- a/cloudflare/src/framework/mock.rs +++ b/cloudflare/src/framework/mock.rs @@ -3,7 +3,6 @@ use crate::framework::async_api; use crate::framework::endpoint::{Endpoint, Method}; use crate::framework::response::{ApiError, ApiErrors, ApiFailure, ApiResponse, ApiResult}; use async_trait::async_trait; -use reqwest; use std::collections::HashMap; pub struct MockApiClient {} diff --git a/cloudflare/src/framework/mod.rs b/cloudflare/src/framework/mod.rs index 05023d41..5aa4e4cc 100644 --- a/cloudflare/src/framework/mod.rs +++ b/cloudflare/src/framework/mod.rs @@ -4,11 +4,11 @@ This module controls how requests are sent to Cloudflare's API, and how response pub mod apiclient; pub mod async_api; pub mod auth; -#[cfg(not(target_arch = "wasm32"))] // There is no blocking implementation for wasm. +#[cfg(not(target_arch = "wasm32"))] // There is no blocking implementation for wasm. pub mod blocking_api; pub mod endpoint; pub mod json_utils; -#[cfg(not(target_arch = "wasm32"))] // The mock contains a blocking implementation. +#[cfg(not(target_arch = "wasm32"))] // The mock contains a blocking implementation. pub mod mock; mod reqwest_adaptors; pub mod response; diff --git a/cloudflare/src/framework/reqwest_adaptors.rs b/cloudflare/src/framework/reqwest_adaptors.rs index 6218e809..307ba819 100644 --- a/cloudflare/src/framework/reqwest_adaptors.rs +++ b/cloudflare/src/framework/reqwest_adaptors.rs @@ -1,5 +1,4 @@ use crate::framework::endpoint::Method; -use reqwest; pub fn match_reqwest_method(method: Method) -> reqwest::Method { match method {