Skip to content

Commit f9a4a9c

Browse files
authored
Clean up filenames produced by the cli (#400)
- Remove root - Remove current directory symbol - Avoid having duplicates filenames
1 parent 0e7db3a commit f9a4a9c

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

rust-code-analysis-cli/src/formats.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,23 @@ impl Format {
6161
Format::Yaml => ".yml",
6262
};
6363

64-
// Remove . / \ .. symbols from a path to create a unique filename
64+
// Remove root /
65+
let path = path.strip_prefix("/").unwrap_or(path);
66+
67+
// Remove root ./
68+
let path = path.strip_prefix("./").unwrap_or(path);
69+
70+
// Replace .. symbol with "_" to create a unique filename
6571
let cleaned_path: Vec<&str> = path
6672
.iter()
67-
.filter(|v| {
68-
if let Some(s) = v.to_str() {
69-
![".", ".."].contains(&s)
73+
.map(|os_str| {
74+
let s_str = os_str.to_str().unwrap();
75+
if s_str == ".." {
76+
"_"
7077
} else {
71-
false
78+
s_str
7279
}
7380
})
74-
.map(|s| s.to_str().unwrap())
7581
.collect();
7682

7783
// Create the filename

0 commit comments

Comments
 (0)