autofixCollectEdits function

Collects all text edits requested by a rule autofix callback. The result is a list of text edits which the caller can use to modify the text.

Syntax

autofixCollectEdits(fix, text);

Return value

A promise resolving to the list of TextEdit objects requested by the callback, sorted in reverse (descending) offset order.

Throws if any edit has an invalid or out-of-bounds location, or if two edits overlap.

Parameters

Example

Given a Message object, e.g. from the result of htmlvalidate.validateString():

import { TextEditKind, autofixCollectEdits } from "html-validate";

const edits = await autofixCollectEdits(message.fix, text);

for (const edit of edits) {
  switch (edit.kind) {
    case TextEditKind.Remove:
      /* remove text at location */
      break;
    case TextEditKind.Replace:
      /* replace text at location */
      break;
  }
}