Skip to content

Commit

Permalink
Enable the unicorn/prefer-modern-dom-apis ESLint plugin rule
Browse files Browse the repository at this point in the history
This rule will help enforce slightly shorter code, and according to MDN both `Element.replaceWith()` and `Element.before()` are available in all browsers that we currently support.

Please find additional information here:
 - https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-modern-dom-apis.md
 - https://developer.mozilla.org/en-US/docs/Web/API/Element/replaceWith
 - https://developer.mozilla.org/en-US/docs/Web/API/Element/before
  • Loading branch information
Snuffleupagus committed Jun 12, 2022
1 parent 0c65926 commit 4d39898
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"unicorn/prefer-date-now": "error",
"unicorn/prefer-dom-node-append": "error",
"unicorn/prefer-dom-node-remove": "error",
"unicorn/prefer-modern-dom-apis": "error",
"unicorn/prefer-string-starts-ends-with": "error",

// Possible errors
Expand Down
2 changes: 1 addition & 1 deletion extensions/chromium/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function updateEmbedElement(elem) {
elem.type = "text/html";
elem.src = getEmbeddedViewerURL(elem.src);
if (parentNode) {
parentNode.insertBefore(elem, nextSibling);
nextSibling.before(elem);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2559,9 +2559,9 @@ class AnnotationLayer {
if (!firstChild) {
element.append(canvas);
} else if (firstChild.nodeName === "CANVAS") {
element.replaceChild(canvas, firstChild);
firstChild.replaceWith(canvas);
} else {
element.insertBefore(canvas, firstChild);
firstChild.before(canvas);
}
}
annotationCanvasMap.clear();
Expand Down
4 changes: 2 additions & 2 deletions web/pdf_page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ class PDFPageView {

if (lastDivBeforeTextDiv) {
// The annotation layer needs to stay on top.
div.insertBefore(canvasWrapper, lastDivBeforeTextDiv);
lastDivBeforeTextDiv.before(canvasWrapper);
} else {
div.append(canvasWrapper);
}
Expand All @@ -640,7 +640,7 @@ class PDFPageView {
textLayerDiv.style.height = canvasWrapper.style.height;
if (lastDivBeforeTextDiv) {
// The annotation layer needs to stay on top.
div.insertBefore(textLayerDiv, lastDivBeforeTextDiv);
lastDivBeforeTextDiv.before(textLayerDiv);
} else {
div.append(textLayerDiv);
}
Expand Down

0 comments on commit 4d39898

Please sign in to comment.