Skip to content

Commit 58796c3

Browse files
authored
chore: modernize string formatting with string interpolation (#118)
This PR updates string formatting across multiple files to use Rust's string interpolation syntax with named variables instead of positional formatting arguments. The changes include: * Replacing `"{}", var` with `"{var}"` for cleaner, more readable code and to make `clippy` happy
1 parent e3daf6f commit 58796c3

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/bundler.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,12 @@ impl Bundler {
6363
Some(status) => {
6464
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
6565
Err(format!(
66-
"'bundle' command failed (status: {})\nError: {}",
67-
status, stderr
66+
"'bundle' command failed (status: {status})\nError: {stderr}",
6867
))
6968
}
7069
None => {
7170
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
72-
Err(format!("Failed to execute 'bundle' command: {}", stderr))
71+
Err(format!("Failed to execute 'bundle' command: {stderr}"))
7372
}
7473
})
7574
}
@@ -156,7 +155,7 @@ mod tests {
156155
gem: &str,
157156
) -> MockCommandExecutor {
158157
let mock = MockCommandExecutor::new();
159-
let gemfile_path = format!("{}/Gemfile", dir);
158+
let gemfile_path = format!("{dir}/Gemfile");
160159
mock.expect(
161160
"bundle",
162161
&["info", "--version", gem],

src/gemset.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl Gemset {
2424

2525
path.to_str()
2626
.map(ToString::to_string)
27-
.ok_or_else(|| format!("Failed to convert path for '{}'", bin_name))
27+
.ok_or_else(|| format!("Failed to convert path for '{bin_name}'"))
2828
}
2929

3030
pub fn gem_path_env(&self) -> Vec<(String, String)> {
@@ -43,20 +43,20 @@ impl Gemset {
4343
];
4444

4545
self.execute_gem_command("install".into(), args)
46-
.map_err(|e| format!("Failed to install gem '{}': {}", name, e))?;
46+
.map_err(|e| format!("Failed to install gem '{name}': {e}"))?;
4747

4848
Ok(())
4949
}
5050

5151
pub fn update_gem(&self, name: &str) -> Result<(), String> {
5252
self.execute_gem_command("update".into(), vec![name.into()])
53-
.map_err(|e| format!("Failed to update gem '{}': {}", name, e))?;
53+
.map_err(|e| format!("Failed to update gem '{name}': {e}"))?;
5454
Ok(())
5555
}
5656

5757
pub fn installed_gem_version(&self, name: &str) -> Result<Option<String>, String> {
58-
let re = Regex::new(r"^(\S+) \((.+)\)$")
59-
.map_err(|e| format!("Failed to compile regex: {}", e))?;
58+
let re =
59+
Regex::new(r"^(\S+) \((.+)\)$").map_err(|e| format!("Failed to compile regex: {e}"))?;
6060

6161
let args = vec!["--exact".to_string(), name.into()];
6262
let output_str = self.execute_gem_command("list".into(), args)?;
@@ -100,13 +100,12 @@ impl Gemset {
100100
Some(status) => {
101101
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
102102
Err(format!(
103-
"Gem command failed (status: {})\nError: {}",
104-
status, stderr
103+
"Gem command failed (status: {status})\nError: {stderr}",
105104
))
106105
}
107106
None => {
108107
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
109-
Err(format!("Failed to execute gem command: {}", stderr))
108+
Err(format!("Failed to execute gem command: {stderr}"))
110109
}
111110
})
112111
}

src/language_servers/language_server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl WorktreeLike for FakeWorktree {
9797
self.files
9898
.get(path)
9999
.cloned()
100-
.unwrap_or_else(|| Err(format!("File not found in mock: {}", path)))
100+
.unwrap_or_else(|| Err(format!("File not found in mock: {path}")))
101101
}
102102

103103
fn lsp_binary_settings(&self, server_id: &str) -> Result<Option<LspBinarySettings>, String> {
@@ -212,7 +212,7 @@ pub trait LanguageServer {
212212
worktree: &zed::Worktree,
213213
) -> zed::Result<LanguageServerBinary> {
214214
let gem_home = std::env::current_dir()
215-
.map_err(|e| format!("Failed to get extension directory: {}", e))?
215+
.map_err(|e| format!("Failed to get extension directory: {e}"))?
216216
.to_string_lossy()
217217
.to_string();
218218

0 commit comments

Comments
 (0)