How to use the yaml-ast-parser.safeLoad function in yaml-ast-parser

To help you get started, we’ve selected a few yaml-ast-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github matt-deboer / kuill / pkg / ui / src / utils / yaml-utils.js View on Github external
constructor(contents, row, col) {
    
    this.ast = loadYaml(contents)
    let lines = this.lines = contents.split(/\n/g, -1)

    this._index = {
      range: new IntervalTree(),
      nodePos: [],
      nodePath: {},
      posToRow: [],
    }
    
    // create index of pos to row,col
    let pos = 0
    for (let s = 0, len=lines.length; s < len; ++s) {
      this._index.posToRow.push([pos, lines[s].length])
      pos += lines[s].length + 1
    }
    this.visit(this.ast)
github replicatedhq / replicated-lint / dist / lint.js View on Github external
var offset = positionOffset || 0;
    lineColumnFinder = lineColumnFinder || lineColumn(inYaml);
    if (!inYaml) {
        return [noDocError(inYaml)];
    }
    var root;
    try {
        root = yaml.safeLoad(inYaml);
    }
    catch (err) {
        return [loadYamlError(err, inYaml, lineColumnFinder, offset)];
    }
    if (!root) {
        return [noDocError(inYaml)];
    }
    var yamlAST = ast.safeLoad(inYaml, null);
    if (_.isEmpty(rules)) {
        return [];
    }
    var ruleTriggers = [];
    _.forEach(rules, function (rule) {
        var result = rule.test.test(root);
        if (result.matched) {
            var positions = _.flatMap(result.paths, function (path) { return ast_1.astPosition(yamlAST, path, lineColumnFinder, offset); });
            if (_.isEmpty(positions)) {
                var shorterPaths = _.map(result.paths, function (p) { return p.split(".").slice(0, -1).join("."); });
                positions = _.flatMap(shorterPaths, function (path) { return ast_1.astPosition(yamlAST, path, lineColumnFinder, offset); });
            }
            ruleTriggers.push({
                type: rule.type,
                rule: rule.name,
                received: _.map(result.paths, function (p) { return _.get(root, p); })[0],
github tangrams / tangram-play / src / js / editor / codemirror / yaml-parser.js View on Github external
function parseDoc(cm) {
  const doc = cm.getDoc();
  const content = doc.getValue();
  doc.yamlNodes = findAnchorRefParents(YAML.safeLoad(content));
}
github Azure / vscode-kubernetes-tools / src / yaml-support / jsonalike-symbol-provider.ts View on Github external
async provideDocumentSymbolsImpl(document: vscode.TextDocument, _token: vscode.CancellationToken): Promise {
        const fakeText = document.getText().replace(/{{[^}]*}}/g, (s) => encodeWithTemplateMarkers(s));
        const root = yp.safeLoad(fakeText);
        const syms: vscode.SymbolInformation[] = [];
        walk(root, '', document, document.uri, syms);
        return syms;
    }
}
github Azure / autorest / src / autorest-core / lib / ref / yaml.ts View on Github external
export function ParseToAst(rawYaml: string): YAMLNode {
  return yamlAst.safeLoad(rawYaml, null) as YAMLNode;
}
github Azure / vscode-kubernetes-tools / src / helm.symbolProvider.ts View on Github external
async provideDocumentSymbolsImpl(document: vscode.TextDocument, _token: vscode.CancellationToken): Promise {
        const fakeText1 = document.getText();
        const fakeText2 = substituteStatements(fakeText1);
        const fakeText3 = substituteExpressions(fakeText2);
        const root = yp.safeLoad(fakeText3);
        const syms: vscode.SymbolInformation[] = [];
        walk(root, '', document, document.uri, syms);
        return syms;
    }
}
github replicatedhq / ship / web / init / src / components / kustomize / kustomize_overlay / AceEditorHOC.jsx View on Github external
createMarkers = (fileToView) => {
    if (this.aceEditorBase) {
      let markers = [];
      const loadedAst = ast.safeLoad(fileToView.baseContent, null);
      this.createMarkersRec(loadedAst, [], markers);
      return markers;
    }
  }