Skip to content

Updated clippy config #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,40 @@ panic = 'abort'

[profile.dev]
panic = 'abort'

[lints.clippy]
wildcard_dependencies = "deny"

collapsible_if = "allow"
collapsible_else_if = "allow"

allow_attributes_without_reason = "warn"

# Panics
expect_used = "warn"
fallible_impl_from = "warn"
indexing_slicing = "warn"
panic = "warn"
panic_in_result_fn = "warn"
string_slice = "warn"
todo = "warn"
unchecked_duration_subtraction = "warn"
unreachable = "warn"
unwrap_in_result = "warn"
unwrap_used = "warn"

# Correctness
cast_lossless = "warn"
cast_possible_truncation = "warn"
cast_possible_wrap = "warn"
cast_sign_loss = "warn"
collection_is_never_read = "warn"
match_wild_err_arm = "warn"
path_buf_push_overwrite = "warn"
read_zero_byte_vec = "warn"
same_name_method = "warn"
suspicious_operation_groupings = "warn"
suspicious_xor_used_as_pow = "warn"
unused_self = "warn"
used_underscore_binding = "warn"
while_float = "warn"
4 changes: 4 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
allow-unwrap-in-tests = true
allow-expect-in-tests = true
allow-indexing-slicing-in-tests = true
allow-panic-in-tests = true
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.86.0"
channel = "1.88.0"
profile = "minimal"
components = ["rustfmt", "clippy"]
9 changes: 5 additions & 4 deletions src/agent/legacy_schedule.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Market hours metadata parsing and evaluation logic
#![allow(deprecated)]
#![allow(deprecated, reason = "publishers depend on legacy schedule")]

