Registry / data / yaml-eslint-parser

yaml-eslint-parser

JSON →
library2.0.0jsnpmunverified

yaml-eslint-parser is a critical utility for integrating YAML linting into the ESLint ecosystem, transforming YAML files into an Abstract Syntax Tree (AST) that is fully compatible with ESLint's API. This enables developers to use standard ESLint rules and plugins (like `eslint-plugin-yml`) to lint YAML configuration, data, and schema files, ensuring consistent formatting and catching potential issues. Currently at stable version 2.0.0, the package demonstrates an active release cadence with regular patch and minor updates, and recent major version bumps aligning with Node.js LTS releases. Its key differentiator is its foundation on the robust `yaml` package by Eemeli, providing accurate and spec-compliant YAML parsing, along with options to specify the YAML version (e.g., 1.1 or 1.2) for documents lacking an explicit `%YAML` directive. This approach contrasts with older or simpler parsers that might not provide a full AST or be as spec-compliant, making it a reliable choice for advanced YAML linting needs.

dataserializationhttp-networking
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.

ESLint v9+ uses flat configuration which is ESM-first, requiring `import` syntax for parsers. Previous versions (ESLint v8-) could use CommonJS `require()` in `.eslintrc.js` files, but the parser itself was referenced as a string.

import * as yamlParser from 'yaml-eslint-parser';

Used for TypeScript-based custom ESLint rules or direct AST manipulation, providing type definitions for the generated YAML AST nodes.

import type { AST } from 'yaml-eslint-parser';

For direct programmatic parsing outside of the ESLint configuration context, enabling custom tools or deeper integration. Also exports `getStaticYAMLValue`.

import { parseYAML } from 'yaml-eslint-parser';

Demonstrates configuring `yaml-eslint-parser` as the parser for `.yaml` and `.yml` files in an ESLint v9+ flat configuration file (`eslint.config.js`). It also shows how to apply `parserOptions`.

import * as yamlParser from "yaml-eslint-parser"; export default [ { files: ["*.yaml", "*.yml"], languageOptions: { parser: yamlParser, // Optional: Set default YAML version for documents without a %YAML directive parserOptions: { defaultYAMLVersion: "1.2", // Defaults to '1.2' if not specified }, }, // Add rules from a YAML ESLint plugin, e.g., eslint-plugin-yml // plugins: { yml: someYmlPlugin }, // rules: { // 'yml/no-empty-document': 'error', // }, }, ];
Debug
Known footguns
breakingVersion 2.0.0 drops support for Node.js versions prior to `^20.19.0 || ^22.13.0 || >=24`. Projects running on older Node.js runtimes will need to upgrade their Node.js environment or remain on `yaml-eslint-parser` v1.x.
gotchaWhen migrating from ESLint v8 to v9 flat configuration, parsers must be imported as modules (e.g., `import * as parser from 'pkg'`) instead of being referenced by a string. Older `.eslintrc.js` files used a string value for the `parser` property.
gotchaFor ESLint v8 and earlier, configuring `yaml-eslint-parser` involved setting the `parser` property to the string `'yaml-eslint-parser'` within an `overrides` block in `.eslintrc.js` or `.eslintrc.yaml`. Direct `import` statements for the parser in `.eslintrc.js` were less common or not supported in the same way as with flat config.
gotchaThe `parserOptions.defaultYAMLVersion` option controls which YAML specification (1.1 or 1.2) is used for documents that do not explicitly declare a version using the `%YAML` directive. Misconfiguring this can lead to unexpected parsing behavior or errors for specific YAML syntaxes.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
8 hits · last 30 days
gptbot
4
ahrefsbot
3
script
1
Resources