Skip to content

Commit

Permalink
Forbid calling to_string on &str
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Nov 3, 2024
1 parent 1c3fea1 commit 4e8c33a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<String> {
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)
}

Expand Down Expand Up @@ -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(),
));

Expand All @@ -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(),
));

Expand All @@ -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")))
Expand Down Expand Up @@ -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(),
));

Expand Down
4 changes: 2 additions & 2 deletions src/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())))
Expand Down Expand Up @@ -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)
}
Expand Down
12 changes: 6 additions & 6 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)?;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 4e8c33a

Please sign in to comment.