A YAML parser that produces output compatible with ESLint
npm install yaml-eslint-parserA YAML parser that produces output compatible with ESLint.
_This parser is backed by excellent yaml package and it is heavily inspired by yaml-unist-parser package._









``bash`
npm install --save-dev yaml-eslint-parser
Use eslint.config.js file to configure parser (ESLint v9+). See also: https://eslint.org/docs/latest/use/configure/.
Example eslint.config.js:
`js
import * as yamlParser from "yaml-eslint-parser";
export default [
{
files: [".yaml", ".yml"],
languageOptions: {
parser: yamlParser,
},
},
];
`
For ESLint v8 and earlier (.eslintrc.js)
`js`
module.exports = {
overrides: [
{
files: [".yaml", ".yml"],
parser: "yaml-eslint-parser",
},
],
};
The following additional configuration options are available by specifying them in parserOptions in your ESLint configuration file.
Example eslint.config.js:
`js
import * as yamlParser from "yaml-eslint-parser";
export default [
{
files: [".yaml", ".yml"],
languageOptions: {
parser: yamlParser,
// Additional configuration options
parserOptions: {
defaultYAMLVersion: "1.2",
},
},
},
];
`
For ESLint v8 and earlier (.eslintrc.js)
`js`
module.exports = {
overrides: [
{
files: [".yaml", ".yml"],
parser: "yaml-eslint-parser",
// Additional configuration options
parserOptions: {
defaultYAMLVersion: "1.2",
},
},
],
};
#### parserOptions.defaultYAMLVersion
Set to "1.2" or "1.1". Select the YAML version used by documents without a %YAML directive. version
If not specified, the yaml's default option ("1.2") is used.
See
- AST.md is AST specification.
- block-mapping.ts is an example.
- You can see the AST on the Online DEMO.
Example:
`ts
import type { AST } from "yaml-eslint-parser";
import { parseYAML, getStaticYAMLValue } from "yaml-eslint-parser";
const code =
american:
- Boston Red Sox
- Detroit Tigers
- New York Yankees
national:
- New York Mets
- Chicago Cubs
- Atlanta Braves;
const ast: AST.YAMLProgram = parseYAML(code);
console.log(ast);
const value = getStaticYAMLValue(ast);
console.log(value);
``
- eslint-plugin-jsonc ... ESLint plugin for JSON, JSON with comments (JSONC) and JSON5.
- eslint-plugin-yml ... ESLint plugin for YAML.
- eslint-plugin-toml ... ESLint plugin for TOML.
- eslint-plugin-json-schema-validator ... ESLint plugin that validates data using JSON Schema Validator.
- jsonc-eslint-parser ... JSON, JSONC and JSON5 parser for use with ESLint plugins.
- toml-eslint-parser ... TOML parser for use with ESLint plugins.