use {
anyhow::{
Expand Down Expand Up @@ -46,6 +46,7 @@ pub struct LegacySchedule {
pub sun: MHKind,
}

#[allow(deprecated, reason = "publishers depend on legacy schedule")]
impl LegacySchedule {
pub fn all_closed() -> Self {
Self {
Expand Down Expand Up @@ -93,7 +94,7 @@ impl FromStr for LegacySchedule {
.trim()
.parse()
.map_err(|e: ParseError| anyhow!(e))
.context(format!("Could parse timezone from {:?}", tz_str))?;
.context(format!("Could parse timezone from {tz_str:?}"))?;

let mut weekday_schedules = Vec::with_capacity(7);

Expand All @@ -112,8 +113,7 @@ impl FromStr for LegacySchedule {
))?;

let mhkind: MHKind = mhkind_str.trim().parse().context(format!(
"Could not parse {} field from {:?}",
weekday, mhkind_str
"Could not parse {weekday} field from {mhkind_str:?}",
))?;

weekday_schedules.push(mhkind);
Expand Down Expand Up @@ -225,6 +225,7 @@ impl FromStr for MHKind {
}

#[cfg(test)]
#[allow(clippy::panic_in_result_fn, reason = "")]
mod tests {
use {
super::*,
Expand Down
11 changes: 6 additions & 5 deletions src/agent/market_schedule.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Holiday hours metadata parsing and evaluation logic

#[allow(deprecated)]
#[allow(deprecated, reason = "publishers depend on legacy schedule")]
use {
super::legacy_schedule::{
LegacySchedule,
Expand Down Expand Up @@ -68,14 +68,14 @@ impl Display for MarketSchedule {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{};", self.timezone)?;
for (i, day) in self.weekly_schedule.iter().enumerate() {
write!(f, "{}", day)?;
write!(f, "{day}")?;
if i < 6 {
write!(f, ",")?;
}
}
write!(f, ";")?;
for (i, holiday) in self.holidays.iter().enumerate() {
write!(f, "{}", holiday)?;
write!(f, "{holiday}")?;
if i < self.holidays.len() - 1 {
write!(f, ",")?;
}
Expand Down Expand Up @@ -131,7 +131,7 @@ impl FromStr for MarketSchedule {
}
}

#[allow(deprecated)]
#[allow(deprecated, reason = "publishers still depend on legacy schedule")]
impl From<LegacySchedule> for MarketSchedule {
fn from(legacy: LegacySchedule) -> Self {
Self {
Expand Down Expand Up @@ -283,6 +283,7 @@ impl From<MHKind> for ScheduleDayKind {
}

#[cfg(test)]
#[allow(clippy::panic_in_result_fn, reason = "")]
mod tests {
use {
super::*,
Expand Down Expand Up @@ -604,7 +605,7 @@ mod tests {

#[test]
fn parse_valid_holiday_day_schedule(s in VALID_SCHEDULE_DAY_KIND_REGEX, d in VALID_MONTH_DAY_REGEX) {
let valid_holiday_day = format!("{}/{}", d, s);
let valid_holiday_day = format!("{d}/{s}");
assert!(valid_holiday_day.parse::<HolidayDaySchedule>().is_ok());
}

Expand Down
7 changes: 4 additions & 3 deletions src/agent/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use {
};

pub fn default_bind_address() -> SocketAddr {
#[allow(clippy::unwrap_used, reason = "hardcoded value valid")]
"127.0.0.1:8888".parse().unwrap()
}

Expand Down Expand Up @@ -63,7 +64,7 @@ pub async fn spawn(addr: impl Into<SocketAddr> + 'static) {
.and(warp::path::end())
.and_then(move || async move {
let mut buf = String::new();
#[allow(clippy::needless_borrow)]
#[allow(clippy::needless_borrow, reason = "false positive")]
let response = encode(&mut buf, &&PROMETHEUS_REGISTRY.lock().await)
.map_err(|e| -> Box<dyn std::error::Error> { e.into() })
.map(|_| Box::new(reply::with_status(buf, StatusCode::OK)))
Expand Down Expand Up @@ -118,7 +119,7 @@ impl ProductGlobalMetrics {
pub fn update(&self, product_key: &Pubkey, maybe_symbol: Option<SmolStr>) {
let symbol_string = maybe_symbol
.map(|x| x.into())
.unwrap_or(format!("unknown_{}", product_key));
.unwrap_or(format!("unknown_{product_key}"));

#[deny(unused_variables)]
let Self { update_count } = self;
Expand Down Expand Up @@ -248,7 +249,7 @@ impl PriceGlobalMetrics {
expo.get_or_create(&PriceGlobalLabels {
pubkey: price_key.to_string(),
})
.set(price_account.expo as i64);
.set(i64::from(price_account.expo));

conf.get_or_create(&PriceGlobalLabels {
pubkey: price_key.to_string(),
Expand Down
6 changes: 5 additions & 1 deletion src/agent/pyth/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ async fn handle_connection<S>(
}
}

#[allow(clippy::too_many_arguments)]
#[allow(clippy::too_many_arguments, reason = "")]
async fn handle_next<S>(
state: &S,
ws_tx: &mut SplitSink<WebSocket, Message>,
Expand Down Expand Up @@ -266,6 +266,10 @@ where
if is_batch {
feed_text(ws_tx, &serde_json::to_string(&responses)?).await?;
} else {
#[allow(
clippy::indexing_slicing,
reason = "single response guaranteed to have one item"
)]
feed_text(ws_tx, &serde_json::to_string(&responses[0])?).await?;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/agent/services/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ where
handles
}

#[allow(clippy::module_inception)]
#[allow(clippy::module_inception, reason = "")]
mod exporter {
use {
super::NetworkState,
Expand Down
1 change: 1 addition & 0 deletions src/agent/services/keypairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use {
const DEFAULT_MIN_KEYPAIR_BALANCE_SOL: u64 = 1;

pub fn default_bind_address() -> SocketAddr {
#[allow(clippy::expect_used, reason = "hardcoded value valid")]
"127.0.0.1:9001"
.parse()
.expect("INTERNAL: Could not build default remote keypair loader bind address")
Expand Down
13 changes: 8 additions & 5 deletions src/agent/services/lazer_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ fn get_signing_key(config: &Config) -> Result<SigningKey> {
pub fn lazer_exporter(config: Config, state: Arc<state::State>) -> Vec<JoinHandle<()>> {
let mut handles = vec![];

#[allow(clippy::panic, reason = "agent can't work without keypair")]
let signing_key = match get_signing_key(&config) {
Ok(signing_key) => signing_key,
Err(e) => {
Expand Down Expand Up @@ -324,7 +325,7 @@ pub fn lazer_exporter(config: Config, state: Arc<state::State>) -> Vec<JoinHandl
handles
}

#[allow(clippy::module_inception)]
#[allow(clippy::module_inception, reason = "")]
mod lazer_exporter {
use {
crate::agent::{
Expand Down Expand Up @@ -381,6 +382,7 @@ mod lazer_exporter {
S: LocalStore,
S: Send + Sync + 'static,
{
#[allow(clippy::panic, reason = "lazer exporter can't work without symbols")]
// We can't publish to Lazer without symbols, so crash the process if it fails.
let mut lazer_symbols = match get_lazer_symbol_map(&config.history_url).await {
Ok(symbol_map) => {
Expand Down Expand Up @@ -435,6 +437,7 @@ mod lazer_exporter {
let source_timestamp_micros = price_info.timestamp.and_utc().timestamp_micros();
let source_timestamp = MessageField::some(Timestamp {
seconds: source_timestamp_micros / 1_000_000,
#[allow(clippy::cast_possible_truncation, reason = "value is always less than one billion")]
nanos: (source_timestamp_micros % 1_000_000 * 1000) as i32,
special_fields: Default::default(),
});
Expand Down Expand Up @@ -710,7 +713,7 @@ mod tests {
let mut temp_file = NamedTempFile::new().unwrap();
temp_file
.as_file_mut()
.write(private_key_string.as_bytes())
.write_all(private_key_string.as_bytes())
.unwrap();
temp_file.flush().unwrap();
temp_file
Expand Down Expand Up @@ -758,8 +761,8 @@ mod tests {
.unwrap();
let price = PriceInfo {
status: PriceStatus::Trading,
price: 100_000_00000000i64,
conf: 1_00000000u64,
price: 10_000_000_000_000i64,
conf: 100_000_000u64,
timestamp: Default::default(),
};
state.update(btc_id, price).await.unwrap();
Expand Down Expand Up @@ -787,7 +790,7 @@ mod tests {
} else {
panic!("expected price_update")
};
assert_eq!(price_update.price, Some(100_000_00000000i64));
assert_eq!(price_update.price, Some(10_000_000_000_000i64));
}
_ => panic!("channel should have a transaction waiting"),
}
Expand Down
4 changes: 4 additions & 0 deletions src/agent/services/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ where
let sleep_time = config.oracle.subscriber_finished_sleep_time;
let mut wss_url_index: usize = 0;

#[allow(
clippy::indexing_slicing,
reason = "index will always be valid unless wss_urls is empty"
)]
handles.push(tokio::spawn(async move {
loop {
let current_time = Instant::now();
Expand Down
2 changes: 2 additions & 0 deletions src/agent/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ pub mod network {
Secondary,
}

#[allow(clippy::unwrap_used, reason = "hardcoded value valid")]
pub fn default_rpc_urls() -> Vec<Url> {
vec![Url::parse("http://localhost:8899").unwrap()]
}

#[allow(clippy::unwrap_used, reason = "hardcoded value valid")]
pub fn default_wss_urls() -> Vec<Url> {
vec![Url::parse("http://localhost:8900").unwrap()]
}
Expand Down
4 changes: 2 additions & 2 deletions src/agent/state/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn solana_price_account_to_pythd_api_price_account(
PriceAccount {
account: price_account_key.to_smolstr(),
price_type: "price".into(),
price_exponent: price_account.expo as i64,
price_exponent: i64::from(price_account.expo),
status: price_status_to_str(price_account.agg.status),
price: price_account.agg.price,
conf: price_account.agg.conf,
Expand Down Expand Up @@ -228,7 +228,7 @@ where
.map(|(price_account_key, price_account)| PriceAccountMetadata {
account: price_account_key.to_smolstr(),
price_type: "price".into(),
price_exponent: price_account.expo as i64,
price_exponent: i64::from(price_account.expo),
})
.collect();

Expand Down
8 changes: 6 additions & 2 deletions src/agent/state/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ async fn estimate_compute_unit_price_micro_lamports(
/// - Degrade gracefully if the blockchain RPC node exhibits poor performance. If the RPC node takes a long
/// time to respond, no internal queues grow unboundedly. At any single point in time there are at most
/// (n / batch_size) requests in flight.
#[allow(clippy::too_many_arguments)]
#[allow(clippy::too_many_arguments, reason = "")]
#[instrument(
skip(state, rpc_multi_client, network_state_rx, publish_keypair, staleness_threshold, permissioned_updates),
fields(
Expand Down Expand Up @@ -528,7 +528,7 @@ where
Ok(())
}

#[allow(clippy::too_many_arguments)]
#[allow(clippy::too_many_arguments, reason = "")]
#[instrument(
skip(state, rpc_multi_client, network_state, publish_keypair, batch, staleness_threshold),
fields(
Expand Down Expand Up @@ -624,6 +624,10 @@ where
}

// Pay priority fees, if configured
#[allow(
clippy::cast_possible_truncation,
reason = "number of instructions won't exceed u32"
)]
let total_compute_limit: u32 = compute_unit_limit * instructions.len() as u32;

instructions.push(ComputeBudgetInstruction::set_compute_unit_limit(
Expand Down
Loading
Loading