Skip to content

Commit e519aa9

Browse files
committed
Refactor GTS Documentation Validator: Migrate from Python to Rust CLI
- Updated README.md to reflect the transition from a Python script to a Rust CLI tool for validating GTS identifiers in documentation. - Removed the Python script `validate_gts_docs.py` and its associated unit tests. - Enhanced the documentation to include new file types (.yaml, .yml) and vendor validation options. - Added new commands for running tests and validating vendor consistency. Signed-off-by: Fabio Del Vigna <delvifabio@gmail.com>
1 parent b1a1099 commit e519aa9

12 files changed

Lines changed: 1377 additions & 1009 deletions

File tree

Cargo.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ codegen-units = 1
2020
[workspace]
2121
members = [
2222
"apps/hyperspot-server",
23+
"apps/gts-docs-validator",
2324
"libs/modkit",
2425
"libs/modkit-macros",
2526
"libs/modkit-db",
@@ -262,6 +263,10 @@ urlencoding = "2.1"
262263
# Regex for env expansion
263264
regex = "1.10"
264265

266+
# CLI and terminal output
267+
glob = "0.3"
268+
colored = "2"
269+
265270
# gRPC support
266271
tonic = { version = "0.14", features = ["transport"] }
267272
prost = { version = "0.14" }

Makefile

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fmt:
6666
# | | - Use 'make dylint-list' to see all available custom lints |
6767
# +-------------+----------------------------------------------------------------------+
6868

69-
.PHONY: clippy kani geiger safety lint dylint dylint-list dylint-test gts-docs gts-docs-test
69+
.PHONY: clippy kani geiger safety lint dylint dylint-list dylint-test gts-docs gts-docs-vendor gts-docs-release gts-docs-vendor-release gts-docs-test
7070

7171
# Run clippy linter (excludes gts-rust submodule which has its own lint settings)
7272
clippy:
@@ -90,12 +90,40 @@ lint:
9090
RUSTFLAGS="-D warnings" cargo check --workspace --all-targets --all-features
9191

9292
## Validate GTS identifiers in .md and .json files (DE0903)
93+
# Uses gts-docs-validator from apps/gts-docs-validator
94+
# Vendor enforcement is available via the gts-docs-vendor target (--vendor x)
9395
gts-docs:
94-
@python3 dylint_lints/validate_gts_docs.py
96+
cargo run -p gts-docs-validator -- \
97+
--exclude "target/*" \
98+
--exclude "docs/api/*" \
99+
docs modules libs examples
100+
101+
## Validate GTS docs with vendor check (ensures all IDs use vendor "x")
102+
gts-docs-vendor:
103+
cargo run -p gts-docs-validator -- \
104+
--vendor x \
105+
--exclude "target/*" \
106+
--exclude "docs/api/*" \
107+
docs modules libs examples
108+
109+
## Validate GTS identifiers (release build)
110+
gts-docs-release:
111+
cargo run --release -p gts-docs-validator -- \
112+
--exclude "target/*" \
113+
--exclude "docs/api/*" \
114+
docs modules libs examples
115+
116+
## Validate GTS docs with vendor check (release build)
117+
gts-docs-vendor-release:
118+
cargo run --release -p gts-docs-validator -- \
119+
--vendor x \
120+
--exclude "target/*" \
121+
--exclude "docs/api/*" \
122+
docs modules libs examples
95123

96124
## Run tests for GTS documentation validator
97125
gts-docs-test:
98-
@python3 dylint_lints/test_validate_gts_docs.py
126+
cargo test -p gts-docs-validator
99127

100128
## List all custom project compliance lints (see dylint_lints/README.md)
101129
dylint-list:
@@ -294,7 +322,7 @@ oop-example:
294322
cargo run --bin hyperspot-server --features oop-example,users-info-example,tenant-resolver-example -- --config config/quickstart.yaml run
295323

296324
# Run all quality checks
297-
check: fmt clippy security dylint-test dylint test
325+
check: fmt clippy security dylint-test dylint gts-docs test
298326

299327
# Run CI pipeline
300328
ci: check

apps/gts-docs-validator/Cargo.toml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[package]
2+
name = "gts-docs-validator"
3+
version.workspace = true
4+
edition.workspace = true
5+
license.workspace = true
6+
authors.workspace = true
7+
repository.workspace = true
8+
description = "GTS identifier validator for documentation files (DE0903)"
9+
10+
[[bin]]
11+
name = "gts-docs-validator"
12+
path = "src/main.rs"
13+
14+
[dependencies]
15+
# CLI parsing
16+
clap = { workspace = true }
17+
18+
# GTS library for ID validation
19+
gts = { workspace = true }
20+
21+
# File system traversal
22+
walkdir = { workspace = true }
23+
glob = { workspace = true }
24+
25+
# Regex for pattern matching
26+
regex = { workspace = true }
27+
28+
# Serialization
29+
serde = { workspace = true }
30+
serde_json = { workspace = true }
31+
32+
# Error handling
33+
anyhow = { workspace = true }
34+
thiserror = { workspace = true }
35+
36+
# For colored terminal output
37+
colored = { workspace = true }
38+
39+
[dev-dependencies]
40+
tempfile = { workspace = true }
41+
42+
[lints]
43+
workspace = true

apps/gts-docs-validator/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# GTS Documentation Validator (DE0903)
2+
3+
A Rust CLI tool that validates GTS (Global Type System) identifiers in documentation files (`.md`, `.json`, `.yaml`, `.yml`).
4+
5+
This complements the Dylint-based DE0901 lint that validates GTS identifiers in Rust source code.
6+
7+
## Usage
8+
9+
```bash
10+
# Basic validation
11+
gts-docs-validator docs modules libs examples
12+
13+
# With vendor validation (ensures all IDs use expected vendor)
14+
gts-docs-validator --vendor x docs modules libs examples
15+
16+
# With exclusions
17+
gts-docs-validator --exclude "target/*" --exclude "docs/api/*" .
18+
19+
# JSON output (for CI integration)
20+
gts-docs-validator --json docs
21+
22+
# Verbose output (shows files being scanned)
23+
gts-docs-validator --verbose docs
24+
```
25+
26+
## Makefile Targets
27+
28+
```bash
29+
make gts-docs # Validate GTS IDs (structural only)
30+
make gts-docs-vendor # Validate with --vendor x check
31+
make gts-docs-test # Run unit tests
32+
```
33+
34+
## Options
35+
36+
| Option | Description |
37+
|--------|-------------|
38+
| `--vendor <VENDOR>` | Expected vendor for all GTS IDs (e.g., `--vendor x`) |
39+
| `--exclude <PATTERN>` | Glob patterns to exclude (can be repeated) |
40+
| `--json` | Output results as JSON |
41+
| `--verbose` | Show file scanning progress |
42+
43+
## Example Vendors
44+
45+
When using `--vendor`, the following example/placeholder vendors are always tolerated (commonly used in documentation and tutorials):
46+
47+
- `acme`
48+
- `globex`
49+
- `example`
50+
- `demo`
51+
- `test`
52+
- `sample`
53+
- `tutorial`
54+
55+
## Smart Context Detection
56+
57+
The validator automatically handles:
58+
59+
- **Wildcard patterns**: `gts.x.*` is allowed in filter/pattern contexts (e.g., `$filter`, `pattern`, `match`)
60+
- **Bad examples**: GTS IDs near "invalid", "wrong", "❌" markers are skipped
61+
- **Trailing tildes**: Schema IDs ending with `~` are properly validated
62+
63+
## GTS Identifier Format
64+
65+
```text
66+
gts.<vendor>.<org>.<package>.<type>.<version>~
67+
│ │ │ │ └── Version (v1, v1.2, etc.)
68+
│ │ │ └── Type name (snake_case)
69+
│ │ └── Package name
70+
│ └── Organization
71+
└── Vendor identifier
72+
```
73+
74+
## Exit Codes
75+
76+
- `0` - All GTS identifiers are valid
77+
- `1` - Invalid GTS identifiers found
78+
79+
## Related
80+
81+
- **DE0901**: Dylint lint for GTS patterns in Rust source (`make dylint`)
82+
- **DE0902**: Prevents `schema_for!` on GTS structs (`make dylint`)

0 commit comments

Comments
 (0)