Skip to content

Commit b9b366f

Browse files
authored
Merge pull request #266 from yoskini/chore/#185_Validate_GTS_identifiers
feat: Add GTS documentation validator and associated tests
2 parents 63d0e26 + e519aa9 commit b9b366f

12 files changed

Lines changed: 1495 additions & 22 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",
@@ -264,6 +265,10 @@ urlencoding = "2.1"
264265
# Regex for env expansion
265266
regex = "1.10"
266267

268+
# CLI and terminal output
269+
glob = "0.3"
270+
colored = "2"
271+
267272
# gRPC support
268273
tonic = { version = "0.14", features = ["transport"] }
269274
prost = { version = "0.14" }

Makefile

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fmt:
6969
# | | - Use 'make dylint-list' to see all available custom lints |
7070
# +-------------+----------------------------------------------------------------------+
7171

72-
.PHONY: clippy kani geiger safety lint dylint dylint-list dylint-test
72+
.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
7373

7474
# Run clippy linter (excludes gts-rust submodule which has its own lint settings)
7575
clippy:
@@ -92,6 +92,42 @@ geiger:
9292
lint:
9393
RUSTFLAGS="-D warnings" cargo check --workspace --all-targets --all-features
9494

95+
## Validate GTS identifiers in .md and .json files (DE0903)
96+
# Uses gts-docs-validator from apps/gts-docs-validator
97+
# Vendor enforcement is available via the gts-docs-vendor target (--vendor x)
98+
gts-docs:
99+
cargo run -p gts-docs-validator -- \
100+
--exclude "target/*" \
101+
--exclude "docs/api/*" \
102+
docs modules libs examples
103+
104+
## Validate GTS docs with vendor check (ensures all IDs use vendor "x")
105+
gts-docs-vendor:
106+
cargo run -p gts-docs-validator -- \
107+
--vendor x \
108+
--exclude "target/*" \
109+
--exclude "docs/api/*" \
110+
docs modules libs examples
111+
112+
## Validate GTS identifiers (release build)
113+
gts-docs-release:
114+
cargo run --release -p gts-docs-validator -- \
115+
--exclude "target/*" \
116+
--exclude "docs/api/*" \
117+
docs modules libs examples
118+
119+
## Validate GTS docs with vendor check (release build)
120+
gts-docs-vendor-release:
121+
cargo run --release -p gts-docs-validator -- \
122+
--vendor x \
123+
--exclude "target/*" \
124+
--exclude "docs/api/*" \
125+
docs modules libs examples
126+
127+
## Run tests for GTS documentation validator
128+
gts-docs-test:
129+
cargo test -p gts-docs-validator
130+
95131
## List all custom project compliance lints (see dylint_lints/README.md)
96132
dylint-list:
97133
@cd dylint_lints && \
@@ -289,7 +325,7 @@ oop-example:
289325
cargo run --bin hyperspot-server --features oop-example,users-info-example,tenant-resolver-example -- --config config/quickstart.yaml run
290326

291327
# Run all quality checks
292-
check: fmt clippy security dylint-test dylint test
328+
check: fmt clippy security dylint-test dylint gts-docs test
293329

294330
# Run CI pipeline
295331
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)