1. yaml-eslint-parser
A YAML parser that produces output compatible with ESLint
yaml-eslint-parser
Package: yaml-eslint-parser
Created by: ota-meshi
Last modified: Sun, 09 Jul 2023 22:08:45 GMT
Version: 1.2.2
License: MIT
Downloads: 2,825,414
Repository: https://github.com/ota-meshi/yaml-eslint-parser

Install

npm install yaml-eslint-parser
yarn add yaml-eslint-parser

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 .eslintrc.* file to configure parser. See also: https://eslint.org/docs/user-guide/configuring.

Example .eslintrc.js:

 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 .eslintrc.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.
If not specified, 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 POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code