Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
- name: Build
run: cargo build --workspace --all-targets --all-features

- name: Lint taxonomy TOML
run: bash scripts/lint_taxonomy.sh

- name: Run Tests
run: cargo test --workspace --all-targets --all-features

Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,8 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
# Metrics / Observability
prometheus = "0.13"

# URL parsing
url = "2"

# Shared internal crates
grat-core = { path = "crates/core" }
8 changes: 8 additions & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,16 @@ prometheus = { workspace = true }
anyhow = { workspace = true }
thiserror = { workspace = true }

# URL parsing (for taxonomy linter documentation_url validation)
url = { workspace = true }

[[bin]]
name = "taxonomy_linter"
path = "src/bin/taxonomy_linter.rs"

[dev-dependencies]
tokio-test = "0.4"
insta = { version = "1", features = ["json"] }
tracing-subscriber = { workspace = true }
ctor = "0.2"
tempfile = "3"
50 changes: 50 additions & 0 deletions crates/core/src/bin/taxonomy_linter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//! Taxonomy Linter — validate taxonomy TOML files against the schema.
//!
//! Usage:
//! taxonomy_linter [<directory>]
//!
//! Defaults to `crates/core/src/taxonomy/data` when no argument is given.
//! Exits with status 0 if no issues found, 1 otherwise.

use std::path::PathBuf;
use std::process;

fn main() {
let dir: PathBuf = std::env::args()
.nth(1)
.map(PathBuf::from)
.unwrap_or_else(|| {
// Default to the data directory relative to the binary's workspace root.
let mut p = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
p.push("src/taxonomy/data");
p
});

if !dir.is_dir() {
eprintln!("error: '{}' is not a directory", dir.display());
process::exit(1);
}

let issues = match grat_core::taxonomy::linter::lint_dir(&dir) {
Ok(issues) => issues,
Err(e) => {
eprintln!("error: lint_dir failed: {e}");
process::exit(1);
}
};

if issues.is_empty() {
println!("✅ No issues found in {}", dir.display());
process::exit(0);
}

for issue in &issues {
match &issue.entry_id {
Some(eid) => eprintln!("{}:{}: {}", issue.file, eid, issue.message),
None => eprintln!("{}:: {}", issue.file, issue.message),
}
}

eprintln!("❌ Found {} issue(s) in {}", issues.len(), dir.display());
process::exit(1);
}
Loading
Loading