ErrorFixer interface
Methods to modify the original source to fix errors.
insertTextBefore method
Inserts text at just before location.
Syntax
insertTextBefore(location, insert);
Return value
This method has no return value.
Parameters
location: Location: The location where text will be inserted at.insert: string: The text to insert.
Example
/* inserts "before" to just before given location */
fixer.insertTextBefore(location, "before");
If location refers to the word "ipsum", the following change would be applied:
-lorem ipsum dolor sit amet
+lorem beforeipsum dolor sit amet
insertTextAfter method
Inserts text at just after location.
Syntax
insertTextAfter(location, insert);
Return value
This method has no return value.
Parameters
location: Location: The location where text will be inserted at.insert: string: The text to insert.
Example
/* inserts "after" to just after given location */
fixer.insertTextAfter(location, "after");
If location refers to the word "ipsum", the following change would be applied:
-lorem ipsum dolor sit amet
+lorem ipsumafter dolor sit amet
replaceText method
Replaces the text at location.
Syntax
replaceText(location, replacement);
Return value
This method has no return value.
Parameters
location: Location: The location of text to replace.replacement: string: The text to replace current text with.
Example
/* replace the text at given location with "lorem ipsum" */
fixer.replaceText(location, "lorem ipsum");
renameTag method
Renames the tag of an element, updating both the start tag and the end tag (if present). Attributes are left untouched even if they are not valid on the renamed element.
Elements without an end tag (void elements, elements with optional end tags, etc) only get the start tag renamed.
Elements implicitly opened by the parser (such as an omitted <body>) are not present in the source and are ignored.
Syntax
renameTag(element, newName);
Return value
This method has no return value.
Parameters
element: HtmlElement: The element to rename.newName: string: The new tag name.
Example
Given the following markup:
<div class="foo"></div>
To rename the element:
fixer.renameTag(element, "span");
Resulting in:
<span class="foo"></span>
removeText method
Removes the text at location, optionally trimming whitespace before or after.
Syntax
removeText(location, [options]);
Return value
This method has no return value.
Parameters
location: Location: The location of text to remove.options.trimStart: boolean(optional): Remove whitespace characters before the specified location, up to and including a single newline if present. Defaults tofalse.options.trimEnd: boolean(optional): Remove whitespace characters after the specified location, up to and including a single newline if present. Defaults tofalse.
Example
Given an element with the foo attribute:
<div foo="bar"></div>
To remove the attribute:
fixer.removeText(attr.location);
After removal the result would be:
<div ></div>
The whitespace before the attribute can be trimmed:
fixer.removeText(attr.location, { trimStart: true });
Resulting in <div> instead of <div >:
<div></div>