Registry / devops / yaml-lint

yaml-lint

JSON →
library1.7.0jsnpmunverified

yaml-lint is a straightforward command-line interface (CLI) tool and programmatic API for validating YAML files against a specified schema or for general syntax correctness. It's currently stable at version 1.7.0. The package has seen consistent maintenance releases, with the latest significant update fixing glob pattern issues on Windows and migrating to TypeScript in version 1.3.0. Its key differentiators include the ability to specify different YAML schemas (DEFAULT, FAILSAFE, JSON, CORE), flexible configuration via JSON files, environment variables, or CLI arguments, and support for ignoring files using glob patterns. It processes multi-document YAML sources and provides clear error reporting for invalid files.

npm install yaml-lint
INSTALL
IMPORT
SIG · YAML-LINT
Y
yaml-lint
devopsjavascriptv1.7.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

yamlLint
import yamlLint from 'yaml-lint';
const yamlLint = require('yaml-lint');
While CommonJS `require` still works for the main export, `yaml-lint` migrated to TypeScript and ES2015+ syntax in v1.3.0 and v1.1.0 respectively. For modern Node.js and bundled environments, ESM imports are preferred.
lint
import yamlLint from 'yaml-lint'; yamlLint.lint('...');
The primary programmatic function is accessed as a method on the default export. There is no direct named export for `lint` itself.
Types
import type { LintOptions } from 'yaml-lint';
Since v1.3.0, the package ships with TypeScript types. Specific types for options or results can be imported directly.

Demonstrates both direct string linting and how to lint the content of a file using the programmatic API.

import yamlLint from 'yaml-lint'; import { readFileSync } from 'fs'; import { join } from 'path'; // Example 1: Linting a string directly yamlLint .lint('key: value\narray:\n - item1\n - item2') .then(() => { console.log('String content is valid YAML.'); }) .catch((error) => { console.error('String content is invalid YAML:', error.message); }); // Example 2: Linting a file (assuming a test.yaml exists for this example) const filePath = join(process.cwd(), 'test.yaml'); // To make this runnable, create a dummy test.yaml for demonstration: // fs.writeFileSync(filePath, 'foo: bar\nversion: 1.0'); // For a real scenario, ensure 'test.yaml' exists and contains valid YAML try { const fileContent = readFileSync(filePath, 'utf8'); yamlLint.lint(fileContent) .then(() => console.log(`${filePath} is valid YAML.`)) .catch(error => console.error(`${filePath} is invalid YAML:`, error.message)); } catch (err) { console.warn(`Could not read ${filePath}. Please create it for file linting demo.`); // Example of how you'd explicitly fail a file lint for a broken file: // yamlLint.lint('invalid: - \n - yaml') // .catch(error => console.error('Intentional invalid file content error:', error.message)); }
yaml-lint --version
Debug
Known issues
breakingNode.js 0.x is no longer supported. Users on older Node.js versions must upgrade to at least Node.js 8 or newer.
fix
Upgrade your Node.js runtime to version 8 or higher. The current package targets modern Node.js environments.
affects: >=1.0.0
gotchaWhen configuring ignore patterns, always use forward slashes (e.g., `dir/*.yaml`) regardless of the operating system. Backslashes on Windows might lead to patterns not being correctly applied.
fix
Ensure all `ignore` glob patterns consistently use forward slashes. This was specifically fixed in v1.7.0 to enforce forward slashes, but user input still needs to adhere to this.
affects: >=1.7.0
deprecatedThe `nocase` rule for glob patterns was removed in an earlier version (1.2.3) to prevent issues on Windows. This might affect how case-insensitive file matching works for ignore patterns.
fix
Adjust glob patterns to be explicit about case if necessary, as automatic case-insensitivity might not be applied as expected across all platforms.
affects: >=1.2.3
gotchaBy default, the CLI will only display the first failing file it encounters. To see all failing files, ensure you are using a version that supports displaying multiple errors.
fix
Update to `yaml-lint` version 1.4.0 or newer to ensure all failing files are reported when using the CLI.
affects: <1.4.0
Errors
Common errors & fixes
Error: YAMLLINT_SCHEMA environment variable value is not a valid schema type.
An unsupported or misspelled schema name was provided via the `YAMLLINT_SCHEMA` environment variable.
fix
Set `YAMLLINT_SCHEMA` to one of the valid schema types: `DEFAULT_SCHEMA`, `FAILSAFE_SCHEMA`, `JSON_SCHEMA`, or `CORE_SCHEMA`.
Cannot find module 'yaml-lint'
The `yaml-lint` package is not installed or not accessible in the current project's `node_modules`.
fix
Run `npm install --save-dev yaml-lint` for local project usage or `npm install -g yaml-lint` for global CLI use.
SyntaxError: Unexpected token 'export'
Attempting to use `require()` on a module that primarily uses ES Modules syntax in an environment that doesn't correctly transpile or resolve ESM.
fix
Ensure your Node.js environment supports ESM (Node.js 12+ with 'type: module' in package.json, or file extension .mjs). Alternatively, use `import yamlLint from 'yaml-lint';` in an ESM context.
Upgrade
Version history
1.7.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
23 hits · last 30 days
node
20
OpenAI (training)
1
Resources
yaml-lint — npm install yaml-lint · libregistry