configfilevalidator

package module
v2.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

README

Config File Validator logo

Config File Validator

Single cross-platform CLI tool to validate different configuration file types

Code Coverage OpenSSF Scorecard OpenSSF Best Practices Apache 2 License Awesome Go Go Reference Go Report Card Pipeline Status

About

Config File Validator is a cross-platform CLI tool for validating and linting configuration files in your project. It supports syntax checking and JSON Schema validation for JSON, YAML, TOML, XML, HCL, INI, HOCON, ENV, CSV, Properties, EDITORCONFIG, PList, SARIF, and TOON files. Use it locally, in CI/CD pipelines, or as a Go library to catch configuration errors before deployment.

Supported Configuration File Formats

Format Syntax Validation Schema Validation
Apple PList XML
CSV
EDITORCONFIG
ENV
HCL
HOCON
INI
JSON ✅ ($schema property)
Properties
SARIF ✅ (built-in per version)
TOML ✅ ($schema key)
TOON ✅ ("$schema" key)
XML ✅ (xsi:noNamespaceSchemaLocation)
YAML ✅ (yaml-language-server comment)

XML files with inline DTD declarations (<!DOCTYPE>) are automatically validated against the DTD during syntax checking.

Demo

Config File Validator CLI demo showing JSON YAML TOML XML validation

Installation

There are several options to install the config file validator tool.

Binary Releases

Download and unpack from https://github.com/Boeing/config-file-validator/releases

Package Managers

Homebrew
brew install config-file-validator
MacPorts
sudo port install config-file-validator
Aqua
aqua g -i Boeing/config-file-validator
Winget
winget install Boeing.config-file-validator
Scoop
scoop install config-file-validator

Arch Linux

We maintain and release an AUR package for the config-file-validator

git clone https://aur.archlinux.org/config-file-validator.git
cd config-file-validator
makepkg -si

go install

If you have a go environment on your desktop you can use go install to install the validator executable. The validator executable will be installed to the directory named by the GOBIN environment variable, which defaults to $GOPATH/bin or $HOME/go/bin if the GOPATH environment variable is not set.

go install github.com/Boeing/config-file-validator/v2/cmd/validator@latest

GitHub Action

A GitHub Action is available to run the config-file-validator as part of your CI/CD pipeline. It posts validation results as PR comments with inline annotations on the affected files and lines.

- uses: Boeing/validate-configs-action@v2.0.0

See the validate-configs-action repository for full usage and configuration options.

Usage

Usage: validator [OPTIONS] [<search_path>...]

positional arguments:
    search_path: The search path on the filesystem for configuration files. Defaults to the current working directory if no search_path provided

Schema validation runs automatically when a file declares a schema:
  JSON:  {"$schema": "schema.json", ...}
  YAML:  # yaml-language-server: $schema=schema.json
  TOML:  "$schema" = "schema.json"
  TOON:  "$schema": schema.json
  XML:   xsi:noNamespaceSchemaLocation="schema.xsd"
  XML:   <!DOCTYPE> with inline DTD (validated during syntax check)

optional flags:
  -depth int
        Depth of recursion for the provided search paths. Set depth to 0 to disable recursive path traversal
  -exclude-dirs string
        Subdirectories to exclude when searching for configuration files
  -exclude-file-types string
        A comma separated list of file types to ignore
  -file-types string
        A comma separated list of file types to validate
  -globbing
        If globbing flag is set, check for glob patterns in the arguments.
  -groupby string
        Group output by filetype, directory, pass-fail, error-type. Supported for Standard and JSON reports
  -no-schema
        Disable all schema validation. Only syntax is checked.
        Cannot be used with --require-schema, --schema-map, or --schemastore.
  -quiet
        If quiet flag is set. It doesn't print any output to stdout.
  -reporter value
        Report format and optional output path. Format: <type>:<path> Supported: standard, json, junit, sarif (default: standard)
  -require-schema
        Fail validation if a file supports schema validation but does not declare a schema.
        Supported types: JSON ($schema property), YAML (yaml-language-server comment),
        TOML ($schema key), TOON ("$schema" key), XML (xsi:noNamespaceSchemaLocation).
        Other file types (INI, CSV, ENV, HCL, HOCON, Properties, PList, EditorConfig) are not affected.
        Cannot be used with --no-schema.
  -schema-map value
        Map a glob pattern to a schema file for validation.
        Format: <pattern>:<schema_path>
        Use JSON Schema (.json) for JSON, YAML, TOML, and TOON files.
        Use XSD (.xsd) for XML files. Paths are relative to the current directory.
        Multiple mappings can be specified.
        Examples:
          --schema-map="**/package.json:schemas/package.schema.json"
          --schema-map="**/config.xml:schemas/config.xsd"
  -schemastore string
        Path to a local SchemaStore clone for automatic schema lookup by filename.
        Download with: git clone --depth=1 https://github.com/SchemaStore/schemastore.git
        Files matching the catalog are validated against the corresponding schema.
        Document-declared schemas and --schema-map take priority over SchemaStore.
  -type-map value
        Map a glob pattern to a file type. Format: <pattern>:<type> Example: --type-map="**/inventory:ini"
  -version
        Version prints the release version of validator

