From 36979e9eb2ef751c24662834b44403d3daf5feb4 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 17 Feb 2025 15:45:44 +0100 Subject: [PATCH] Fix all outstanding ESLint `arrow-body-style` warnings Currently this rule is disabled in a number of spots across the code-base, and unless absolutely necessary we probably shouldn't disable linting, so let's just update the code to fix all the outstanding cases. --- src/core/annotation.js | 19 +++++++--------- src/core/document.js | 36 +++++++++++++++--------------- src/core/evaluator.js | 6 ++--- test/driver.js | 50 +++++++++++++++++++++--------------------- test/unit/api_spec.js | 42 +++++++++++++++-------------------- 5 files changed, 71 insertions(+), 82 deletions(-) diff --git a/src/core/annotation.js b/src/core/annotation.js index 0693a04dc..23d383e93 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -84,17 +84,14 @@ class AnnotationFactory { // with "GoToE" actions, from throwing and thus breaking parsing: pdfManager.ensureCatalog("attachments"), ]).then( - // eslint-disable-next-line arrow-body-style - ([acroForm, xfaDatasets, structTreeRoot, baseUrl, attachments]) => { - return { - pdfManager, - acroForm: acroForm instanceof Dict ? acroForm : Dict.empty, - xfaDatasets, - structTreeRoot, - baseUrl, - attachments, - }; - }, + ([acroForm, xfaDatasets, structTreeRoot, baseUrl, attachments]) => ({ + pdfManager, + acroForm: acroForm instanceof Dict ? acroForm : Dict.empty, + xfaDatasets, + structTreeRoot, + baseUrl, + attachments, + }), reason => { warn(`createGlobals: "${reason}".`); return null; diff --git a/src/core/document.js b/src/core/document.js index ffaeeb738..b3a550c4e 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -1620,24 +1620,24 @@ class PDFDocument { } else { promise = catalog.getPageDict(pageIndex); } - // eslint-disable-next-line arrow-body-style - promise = promise.then(([pageDict, ref]) => { - return new Page({ - pdfManager: this.pdfManager, - xref: this.xref, - pageIndex, - pageDict, - ref, - globalIdFactory: this._globalIdFactory, - fontCache: catalog.fontCache, - builtInCMapCache: catalog.builtInCMapCache, - standardFontDataCache: catalog.standardFontDataCache, - globalImageCache: catalog.globalImageCache, - systemFontCache: catalog.systemFontCache, - nonBlendModesSet: catalog.nonBlendModesSet, - xfaFactory, - }); - }); + promise = promise.then( + ([pageDict, ref]) => + new Page({ + pdfManager: this.pdfManager, + xref: this.xref, + pageIndex, + pageDict, + ref, + globalIdFactory: this._globalIdFactory, + fontCache: catalog.fontCache, + builtInCMapCache: catalog.builtInCMapCache, + standardFontDataCache: catalog.standardFontDataCache, + globalImageCache: catalog.globalImageCache, + systemFontCache: catalog.systemFontCache, + nonBlendModesSet: catalog.nonBlendModesSet, + xfaFactory, + }) + ); this._pagePromises.set(pageIndex, promise); return promise; diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 46026836c..484e167c0 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -1231,15 +1231,13 @@ class PartialEvaluator { fallbackFontDict = null, cssFontInfo = null ) { - // eslint-disable-next-line arrow-body-style - const errorFont = async () => { - return new TranslatedFont({ + const errorFont = async () => + new TranslatedFont({ loadedName: "g_font_error", font: new ErrorFont(`Font "${fontName}" is not available.`), dict: font, evaluatorOptions: this.options, }); - }; let fontRef; if (font) { diff --git a/test/driver.js b/test/driver.js index 67fb667d6..f9fbee52e 100644 --- a/test/driver.js +++ b/test/driver.js @@ -106,33 +106,33 @@ async function inlineImages(node, silentErrors = false) { } return response.blob(); }) - // eslint-disable-next-line arrow-body-style - .then(blob => { - return new Promise((resolve, reject) => { - const reader = new FileReader(); - reader.onload = () => { - resolve(reader.result); - }; - reader.onerror = reject; + .then( + blob => + new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onload = () => { + resolve(reader.result); + }; + reader.onerror = reject; - reader.readAsDataURL(blob); - }); - }) - // eslint-disable-next-line arrow-body-style - .then(dataUrl => { - return new Promise((resolve, reject) => { - image.onload = resolve; - image.onerror = evt => { - if (silentErrors) { - resolve(); - return; - } - reject(evt); - }; + reader.readAsDataURL(blob); + }) + ) + .then( + dataUrl => + new Promise((resolve, reject) => { + image.onload = resolve; + image.onerror = evt => { + if (silentErrors) { + resolve(); + return; + } + reject(evt); + }; - image.src = dataUrl; - }); - }) + image.src = dataUrl; + }) + ) .catch(reason => { throw new Error(`Error inlining image (${url}): ${reason}`); }) diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index bc0e8bb94..5e2c2550f 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -4110,34 +4110,28 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`) }) ); - // eslint-disable-next-line arrow-body-style - const result1 = loadingTask1.promise.then(pdfDoc => { - // eslint-disable-next-line arrow-body-style - return pdfDoc.getPage(1).then(pdfPage => { - return pdfPage.getOperatorList().then(opList => { - expect(opList.fnArray.length).toBeGreaterThan(100); - expect(opList.argsArray.length).toBeGreaterThan(100); - expect(opList.lastChunk).toEqual(true); - expect(opList.separateAnnots).toEqual(null); + const result1 = loadingTask1.promise.then(async pdfDoc => { + const pdfPage = await pdfDoc.getPage(1); + const opList = await pdfPage.getOperatorList(); - return loadingTask1.destroy(); - }); - }); + expect(opList.fnArray.length).toBeGreaterThan(100); + expect(opList.argsArray.length).toBeGreaterThan(100); + expect(opList.lastChunk).toEqual(true); + expect(opList.separateAnnots).toEqual(null); + + await loadingTask1.destroy(); }); - // eslint-disable-next-line arrow-body-style - const result2 = loadingTask2.promise.then(pdfDoc => { - // eslint-disable-next-line arrow-body-style - return pdfDoc.getPage(1).then(pdfPage => { - return pdfPage.getOperatorList().then(opList => { - expect(opList.fnArray.length).toEqual(0); - expect(opList.argsArray.length).toEqual(0); - expect(opList.lastChunk).toEqual(true); - expect(opList.separateAnnots).toEqual(null); + const result2 = loadingTask2.promise.then(async pdfDoc => { + const pdfPage = await pdfDoc.getPage(1); + const opList = await pdfPage.getOperatorList(); - return loadingTask2.destroy(); - }); - }); + expect(opList.fnArray.length).toEqual(0); + expect(opList.argsArray.length).toEqual(0); + expect(opList.lastChunk).toEqual(true); + expect(opList.separateAnnots).toEqual(null); + + await loadingTask2.destroy(); }); await Promise.all([result1, result2]);