Added allow-expect-in-tests / allow-unwrap-in-tests (#2328)

This PR:
* Added the clippy.toml to configure allowable expect / unwrap usage in
tests
* Removed as many expect/allow lines as possible from tests
* moved a bunch of allows to expects where possible

Note: in integration tests, non `#[test]` helper functions are not
covered by this so we had to leave a few lingering `expect(expect_used`
checks around
This commit is contained in:
Parker Thompson
2025-08-14 17:59:01 -07:00
committed by GitHub
parent 8bdb4521c9
commit a075424437
72 changed files with 38 additions and 126 deletions

View File

@@ -188,7 +188,7 @@ impl App<'_> {
}
}
#[allow(clippy::expect_used)]
#[expect(clippy::expect_used)]
let deadline = next_deadline.expect("deadline set");
let now = Instant::now();
let timeout = if deadline > now {

View File

@@ -182,7 +182,6 @@ impl ChatComposerHistory {
#[cfg(test)]
mod tests {
#![expect(clippy::expect_used)]
use super::*;
use crate::app_event::AppEvent;
use codex_core::protocol::Op;

View File

@@ -801,7 +801,7 @@ impl TextArea {
}
}
#[allow(clippy::unwrap_used)]
#[expect(clippy::unwrap_used)]
fn wrapped_lines(&self, width: u16) -> Ref<'_, Vec<Range<usize>>> {
// Ensure cache is ready (potentially mutably borrow, then drop)
{
@@ -926,7 +926,6 @@ impl TextArea {
}
#[cfg(test)]
#[allow(clippy::unwrap_used)]
mod tests {
use super::*;
// crossterm types are intentionally not imported here to avoid unused warnings
@@ -1432,7 +1431,6 @@ mod tests {
// Seed the RNG based on the current day in Pacific Time (PST/PDT). This
// keeps the fuzz test deterministic within a day while still varying
// day-to-day to improve coverage.
#[allow(clippy::unwrap_used)]
let pst_today_seed: u64 = (chrono::Utc::now() - chrono::Duration::hours(8))
.date_naive()
.and_hms_opt(0, 0, 0)

View File

@@ -1,5 +1,3 @@
#![allow(clippy::unwrap_used, clippy::expect_used, unnameable_test_items)]
use super::*;
use crate::app_event::AppEvent;
use crate::app_event_sender::AppEventSender;

View File

@@ -1,4 +1,4 @@
#![allow(clippy::expect_used)]
#![expect(clippy::expect_used)]
use regex_lite::Regex;

View File

@@ -357,7 +357,6 @@ fn style_del() -> Style {
Style::default().fg(Color::Red)
}
#[allow(clippy::expect_used)]
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -31,10 +31,7 @@ use std::time::Duration;
use crate::app_event::AppEvent;
use crate::app_event_sender::AppEventSender;
#[allow(clippy::unwrap_used)]
const MAX_FILE_SEARCH_RESULTS: NonZeroUsize = NonZeroUsize::new(8).unwrap();
#[allow(clippy::unwrap_used)]
const NUM_FILE_SEARCH_THREADS: NonZeroUsize = NonZeroUsize::new(2).unwrap();
/// How long to wait after a keystroke before firing the first search when none
@@ -84,7 +81,7 @@ impl FileSearchManager {
/// Call whenever the user edits the `@` token.
pub fn on_user_query(&self, query: String) {
{
#[allow(clippy::unwrap_used)]
#[expect(clippy::unwrap_used)]
let mut st = self.state.lock().unwrap();
if query == st.latest_query {
// No change, nothing to do.
@@ -125,7 +122,7 @@ impl FileSearchManager {
// `active_search` is cleared.
thread::sleep(FILE_SEARCH_DEBOUNCE);
loop {
#[allow(clippy::unwrap_used)]
#[expect(clippy::unwrap_used)]
if state.lock().unwrap().active_search.is_none() {
break;
}
@@ -137,7 +134,7 @@ impl FileSearchManager {
let cancellation_token = Arc::new(AtomicBool::new(false));
let token = cancellation_token.clone();
let query = {
#[allow(clippy::unwrap_used)]
#[expect(clippy::unwrap_used)]
let mut st = state.lock().unwrap();
let query = st.latest_query.clone();
st.is_search_scheduled = false;
@@ -188,7 +185,7 @@ impl FileSearchManager {
// that we are clearing the ActiveSearch that corresponds to the
// cancellation token we were given.
{
#[allow(clippy::unwrap_used)]
#[expect(clippy::unwrap_used)]
let mut st = search_state.lock().unwrap();
if let Some(active_search) = &st.active_search {
if Arc::ptr_eq(&active_search.cancellation_token, &cancellation_token) {

View File

@@ -379,7 +379,6 @@ fn slice_line_spans(
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used)]
use super::*;
#[test]

View File

@@ -295,7 +295,6 @@ fn restore() {
}
}
#[allow(clippy::unwrap_used)]
fn should_show_login_screen(config: &Config) -> bool {
if config.model_provider.requires_openai_auth {
// Reading the OpenAI API key is an async operation because it may need

View File

@@ -102,7 +102,6 @@ pub(crate) fn truncate_text(text: &str, max_graphemes: usize) -> String {
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used)]
use super::*;
use pretty_assertions::assert_eq;