diff --git a/.eslintrc b/.eslintrc index f7e7d2def..d4dc30f40 100644 --- a/.eslintrc +++ b/.eslintrc @@ -242,6 +242,7 @@ }], // ECMAScript 6 + "arrow-body-style": ["error", "as-needed"], "constructor-super": "error", "no-class-assign": "error", "no-const-assign": "error", diff --git a/src/core/annotation.js b/src/core/annotation.js index e478a19b5..e795f8572 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -79,6 +79,7 @@ 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, @@ -2133,11 +2134,8 @@ class WidgetAnnotation extends Annotation { value, }; - const encoder = val => { - return isAscii(val) - ? val - : stringToUTF16String(val, /* bigEndian = */ true); - }; + const encoder = val => + isAscii(val) ? val : stringToUTF16String(val, /* bigEndian = */ true); dict.set("V", Array.isArray(value) ? value.map(encoder) : encoder(value)); this.amendSavedDict(annotationStorage, dict); diff --git a/src/core/catalog.js b/src/core/catalog.js index c82405585..c308a87f3 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -893,14 +893,13 @@ class Catalog { case "PrintPageRange": // The number of elements must be even. if (Array.isArray(value) && value.length % 2 === 0) { - const isValid = value.every((page, i, arr) => { - return ( + const isValid = value.every( + (page, i, arr) => Number.isInteger(page) && page > 0 && (i === 0 || page >= arr[i - 1]) && page <= this.numPages - ); - }); + ); if (isValid) { prefValue = value; } diff --git a/src/core/document.js b/src/core/document.js index 00467497f..37d81d9bc 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -1577,6 +1577,7 @@ 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, diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 5e9d7b8fa..374c903d3 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -1039,14 +1039,15 @@ class PartialEvaluator { return translated; }) - .catch(reason => { - return new TranslatedFont({ - loadedName: "g_font_error", - font: new ErrorFont(`Type3 font load error: ${reason}`), - dict: translated.font, - evaluatorOptions: this.options, - }); - }); + .catch( + reason => + new TranslatedFont({ + loadedName: "g_font_error", + font: new ErrorFont(`Type3 font load error: ${reason}`), + dict: translated.font, + evaluatorOptions: this.options, + }) + ); }) .then(translated => { state.font = translated.font; @@ -1129,6 +1130,7 @@ class PartialEvaluator { case "Font": isSimpleGState = false; + // eslint-disable-next-line arrow-body-style promise = promise.then(() => { return this.handleSetFont( resources, @@ -1154,6 +1156,7 @@ class PartialEvaluator { if (value instanceof Dict) { isSimpleGState = false; + // eslint-disable-next-line arrow-body-style promise = promise.then(() => { return this.handleSMask( value, @@ -1214,6 +1217,7 @@ class PartialEvaluator { fallbackFontDict = null, cssFontInfo = null ) { + // eslint-disable-next-line arrow-body-style const errorFont = async () => { return new TranslatedFont({ loadedName: "g_font_error", diff --git a/src/core/xfa/utils.js b/src/core/xfa/utils.js index 14509202f..6db780e4a 100644 --- a/src/core/xfa/utils.js +++ b/src/core/xfa/utils.js @@ -129,12 +129,10 @@ function getRelevant(data) { return data .trim() .split(/\s+/) - .map(e => { - return { - excluded: e[0] === "-", - viewname: e.substring(1), - }; - }); + .map(e => ({ + excluded: e[0] === "-", + viewname: e.substring(1), + })); } function getColor(data, def = [0, 0, 0]) { diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 70d25a974..4d862e6c9 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -1838,9 +1838,10 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement { const getItems = event => { const options = event.target.options; - return Array.prototype.map.call(options, option => { - return { displayValue: option.textContent, exportValue: option.value }; - }); + return Array.prototype.map.call(options, option => ({ + displayValue: option.textContent, + exportValue: option.value, + })); }; if (this.enableScripting && this.hasJSActions) { diff --git a/src/display/api.js b/src/display/api.js index f56dcc355..1fb547bbf 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -3013,14 +3013,12 @@ class WorkerTransport { } const promise = this.messageHandler .sendWithPromise(name, null) - .then(results => { - return { - info: results[0], - metadata: results[1] ? new Metadata(results[1]) : null, - contentDispositionFilename: this._fullReader?.filename ?? null, - contentLength: this._fullReader?.contentLength ?? null, - }; - }); + .then(results => ({ + info: results[0], + metadata: results[1] ? new Metadata(results[1]) : null, + contentDispositionFilename: this._fullReader?.filename ?? null, + contentLength: this._fullReader?.contentLength ?? null, + })); this.#methodPromises.set(name, promise); return promise; } diff --git a/src/display/canvas.js b/src/display/canvas.js index c43bc6a6a..808c9c693 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -2359,8 +2359,8 @@ class CanvasGraphics { const color = IR[1]; const baseTransform = this.baseTransform || getCurrentTransform(this.ctx); const canvasGraphicsFactory = { - createCanvasGraphics: ctx => { - return new CanvasGraphics( + createCanvasGraphics: ctx => + new CanvasGraphics( ctx, this.commonObjs, this.objs, @@ -2370,8 +2370,7 @@ class CanvasGraphics { optionalContentConfig: this.optionalContentConfig, markedContentStack: this.markedContentStack, } - ); - }, + ), }; pattern = new TilingPattern( IR, diff --git a/src/display/display_utils.js b/src/display/display_utils.js index e46b67295..e7e52c6c1 100644 --- a/src/display/display_utils.js +++ b/src/display/display_utils.js @@ -466,15 +466,13 @@ class DOMCMapReaderFactory extends BaseCMapReaderFactory { return fetchData( url, /* type = */ this.isCompressed ? "arraybuffer" : "text" - ).then(data => { - return { - cMapData: - data instanceof ArrayBuffer - ? new Uint8Array(data) - : stringToBytes(data), - compressionType, - }; - }); + ).then(data => ({ + cMapData: + data instanceof ArrayBuffer + ? new Uint8Array(data) + : stringToBytes(data), + compressionType, + })); } } diff --git a/src/display/editor/tools.js b/src/display/editor/tools.js index cdd3232cd..4794012ba 100644 --- a/src/display/editor/tools.js +++ b/src/display/editor/tools.js @@ -606,15 +606,14 @@ class AnnotationEditorUIManager { static get _keyboardManager() { const proto = AnnotationEditorUIManager.prototype; - const arrowChecker = self => { - // If the focused element is an input, we don't want to handle the arrow. - // For example, sliders can be controlled with the arrow keys. - return ( - self.#container.contains(document.activeElement) && - document.activeElement.tagName !== "BUTTON" && - self.hasSomethingToControl() - ); - }; + /** + * If the focused element is an input, we don't want to handle the arrow. + * For example, sliders can be controlled with the arrow keys. + */ + const arrowChecker = self => + self.#container.contains(document.activeElement) && + document.activeElement.tagName !== "BUTTON" && + self.hasSomethingToControl(); const textInputChecker = (_self, { target: el }) => { if (el instanceof HTMLInputElement) { diff --git a/src/display/node_utils.js b/src/display/node_utils.js index 643d3f4d3..eb1219e8e 100644 --- a/src/display/node_utils.js +++ b/src/display/node_utils.js @@ -98,9 +98,7 @@ class NodeCMapReaderFactory extends BaseCMapReaderFactory { * @ignore */ _fetchData(url, compressionType) { - return fetchData(url).then(data => { - return { cMapData: data, compressionType }; - }); + return fetchData(url).then(data => ({ cMapData: data, compressionType })); } } diff --git a/src/shared/util.js b/src/shared/util.js index a750a0b6e..eb184a56c 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -1039,9 +1039,9 @@ function normalizeUnicode(str) { /([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu; NormalizationMap = new Map([["ſt", "ſt"]]); } - return str.replaceAll(NormalizeRegex, (_, p1, p2) => { - return p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2); - }); + return str.replaceAll(NormalizeRegex, (_, p1, p2) => + p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2) + ); } function getUuid() { diff --git a/test/driver.js b/test/driver.js index 6e4ae0393..6a6c80bbb 100644 --- a/test/driver.js +++ b/test/driver.js @@ -106,6 +106,7 @@ 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(); @@ -117,6 +118,7 @@ async function inlineImages(node, silentErrors = false) { reader.readAsDataURL(blob); }); }) + // eslint-disable-next-line arrow-body-style .then(dataUrl => { return new Promise((resolve, reject) => { image.onload = resolve; diff --git a/test/integration/highlight_editor_spec.mjs b/test/integration/highlight_editor_spec.mjs index 8c79f217c..1c8ba8db4 100644 --- a/test/integration/highlight_editor_spec.mjs +++ b/test/integration/highlight_editor_spec.mjs @@ -38,8 +38,8 @@ const getXY = (page, selector) => return `${bbox.x}::${bbox.y}`; }, selector); -const getSpanRectFromText = (page, pageNumber, text) => { - return page.evaluate( +const getSpanRectFromText = (page, pageNumber, text) => + page.evaluate( (number, content) => { for (const el of document.querySelectorAll( `.page[data-page-number="${number}"] > .textLayer > span` @@ -54,7 +54,6 @@ const getSpanRectFromText = (page, pageNumber, text) => { pageNumber, text ); -}; describe("Highlight Editor", () => { describe("Editor must be removed without exception", () => { diff --git a/test/integration/test_utils.mjs b/test/integration/test_utils.mjs index f99b9e4e2..4705a2f49 100644 --- a/test/integration/test_utils.mjs +++ b/test/integration/test_utils.mjs @@ -265,9 +265,10 @@ async function serializeBitmapDimensions(page) { const { map } = window.PDFViewerApplication.pdfDocument.annotationStorage.serializable; return map - ? Array.from(map.values(), x => { - return { width: x.bitmap.width, height: x.bitmap.height }; - }) + ? Array.from(map.values(), x => ({ + width: x.bitmap.width, + height: x.bitmap.height, + })) : []; }); } diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index 333a73ef9..ad15bff75 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -2689,9 +2689,7 @@ describe("api", function () { const viewPromises = []; for (let i = 0; i < numPages; i++) { - viewPromises[i] = pdfDoc.getPage(i + 1).then(pdfPage => { - return pdfPage.view; - }); + viewPromises[i] = pdfDoc.getPage(i + 1).then(pdfPage => pdfPage.view); } const [page1, page2, page3] = await Promise.all(viewPromises); @@ -3412,7 +3410,9 @@ 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); @@ -3425,7 +3425,9 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`) }); }); + // 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); diff --git a/test/unit/scripting_spec.js b/test/unit/scripting_spec.js index 89e45bced..f9fbb58ce 100644 --- a/test/unit/scripting_spec.js +++ b/test/unit/scripting_spec.js @@ -152,14 +152,12 @@ describe("Scripting", function () { }); it("should get field using a path", async () => { - const base = value => { - return { - id: getId(), - value, - actions: {}, - type: "text", - }; - }; + const base = value => ({ + id: getId(), + value, + actions: {}, + type: "text", + }); const data = { objects: { A: [base(1)], diff --git a/web/pdf_document_properties.js b/web/pdf_document_properties.js index 2fa9fdc6c..f67ab0e30 100644 --- a/web/pdf_document_properties.js +++ b/web/pdf_document_properties.js @@ -129,6 +129,7 @@ class PDFDocumentProperties { this.#parseFileSize(contentLength), this.#parseDate(info.CreationDate), this.#parseDate(info.ModDate), + // eslint-disable-next-line arrow-body-style this.pdfDocument.getPage(currentPageNumber).then(pdfPage => { return this.#parsePageSize(getPageSizeInches(pdfPage), pagesRotation); }), diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index afb565e97..99de91582 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -842,12 +842,11 @@ class PDFFindController { const extractTextCapability = new PromiseCapability(); this._extractTextPromises[i] = extractTextCapability.promise; + // eslint-disable-next-line arrow-body-style promise = promise.then(() => { return this._pdfDocument .getPage(i + 1) - .then(pdfPage => { - return pdfPage.getTextContent(textOptions); - }) + .then(pdfPage => pdfPage.getTextContent(textOptions)) .then( textContent => { const strBuf = [];