How to use @textlint/ast-traverse - 1 common examples

To help you get started, we’ve selected a few @textlint/ast-traverse 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 orangain / textlint-plugin-review / src / review-to-ast.js View on Github external
function validateAST(ast, text, lines) {
  testTextlintAST(ast);

  let prevNode = ast;
  traverse(ast, {
    enter(node) {
      try {
        assert(node.raw === text.slice(node.range[0], node.range[1]));

        if (node.loc.start.line === node.loc.end.line) {
          // single line
          const line = lines[node.loc.start.line - 1];
          assert(node.raw === line.slice(node.loc.start.column, node.loc.end.column));
        } else {
          // multi line
          const firstLine = lines[node.loc.start.line - 1];
          assert(node.raw.startsWith(firstLine.substr(node.loc.start.column)));
          const lastLine = lines[node.loc.end.line - 1];
          assert(node.raw.endsWith(lastLine.substr(0, node.loc.end.column)));
        }
      } catch (ex) {

@textlint/ast-traverse

TxtNode traverse library

MIT
Latest version published 2 months ago

Package Health Score

89 / 100
Full package analysis

Popular @textlint/ast-traverse functions