From 3c4b7c8a5a1827ac69cd9948c670ff14602c591b Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:42:23 +0300 Subject: [PATCH 1/3] Do not remove space before .ext --- rust/src/project.rs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/rust/src/project.rs b/rust/src/project.rs index 7d73e1b..b17af4a 100644 --- a/rust/src/project.rs +++ b/rust/src/project.rs @@ -26,6 +26,7 @@ pub fn fix( return; } let table = &mut table_element.unwrap().first().unwrap().borrow_mut(); + let re = Regex::new(r" \.(\W)").unwrap(); expand_entry_points_inline_tables(table); for_entries(table, &mut |key, entry| match key.split('.').next().unwrap() { "name" => { @@ -36,18 +37,21 @@ pub fn fix( } "description" => { update_content(entry, |s| { - s.trim() - .lines() - .map(|part| { - part.trim() - .split(char::is_whitespace) - .filter(|part| !part.trim().is_empty()) - .collect::>() - .join(" ") - .replace(" .", ".") - }) - .collect::>() - .join(" ") + re.replace_all( + &s.trim() + .lines() + .map(|part| { + part.trim() + .split(char::is_whitespace) + .filter(|part| !part.trim().is_empty()) + .collect::>() + .join(" ") + }) + .collect::>() + .join(" "), + ".$1", + ) + .to_string() }); } "requires-python" => { @@ -659,10 +663,10 @@ mod tests { (3, 13), )] #[case::project_description_whitespace( - "[project]\ndescription = ' A magic stuff \t is great\t\t.\r\n Like really .\t\'\nrequires-python = '==3.12'", + "[project]\ndescription = ' A magic stuff \t is great\t\t.\r\n Like really . Works on .rst and .NET :)\t\'\nrequires-python = '==3.12'", indoc ! {r#" [project] - description = "A magic stuff is great. Like really." + description = "A magic stuff is great. Like really. Works on .rst and .NET :)" requires-python = "==3.12" classifiers = [ "Programming Language :: Python :: 3 :: Only", From 3c4720148e4cee701e55d404de1a97f43527f0c4 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:44:28 +0300 Subject: [PATCH 2/3] Prefer .split_whitespace() --- rust/src/project.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/src/project.rs b/rust/src/project.rs index b17af4a..ad14c23 100644 --- a/rust/src/project.rs +++ b/rust/src/project.rs @@ -42,7 +42,7 @@ pub fn fix( .lines() .map(|part| { part.trim() - .split(char::is_whitespace) + .split_whitespace() .filter(|part| !part.trim().is_empty()) .collect::>() .join(" ") From d09563ed9c5bc4effc81d000bdc4cec24fb9e5e4 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 11 Oct 2024 15:37:16 +0300 Subject: [PATCH 3/3] clippy: remove trim before split_whitespace --- rust/src/project.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rust/src/project.rs b/rust/src/project.rs index ad14c23..7ac9ee7 100644 --- a/rust/src/project.rs +++ b/rust/src/project.rs @@ -41,8 +41,7 @@ pub fn fix( &s.trim() .lines() .map(|part| { - part.trim() - .split_whitespace() + part.split_whitespace() .filter(|part| !part.trim().is_empty()) .collect::>() .join(" ")