Environment Variables

The config-file-validator supports setting options via environment variables. If both command-line flags and environment variables are set, the command-line flags will take precedence. The supported environment variables are as follows:

Environment Variable Equivalent Flag
CFV_DEPTH -depth
CFV_EXCLUDE_DIRS -exclude-dirs
CFV_EXCLUDE_FILE_TYPES -exclude-file-types
CFV_FILE_TYPES -file-types
CFV_REPORTER -reporter
CFV_GROUPBY -groupby
CFV_QUIET -quiet
CFV_REQUIRE_SCHEMA -require-schema
CFV_NO_SCHEMA -no-schema
CFV_SCHEMASTORE -schemastore
CFV_GLOBBING -globbing

Examples

Standard Run

If the search path is omitted it will search the current directory

validator /path/to/search

Standard Run

Multiple search paths

Multiple search paths are supported, and the results will be merged into a single report

validator /path/to/search /another/path/to/search

Multiple Search Paths Run

Exclude directories

Exclude subdirectories in the search path

validator --exclude-dirs=/path/to/search/tests /path/to/search

Exclude Dirs Run

Exclude file types

Exclude file types in the search path. Available file types are csv, env, hcl, hocon, ini, json, plist, properties, toml, toon, xml, yaml, and yml

validator --exclude-file-types=json /path/to/search

Exclude File Types Run

Include only specific file types

Validate only the specified file types. Cannot be used together with --exclude-file-types.

validator --file-types=json,yaml /path/to/search
Customize recursion depth

By default there is no recursion limit. If desired, the recursion depth can be set to an integer value. If depth is set to 0 recursion will be disabled and only the files in the search path will be validated.

validator --depth=0 /path/to/search

Custom Recursion Run

Customize report output

You can customize the report output and save the results to a file (default name is result.{extension}). The available report types are standard, junit, json, and sarif. You can specify multiple report types by chaining the --reporter flags.

You can specify a path to an output file for any reporter by appending :<path> to the name of the reporter. Providing an output file is optional and the results will be printed to stdout by default. To explicitly direct the output to stdout, use :- as the file path.

validator --reporter=json:- /path/to/search
validator --reporter=json:output.json --reporter=standard /path/to/search

Exclude File Types Run

Group report output

Group the report output by file type, directory, pass-fail, or error-type. Supports one or more groupings.

validator -groupby filetype

Groupby File Type

Multiple groups
validator -groupby directory,pass-fail

Groupby File Type and Pass/Fail

Output results to a file

Output report results to a file (default name is result.{extension}). Must provide reporter flag with a supported extension format. Available options are junit and json. If an existing directory is provided, create a file named default name in the given directory. If a file name is provided, create a file named the given name at the current working directory.

validator --reporter=json --output=/path/to/dir

Suppress output

Passing the --quiet flag suppresses all output to stdout. If there are invalid config files the validator tool will exit with 1. Any errors in execution such as an invalid path will still be displayed.

validator --quiet /path/to/search

Schema validation

Schema validation runs automatically for file types that support it. Files without a schema declaration pass with syntax validation only. The document is converted to JSON internally and validated against the referenced JSON Schema.

Use --require-schema to fail validation for files that support schema validation but don't declare a schema:

validator --require-schema /path/to/search
Declaring a schema

Each file type uses a different convention to declare its schema:

JSON — Add a $schema property at the top level:

{
  "$schema": "https://json.schemastore.org/package.json",
  "name": "my-package",
  "version": "1.0.0"
}

YAML — Add a yaml-language-server modeline comment before any content:

# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: CI
on: push
jobs:
  build:
    runs-on: ubuntu-latest

TOML — Add a $schema key at the top level:

"$schema" = "https://json.schemastore.org/pyproject.json"

[project]
name = "my-project"
version = "1.0.0"

TOON — Add a quoted "$schema" key at the top level:

"$schema": https://example.com/schema.json
host: localhost
port: 5432

SARIF — Schema validation is built-in per SARIF version (2.1.0 and 2.2). No declaration needed.

XML — Add an xsi:noNamespaceSchemaLocation attribute on the root element:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="config.xsd">
  <host>db.example.com</host>
  <port>5432</port>
</config>

XML schemas use XSD (XML Schema Definition) files rather than JSON Schema.

