Skip to content

Commit

Permalink
Clean up filenames produced by the cli
Browse files Browse the repository at this point in the history
- Remove root
- Remove current directory symbol
- Avoid having duplicates filenames
  • Loading branch information
Luni-4 committed Dec 22, 2020
1 parent 0e7db3a commit f263eba
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions rust-code-analysis-cli/src/formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,23 @@ impl Format {
Format::Yaml => ".yml",
};

// Remove . / \ .. symbols from a path to create a unique filename
// Remove root /
let path = path.strip_prefix("/").unwrap_or(path);

// Remove root ./
let path = path.strip_prefix("./").unwrap_or(path);

// Remove . .. symbols from a path to create a unique filename
let cleaned_path: Vec<&str> = path
.iter()
.filter(|v| {
if let Some(s) = v.to_str() {
![".", ".."].contains(&s)
.map(|os_str| {
let s_str = os_str.to_str().unwrap();
if s_str == ".." {
"_"
} else {
false
s_str
}
})
.map(|s| s.to_str().unwrap())
.collect();

// Create the filename
Expand Down

0 comments on commit f263eba

Please sign in to comment.