Provides an easy way to validate YAML files against given schemas utilizing the yaml-language-server project.
This package contains a CLI, a GitHub action, and the library itself.
Install the CLI via npm:
npm install --global yaml-ls-checkThe CLI should now be accessible as yaml-ls-check or the short-hand ylsc, and can be used to validate YAML files:
# Validate all YAML files in the given directory, using the .vscode/settings.json file in it, if present.
ylsc <directory>
ylsc dir <directory>
# Optionally, you can provide a list of files to exclude from validation. File paths can be given as glob patterns.
ylsc <directory> --exclude <files...>
# Validate given YAML files against the given schema.
# Schema can either be a local or remote one. File paths can be given as glob patterns.
ylsc schema <schema> <files...>If you have a .vscode/settings.json in the root of your repository directory, you can just use the action directly:
steps:
- uses: actions/checkout@v2
- uses: ds-ukassel/yaml-ls-check@v2.0.1Additional settings for it are:
root: If the repository root should not act as root for the validation.schemaMapping: Specify mapping of schema to file patterns that should match the schema. This overwrites the mapping found in any potential.vscode/settings.jsonfile.excludedFiles: A list of file paths or glob patterns to exclude from validation relative to the root.
steps:
- uses: actions/checkout@v2
- uses: ds-ukassel/yaml-ls-check@v2.0.1
with:
root: data
schemaMapping: |
{
"schemas/my-schema.json": [ "files/*.yml" ]
}
excludedFiles: |
"helm/**/*.yaml"npm install yaml-ls-checkimport { validateDirectory } from 'yaml-ls-check';
async function someFunction() {
const invalidFiles = await validateDirectory('path/to/a/folder');
// invalidFiles is now an array containing paths to files that failed validation
// and the found errors in the form: { filePath: string, errors: Diagnostics[] }
}