Enable clippy::useless_format (#8758)

This PR enables the
[`clippy::useless_format`](https://rust-lang.github.io/rust-clippy/master/index.html#/useless_format)
rule and fixes the outstanding violations.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-03-02 23:31:58 -05:00 committed by GitHub
parent 373e18bc88
commit 33790b81fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 70 additions and 46 deletions

View file

@ -355,40 +355,68 @@ struct ToUpload {
impl ToUpload { impl ToUpload {
pub async fn upload(&self, clickhouse_client: &clickhouse::Client) -> anyhow::Result<()> { pub async fn upload(&self, clickhouse_client: &clickhouse::Client) -> anyhow::Result<()> {
Self::upload_to_table("editor_events", &self.editor_events, clickhouse_client) const EDITOR_EVENTS_TABLE: &str = "editor_events";
Self::upload_to_table(EDITOR_EVENTS_TABLE, &self.editor_events, clickhouse_client)
.await .await
.with_context(|| format!("failed to upload to table 'editor_events'"))?; .with_context(|| format!("failed to upload to table '{EDITOR_EVENTS_TABLE}'"))?;
Self::upload_to_table("copilot_events", &self.copilot_events, clickhouse_client)
.await const COPILOT_EVENTS_TABLE: &str = "copilot_events";
.with_context(|| format!("failed to upload to table 'copilot_events'"))?;
Self::upload_to_table( Self::upload_to_table(
"assistant_events", COPILOT_EVENTS_TABLE,
&self.copilot_events,
clickhouse_client,
)
.await
.with_context(|| format!("failed to upload to table '{COPILOT_EVENTS_TABLE}'"))?;
const ASSISTANT_EVENTS_TABLE: &str = "assistant_events";
Self::upload_to_table(
ASSISTANT_EVENTS_TABLE,
&self.assistant_events, &self.assistant_events,
clickhouse_client, clickhouse_client,
) )
.await .await
.with_context(|| format!("failed to upload to table 'assistant_events'"))?; .with_context(|| format!("failed to upload to table '{ASSISTANT_EVENTS_TABLE}'"))?;
Self::upload_to_table("call_events", &self.call_events, clickhouse_client)
const CALL_EVENTS_TABLE: &str = "call_events";
Self::upload_to_table(CALL_EVENTS_TABLE, &self.call_events, clickhouse_client)
.await .await
.with_context(|| format!("failed to upload to table 'call_events'"))?; .with_context(|| format!("failed to upload to table '{CALL_EVENTS_TABLE}'"))?;
Self::upload_to_table("cpu_events", &self.cpu_events, clickhouse_client)
const CPU_EVENTS_TABLE: &str = "cpu_events";
Self::upload_to_table(CPU_EVENTS_TABLE, &self.cpu_events, clickhouse_client)
.await .await
.with_context(|| format!("failed to upload to table 'cpu_events'"))?; .with_context(|| format!("failed to upload to table '{CPU_EVENTS_TABLE}'"))?;
Self::upload_to_table("memory_events", &self.memory_events, clickhouse_client)
const MEMORY_EVENTS_TABLE: &str = "memory_events";
Self::upload_to_table(MEMORY_EVENTS_TABLE, &self.memory_events, clickhouse_client)
.await .await
.with_context(|| format!("failed to upload to table 'memory_events'"))?; .with_context(|| format!("failed to upload to table '{MEMORY_EVENTS_TABLE}'"))?;
Self::upload_to_table("app_events", &self.app_events, clickhouse_client)
const APP_EVENTS_TABLE: &str = "app_events";
Self::upload_to_table(APP_EVENTS_TABLE, &self.app_events, clickhouse_client)
.await .await
.with_context(|| format!("failed to upload to table 'app_events'"))?; .with_context(|| format!("failed to upload to table '{APP_EVENTS_TABLE}'"))?;
Self::upload_to_table("setting_events", &self.setting_events, clickhouse_client)
const SETTING_EVENTS_TABLE: &str = "setting_events";
Self::upload_to_table(
SETTING_EVENTS_TABLE,
&self.setting_events,
clickhouse_client,
)
.await
.with_context(|| format!("failed to upload to table '{SETTING_EVENTS_TABLE}'"))?;
const EDIT_EVENTS_TABLE: &str = "edit_events";
Self::upload_to_table(EDIT_EVENTS_TABLE, &self.edit_events, clickhouse_client)
.await .await
.with_context(|| format!("failed to upload to table 'setting_events'"))?; .with_context(|| format!("failed to upload to table '{EDIT_EVENTS_TABLE}'"))?;
Self::upload_to_table("edit_events", &self.edit_events, clickhouse_client)
const ACTION_EVENTS_TABLE: &str = "action_events";
Self::upload_to_table(ACTION_EVENTS_TABLE, &self.action_events, clickhouse_client)
.await .await
.with_context(|| format!("failed to upload to table 'edit_events'"))?; .with_context(|| format!("failed to upload to table '{ACTION_EVENTS_TABLE}'"))?;
Self::upload_to_table("action_events", &self.action_events, clickhouse_client)
.await
.with_context(|| format!("failed to upload to table 'action_events'"))?;
Ok(()) Ok(())
} }

View file

@ -23,7 +23,7 @@ pub struct TestDb {
impl TestDb { impl TestDb {
pub fn sqlite(background: BackgroundExecutor) -> Self { pub fn sqlite(background: BackgroundExecutor) -> Self {
let url = format!("sqlite::memory:"); let url = "sqlite::memory:";
let runtime = tokio::runtime::Builder::new_current_thread() let runtime = tokio::runtime::Builder::new_current_thread()
.enable_io() .enable_io()
.enable_time() .enable_time()

View file

@ -10,10 +10,10 @@ test_both_dbs!(
async fn test_contributors(db: &Arc<Database>) { async fn test_contributors(db: &Arc<Database>) {
db.create_user( db.create_user(
&format!("user1@example.com"), "user1@example.com",
false, false,
NewUserParams { NewUserParams {
github_login: format!("user1"), github_login: "user1".to_string(),
github_user_id: 1, github_user_id: 1,
}, },
) )

View file

@ -494,7 +494,7 @@ async fn test_project_count(db: &Arc<Database>) {
let user1 = db let user1 = db
.create_user( .create_user(
&format!("admin@example.com"), "admin@example.com",
true, true,
NewUserParams { NewUserParams {
github_login: "admin".into(), github_login: "admin".into(),
@ -505,7 +505,7 @@ async fn test_project_count(db: &Arc<Database>) {
.unwrap(); .unwrap();
let user2 = db let user2 = db
.create_user( .create_user(
&format!("user@example.com"), "user@example.com",
false, false,
NewUserParams { NewUserParams {
github_login: "user".into(), github_login: "user".into(),

View file

@ -13,10 +13,10 @@ test_both_dbs!(
async fn test_get_user_flags(db: &Arc<Database>) { async fn test_get_user_flags(db: &Arc<Database>) {
let user_1 = db let user_1 = db
.create_user( .create_user(
&format!("user1@example.com"), "user1@example.com",
false, false,
NewUserParams { NewUserParams {
github_login: format!("user1"), github_login: "user1".to_string(),
github_user_id: 1, github_user_id: 1,
}, },
) )
@ -26,10 +26,10 @@ async fn test_get_user_flags(db: &Arc<Database>) {
let user_2 = db let user_2 = db
.create_user( .create_user(
&format!("user2@example.com"), "user2@example.com",
false, false,
NewUserParams { NewUserParams {
github_login: format!("user2"), github_login: "user2".to_string(),
github_user_id: 2, github_user_id: 2,
}, },
) )

View file

@ -376,7 +376,7 @@ impl Item for ChannelView {
(_, false) => format!("#{} (disconnected)", channel.name), (_, false) => format!("#{} (disconnected)", channel.name),
} }
} else { } else {
format!("channel notes (disconnected)") "channel notes (disconnected)".to_string()
}; };
Label::new(label) Label::new(label)
.color(if selected { .color(if selected {

View file

@ -137,9 +137,9 @@ impl MessageEditor {
) { ) {
self.editor.update(cx, |editor, cx| { self.editor.update(cx, |editor, cx| {
if let Some(channel_name) = channel_name { if let Some(channel_name) = channel_name {
editor.set_placeholder_text(format!("Message #{}", channel_name), cx); editor.set_placeholder_text(format!("Message #{channel_name}"), cx);
} else { } else {
editor.set_placeholder_text(format!("Message Channel"), cx); editor.set_placeholder_text("Message Channel", cx);
} }
}); });
self.channel_id = Some(channel_id); self.channel_id = Some(channel_id);

View file

@ -952,7 +952,7 @@ impl CollabPanel {
}) })
.ok(); .ok();
})) }))
.tooltip(move |cx| Tooltip::text(format!("Open shared screen"), cx)) .tooltip(move |cx| Tooltip::text("Open shared screen", cx))
}) })
} }
@ -2220,7 +2220,7 @@ impl CollabPanel {
}); });
if let Some(name) = channel_name { if let Some(name) = channel_name {
SharedString::from(format!("{}", name)) SharedString::from(name.to_string())
} else { } else {
SharedString::from("Current Call") SharedString::from("Current Call")
} }

View file

@ -778,7 +778,7 @@ fn format_timestamp(
"just now".to_string() "just now".to_string()
} }
} else if date.next_day() == Some(today) { } else if date.next_day() == Some(today) {
format!("yesterday") "yesterday".to_string()
} else { } else {
format!("{:02}/{}/{}", date.month() as u32, date.day(), date.year()) format!("{:02}/{}/{}", date.month() as u32, date.day(), date.year())
} }

View file

@ -693,22 +693,22 @@ mod tests {
Inlay { Inlay {
id: InlayId::Suggestion(post_inc(&mut id)), id: InlayId::Suggestion(post_inc(&mut id)),
position: buffer_snapshot.anchor_at(offset, Bias::Left), position: buffer_snapshot.anchor_at(offset, Bias::Left),
text: format!("test").into(), text: "test".into(),
}, },
Inlay { Inlay {
id: InlayId::Suggestion(post_inc(&mut id)), id: InlayId::Suggestion(post_inc(&mut id)),
position: buffer_snapshot.anchor_at(offset, Bias::Right), position: buffer_snapshot.anchor_at(offset, Bias::Right),
text: format!("test").into(), text: "test".into(),
}, },
Inlay { Inlay {
id: InlayId::Hint(post_inc(&mut id)), id: InlayId::Hint(post_inc(&mut id)),
position: buffer_snapshot.anchor_at(offset, Bias::Left), position: buffer_snapshot.anchor_at(offset, Bias::Left),
text: format!("test").into(), text: "test".into(),
}, },
Inlay { Inlay {
id: InlayId::Hint(post_inc(&mut id)), id: InlayId::Hint(post_inc(&mut id)),
position: buffer_snapshot.anchor_at(offset, Bias::Right), position: buffer_snapshot.anchor_at(offset, Bias::Right),
text: format!("test").into(), text: "test".into(),
}, },
] ]
}) })

View file

@ -272,10 +272,7 @@ impl NeovimConnection {
#[cfg(feature = "neovim")] #[cfg(feature = "neovim")]
pub async fn exec(&mut self, value: &str) { pub async fn exec(&mut self, value: &str) {
self.nvim self.nvim.command_output(value).await.unwrap();
.command_output(format!("{}", value).as_str())
.await
.unwrap();
self.data.push_back(NeovimData::Exec { self.data.push_back(NeovimData::Exec {
command: value.to_string(), command: value.to_string(),

View file

@ -113,7 +113,6 @@ fn run_clippy(args: ClippyArgs) -> Result<()> {
"clippy::type_complexity", "clippy::type_complexity",
"clippy::unnecessary_to_owned", "clippy::unnecessary_to_owned",
"clippy::useless_conversion", "clippy::useless_conversion",
"clippy::useless_format",
"clippy::vec_init_then_push", "clippy::vec_init_then_push",
]; ];