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-parserVerified import paths — ran on the pinned version, not inferred.
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`.
Upgrade Node.js to version `^20.19.0`, `^22.13.0`, or `>=24`. Alternatively, downgrade `yaml-eslint-parser` to version `1.x`.
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,`.
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' }] };`.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'.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`.
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.
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.