Enable the mozilla/avoid-removeChild ESLint rule globally

This rule is available from https://www.npmjs.com/package/eslint-plugin-mozilla, and is enforced in mozilla-central. Note that we have a polyfill for `ChildNode.remove()` and that most cases have already been fixed, see PRs 8056 and 8138.
This commit is contained in:
Jonas Jenwald 2018-02-10 16:19:45 +01:00
parent 9767b8a9f1
commit 2eb29409bc
5 changed files with 12 additions and 5 deletions

View File

@ -4,6 +4,10 @@
"sourceType": "module", "sourceType": "module",
}, },
"plugins": [
"mozilla"
],
"env": { "env": {
"browser": true, "browser": true,
"es6": true, "es6": true,
@ -18,6 +22,9 @@
}, },
"rules": { "rules": {
// Plugins
"mozilla/avoid-removeChild": "error",
// Possible errors // Possible errors
"for-direction": "error", "for-direction": "error",
"no-cond-assign": ["error", "except-parens"], "no-cond-assign": ["error", "except-parens"],

View File

@ -152,6 +152,7 @@ PDFJS.compatibilityChecked = true;
} }
Element.prototype.remove = function () { Element.prototype.remove = function () {
if (this.parentNode) { if (this.parentNode) {
// eslint-disable-next-line mozilla/avoid-removeChild
this.parentNode.removeChild(this); this.parentNode.removeChild(this);
} }
}; };

View File

@ -367,8 +367,7 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars
while (styleSheet.cssRules.length > 0) { while (styleSheet.cssRules.length > 0) {
styleSheet.deleteRule(0); styleSheet.deleteRule(0);
} }
let ownerNode = styleSheet.ownerNode; styleSheet.ownerNode.remove();
ownerNode.parentNode.removeChild(ownerNode);
} }
let body = document.body; let body = document.body;
while (body.lastChild !== this.end) { while (body.lastChild !== this.end) {

View File

@ -43,7 +43,7 @@ function download(blobUrl, filename) {
// (otherwise .click() is ignored) // (otherwise .click() is ignored)
(document.body || document.documentElement).appendChild(a); (document.body || document.documentElement).appendChild(a);
a.click(); a.click();
a.parentNode.removeChild(a); a.remove();
} else { } else {
if (window.top === window && if (window.top === window &&
blobUrl.split('#')[0] === window.location.href.split('#')[0]) { blobUrl.split('#')[0] === window.location.href.split('#')[0]) {

View File

@ -111,8 +111,8 @@ PDFPrintService.prototype = {
return; return;
} }
this.printContainer.textContent = ''; this.printContainer.textContent = '';
if (this.pageStyleSheet && this.pageStyleSheet.parentNode) { if (this.pageStyleSheet) {
this.pageStyleSheet.parentNode.removeChild(this.pageStyleSheet); this.pageStyleSheet.remove();
this.pageStyleSheet = null; this.pageStyleSheet = null;
} }
this.scratchCanvas.width = this.scratchCanvas.height = 0; this.scratchCanvas.width = this.scratchCanvas.height = 0;