Skip to content

Commit

Permalink
fix: make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
0x471 committed Dec 29, 2024
1 parent 0f93702 commit 9b755da
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,37 +137,35 @@ mod test {
let allowed_dirs = ["experimental", "testing"];
let root_dirs_with_exceptions = ["general", "supplementary", "restriction"];

for entry in WalkDir::new("examples") {
if let Ok(entry) = entry {
let path = entry.path();
let normalized_path = path.strip_prefix("examples").unwrap_or(path);
for entry in WalkDir::new("examples").into_iter().flatten() {
let path = entry.path();
let normalized_path = path.strip_prefix("examples").unwrap_or(path);

if let Some(file_name) = normalized_path.file_name().and_then(OsStr::to_str) {
if forbidden_files_general.contains(&file_name) {
panic!(
"Forbidden file `.gitignore` found in examples directory: {:?}",
normalized_path
);
}
if let Some(file_name) = normalized_path.file_name().and_then(OsStr::to_str) {
if forbidden_files_general.contains(&file_name) {
panic!(
"Forbidden file `.gitignore` found in examples directory: {}",
normalized_path.display()
);
}

if forbidden_files_specific.contains(&file_name) {
let is_in_allowed_directory = allowed_dirs
.iter()
.any(|&allowed| normalized_path.starts_with(allowed));
if forbidden_files_specific.contains(&file_name) {
let is_in_allowed_directory = allowed_dirs
.iter()
.any(|&allowed| normalized_path.starts_with(allowed));

let is_in_root_of_exception_dirs =
root_dirs_with_exceptions.iter().any(|&exception| {
normalized_path.starts_with(exception)
&& normalized_path.components().count() == 2
});
let is_in_root_of_exception_dirs =
root_dirs_with_exceptions.iter().any(|&exception| {
normalized_path.starts_with(exception)
&& normalized_path.components().count() == 2
});

if !is_in_allowed_directory && !is_in_root_of_exception_dirs {
panic!(
"Forbidden file {:?} found in non-allowed directory: {:?}",
file_name, normalized_path
);
}
}
assert!(
!(is_in_allowed_directory || is_in_root_of_exception_dirs),
"Forbidden file {} found in non-allowed directory: {}",
file_name,
normalized_path.display()
);
}
}
}
Expand Down

0 comments on commit 9b755da

Please sign in to comment.