Skip to content

Commit 13ada97

Browse files
authored
Updated clippy config (#170)
1 parent 7e1305e commit 13ada97

File tree

15 files changed

+100
-32
lines changed

15 files changed

+100
-32
lines changed

Cargo.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,43 @@ panic = 'abort'
6666

6767
[profile.dev]
6868
panic = 'abort'
69+
70+
[lints.rust]
71+
unsafe_code = "deny"
72+
73+
[lints.clippy]
74+
wildcard_dependencies = "deny"
75+
76+
collapsible_if = "allow"
77+
collapsible_else_if = "allow"
78+
79+
allow_attributes_without_reason = "warn"
80+
81+
# Panics
82+
expect_used = "warn"
83+
fallible_impl_from = "warn"
84+
indexing_slicing = "warn"
85+
panic = "warn"
86+
panic_in_result_fn = "warn"
87+
string_slice = "warn"
88+
todo = "warn"
89+
unchecked_duration_subtraction = "warn"
90+
unreachable = "warn"
91+
unwrap_in_result = "warn"
92+
unwrap_used = "warn"
93+
94+
# Correctness
95+
cast_lossless = "warn"
96+
cast_possible_truncation = "warn"
97+
cast_possible_wrap = "warn"
98+
cast_sign_loss = "warn"
99+
collection_is_never_read = "warn"
100+
match_wild_err_arm = "warn"
101+
path_buf_push_overwrite = "warn"
102+
read_zero_byte_vec = "warn"
103+
same_name_method = "warn"
104+
suspicious_operation_groupings = "warn"
105+
suspicious_xor_used_as_pow = "warn"
106+
unused_self = "warn"
107+
used_underscore_binding = "warn"
108+
while_float = "warn"

clippy.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
allow-unwrap-in-tests = true
2+
allow-expect-in-tests = true
3+
allow-indexing-slicing-in-tests = true
4+
allow-panic-in-tests = true

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
2-
channel = "1.86.0"
2+
channel = "1.88.0"
33
profile = "minimal"
44
components = ["rustfmt", "clippy"]

src/agent/legacy_schedule.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Market hours metadata parsing and evaluation logic
2-
#![allow(deprecated)]
2+
#![allow(deprecated, reason = "publishers depend on legacy schedule")]
33

44
use {
55
anyhow::{
@@ -46,6 +46,7 @@ pub struct LegacySchedule {
4646
pub sun: MHKind,
4747
}
4848

49+
#[allow(deprecated, reason = "publishers depend on legacy schedule")]
4950
impl LegacySchedule {
5051
pub fn all_closed() -> Self {
5152
Self {
@@ -93,7 +94,7 @@ impl FromStr for LegacySchedule {
9394
.trim()
9495
.parse()
9596
.map_err(|e: ParseError| anyhow!(e))
96-
.context(format!("Could parse timezone from {:?}", tz_str))?;
97+
.context(format!("Could parse timezone from {tz_str:?}"))?;
9798

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

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

114115
let mhkind: MHKind = mhkind_str.trim().parse().context(format!(
115-
"Could not parse {} field from {:?}",
116-
weekday, mhkind_str
116+
"Could not parse {weekday} field from {mhkind_str:?}",
117117
))?;
118118

119119
weekday_schedules.push(mhkind);
@@ -225,6 +225,7 @@ impl FromStr for MHKind {
225225
}
226226

227227
#[cfg(test)]
228+
#[allow(clippy::panic_in_result_fn, reason = "")]
228229
mod tests {
229230
use {
230231
super::*,

src/agent/market_schedule.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Holiday hours metadata parsing and evaluation logic
22
3-
#[allow(deprecated)]
3+
#[allow(deprecated, reason = "publishers depend on legacy schedule")]
44
use {
55
super::legacy_schedule::{
66
LegacySchedule,
@@ -68,14 +68,14 @@ impl Display for MarketSchedule {
6868
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6969
write!(f, "{};", self.timezone)?;
7070
for (i, day) in self.weekly_schedule.iter().enumerate() {
71-
write!(f, "{}", day)?;
71+
write!(f, "{day}")?;
7272
if i < 6 {
7373
write!(f, ",")?;
7474
}
7575
}
7676
write!(f, ";")?;
7777
for (i, holiday) in self.holidays.iter().enumerate() {
78-
write!(f, "{}", holiday)?;
78+
write!(f, "{holiday}")?;
7979
if i < self.holidays.len() - 1 {
8080
write!(f, ",")?;
8181
}
@@ -131,7 +131,7 @@ impl FromStr for MarketSchedule {
131131
}
132132
}
133133

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

285285
#[cfg(test)]
286+
#[allow(clippy::panic_in_result_fn, reason = "")]
286287
mod tests {
287288
use {
288289
super::*,
@@ -604,7 +605,7 @@ mod tests {
604605

605606
#[test]
606607
fn parse_valid_holiday_day_schedule(s in VALID_SCHEDULE_DAY_KIND_REGEX, d in VALID_MONTH_DAY_REGEX) {
607-
let valid_holiday_day = format!("{}/{}", d, s);
608+
let valid_holiday_day = format!("{d}/{s}");
608609
assert!(valid_holiday_day.parse::<HolidayDaySchedule>().is_ok());
609610
}
610611

src/agent/metrics.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use {
3535
};
3636

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

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

123124
#[deny(unused_variables)]
124125
let Self { update_count } = self;
@@ -248,7 +249,7 @@ impl PriceGlobalMetrics {
248249
expo.get_or_create(&PriceGlobalLabels {
249250
pubkey: price_key.to_string(),
250251
})
251-
.set(price_account.expo as i64);
252+
.set(i64::from(price_account.expo));
252253

253254
conf.get_or_create(&PriceGlobalLabels {
254255
pubkey: price_key.to_string(),

src/agent/pyth/rpc.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ async fn handle_connection<S>(
170170
}
171171
}
172172

173-
#[allow(clippy::too_many_arguments)]
173+
#[allow(clippy::too_many_arguments, reason = "")]
174174
async fn handle_next<S>(
175175
state: &S,
176176
ws_tx: &mut SplitSink<WebSocket, Message>,
@@ -266,6 +266,10 @@ where
266266
if is_batch {
267267
feed_text(ws_tx, &serde_json::to_string(&responses)?).await?;
268268
} else {
269+
#[allow(
270+
clippy::indexing_slicing,
271+
reason = "single response guaranteed to have one item"
272+
)]
269273
feed_text(ws_tx, &serde_json::to_string(&responses[0])?).await?;
270274
}
271275
}

src/agent/services/exporter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ where
210210
handles
211211
}
212212

213-
#[allow(clippy::module_inception)]
213+
#[allow(clippy::module_inception, reason = "")]
214214
mod exporter {
215215
use {
216216
super::NetworkState,

src/agent/services/keypairs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use {
3838
const DEFAULT_MIN_KEYPAIR_BALANCE_SOL: u64 = 1;
3939

4040
pub fn default_bind_address() -> SocketAddr {
41+
#[allow(clippy::expect_used, reason = "hardcoded value valid")]
4142
"127.0.0.1:9001"
4243
.parse()
4344
.expect("INTERNAL: Could not build default remote keypair loader bind address")

src/agent/services/lazer_exporter.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ fn get_signing_key(config: &Config) -> Result<SigningKey> {
282282
pub fn lazer_exporter(config: Config, state: Arc<state::State>) -> Vec<JoinHandle<()>> {
283283
let mut handles = vec![];
284284

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

327-
#[allow(clippy::module_inception)]
328+
#[allow(clippy::module_inception, reason = "")]
328329
mod lazer_exporter {
329330
use {
330331
crate::agent::{
@@ -381,6 +382,7 @@ mod lazer_exporter {
381382
S: LocalStore,
382383
S: Send + Sync + 'static,
383384
{
385+
#[allow(clippy::panic, reason = "lazer exporter can't work without symbols")]
384386
// We can't publish to Lazer without symbols, so crash the process if it fails.
385387
let mut lazer_symbols = match get_lazer_symbol_map(&config.history_url).await {
386388
Ok(symbol_map) => {
@@ -435,6 +437,7 @@ mod lazer_exporter {
435437
let source_timestamp_micros = price_info.timestamp.and_utc().timestamp_micros();
436438
let source_timestamp = MessageField::some(Timestamp {
437439
seconds: source_timestamp_micros / 1_000_000,
440+
#[allow(clippy::cast_possible_truncation, reason = "value is always less than one billion")]
438441
nanos: (source_timestamp_micros % 1_000_000 * 1000) as i32,
439442
special_fields: Default::default(),
440443
});
@@ -710,7 +713,7 @@ mod tests {
710713
let mut temp_file = NamedTempFile::new().unwrap();
711714
temp_file
712715
.as_file_mut()
713-
.write(private_key_string.as_bytes())
716+
.write_all(private_key_string.as_bytes())
714717
.unwrap();
715718
temp_file.flush().unwrap();
716719
temp_file
@@ -758,8 +761,8 @@ mod tests {
758761
.unwrap();
759762
let price = PriceInfo {
760763
status: PriceStatus::Trading,
761-
price: 100_000_00000000i64,
762-
conf: 1_00000000u64,
764+
price: 10_000_000_000_000i64,
765+
conf: 100_000_000u64,
763766
timestamp: Default::default(),
764767
};
765768
state.update(btc_id, price).await.unwrap();
@@ -787,7 +790,7 @@ mod tests {
787790
} else {
788791
panic!("expected price_update")
789792
};
790-
assert_eq!(price_update.price, Some(100_000_00000000i64));
793+
assert_eq!(price_update.price, Some(10_000_000_000_000i64));
791794
}
792795
_ => panic!("channel should have a transaction waiting"),
793796
}

0 commit comments

Comments
 (0)