From a2d15ceb84122167af465435199ff7d37044fad1 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 17 Feb 2025 13:40:09 +0100 Subject: [PATCH] Remove a few `eslint-disable` statements in the `web/` folder These cases could be easily re-written to avoid having to disable ESLint rules. --- web/generic_scripting.js | 10 ++-------- web/pdf_find_controller.js | 9 ++++----- web/pdf_print_service.js | 38 ++++++++++++++++++-------------------- 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/web/generic_scripting.js b/web/generic_scripting.js index 7883c5c5024d1..b29554dad3210 100644 --- a/web/generic_scripting.js +++ b/web/generic_scripting.js @@ -18,19 +18,13 @@ import { getPdfFilenameFromUrl } from "pdfjs-lib"; async function docProperties(pdfDocument) { const url = "", baseUrl = url.split("#", 1)[0]; - // eslint-disable-next-line prefer-const - let { info, metadata, contentDispositionFilename, contentLength } = + const { info, metadata, contentDispositionFilename, contentLength } = await pdfDocument.getMetadata(); - if (!contentLength) { - const { length } = await pdfDocument.getDownloadInfo(); - contentLength = length; - } - return { ...info, baseURL: baseUrl, - filesize: contentLength, + filesize: contentLength || (await pdfDocument.getDownloadInfo()).length, filename: contentDispositionFilename || getPdfFilenameFromUrl(url), metadata: metadata?.getRaw(), authors: metadata?.get("dc:creator"), diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index a9fa441a13728..6e87c3149c21a 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -886,9 +886,8 @@ class PDFFindController { const { promise, resolve } = Promise.withResolvers(); this._extractTextPromises[i] = promise; - // eslint-disable-next-line arrow-body-style - deferred = deferred.then(() => { - return this._pdfDocument + deferred = deferred.then(() => + this._pdfDocument .getPage(i + 1) .then(pdfPage => pdfPage.getTextContent(textOptions)) .then( @@ -921,8 +920,8 @@ class PDFFindController { this._hasDiacritics[i] = false; resolve(); } - ); - }); + ) + ); } } diff --git a/web/pdf_print_service.js b/web/pdf_print_service.js index 77452e48422e2..417c90b0ed495 100644 --- a/web/pdf_print_service.js +++ b/web/pdf_print_service.js @@ -260,27 +260,25 @@ window.print = function () { ensureOverlay().then(function () { overlayManager.closeIfActive(dialog); }); - return; // eslint-disable-line no-unsafe-finally + } else { + const activeServiceOnEntry = activeService; + activeService + .renderPages() + .then(() => activeServiceOnEntry.performPrint()) + .catch(() => { + // Ignore any error messages. + }) + .then(() => { + // aborts acts on the "active" print request, so we need to check + // whether the print request (activeServiceOnEntry) is still active. + // Without the check, an unrelated print request (created after + // aborting this print request while the pages were being generated) + // would be aborted. + if (activeServiceOnEntry.active) { + abort(); + } + }); } - const activeServiceOnEntry = activeService; - activeService - .renderPages() - .then(function () { - return activeServiceOnEntry.performPrint(); - }) - .catch(function () { - // Ignore any error messages. - }) - .then(function () { - // aborts acts on the "active" print request, so we need to check - // whether the print request (activeServiceOnEntry) is still active. - // Without the check, an unrelated print request (created after aborting - // this print request while the pages were being generated) would be - // aborted. - if (activeServiceOnEntry.active) { - abort(); - } - }); } };