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.

npm install yaml-eslint-parser
INSTALL
IMPORT
SIG · YAML-ESLINT-PARSER
Y
yaml-eslint-parser
datajavascriptv2.0.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.

default export (as yamlParser)
import * as yamlParser from 'yaml-eslint-parser';
const yamlParser = require('yaml-eslint-parser');
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.
AST
import type { AST } from 'yaml-eslint-parser';
Used for TypeScript-based custom ESLint rules or direct AST manipulation, providing type definitions for the generated YAML AST nodes.
parseYAML
import { parseYAML } from 'yaml-eslint-parser';
For direct programmatic parsing outside of the ESLint configuration context, enabling custom tools or deeper integration. Also exports `getStaticYAMLValue`.

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 issues
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.
fix
Upgrade Node.js to version `^20.19.0`, `^22.13.0`, or `>=24`. Alternatively, downgrade `yaml-eslint-parser` to version `1.x`.
affects: >=2.0.0
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.
fix
Update your ESLint configuration file (e.g., `eslint.config.js`) to `import` the parser directly: `import * as yamlParser from 'yaml-eslint-parser';` and then use the imported object: `parser: yamlParser,`.
affects: >=1.0.0 (when used with ESLint v9+)
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.
fix
For ESLint v8 or earlier, ensure your `.eslintrc.js` (or similar) uses `parser: 'yaml-eslint-parser'` as a string, typically within an `overrides` array for YAML files. Example: `module.exports = { overrides: [{ files: ['*.yaml', '*.yml'], parser: 'yaml-eslint-parser' }] };`.
affects: <2.0.0 (when used with ESLint v8-)
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.
fix
Explicitly set `parserOptions: { defaultYAMLVersion: '1.2' }` (or `'1.1'`) in your ESLint configuration if your YAML files rely on specific version features or if you encounter unexpected parsing issues with certain syntax constructs. The default is '1.2'.
affects: >=1.1.0
Errors
Common errors & fixes
ESLint couldn't find the parser 'yaml-eslint-parser' configured in your .eslintrc.js
The `yaml-eslint-parser` package is not installed or not resolvable by ESLint.
fix
Run `npm install --save-dev yaml-eslint-parser` (or `yarn add --dev yaml-eslint-parser`) to install the package. Ensure it's listed in your `package.json`.
TypeError: context.getScope is not a function (when using with ESLint v9+)
While `yaml-eslint-parser` itself is updated for ESLint v9, an associated plugin (e.g., `eslint-plugin-yml`) might not be fully compatible with ESLint v9's rule API.
fix
Ensure all ESLint plugins used with `yaml-eslint-parser` are updated to their latest versions that explicitly support ESLint v9. Check the plugin's documentation for compatibility notes. This error is more likely from an incompatible plugin than the parser itself.
Error: The 'engines.node' requirement of 'yaml-eslint-parser' is not satisfied by your current Node.js version.
Your Node.js runtime version is older than the minimum required by `yaml-eslint-parser` v2.0.0.
fix
Upgrade your Node.js environment to a compatible version (e.g., `^20.19.0 || ^22.13.0 || >=24`). Consider using a Node.js version manager like `nvm` to easily switch versions.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
yamlrequiredCore parsing engine for YAML content.
eslint-visitor-keysrequiredProvides visitor keys for ESLint AST traversal.
Agent activity
35 hits · last 30 days
node
30
OpenAI (training)
1
Resources
yaml-eslint-parser — npm install yaml-eslint-parser · libregistry