Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {