Add TaxonomyLinter to validate taxonomy TOML files against schema - #385
Conversation
|
@webdevayo Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
📝 WalkthroughWalkthroughChangesTaxonomy linting
Estimated code review effort: 4 (Complex) | ~45 minutes Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant CI as CI workflow
participant Script as lint_taxonomy.sh
participant CLI as taxonomy_linter
participant Linter as lint_dir
CI->>Script: run taxonomy lint step
Script->>CLI: invoke cargo run with taxonomy directory
CLI->>Linter: lint directory
Linter-->>CLI: return lint issues
CLI-->>Script: exit success or failure
Script-->>CI: report lint status
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/core/src/taxonomy/linter.rs (1)
77-169: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winReduce repeated
LintIssueconstruction with a small helper.The same three-field struct literal is repeated ~10 times for each check. A tiny helper cuts boilerplate and makes it easier to add checks going forward.
♻️ Proposed refactor
+ let mut push_issue = |issues: &mut Vec<LintIssue>, file: &str, entry_id: &str, message: String| { + issues.push(LintIssue { + file: file.to_string(), + entry_id: Some(entry_id.to_string()), + message, + }); + }; + for entry in schema.errors { let entry_id = entry.id.clone(); // ── id must be non-empty ───────────────────────────────── if entry.id.trim().is_empty() { - issues.push(LintIssue { - file: file_name.clone(), - entry_id: Some(entry_id.clone()), - message: "id is empty".to_string(), - }); + push_issue(&mut issues, &file_name, &entry_id, "id is empty".to_string()); }Separately,
documentation_urlis only checked for parseability, so non-http(s)absolute URLs (e.g.mailto:,ftp:) would pass as "valid" — worth a scheme allow-list if strict doc-link hygiene matters here.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/core/src/taxonomy/linter.rs` around lines 77 - 169, Introduce a small local helper around the linter loop to construct and append a LintIssue from file_name, entry_id, and message, then replace the repeated LintIssue literals in each validation branch with that helper. Keep the existing validation conditions and messages unchanged; do not expand the documentation_url URL validation unless separately requested.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/core/src/taxonomy/linter.rs`:
- Around line 77-169: Introduce a small local helper around the linter loop to
construct and append a LintIssue from file_name, entry_id, and message, then
replace the repeated LintIssue literals in each validation branch with that
helper. Keep the existing validation conditions and messages unchanged; do not
expand the documentation_url URL validation unless separately requested.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 931bd7a3-8e2c-4061-b3c1-2e14fb3b87e1
📒 Files selected for processing (7)
.github/workflows/ci.ymlCargo.tomlcrates/core/Cargo.tomlcrates/core/src/bin/taxonomy_linter.rscrates/core/src/taxonomy/linter.rscrates/core/src/taxonomy/mod.rsscripts/lint_taxonomy.sh
|
@codeZe-us CI is failing on Confirmed via
|
What
Closes #380 — adds a
TaxonomyLinterthat validates every taxonomy TOML filein
crates/core/src/taxonomy/data/against theTaxonomyEntryschema, andwires it into CI so malformed entries are rejected automatically.
Changes
crates/core/src/taxonomy/linter.rs— new module that parses each TOMLfile via the existing
TaxonomyParserand validates:id,name,summary,detailed_explanation) arenon-empty
(category, code)pairs across the directoryseverityis a recognized valuesince_protocol/deprecated_protocolare well-formed and consistentwith each other when both are present
documentation_url, when present, is a structurally valid URL (checkedvia the
urlcrate — no live network calls, to keep CI deterministic)related_errorsreferences resolve to real entry ids across the fulldata set
crates/core/src/bin/taxonomy_linter.rs— small binary that runs thelinter against a given directory (defaults to the real taxonomy data dir)
and exits non-zero if any issues are found
scripts/lint_taxonomy.sh— shell wrapper that invokes the binary.github/workflows/ci.yml— added a "Lint taxonomy TOML" step to theexisting
rust_checksjob so this runs on every push/PRVerification
cargo test -p grat-core— all existing taxonomy tests still pass, plusnew unit tests for the linter (valid entry, missing field, duplicate code,
bad URL, invalid severity)
cargo fmt --all -- --checkandcargo clippy --workspace --all-targets --all-features— cleancrates/core/src/taxonomy/data/directory— no issues reported, confirming the existing data is schema-compliant
Notes
URL validation is structural only (via
url::Url::parse), not a livereachability check, to avoid flaky CI from network calls or third-party
downtime.
Summary by CodeRabbit
New Features
Bug Fixes
Tests