Skip to main content

wowlab_tidy/languages/toml/rules/manifest/
mod.rs

1mod comment_blocks;
2mod field_order;
3mod formatting;
4mod references;
5mod repository;
6mod schema;
7mod schema_version;
8mod section_contiguity;
9mod shared_anchors;
10
11use wowlab_fs::{
12    directory::{self, EntryKind},
13    path::{Path, PathBuf},
14};
15
16const MANIFEST_PREFIX: &str = "crates/engine/manifests/";
17const ITEMS_REL: &str = "crates/engine/manifests/items.toml";
18
19fn manifest_repository_root(path: &Path) -> Option<PathBuf> {
20    path.ancestors()
21        .find(|ancestor| ancestor.file_name().is_some_and(|name| name == "manifests"))
22        .map(Path::to_path_buf)
23}
24
25fn workspace_relative(path: &Path) -> String {
26    let absolute = directory::canonicalize(path).unwrap_or_else(|_| path.to_path_buf());
27    let workspace = absolute
28        .ancestors()
29        .find(|ancestor| {
30            directory::inspect(&ancestor.join("crates"))
31                .ok()
32                .flatten()
33                .is_some_and(|entry| entry.kind() == EntryKind::Directory)
34        })
35        .unwrap_or_else(|| Path::new(""));
36
37    absolute
38        .strip_prefix(workspace)
39        .unwrap_or(&absolute)
40        .display()
41        .to_string()
42}