Skip to content

feat(validator): add CUE file validation support#467

Open
mvanhorn wants to merge 1 commit into
Boeing:mainfrom
mvanhorn:osc/462-add-cue-validator
Open

feat(validator): add CUE file validation support#467
mvanhorn wants to merge 1 commit into
Boeing:mainfrom
mvanhorn:osc/462-add-cue-validator

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

@mvanhorn mvanhorn commented May 3, 2026

Summary

Adds syntax validation for CUE (.cue) files using the official cuelang.org/go SDK. CUE is gaining traction in the Kubernetes / DevOps ecosystem (Dagger, KubeVela), and the issue specifically calls out the pure-Go SDK as the right entry point.

What changed

  • pkg/validator/cue.go — new file. CueValidator wraps cue/parser.ParseFile and returns ValidationError{Err, Line, Column} when the parse fails. Mirrors the position-extraction pattern in TomlValidator (pkg/validator/toml.go:11).
  • pkg/filetype/file_type.go — new CueFileType (extension cue), registered in fileTypeRegistry and added to the FileTypes slice in init() so the file is dispatched to the new validator.
  • pkg/validator/validator_test.govalidCue and invalidCue cases added to the existing testData slice.
  • .pre-commit-hooks.yamlcue added to both types_or and the files regex on the config-file-validator hook so that changed .cue files actually invoke the validator under the standard pre-commit integration. (Without this, the hook's type filter would silently skip .cue files even though the validator is registered.)
  • go.mod / go.sum — adds cuelang.org/go and its transitive dependencies via go get + go mod tidy.

68 lines added, 19 removed (the bulk of go.sum accounts for the rest).

Verification

  • go build ./... — pass
  • go vet ./... — pass
  • go test ./pkg/validator/... ./pkg/filetype/... — pass

Scope notes

  • Schema validation deferred. CUE has a built-in constraint system; that can land as a follow-up implementing SchemaValidator on CueValidator. This PR is the syntax-only foundation called out in the issue.

Closes #462

This contribution was developed with AI assistance.

@mvanhorn mvanhorn requested a review from a team as a code owner May 3, 2026 07:23
@kehoecj
Copy link
Copy Markdown
Collaborator

kehoecj commented May 4, 2026

@mvanhorn Please try to limit the amount of PR's to one or two at a time. Especially when the previous ones have undressed issues.

@mvanhorn
Copy link
Copy Markdown
Contributor Author

mvanhorn commented May 5, 2026

Fair point, apologies. I'll focus on getting #461 (lint + changelog) and #464 (changelog) cleaned up first, and hold off on new PRs to this repo until those land.

@kehoecj kehoecj added pr-action-requested PR is awaiting feedback from the submitting developer OSS Community Contribution Contributions from the OSS Community labels May 5, 2026
Copy link
Copy Markdown
Collaborator

@kehoecj kehoecj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mvanhorn Implementation is solid and passed against a set of real cue files. A few things to clean up before merging (I'm going to assume KDL goes before this one):

  • CHANGELOG entry
  • Rebase. Your branch is downgrading several dependencies because it's based off an older main. After rebasing, run go get cuelang.org/go@v0.16.1 then go mod tidy. This will also pull in my docs update.
  • The current dependency is a dev pre-release (v0.17.0-0.dev.0.20260319...). I checked and v0.16.1 (latest stable) has the same parser.ParseFile API. Please use cuelang.org/go v0.16.1 instead.
  • Docs updates:
    • website/docs/reference/supported-file-types.md: Add cue
    • website/docs/introduction.md: update format count from 17 -> 18
    • README.md: update format count from 17 -> 18 and add cue

CUE (Configure, Unify, Execute, https://cuelang.org) is a typed
configuration language increasingly used for Kubernetes, OPA, and
config DSLs. Add a syntax-only CUE validator wired into the
existing FileType registry.

- New CueValidator in pkg/validator/cue.go calls
  cuelang.org/go/cue/parser.ParseFile. Errors are surfaced as
  cueerrors.Error so consumers see CUE's structured diagnostics.
- New CueFileType in pkg/filetype with the .cue extension. Added
  to fileTypeRegistry and the FileTypes slice.
- Two table-driven test cases (valid + invalid CUE).
- README format count bumped from 16 to 17 to reflect the new
  validator.
- CHANGELOG entry under Unreleased / Added referencing Boeing#462.

Per review feedback (@kehoecj):
- Rebased on current main (go.sum conflict resolved).
- Switched cuelang.org/go from the dev pre-release
  (v0.17.0-0.dev.0...) to the latest stable v0.16.1, which exposes
  the same parser.ParseFile API. go mod tidy applied.

Closes Boeing#462

Signed-off-by: Matt Van Horn <mvanhorn@gmail.com>
@mvanhorn mvanhorn force-pushed the osc/462-add-cue-validator branch from aab5e09 to a650a72 Compare May 23, 2026 18:42
@mvanhorn
Copy link
Copy Markdown
Contributor Author

Thanks @kehoecj. Pushed a650a72:

  1. Rebased on current main (go.sum conflict resolved).
  2. Switched cuelang.org/go from v0.17.0-0.dev.0 to v0.16.1. parser.ParseFile API is identical; tests pass. go mod tidy applied.
  3. CHANGELOG entry under Unreleased / Added.
  4. README format count bumped from 16 to 17. Note: assumes this PR lands before KDL feat: add KDL file validation support #464; if KDL lands first the count will already be 17 and this needs to be 17->18 instead. Happy to rebase on feat: add KDL file validation support #464 if you want them stacked.

The website/ docs paths in the review (supported-file-types.md, introduction.md) don't exist in this repo - looks like that's published from elsewhere or planned but not yet in tree. Let me know if I should add anything else.

go test ./..., go vet ./..., and golangci-lint run ./pkg/validator/... all clean.

Comment thread README.md
</p>

Config File Validator validates config files across 16 formats.
Config File Validator validates config files across 17 formats.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Config File Validator validates config files across 17 formats.
Config File Validator validates config files across 18 formats.

@kehoecj
Copy link
Copy Markdown
Collaborator

kehoecj commented May 26, 2026

@mvanhorn KDL was merged, please resolve conflicts and bump count to 18. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OSS Community Contribution Contributions from the OSS Community pr-action-requested PR is awaiting feedback from the submitting developer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add CUE file validation support

2 participants