Schema URLs can be absolute (https://...), absolute file paths, or relative paths (resolved from the document's directory).

Automatic schema lookup with SchemaStore

SchemaStore is a community-maintained collection of JSON Schemas for hundreds of common configuration files — including package.json, tsconfig.json, .eslintrc.json, GitHub Actions workflows, pyproject.toml, and many more.

With the --schemastore flag, the validator automatically matches files by name against the SchemaStore catalog and validates them against the corresponding schema — no $schema declaration needed in your files.

Setup:

# Clone the SchemaStore catalog (only needed once)
git clone --depth=1 https://github.com/SchemaStore/schemastore.git

# Validate your project using automatic schema lookup
validator --schemastore=./schemastore /path/to/project

For example, if your project contains a package.json, tsconfig.json, and .github/workflows/ci.yml, the validator will automatically find and apply the correct schema for each file without any configuration.

Priority order: When multiple schema sources are available, the validator uses this precedence:

  1. Schema declared in the document ($schema, yaml-language-server, xsi:noNamespaceSchemaLocation)
  2. --schema-map patterns
  3. --schemastore catalog lookup

This means document-level declarations always win, and --schemastore acts as a safety net for files that don't declare their own schema.

External schema mapping

Use --schema-map to apply a schema to files matching a glob pattern. This is useful when you can't or don't want to add schema declarations to the files themselves.

# Apply a JSON Schema to all package.json files
validator --schema-map="**/package.json:schemas/package.schema.json" /path/to/project

# Apply an XSD to XML config files
validator --schema-map="**/config.xml:schemas/config.xsd" /path/to/project

# Multiple mappings
validator --schema-map="**/package.json:schemas/pkg.json" \
          --schema-map="**/*.xml:schemas/config.xsd" /path/to/project

Use JSON Schema (.json) for JSON, YAML, TOML, and TOON files. Use XSD (.xsd) for XML files. Paths are relative to the current working directory.

Map file types with glob patterns

Use the --type-map flag to map files matching a glob pattern to a specific file type. This is useful for files without extensions or with non-standard extensions. Multiple mappings can be specified.

# Treat all files named "inventory" as ini
validator --type-map="**/inventory:ini" /path/to/search

# Map all files in a configs directory as properties
validator --type-map="**/configs/*:properties" /path/to/search

# Multiple mappings
validator --type-map="**/inventory:ini" --type-map="**/*.cfg:json" /path/to/search

Search files using a glob pattern

Use the -globbing flag to validate files matching a specified pattern. Include the pattern as a positional argument in double quotes. Multiple glob patterns and direct file paths are supported. If invalid config files are detected, the validator tool exits with code 1, and errors (e.g., invalid patterns) are displayed.

Learn more about glob patterns

# Validate all `.json` files in a directory
validator -globbing "/path/to/files/*.json"

# Recursively validate all `.json` files in subdirectories
validator -globbing "/path/to/files/**/*.json"

# Mix glob patterns and paths
validator -globbing "/path/*.json" /path/to/search

Calling the config-file-validator programmatically

The config-file-validator can be called programmatically from within a Go program through the cli package.

Default configuration

The default configuration will perform the following actions:

  • Search for all supported configuration file types in the current directory and its subdirectories
  • Uses the default reporter which will output validation results to console (stdout)
package main

import (
	"os"
	"log"

	"github.com/Boeing/config-file-validator/v2/pkg/cli"
)

func main() {

	// Initialize the CLI
	cfv := cli.Init()
	
	// Run the config file validation
	exitStatus, err := cfv.Run()
	if err != nil {
	  log.Printf("Errors occurred during execution: %v", err)
	}
	
	os.Exit(exitStatus)
}

Custom Search Paths

The below example will search the provided search paths.

package main

import (
	"os"
	"log"

	"github.com/Boeing/config-file-validator/v2/pkg/cli"
	"github.com/Boeing/config-file-validator/v2/pkg/finder"
)

func main() {

	// Initialize a file system finder
	fileSystemFinder := finder.FileSystemFinderInit(
		finder.WithPathRoots("/path/to/search", "/another/path/to/search"),
	)

	// Initialize the CLI
	cfv := cli.Init(
		cli.WithFinder(fileSystemFinder),
	)
	
	// Run the config file validation
	exitStatus, err := cfv.Run()
	if err != nil {
	  log.Printf("Errors occurred during execution: %v", err)
	}
	
	os.Exit(exitStatus)
}

Custom Reporter

Will output JSON to stdout. To output to a file, pass a value to the reporter.NewJSONReporter constructor.

package main

import (
	"os"
	"log"

	"github.com/Boeing/config-file-validator/v2/pkg/cli"
	"github.com/Boeing/config-file-validator/v2/pkg/reporter"
)

func main() {
	// Initialize reporter type
	var outputDir string
	jsonReporter := reporter.NewJSONReporter(outputDir)

	// Initialize the CLI
	cfv := cli.Init(
		cli.WithFinder(fileSystemFinder),
		cli.WithReporters(jsonReporter),
	)
	
	// Run the config file validation
	exitStatus, err := cfv.Run()
	if err != nil {
	  log.Printf("Errors occurred during execution: %v", err)
	}
	
	os.Exit(exitStatus)
}

Additional Configuration Options

Exclude Directories
excludeDirs := []string{"test", "subdir"}
fileSystemFinder := finder.FileSystemFinderInit(
	finder.WithExcludeDirs(excludeDirs),
)
cfv := cli.Init(
      cli.WithFinder(fileSystemFinder),
)
Exclude File Types
excludeFileTypes := []string{"yaml", "json"}
fileSystemFinder := finder.FileSystemFinderInit(
      finder.WithExcludeFileTypes(excludeFileTypes),
)
cfv := cli.Init(
      cli.WithFinder(fileSystemFinder),
)
Set Recursion Depth
fileSystemFinder := finder.FileSystemFinderInit(
      finder.WithDepth(0)
)
cfv := cli.Init(
      cli.WithFinder(fileSystemFinder),
)

Suppress Output

cfv := cli.Init(
      cli.WithQuiet(true),
)

Group Output

groupOutput := []string{"pass-fail"} 
cfv := cli.Init(
      cli.WithGroupOutput(groupOutput),
)

Schema Validation Options

Require Schema

Fail validation for files that support schema validation but don't declare one.

cfv := cli.Init(
      cli.WithRequireSchema(true),
)
Disable Schema Validation

Skip all schema validation. Only syntax is checked.

cfv := cli.Init(
      cli.WithNoSchema(true),
)
Schema Map

Map file patterns to schema files. Use JSON Schema (.json) for JSON, YAML, TOML, and TOON files. Use XSD (.xsd) for XML files.

schemaMap := map[string]string{
      "**/package.json": "schemas/package.schema.json",
      "**/config.xml":   "schemas/config.xsd",
}
cfv := cli.Init(
      cli.WithSchemaMap(schemaMap),
)
SchemaStore

Use a local SchemaStore clone for automatic schema lookup by filename.

import "github.com/Boeing/config-file-validator/v2/pkg/schemastore"

store, err := schemastore.Open("/path/to/schemastore")
if err != nil {
      log.Fatal(err)
}
cfv := cli.Init(
      cli.WithSchemaStore(store),
)

Build

The project can be downloaded and built from source using an environment with Go 1.26+ installed. After a successful build, the binary can be moved to a location on your operating system PATH.

macOS

Build
CGO_ENABLED=0 \
GOOS=darwin \
GOARCH=arm64 \ # for Intel use amd64
go build \
-ldflags='-w -s -extldflags "-static"' \
-tags netgo \
-o validator \
cmd/validator/validator.go
Install
cp ./validator /usr/local/bin/
chmod +x /usr/local/bin/validator

Linux

Build
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64 \
go build \
-ldflags='-w -s -extldflags "-static"' \
-tags netgo \
-o validator \
cmd/validator/validator.go
Install
cp ./validator /usr/local/bin/
chmod +x /usr/local/bin/validator

Windows

Build
$env:CGO_ENABLED = '0'; `
$env:GOOS = 'windows'; `
$env:GOARCH = 'amd64'; `
go build `
-ldflags='-w -s -extldflags "-static"' `
-tags netgo `
-o validator.exe `
cmd/validator/validator.go
Install

The below script will install the config-file-validator as a user to Local App Data:

$install = Join-Path $env:LOCALAPPDATA 'Programs\validator'; `
New-Item -Path $install -ItemType Directory -Force | Out-Null; `
Copy-Item -Path .\validator.exe -Destination $install -Force; `
$up = [Environment]::GetEnvironmentVariable('Path', [EnvironmentVariableTarget]::User); `
if (-not ($up.Split(';') -contains $install)) { `
  $new = if ([string]::IsNullOrEmpty($up)) { $install } else { $up + ';' + $install }; `
  [Environment]::SetEnvironmentVariable('Path', $new, [EnvironmentVariableTarget]::User); `
  Write-Host "Added $install to User PATH. Open a new shell to pick up the change."; `
} else { `
  Write-Host "$install is already in the User PATH."; `
}

Docker

You can also use the provided Dockerfile to build the config file validator tool as a container

docker build . -t config-file-validator:latest

Contributors

Config File Validator contributors

Contributing

We welcome contributions! Please refer to our contributing guide

License

The Config File Validator is released under the Apache 2.0 License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Version

type Version struct {
	Version string
}

Version contains config-file-validator version information

func GetVersion

func GetVersion() Version

GetVersion returns the version information

func (Version) String

func (v Version) String() string

String outputs the version as a string

Directories

Path Synopsis
cmd
validator command
internal
pkg
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL