yaml-eslint-parser
A YAML parser that produces output compatible with ESLint
Last updated 3 years ago by ota-meshi .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install yaml-eslint-parser 
SYNC missed versions from official npm registry.

yaml-eslint-parser

A 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.

NPM license NPM version NPM downloads NPM downloads NPM downloads NPM downloads NPM downloads Build Status Coverage Status

Installation

npm install --save-dev yaml-eslint-parser

Usage

Configuration

Use eslint.config.js file to configure parser (ESLint v9+). See also: https://eslint.org/docs/latest/use/configure/.

Example eslint.config.js:

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

export default [
  {
    files: ["*.yaml", "*.yml"],
    languageOptions: {
      parser: yamlParser,
    },
  },
];
<summary>For ESLint v8 and earlier (.eslintrc.js)</summary>
module.exports = {
  overrides: [
    {
      files: ["*.yaml", "*.yml"],
      parser: "yaml-eslint-parser",
    },
  ],
};

Advanced Configuration

The following additional configuration options are available by specifying them in parserOptions in your ESLint configuration file.

Example eslint.config.js:

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

export default [
  {
    files: ["*.yaml", "*.yml"],
    languageOptions: {
      parser: yamlParser,
      // Additional configuration options
      parserOptions: {
        defaultYAMLVersion: "1.2",
      },
    },
  },
];
<summary>For ESLint v8 and earlier (.eslintrc.js)</summary>
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.
If not specified, the yaml's default version option ("1.2") is used.
See https://eemeli.org/yaml/#document-options for details.

Usage for Custom Rules / Plugins

Usage for Directly

Example:

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);

Related Packages

Current Tags

  • 1.2.2                                ...           latest (3 years ago)
  • 1.0.0                                ...           next (4 years ago)

27 Versions

  • 1.2.2                                ...           3 years ago
  • 1.2.1                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
  • 1.0.0-beta.1                                ...           4 years ago
  • 1.0.0-beta.0                                ...           4 years ago
  • 0.5.0                                ...           4 years ago
  • 0.4.1                                ...           5 years ago
  • 0.4.0                                ...           5 years ago
  • 0.3.2                                ...           5 years ago
  • 0.3.1                                ...           5 years ago
  • 0.3.0                                ...           5 years ago
  • 0.2.2                                ...           5 years ago
  • 0.2.1                                ...           5 years ago
  • 0.2.0                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
  • 0.0.8                                ...           6 years ago
  • 0.0.7                                ...           6 years ago
  • 0.0.6                                ...           6 years ago
  • 0.0.5                                ...           6 years ago
  • 0.0.4                                ...           6 years ago
  • 0.0.3                                ...           6 years ago
  • 0.0.2                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
  • 0.0.0                                ...           6 years ago

Copyright 2013 - present © cnpmjs.org | Home |