Skip to content

Commit

Permalink
chore: fix lints (#1342)
Browse files Browse the repository at this point in the history
<!-- Please make sure there is an issue that this PR is correlated to. -->

## Changes

<!-- If there are frontend changes, please include screenshots. -->
  • Loading branch information
NathanFlurry committed Nov 13, 2024
1 parent 9210932 commit a7e2e49
Show file tree
Hide file tree
Showing 77 changed files with 1,121 additions and 1,189 deletions.
15 changes: 7 additions & 8 deletions packages/common/api-helper/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl Parse for EndpointRouter {
None => {
return Err(syn::Error::new(
input.span(),
format!("Missing key `routes`."),
"Missing key `routes`.".to_string(),
));
}
};
Expand Down Expand Up @@ -335,7 +335,7 @@ impl Parse for Mount {
None => {
return Err(syn::Error::new(
input.span(),
format!("Missing key `path`."),
"Missing key `path`.".to_string(),
));
}
};
Expand Down Expand Up @@ -369,10 +369,10 @@ impl Parse for RequestPathSegment {
if let Ok(lit) = fork.parse::<syn::LitStr>() {
input.advance_to(&fork);
if lit.value().is_empty() {
return Err(syn::Error::new(
Err(syn::Error::new(
lit.span(),
format!("Empty segment not allowed"),
));
"Empty segment not allowed".to_string(),
))
} else {
Ok(RequestPathSegment::LitStr(lit))
}
Expand Down Expand Up @@ -614,7 +614,7 @@ impl Parse for EndpointFunction {
// Check for body
let (mut bodies, args) = args
.into_iter()
.partition::<Vec<_>, _>(|arg| arg.label.to_string() == "body");
.partition::<Vec<_>, _>(|arg| arg.label == "body");
let body = bodies
.pop()
.map(|arg| arg.value.expect_expr().cloned())
Expand Down Expand Up @@ -663,8 +663,7 @@ impl EndpointFunction {
if self
.args
.iter()
.find(|arg| arg.label == "with_response")
.is_some()
.any(|arg| arg.label == "with_response")
{
arg_list.insert(0, quote! { response });
}
Expand Down
14 changes: 7 additions & 7 deletions packages/common/api-helper/macros/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ where
{
pub fn expect_expr(&self) -> syn::Result<&syn::Expr> {
match self {
Self::Expr(v) => Ok(&v),
Self::Expr(v) => Ok(v),
Self::Paren(v) => Err(syn::Error::new(v.span(), "Expected single expression")),
Self::Bracket(v) => Err(syn::Error::new(v.span(), "Expected single expression")),
Self::Block(v) => Err(syn::Error::new(v.span(), "Expected single expression")),
Expand All @@ -193,7 +193,7 @@ where
pub fn expect_paren(&self) -> syn::Result<&SimpleTuple<P>> {
match self {
Self::Expr(v) => Err(syn::Error::new(v.span(), "Expected parenthesis block")),
Self::Paren(v) => Ok(&v),
Self::Paren(v) => Ok(v),
Self::Bracket(v) => Err(syn::Error::new(v.span(), "Expected parenthesis block")),
Self::Block(v) => Err(syn::Error::new(v.span(), "Expected parenthesis block")),
}
Expand All @@ -203,7 +203,7 @@ where
match self {
Self::Expr(v) => Err(syn::Error::new(v.span(), "Expected bracket block")),
Self::Paren(v) => Err(syn::Error::new(v.span(), "Expected bracket block")),
Self::Bracket(v) => Ok(&v),
Self::Bracket(v) => Ok(v),
Self::Block(v) => Err(syn::Error::new(v.span(), "Expected bracket block")),
}
}
Expand All @@ -214,7 +214,7 @@ where
Self::Expr(v) => Err(syn::Error::new(v.span(), "Expected block")),
Self::Paren(v) => Err(syn::Error::new(v.span(), "Expected block")),
Self::Bracket(v) => Err(syn::Error::new(v.span(), "Expected block")),
Self::Block(v) => Ok(&v),
Self::Block(v) => Ok(v),
}
}
}
Expand Down Expand Up @@ -281,7 +281,7 @@ pub enum ExprTree {
impl ExprTree {
pub fn expect_expr(&self) -> syn::Result<&syn::Expr> {
match self {
Self::Expr(v) => Ok(&v),
Self::Expr(v) => Ok(v),
Self::Paren(v) => Err(syn::Error::new(v.span(), "Expected single expression")),
Self::Bracket(v) => Err(syn::Error::new(v.span(), "Expected single expression")),
Self::Block(v) => Err(syn::Error::new(v.span(), "Expected single expression")),
Expand All @@ -303,7 +303,7 @@ impl ExprTree {
match self {
Self::Expr(v) => Err(syn::Error::new(v.span(), "Expected bracket block")),
Self::Paren(v) => Err(syn::Error::new(v.span(), "Expected bracket block")),
Self::Bracket(v) => Ok(&v),
Self::Bracket(v) => Ok(v),
Self::Block(v) => Err(syn::Error::new(v.span(), "Expected bracket block")),
}
}
Expand All @@ -313,7 +313,7 @@ impl ExprTree {
Self::Expr(v) => Err(syn::Error::new(v.span(), "Expected map")),
Self::Paren(v) => Err(syn::Error::new(v.span(), "Expected map")),
Self::Bracket(v) => Err(syn::Error::new(v.span(), "Expected map")),
Self::Block(v) => Ok(&v),
Self::Block(v) => Ok(v),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/common/cache/build/src/getter_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ where
{
/// Sets a value with the value provided from the cache.
pub(super) fn resolve_from_cache(&mut self, idx: usize, value: V) {
if let Some(key) = self.keys.iter_mut().nth(idx) {
if let Some(key) = self.keys.get_mut(idx) {
key.value = Some(value);
key.from_cache = true;
} else {
Expand All @@ -144,7 +144,7 @@ where

/// Sets a value with the value provided from the getter function.
pub fn resolve(&mut self, key: &K, value: V) {
self.get_key_for_resolve(&key, |key| key.value = Some(value));
self.get_key_for_resolve(key, |key| key.value = Some(value));
}

pub fn resolve_with_topic<T>(
Expand Down
4 changes: 2 additions & 2 deletions packages/common/cache/build/src/inner.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{env, fmt::Debug, sync::Arc};
use std::{fmt::Debug, sync::Arc};

use rivet_pools::prelude::*;

Expand Down Expand Up @@ -27,7 +27,7 @@ impl CacheInner {
pub fn from_env(pools: rivet_pools::Pools) -> Result<Cache, Error> {
let service_name = rivet_env::service_name();
let service_source_hash = rivet_env::source_hash().to_string();
let redis_cache = pools.redis_cache().map_err(|err| Error::Pools(err))?;
let redis_cache = pools.redis_cache().map_err(Error::Pools)?;

Ok(Self::new(
service_name.to_string(),
Expand Down
6 changes: 3 additions & 3 deletions packages/common/cache/build/src/req_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl RequestConfig {
//
// Drop `keys` bc this is not the same as the keys list in `ctx`, so it should not be used
// again.
let mut ctx = GetterCtx::new(base_key.clone().into(), keys);
let mut ctx = GetterCtx::new(base_key.clone(), keys);

// Build keys to look up values in Redis
let redis_keys = ctx
Expand Down Expand Up @@ -558,10 +558,10 @@ impl RequestConfig {
.collect::<Vec<_>>();

metrics::CACHE_PURGE_REQUEST_TOTAL
.with_label_values(&[&base_key])
.with_label_values(&[base_key])
.inc();
metrics::CACHE_PURGE_VALUE_TOTAL
.with_label_values(&[&base_key])
.with_label_values(&[base_key])
.inc_by(redis_keys.len() as u64);

// Delete keys
Expand Down
2 changes: 1 addition & 1 deletion packages/common/chirp-workflow/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ fn parse_trait_fn(
&format!(
"{} function must have exactly two parameters: ctx: {} and input: &YourInputType",
trait_name,
ctx_ty.to_token_stream().to_string()
ctx_ty.to_token_stream()
),
));
}
Expand Down
4 changes: 2 additions & 2 deletions packages/common/chirp/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ impl Client {
// it's faster.
if M::HISTORY && config.message_limit != 1 {
// Fetch message
let history_key = redis_keys::message_history::<M, _>(&params);
let history_key = redis_keys::message_history::<M, _>(params);
let msg_bufs = conn
.zrangebyscore_limit::<_, _, _, Vec<Vec<u8>>>(
&history_key,
Expand All @@ -1224,7 +1224,7 @@ impl Client {
}
} else {
// Fetch message
let tail_key = redis_keys::message_tail::<M, _>(&params);
let tail_key = redis_keys::message_tail::<M, _>(params);
let msg_buf = conn
.hget::<_, _, Option<Vec<u8>>>(&tail_key, redis_keys::message_tail::BODY)
.await?;
Expand Down
2 changes: 1 addition & 1 deletion packages/common/chirp/client/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ where
ray_id,
req_id,
ts: message.ts,
trace: trace,
trace,
body,
})
}
Expand Down
1 change: 0 additions & 1 deletion packages/common/chirp/perf/src/ctx.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
env,
fmt::Debug,
sync::{
atomic::{AtomicI64, Ordering},
Expand Down
2 changes: 1 addition & 1 deletion packages/common/claims/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ fn decode_proto(
bail_with!(TOKEN_INVALID, reason = "invalid signature");
}

let claims_buf = match base64::decode_config(&claims, base64::URL_SAFE_NO_PAD) {
let claims_buf = match base64::decode_config(claims, base64::URL_SAFE_NO_PAD) {
Ok(claims_buf) => claims_buf,
Err(err) => bail_with!(TOKEN_INVALID, reason = err),
};
Expand Down
27 changes: 1 addition & 26 deletions packages/common/config/src/config/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub use rivet::*;

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
#[derive(Default)]
pub struct Server {
// Secrets
pub jwt: JwtKey,
Expand Down Expand Up @@ -64,32 +65,6 @@ pub struct Server {
pub nomad: Option<Nomad>,
}

impl Default for Server {
fn default() -> Self {
Self {
jwt: JwtKey::default(),
tls: None,
ssh: None,
rivet: rivet::Rivet::default(),
cockroachdb: CockroachDb::default(),
redis: RedisTypes::default(),
clickhouse: None,
prometheus: None,
cloudflare: None,
nats: Nats::default(),
s3: S3::default(),
sendgrid: None,
loops: None,
ip_info: None,
hcaptcha: None,
turnstile: None,
stripe: None,
neon: None,
linode: None,
nomad: None,
}
}
}

impl Server {
pub fn tls(&self) -> GlobalResult<&Tls> {
Expand Down
17 changes: 3 additions & 14 deletions packages/common/config/src/config/server/rivet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,9 @@ impl ApiEdge {
/// Deprecated: Configuration for CDN.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
#[derive(Default)]
pub struct Cdn {}

impl Default for Cdn {
fn default() -> Self {
Self {}
}
}

/// Configuration for DNS management.
#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -419,7 +415,7 @@ impl Datacenter {
pub fn pools(&self) -> HashMap<dc_provision::PoolType, dc_provision::Pool> {
self.provision
.as_ref()
.map_or_else(|| HashMap::new(), |x| x.pools.clone())
.map_or_else(HashMap::new, |x| x.pools.clone())
}

pub fn prebakes_enabled(&self) -> bool {
Expand Down Expand Up @@ -574,21 +570,14 @@ impl Ui {
/// Configuration for various tokens used in the system.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "snake_case", deny_unknown_fields)]
#[derive(Default)]
pub struct Tokens {
/// Token for the API Traefik provider.
pub traefik_provider: Option<Secret<String>>,
/// Token for API status checks.
pub status: Option<Secret<String>>,
}

impl Default for Tokens {
fn default() -> Tokens {
Self {
traefik_provider: None,
status: None,
}
}
}

/// Configuration for the health check service.
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
Expand Down
3 changes: 1 addition & 2 deletions packages/common/formatted-error/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub(crate) fn render_template(template: &'static str, context: &HashMap<String,
template
.chars()
.enumerate()
.map(|(i, c)| {
.filter_map(|(i, c)| {
if c == '{' {
// Double opening bracket (escaped)
if potential_replace && i == start_index + 1 {
Expand Down Expand Up @@ -50,6 +50,5 @@ pub(crate) fn render_template(template: &'static str, context: &HashMap<String,
Some(c.to_string())
}
})
.flatten()
.collect::<String>()
}
6 changes: 3 additions & 3 deletions packages/common/global-error/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl GlobalError {
GlobalError::Internal { .. } | GlobalError::Raw(_) => Ok(None),
GlobalError::BadRequest { metadata, .. } => metadata
.as_ref()
.map(|metadata| serde_json::from_str::<serde_json::Value>(&metadata))
.map(|metadata| serde_json::from_str::<serde_json::Value>(metadata))
.transpose()
.map_err(Into::into),
}
Expand Down Expand Up @@ -214,7 +214,7 @@ impl From<GlobalError> for chirp::response::Err {
chirp::response::Err {
kind: Some(chirp::response::err::Kind::Internal(
chirp::response::err::Internal {
ty: ty,
ty,
message: format!("{}", err),
debug,
},
Expand Down Expand Up @@ -255,7 +255,7 @@ impl BadRequestBuilder {
pub fn build(self) -> GlobalError {
GlobalError::BadRequest {
code: self.code.to_string(),
context: self.context.unwrap_or_else(HashMap::new),
context: self.context.unwrap_or_default(),
metadata: self.metadata.map(|m| m.to_string()),
}
}
Expand Down
2 changes: 0 additions & 2 deletions packages/common/hub-embed/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use reqwest;
use std::{env, fs, path::Path};
use zip;

const HUB_URL: &str = "https://releases.rivet.gg/hub/2024-11-04-19-11-14-7d5a4f5-embed.zip";
const OUT_DIR: &str = "hub_files";
Expand Down
10 changes: 5 additions & 5 deletions packages/common/migrate/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub async fn up(config: rivet_config::Config, services: &[SqlService]) -> Result
crdb_pre_queries.push(query);

// Create users
for (_, user) in &server_config.cockroachdb.provision_users {
for user in server_config.cockroachdb.provision_users.values() {
let username = &user.username;
let password = user.password.read();
let query = match user.role {
Expand Down Expand Up @@ -124,9 +124,9 @@ pub async fn up(config: rivet_config::Config, services: &[SqlService]) -> Result
"
));

for (_, user) in &clickhouse_config.provision_users {
for user in clickhouse_config.provision_users.values() {
let username = &user.username;
let password = &*user.password.read();
let password = user.password.read();

clickhouse_pre_queries.push(formatdoc!(
"
Expand Down Expand Up @@ -371,7 +371,7 @@ async fn migrate_db_url(config: rivet_config::Config, service: &SqlService) -> R

let mut url = url::Url::parse(&format!(
"cockroach://{auth}@{crdb_host}:{crdb_port}/{}",
encode(&service.db_name)
encode(service.db_name)
))?;

if let Some(sslmode) = crdb_url_parsed.query_pairs().find(|(k, _)| k == "sslmode") {
Expand All @@ -395,7 +395,7 @@ async fn migrate_db_url(config: rivet_config::Config, service: &SqlService) -> R

let mut query = format!(
"database={db}&username={username}&x-multi-statement=true&x-migrations-table-engine=ReplicatedMergeTree&secure=true&skip_verify=true",
db = encode(&service.db_name),
db = encode(service.db_name),
username = encode(&clickhouse_config.username),
);
if let Some(password) = &clickhouse_config.password {
Expand Down
Loading

0 comments on commit a7e2e49

Please sign in to comment.