Skip to content

Conversation

@Arpit529Srivastava
Copy link
Contributor

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

  • N
  • Y

fix: kcl-lang/kcl#2043

2. What is the scope of this PR (e.g. component or file name):

cmd/kcl/commands/vet.go

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

This PR adds a --output flag to the kcl vet command, enabling structured output for validation results.

  • Supports json output format.
  • Default behavior (text output) remains unchanged.
  • Parses the underlying KCL runtime error string into a structured JSON object containing file, line, column, message, and errorType.
  • Strips ANSI color codes from the JSON output for cleaner processing.

Motivation:
Currently, kcl vet only outputs unstructured human-readable text which is difficult to parse in CI/CD pipelines. This change allows tools to programmatically consume validation results.

Example Usage:

kcl vet data.json code.k --output json

Output:

{
  "success": false,
  "errCount": 1,
  "errors": [
    {
      "errorType": "EvaluationError",
      "file": "path/to/file.yaml",
      "line": 3,
      "column": 9,
      "message": "Instance check failed",
      "codeSnippet": "app_name: \"test\""
    }
  ]
}

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

Verified manually with both passing and failing validation scenarios:

  1. Created a schema file and data file.
  2. Ran kcl vet data.yaml schema.k --output json.
  3. Verified the JSON structure for errors (including single and multiple errors).
  4. Verified that ANSI codes are stripped from the messages.

Signed-off-by: arpit529srivastava <arpitsrivastava529@gmail.com>
@coveralls
Copy link

Pull Request Test Coverage Report for Build 20861931473

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 27.386%

Totals Coverage Status
Change from base Build 20693487568: 0.0%
Covered Lines: 241
Relevant Lines: 880

💛 - Coveralls

@Arpit529Srivastava
Copy link
Contributor Author

@Peefy PTAL.
Thanks

@Peefy Peefy merged commit c443008 into kcl-lang:main Jan 10, 2026
10 checks passed
@Arpit529Srivastava Arpit529Srivastava deleted the issue2043-vet-cmd branch January 10, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vet command should support structured output formats

3 participants