Merge pull request #9468 from Snuffleupagus/eslint-mozilla-plugin

Enable the `mozilla/avoid-removeChild` and `mozilla/use-includes-instead-of-indexOf` ESLint rules globally
This commit is contained in:
Tim van der Meij 2018-02-11 16:08:18 +01:00 committed by GitHub
commit 368a91b577
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 33 additions and 22 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,10 @@
}, },
"rules": { "rules": {
// Plugins
"mozilla/avoid-removeChild": "error",
"mozilla/use-includes-instead-of-indexOf": "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

@ -46,7 +46,7 @@ limitations under the License.
return; return;
} }
var scheme = url.slice(0, schemeIndex).toLowerCase(); var scheme = url.slice(0, schemeIndex).toLowerCase();
if (schemes.indexOf(scheme) >= 0) { if (schemes.includes(scheme)) {
url = url.split('#')[0]; url = url.split('#')[0];
if (url.charAt(schemeIndex) === ':') { if (url.charAt(schemeIndex) === ':') {
url = encodeURIComponent(url); url = encodeURIComponent(url);

View File

@ -29,7 +29,7 @@ function getViewerURL(pdf_url) {
* @return {boolean} True if the PDF file should be downloaded. * @return {boolean} True if the PDF file should be downloaded.
*/ */
function isPdfDownloadable(details) { function isPdfDownloadable(details) {
if (details.url.indexOf('pdfjs.action=download') >= 0) { if (details.url.includes('pdfjs.action=download')) {
return true; return true;
} }
// Display the PDF viewer regardless of the Content-Disposition header if the // Display the PDF viewer regardless of the Content-Disposition header if the
@ -39,8 +39,7 @@ function isPdfDownloadable(details) {
// viewer to open the PDF, but first check whether the Content-Disposition // viewer to open the PDF, but first check whether the Content-Disposition
// header specifies an attachment. This allows sites like Google Drive to // header specifies an attachment. This allows sites like Google Drive to
// operate correctly (#6106). // operate correctly (#6106).
if (details.type === 'main_frame' && if (details.type === 'main_frame' && !details.url.includes('=download')) {
details.url.indexOf('=download') === -1) {
return false; return false;
} }
var cdHeader = (details.responseHeaders && var cdHeader = (details.responseHeaders &&

2
external/.eslintrc vendored
View File

@ -8,6 +8,8 @@
}, },
"rules": { "rules": {
"mozilla/use-includes-instead-of-indexOf": "off",
"object-shorthand": "off", "object-shorthand": "off",
}, },
} }

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* eslint-disable no-extend-native */ /* eslint-disable no-extend-native, mozilla/use-includes-instead-of-indexOf */
/* globals PDFJS */ /* globals PDFJS */
// Skip compatibility checks for the extensions and if we already ran // Skip compatibility checks for the extensions and if we already ran
@ -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

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* eslint-disable object-shorthand */ /* eslint-disable object-shorthand, mozilla/use-includes-instead-of-indexOf */
'use strict'; 'use strict';

View File

@ -305,7 +305,7 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars
self.manifest = JSON.parse(r.responseText); self.manifest = JSON.parse(r.responseText);
if (self.testFilter && self.testFilter.length) { if (self.testFilter && self.testFilter.length) {
self.manifest = self.manifest.filter(function(item) { self.manifest = self.manifest.filter(function(item) {
return self.testFilter.indexOf(item.id) !== -1; return self.testFilter.includes(item.id);
}); });
} }
self.currentTask = 0; self.currentTask = 0;
@ -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) {
@ -434,7 +433,7 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars
} }
} }
if (task.skipPages && task.skipPages.indexOf(task.pageNum) >= 0) { if (task.skipPages && task.skipPages.includes(task.pageNum)) {
this._log(' Skipping page ' + task.pageNum + '/' + this._log(' Skipping page ' + task.pageNum + '/' +
task.pdfDoc.numPages + '...\n'); task.pdfDoc.numPages + '...\n');
task.pageNum++; task.pageNum++;

View File

@ -1,3 +1,5 @@
/* eslint-disable mozilla/use-includes-instead-of-indexOf */
'use strict'; 'use strict';
var fs = require('fs'); var fs = require('fs');

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* eslint-disable object-shorthand */ /* eslint-disable object-shorthand, mozilla/use-includes-instead-of-indexOf */
'use strict'; 'use strict';

View File

@ -1208,7 +1208,7 @@ let PDFViewerApplication = {
]; ];
if (info.Producer) { if (info.Producer) {
KNOWN_GENERATORS.some(function (generator, s, i) { KNOWN_GENERATORS.some(function (generator, s, i) {
if (generator.indexOf(s) < 0) { if (!generator.includes(s)) {
return false; return false;
} }
generatorId = i + 1; generatorId = i + 1;
@ -1490,7 +1490,7 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
} }
try { try {
let viewerOrigin = new URL(window.location.href).origin || 'null'; let viewerOrigin = new URL(window.location.href).origin || 'null';
if (HOSTED_VIEWER_ORIGINS.indexOf(viewerOrigin) >= 0) { if (HOSTED_VIEWER_ORIGINS.includes(viewerOrigin)) {
// Hosted or local viewer, allow for any file locations // Hosted or local viewer, allow for any file locations
return; return;
} }

View File

@ -338,7 +338,7 @@ var Stepper = (function StepperClosure() {
line.className = 'line'; line.className = 'line';
line.dataset.idx = i; line.dataset.idx = i;
chunk.appendChild(line); chunk.appendChild(line);
var checked = this.breakPoints.indexOf(i) !== -1; var checked = this.breakPoints.includes(i);
var args = operatorList.argsArray[i] || []; var args = operatorList.argsArray[i] || [];
var breakCell = c('td'); var breakCell = c('td');
@ -521,7 +521,7 @@ window.PDFBug = (function PDFBugClosure() {
} }
for (var i = 0; i < tools.length; ++i) { for (var i = 0; i < tools.length; ++i) {
var tool = tools[i]; var tool = tools[i];
if (all || ids.indexOf(tool.id) !== -1) { if (all || ids.includes(tool.id)) {
tool.enabled = true; tool.enabled = true;
} }
} }

View File

@ -43,13 +43,13 @@ 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]) {
// If _parent == self, then opening an identical URL with different // If _parent == self, then opening an identical URL with different
// location hash will only cause a navigation, not a download. // location hash will only cause a navigation, not a download.
let padCharacter = blobUrl.indexOf('?') === -1 ? '?' : '&'; let padCharacter = blobUrl.includes('?') ? '&' : '?';
blobUrl = blobUrl.replace(/#|$/, padCharacter + '$&'); blobUrl = blobUrl.replace(/#|$/, padCharacter + '$&');
} }
window.open(blobUrl, '_parent'); window.open(blobUrl, '_parent');

View File

@ -192,7 +192,7 @@ class PDFLinkService {
*/ */
setHash(hash) { setHash(hash) {
let pageNumber, dest; let pageNumber, dest;
if (hash.indexOf('=') >= 0) { if (hash.includes('=')) {
let params = parseQueryString(hash); let params = parseQueryString(hash);
if ('search' in params) { if ('search' in params) {
this.eventBus.dispatch('findfromurlhash', { this.eventBus.dispatch('findfromurlhash', {
@ -215,7 +215,7 @@ class PDFLinkService {
let zoomArg = zoomArgs[0]; let zoomArg = zoomArgs[0];
let zoomArgNumber = parseFloat(zoomArg); let zoomArgNumber = parseFloat(zoomArg);
if (zoomArg.indexOf('Fit') === -1) { if (!zoomArg.includes('Fit')) {
// If the zoomArg is a number, it has to get divided by 100. If it's // If the zoomArg is a number, it has to get divided by 100. If it's
// a string, it should stay as it is. // a string, it should stay as it is.
dest = [null, { name: 'XYZ', }, dest = [null, { name: 'XYZ', },

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;

View File

@ -420,7 +420,7 @@ function getPDFFileNameFromURL(url, defaultFilename = 'document.pdf') {
reFilename.exec(splitURI[3]); reFilename.exec(splitURI[3]);
if (suggestedFilename) { if (suggestedFilename) {
suggestedFilename = suggestedFilename[0]; suggestedFilename = suggestedFilename[0];
if (suggestedFilename.indexOf('%') !== -1) { if (suggestedFilename.includes('%')) {
// URL-encoded %2Fpath%2Fto%2Ffile.pdf should be file.pdf // URL-encoded %2Fpath%2Fto%2Ffile.pdf should be file.pdf
try { try {
suggestedFilename = suggestedFilename =