From 4e8c33a6d1e47c8848a12c5f4d0a319f17bd4f0e Mon Sep 17 00:00:00 2001 From: Caleb Cox Date: Sun, 3 Nov 2024 14:28:49 -0600 Subject: [PATCH] Forbid calling to_string on &str --- src/main.rs | 14 +++++++------- src/mocks.rs | 4 ++-- src/registry.rs | 12 ++++++------ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index bab07fd..70780b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -#![warn(clippy::pedantic, clippy::nursery)] +#![warn(clippy::str_to_string, clippy::pedantic, clippy::nursery)] #![allow(clippy::module_name_repetitions)] mod allocator; @@ -45,7 +45,7 @@ fn get_active_project<'registry>( // Find and return a reference to the active project based on the current directory fn get_active_repo(deps: &impl Exec) -> Result { deps.exec(Command::new("git").args(["remote", "get-url", "origin"])) - .map(|repo| repo.trim_end().to_string()) + .map(|repo| repo.trim_end().to_owned()) .map_err(ApplicationError::GitCommand) } @@ -724,7 +724,7 @@ Allowed port ranges: 3000-3999 read_var_mock(), ReadFileMock .each_call(matching!((path) if path == &PathBuf::from("/data/config.toml"))) - .answers(&|_, _| Ok(include_str!("fixtures/custom_config.toml").to_string())) + .answers(&|_, _| Ok(include_str!("fixtures/custom_config.toml").to_owned())) .once(), )); @@ -748,11 +748,11 @@ Reserved ports: 2002, 4004 data_dir_mock(), EnvironmentMock .each_call(matching!("PORTMAN_CONFIG")) - .answers(&|_, _| Ok("/data/custom_config.toml".to_string())) + .answers(&|_, _| Ok("/data/custom_config.toml".to_owned())) .at_least_times(1), ReadFileMock .each_call(matching!((path) if path == &PathBuf::from("/data/custom_config.toml"))) - .answers(&|_, _| Ok(include_str!("fixtures/custom_config.toml").to_string())) + .answers(&|_, _| Ok(include_str!("fixtures/custom_config.toml").to_owned())) .once(), )); @@ -775,7 +775,7 @@ Reserved ports: 2002, 4004 args_mock("portman config show"), EnvironmentMock .each_call(matching!("PORTMAN_CONFIG")) - .answers(&|_, _| Ok("/data/custom_config.toml".to_string())) + .answers(&|_, _| Ok("/data/custom_config.toml".to_owned())) .at_least_times(1), ReadFileMock .each_call(matching!((path) if path == &PathBuf::from("/data/custom_config.toml"))) @@ -1089,7 +1089,7 @@ Try running `portman config edit` to edit the config file and modify the `ranges read_var_mock(), ReadFileMock .each_call(matching!((path) if path == &PathBuf::from("/data/config.toml"))) - .answers(&|_, _| Ok(include_str!("fixtures/invalid_config.toml").to_string())) + .answers(&|_, _| Ok(include_str!("fixtures/invalid_config.toml").to_owned())) .once(), )); diff --git a/src/mocks.rs b/src/mocks.rs index bc1cc67..db13627 100644 --- a/src/mocks.rs +++ b/src/mocks.rs @@ -64,7 +64,7 @@ pub fn exec_git_mock(project: &str) -> impl Clause { pub fn read_registry_mock(contents: Option<&str>) -> impl Clause { let result = contents .unwrap_or(include_str!("fixtures/registry.toml")) - .to_string(); + .to_owned(); ReadFileMock .each_call(matching!((path) if path == &PathBuf::from("/data/registry.toml"))) .answers_arc(Arc::new(move |_, _| Ok(result.clone()))) @@ -105,7 +105,7 @@ pub fn write_caddyfile_mock() -> impl Clause { pub fn write_registry_mock(expected_contents: &'static str) -> impl Clause { WriteFileMock - .each_call(matching!((path, contents) if path == &PathBuf::from("/data/registry.toml") && contents == &expected_contents.to_string())) + .each_call(matching!((path, contents) if path == &PathBuf::from("/data/registry.toml") && contents == &expected_contents.to_owned())) .answers(&|_, _, _| Ok(())) .at_least_times(1) } diff --git a/src/registry.rs b/src/registry.rs index cb2f96f..cbf8016 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -150,7 +150,7 @@ impl Registry { Self::validate_name(name)?; if self.projects.contains_key(name) { - return Err(ApplicationError::DuplicateProject(name.to_string())); + return Err(ApplicationError::DuplicateProject(name.to_owned())); } if let Some(directory) = directory.as_ref() { @@ -176,7 +176,7 @@ impl Registry { directory, linked_port: None, }; - self.projects.insert(name.to_string(), new_project.clone()); + self.projects.insert(name.to_owned(), new_project.clone()); if let Some(port) = linked_port { self.link(deps, name, port)?; @@ -286,7 +286,7 @@ impl Registry { self.repos .get(repo) .copied() - .ok_or_else(|| ApplicationError::NonExistentRepo(repo.to_string())) + .ok_or_else(|| ApplicationError::NonExistentRepo(repo.to_owned())) } // Get the port associated with a repo @@ -302,7 +302,7 @@ impl Registry { if deleted_repo.is_some() { self.dirty = true; } - deleted_repo.ok_or_else(|| ApplicationError::NonExistentRepo(repo.to_string())) + deleted_repo.ok_or_else(|| ApplicationError::NonExistentRepo(repo.to_owned())) } // Delete a repo's port association @@ -874,7 +874,7 @@ linked_port = 3000", fn test_set_repo_port() { let mut registry = get_mocked_registry().unwrap(); let repo = "https://github.com/user/project.git"; - registry.set_repo_port(repo.to_string(), 3005); + registry.set_repo_port(repo.to_owned(), 3005); assert!(registry.dirty); assert_eq!(registry.repos.get(repo).unwrap(), &3005); } @@ -883,7 +883,7 @@ linked_port = 3000", fn test_set_repo_port_existing() { let mut registry = get_mocked_registry().unwrap(); let repo = "https://github.com/user/app3.git"; - registry.set_repo_port(repo.to_string(), 3004); + registry.set_repo_port(repo.to_owned(), 3004); assert!(!registry.dirty); assert_eq!(registry.repos.get(repo).unwrap(), &3004); }