Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

yaml-eslint-parser

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yaml-eslint-parser - npm Package Compare versions

Comparing version 0.0.8 to 0.1.0

lib/traverse.d.ts

2

lib/ast.d.ts

@@ -42,3 +42,3 @@ export declare type Range = [number, number];

anchors: {
[key: string]: YAMLAnchor;
[key: string]: YAMLAnchor[];
};

@@ -45,0 +45,0 @@ }

@@ -603,3 +603,4 @@ "use strict";

const ast = Object.assign({ type: "YAMLAnchor", name: value, parent }, loc);
doc.anchors[value] = ast;
const anchors = doc.anchors[value] || (doc.anchors[value] = []);
anchors.push(ast);
const text = code.slice(...loc.range);

@@ -704,3 +705,2 @@ if (text.startsWith("&")) {

const n = {};
// eslint-disable-next-line @mysticatea/prefer-for-of
for (const key in loc) {

@@ -707,0 +707,0 @@ n[key] = clone(loc[key]);

@@ -1,5 +0,12 @@

export * from "./parser";
import { parseForESLint, ParseError } from "./parser";
import type * as AST from "./ast";
import { traverseNodes } from "./traverse";
import { getStaticYAMLValue } from "./utils";
export { AST, getStaticYAMLValue };
export { AST, ParseError };
export { parseForESLint };
export declare const VisitorKeys: import("eslint").SourceCode.VisitorKeys;
export { traverseNodes, getStaticYAMLValue };
/**
* Parse YAML source code
*/
export declare function parseYAML(code: string, _options?: any): AST.YAMLProgram;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.VisitorKeys = exports.getStaticYAMLValue = void 0;
__exportStar(require("./parser"), exports);
exports.parseYAML = exports.getStaticYAMLValue = exports.traverseNodes = exports.VisitorKeys = exports.parseForESLint = exports.ParseError = void 0;
const parser_1 = require("./parser");
Object.defineProperty(exports, "parseForESLint", { enumerable: true, get: function () { return parser_1.parseForESLint; } });
Object.defineProperty(exports, "ParseError", { enumerable: true, get: function () { return parser_1.ParseError; } });
const traverse_1 = require("./traverse");
Object.defineProperty(exports, "traverseNodes", { enumerable: true, get: function () { return traverse_1.traverseNodes; } });
const utils_1 = require("./utils");
Object.defineProperty(exports, "getStaticYAMLValue", { enumerable: true, get: function () { return utils_1.getStaticYAMLValue; } });
const visitor_keys_1 = require("./visitor-keys");
// Keys
// eslint-disable-next-line @typescript-eslint/naming-convention -- ignore
exports.VisitorKeys = visitor_keys_1.KEYS;
/**
* Parse YAML source code
*/
function parseYAML(code, _options) {
return parser_1.parseForESLint(code).ast;
}
exports.parseYAML = parseYAML;

@@ -0,1 +1,3 @@

import type { SourceCode } from "eslint";
import type { YAMLProgram } from "./ast";
/**

@@ -5,4 +7,4 @@ * Parse source code

export declare function parseForESLint(code: string, _options?: any): {
ast: import("./ast").YAMLProgram;
visitorKeys: import("eslint").SourceCode.VisitorKeys;
ast: YAMLProgram;
visitorKeys: SourceCode.VisitorKeys;
services: {

@@ -9,0 +11,0 @@ isYAML: boolean;

@@ -1,2 +0,2 @@

import { YAMLProgram, YAMLContent, YAMLDocument, YAMLMapping, YAMLSequence, YAMLScalar, YAMLAlias, YAMLPair, YAMLWithMeta } from "./ast";
import type { YAMLProgram, YAMLContent, YAMLDocument, YAMLMapping, YAMLSequence, YAMLScalar, YAMLAlias, YAMLPair, YAMLWithMeta } from "./ast";
declare type YAMLContentValue = string | number | boolean | null | YAMLContentValue[] | YAMLMappingValue;

@@ -10,4 +10,3 @@ declare type YAMLMappingValue = {

export declare function getStaticYAMLValue(node: YAMLScalar): string | number | boolean | null;
export declare function getStaticYAMLValue(node: YAMLAlias): YAMLContentValue;
export declare function getStaticYAMLValue(node: YAMLProgram | YAMLDocument | YAMLContent | YAMLPair | YAMLWithMeta): YAMLContentValue;
export declare function getStaticYAMLValue(node: YAMLAlias | YAMLProgram | YAMLDocument | YAMLContent | YAMLPair | YAMLWithMeta): YAMLContentValue;
/**

@@ -14,0 +13,0 @@ * Checks if the given string is true

@@ -20,5 +20,6 @@ "use strict";

: node.body.length === 1
? // eslint-disable-next-line new-cap
? // eslint-disable-next-line new-cap -- traverse key
resolver.YAMLDocument(node.body[0])
: node.body.map(resolver.YAMLDocument);
: // eslint-disable-next-line new-cap -- traverse key
node.body.map((n) => resolver.YAMLDocument(n));
},

@@ -92,3 +93,22 @@ YAMLDocument(node) {

}
return doc.anchors[node.name] || null;
const anchors = doc.anchors[node.name];
if (!anchors) {
return null;
}
let target = {
anchor: null,
distance: Infinity,
};
for (const anchor of anchors) {
if (anchor.range[0] < node.range[0]) {
const distance = node.range[0] - anchor.range[0];
if (target.distance >= distance) {
target = {
anchor,
distance,
};
}
}
}
return target.anchor;
}

@@ -95,0 +115,0 @@ /**

{
"name": "yaml-eslint-parser",
"version": "0.0.8",
"version": "0.1.0",
"description": "A YAML parser that produces output compatible with ESLint",

@@ -41,7 +41,16 @@ "main": "lib/index.js",

"devDependencies": {
"@mysticatea/eslint-plugin": "^13.0.0",
"@ota-meshi/eslint-plugin": "^0.0.6",
"@types/eslint": "^7.2.0",
"@types/eslint-visitor-keys": "^1.0.0",
"@types/mocha": "^7.0.2",
"@types/node": "^14.0.13",
"@typescript-eslint/eslint-plugin": "^4.9.1",
"@typescript-eslint/parser": "^4.9.1",
"eslint": "^7.5.0",
"eslint-config-prettier": "^7.0.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-jsonc": "^0.7.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.2.0",
"eslint-plugin-vue": "^7.2.0",
"mocha": "^7.0.0",

@@ -51,4 +60,5 @@ "nyc": "^15.1.0",

"ts-node": "^8.10.2",
"typescript": "^3.9.7"
"typescript": "^3.9.7",
"vue-eslint-parser": "^7.2.0"
}
}

@@ -42,31 +42,6 @@ # yaml-eslint-parser

### Running ESLint from the command line
## Usage for Custom Rules / Plugins
If you want to run `eslint` from the command line, make sure you include the `.yaml` extension using [the `--ext` option](https://eslint.org/docs/user-guide/configuring#specifying-file-extensions-to-lint) or a glob pattern, because ESLint targets only `.js` files by default.
Examples:
```bash
eslint --ext .js,.yaml,.yml src
eslint "src/**/*.{js,yaml,yml}"
```
## Editor Integrations
### Visual Studio Code
Use the [dbaeumer.vscode-eslint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) extension that Microsoft provides officially.
You have to configure the `eslint.validate` option of the extension to check `.yaml` files, because the extension targets only `*.js` or `*.jsx` files by default.
Example **.vscode/settings.json**:
```json
{
"eslint.validate": [
"javascript",
"javascriptreact",
"yaml"
]
}
```
- [AST.md](./docs/AST.md) is AST specification.
- [block-mapping.ts](https://github.com/ota-meshi/eslint-plugin-yml/blob/master/src/rules/block-mapping.ts) is an example.
- You can see the AST on the [Online DEMO](https://ota-meshi.github.io/yaml-eslint-parser/).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc