Skip to content

Commit 8f09b53

Browse files
committed
chore: clippy
1 parent 5c975fa commit 8f09b53

File tree

11 files changed

+31
-37
lines changed

11 files changed

+31
-37
lines changed

src/builder/compose.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ impl DockerBuilder {
360360
timeout: Some(health.timeout.as_nanos() as i64),
361361
retries: Some(health.retries as i64),
362362
start_period: None,
363-
..Default::default()
364363
}
365364
}
366365

@@ -411,7 +410,7 @@ impl DockerBuilder {
411410
}
412411

413412
// Create a temporary directory for the build context
414-
let temp_dir = tempfile::tempdir().map_err(|e| DockerError::FileError(e.into()))?;
413+
let temp_dir = tempfile::tempdir()?;
415414
let temp_dockerfile = temp_dir.path().join("Dockerfile");
416415

417416
// Copy the Dockerfile to temp directory
@@ -481,7 +480,7 @@ impl DockerBuilder {
481480
};
482481

483482
// Pull the image if it doesn't exist
484-
if let Err(_) = self.client.inspect_image(&image).await {
483+
if self.client.inspect_image(&image).await.is_err() {
485484
let mut pull_stream = self.client.create_image(
486485
Some(bollard::image::CreateImageOptions {
487486
from_image: image.as_str(),

src/builder/docker_file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl DockerBuilder {
102102
env: Option<Vec<String>>,
103103
) -> Result<String, DockerError> {
104104
// Create a temporary directory for the build context
105-
let temp_dir = tempfile::tempdir().map_err(|e| DockerError::FileError(e.into()))?;
105+
let temp_dir = tempfile::tempdir()?;
106106
let dockerfile_path = temp_dir.path().join("Dockerfile");
107107

108108
// Write the Dockerfile content from our config

src/builder/management.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl DockerBuilder {
280280
.volumes
281281
.unwrap_or_default()
282282
.into_iter()
283-
.filter_map(|v| Some(v.name))
283+
.map(|v| v.name)
284284
.collect())
285285
}
286286

src/config/compose.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl ComposeConfig {
9292
for (service_name, service) in &self.services {
9393
if let Some(env) = &service.environment {
9494
for var in vars {
95-
if !env.contains_key(*var) {
95+
if !env.contains_key(var) {
9696
return Err(DockerError::ValidationError(format!(
9797
"Service '{}' is missing required environment variable: {}",
9898
service_name, var
@@ -323,7 +323,7 @@ impl ComposeConfig {
323323
})?;
324324
if entry.path().extension().and_then(|s| s.to_str()) == Some("env") {
325325
println!("Loading common env file: {}", entry.path().display());
326-
match std::fs::read_to_string(&entry.path()) {
326+
match std::fs::read_to_string(entry.path()) {
327327
Ok(content) => {
328328
let file_vars =
329329
crate::parser::compose::ComposeParser::parse_env_file(&content)?;

src/config/docker_file.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use serde::{Deserialize, Serialize};
22
use std::collections::HashMap;
3+
use std::fmt::Display;
34

45
#[derive(Debug, Clone, Serialize, Deserialize)]
56
pub struct DockerfileConfig {
@@ -80,16 +81,16 @@ impl DockerfileConfig {
8081
let mut content = format!("FROM {}\n", self.base_image);
8182

8283
for command in &self.commands {
83-
content.push_str(&format!("{}\n", command.to_string()));
84+
content.push_str(&format!("{}\n", command));
8485
}
8586

8687
content
8788
}
8889
}
8990

90-
impl ToString for DockerCommand {
91-
fn to_string(&self) -> String {
92-
match self {
91+
impl Display for DockerCommand {
92+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
93+
let str = match self {
9394
DockerCommand::Add {
9495
sources,
9596
dest,
@@ -174,7 +175,7 @@ impl ToString for DockerCommand {
174175
format!("LABEL {}", labels)
175176
}
176177
DockerCommand::Maintainer { name } => format!("MAINTAINER {}", name),
177-
DockerCommand::Onbuild { command } => format!("ONBUILD {}", command.to_string()),
178+
DockerCommand::Onbuild { command } => format!("ONBUILD {}", command),
178179
DockerCommand::Run { command } => format!("RUN {}", command),
179180
DockerCommand::Shell { shell } => format!("SHELL {}", shell_words::join(shell)),
180181
DockerCommand::StopSignal { signal } => format!("STOPSIGNAL {}", signal),
@@ -187,6 +188,7 @@ impl ToString for DockerCommand {
187188
}
188189
DockerCommand::Volume { paths } => format!("VOLUME {}", shell_words::join(paths)),
189190
DockerCommand::Workdir { path } => format!("WORKDIR {}", path),
190-
}
191+
};
192+
write!(f, "{}", str)
191193
}
192194
}

src/config/env_vars.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde::{Deserialize, Serialize};
22
use std::collections::HashMap;
33

4-
#[derive(Debug, Clone, Serialize)]
4+
#[derive(Debug, Default, Clone, Serialize)]
55
pub struct EnvironmentVars(HashMap<String, String>);
66

77
impl<'de> Deserialize<'de> for EnvironmentVars {
@@ -53,12 +53,6 @@ impl<'de> Deserialize<'de> for EnvironmentVars {
5353
}
5454
}
5555

56-
impl Default for EnvironmentVars {
57-
fn default() -> Self {
58-
EnvironmentVars(HashMap::new())
59-
}
60-
}
61-
6256
impl EnvironmentVars {
6357
pub fn contains_key(&self, key: &str) -> bool {
6458
self.0.contains_key(key)

src/parser/compose.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ impl ComposeParser {
427427
}
428428

429429
#[cfg(test)]
430+
#[allow(clippy::literal_string_with_formatting_args)]
430431
mod tests {
431432
use super::*;
432433
use std::fs;

src/parser/docker_file.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,21 @@ impl DockerfileParser {
4242
};
4343

4444
let mut current_command = String::new();
45-
let mut lines = content.lines().peekable();
4645

47-
while let Some(line) = lines.next() {
46+
for line in content.lines() {
4847
let line = line.trim();
4948
if line.is_empty() || line.starts_with('#') {
5049
continue;
5150
}
5251

5352
// Handle line continuations
54-
if line.ends_with('\\') {
55-
current_command.push_str(&line[..line.len() - 1]);
53+
if let Some(s) = line.strip_suffix('\\') {
54+
current_command.push_str(s);
5655
current_command.push(' ');
5756
continue;
58-
} else if !current_command.is_empty() {
57+
}
58+
59+
if !current_command.is_empty() {
5960
current_command.push_str(line);
6061
Self::parse_command(&mut config, &current_command)?;
6162
current_command.clear();
@@ -303,9 +304,8 @@ impl DockerfileParser {
303304
let mut current_key = String::new();
304305
let mut current_value = String::new();
305306
let mut in_quotes = false;
306-
let mut chars = args.chars().peekable();
307307

308-
while let Some(c) = chars.next() {
308+
for c in args.chars() {
309309
match c {
310310
'"' => in_quotes = !in_quotes,
311311
'=' if !in_quotes && current_key.is_empty() => {
@@ -323,11 +323,7 @@ impl DockerfileParser {
323323
}
324324
}
325325
_ => {
326-
if current_key.is_empty() {
327-
current_value.push(c);
328-
} else {
329-
current_value.push(c);
330-
}
326+
current_value.push(c);
331327
}
332328
}
333329
}

src/tests/compose_health.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ with_docker_cleanup!(test_healthcheck, async |test_id: &str| {
8585
let container_id = container_ids.get(&service_name).unwrap();
8686

8787
// Wait for container to be healthy
88-
builder.wait_for_container(&container_id).await.unwrap();
88+
builder.wait_for_container(container_id).await.unwrap();
8989

9090
// Verify healthcheck configuration
9191
let inspect = builder

src/tests/docker_file.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async fn test_dockerfile_parsing() {
6565
}
6666

6767
// Verify EXPOSE commands
68-
let expected_ports = vec![30333, 9933, 9944, 9615];
68+
let expected_ports = [30333, 9933, 9944, 9615];
6969
for (i, port) in expected_ports.iter().enumerate() {
7070
match &commands[i + 5] {
7171
DockerCommand::Expose { port: p, protocol } => {
@@ -604,7 +604,7 @@ async fn test_expose_multiple_ports() {
604604
let content = "EXPOSE 30333 9933 9944 9615";
605605
let config = DockerfileParser::parse(content).unwrap();
606606

607-
let expected_ports = vec![30333, 9933, 9944, 9615];
607+
let expected_ports = [30333, 9933, 9944, 9615];
608608
assert_eq!(config.commands.len(), expected_ports.len());
609609

610610
for (i, port) in expected_ports.iter().enumerate() {
@@ -622,7 +622,7 @@ async fn test_expose_multiple_ports() {
622622
let config = DockerfileParser::parse(content).unwrap();
623623
assert_eq!(config.commands.len(), 4);
624624

625-
let expected = vec![
625+
let expected = [
626626
(80, Some("tcp")),
627627
(443, None),
628628
(8080, Some("udp")),
@@ -648,7 +648,7 @@ async fn test_tangle_expose_format() {
648648
let content = "EXPOSE 30333 9933 9944 9615";
649649
let config = DockerfileParser::parse(content).unwrap();
650650

651-
let expected_ports = vec![30333, 9933, 9944, 9615];
651+
let expected_ports = [30333, 9933, 9944, 9615];
652652
assert_eq!(config.commands.len(), expected_ports.len());
653653

654654
for (i, expected_port) in expected_ports.iter().enumerate() {

0 commit comments

Comments
 (0)