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

To help you get started, we’ve selected a few @textlint/ast-tester 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];

@textlint/ast-tester

Compliance tests for textlint's AST(Abstract Syntax Tree).

MIT
Latest version published 21 days ago

Package Health Score

89 / 100
Full package analysis

Popular @textlint/ast-tester functions