How to use unist-util-position - 10 common examples

To help you get started, we’ve selected a few unist-util-position 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 remarkjs / remark-lint / packages / remark-lint-no-consecutive-blank-lines / index.js View on Github external
if (!generated(node) && children) {
      head = children[0]

      if (head && !generated(head)) {
        // Compare parent and first child.
        compare(position.start(node), position.start(head), 0)

        // Compare between each child.
        children.forEach(visitChild)

        tail = children[children.length - 1]

        // Compare parent and last child.
        if (tail !== head && !generated(tail)) {
          compare(position.end(node), position.end(tail), 1)
        }
      }
    }
  }
github vhf / remark-lint-blank-lines-1-0-2 / dist / blank-lines.js View on Github external
visit(tree, function (node, index, parent) {
    var next = parent && parent.children[index + 1];

    if (generated(node)) {
      return;
    }

    if (next && isApplicable(node) && isApplicable(next)) {
      if (node.type === 'heading' && next.type === 'heading') {
        if (position.start(next).line !== position.end(node).line + 2) {
          file.message('Incorrect number of blank lines between headings', node);
        }
      } else if (node.type === 'heading' && next.type !== 'heading') {
        if (position.start(next).line - position.end(node).line !== 2) {
          file.message('Incorrect number of blank lines between heading and section', node);
        }
      } else if (node.type === 'list') {
        if (position.start(next).line - position.end(node).line !== 3) {
          file.message('Incorrect number of blank lines between last section and next heading', node);
        }
      }
    }
  });
}
github vhf / remark-lint-blank-lines-1-0-2 / lib / blank-lines.js View on Github external
visit(tree, (node, index, parent) => {
    const next = parent && parent.children[index + 1];

    if (generated(node)) {
      return;
    }

    if (next && isApplicable(node) && isApplicable(next)) {
      if (node.type === 'heading' && next.type === 'heading') {
        if (position.start(next).line !== position.end(node).line + 2) {
          file.message('Incorrect number of blank lines between headings', node);
        }
      } else if (node.type === 'heading' && next.type !== 'heading') {
        if (position.start(next).line - position.end(node).line !== 2) {
          file.message('Incorrect number of blank lines between heading and section', node);
        }
      } else if (node.type === 'list') {
        if (position.start(next).line - position.end(node).line !== 3) {
          file.message('Incorrect number of blank lines between last section and next heading', node);
        }
      }
    }
  });
}
github vhf / remark-lint-blank-lines-1-0-2 / dist / blank-lines.js View on Github external
if (generated(node)) {
      return;
    }

    if (next && isApplicable(node) && isApplicable(next)) {
      if (node.type === 'heading' && next.type === 'heading') {
        if (position.start(next).line !== position.end(node).line + 2) {
          file.message('Incorrect number of blank lines between headings', node);
        }
      } else if (node.type === 'heading' && next.type !== 'heading') {
        if (position.start(next).line - position.end(node).line !== 2) {
          file.message('Incorrect number of blank lines between heading and section', node);
        }
      } else if (node.type === 'list') {
        if (position.start(next).line - position.end(node).line !== 3) {
          file.message('Incorrect number of blank lines between last section and next heading', node);
        }
      }
    }
  });
}
github remarkjs / remark-lint / packages / remark-lint-no-paragraph-content-indent / index.js View on Github external
function check(node, pos, parent) {
      var start = position.start(node)
      var value
      var index
      var line
      var cumulative
      var indent

      if (!applicable(node)) {
        return
      }

      if (!start.line || !node.position.indent) {
        first = false
        return
      }

      if (first && ws(toString(node).charAt(0))) {
github remarkjs / remark-lint / packages / remark-lint-blockquote-indentation / index.js View on Github external
function check(node) {
  var head = node.children[0]
  var indentation = position.start(head).column - position.start(node).column
  var padding = toString(head).match(/^ +/)

  if (padding) {
    indentation += padding[0].length
  }

  return indentation
}
github vhf / remark-lint-blank-lines-1-0-2 / lib / blank-lines.js View on Github external
if (generated(node)) {
      return;
    }

    if (next && isApplicable(node) && isApplicable(next)) {
      if (node.type === 'heading' && next.type === 'heading') {
        if (position.start(next).line !== position.end(node).line + 2) {
          file.message('Incorrect number of blank lines between headings', node);
        }
      } else if (node.type === 'heading' && next.type !== 'heading') {
        if (position.start(next).line - position.end(node).line !== 2) {
          file.message('Incorrect number of blank lines between heading and section', node);
        }
      } else if (node.type === 'list') {
        if (position.start(next).line - position.end(node).line !== 3) {
          file.message('Incorrect number of blank lines between last section and next heading', node);
        }
      }
    }
  });
}
github wemake-services / remark-lint-are-links-valid / lib / are-links-valid.js View on Github external
function handleLinkError(file, link) {
  const { line, column } = start(link.node);
  file.warn(`Link is broken: ${link.link.href}`, { line, column });
}
github remarkjs / remark-lint / packages / remark-lint-no-multiple-toplevel-headings / index.js View on Github external
function visitor(node) {
    if (!generated(node) && node.depth === style) {
      if (duplicate) {
        file.message(
          'Don’t use multiple top level headings (' + duplicate + ')',
          node
        )
      } else {
        duplicate = stringify(start(node))
      }
    }
  }
}
github wemake-services / remark-lint-are-links-valid / dist / are-links-valid.js View on Github external
function handleLinkDuplicateError(file, link) {
  var _start = start(link.node);

  var line = _start.line;
  var column = _start.column;

  file.warn('Link is a duplicate: ' + link.link.href, { line: line, column: column });
}

unist-util-position

unist utility to get the position of a node

MIT
Latest version published 9 months ago

Package Health Score

74 / 100
Full package analysis

Popular unist-util-position functions