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.
This commit is contained in:
Jonas Jenwald 2025-02-17 15:45:44 +01:00
parent affce70a09
commit 36979e9eb2
5 changed files with 71 additions and 82 deletions

View File

@ -84,17 +84,14 @@ class AnnotationFactory {
// with "GoToE" actions, from throwing and thus breaking parsing: // with "GoToE" actions, from throwing and thus breaking parsing:
pdfManager.ensureCatalog("attachments"), pdfManager.ensureCatalog("attachments"),
]).then( ]).then(
// eslint-disable-next-line arrow-body-style ([acroForm, xfaDatasets, structTreeRoot, baseUrl, attachments]) => ({
([acroForm, xfaDatasets, structTreeRoot, baseUrl, attachments]) => {
return {
pdfManager, pdfManager,
acroForm: acroForm instanceof Dict ? acroForm : Dict.empty, acroForm: acroForm instanceof Dict ? acroForm : Dict.empty,
xfaDatasets, xfaDatasets,
structTreeRoot, structTreeRoot,
baseUrl, baseUrl,
attachments, attachments,
}; }),
},
reason => { reason => {
warn(`createGlobals: "${reason}".`); warn(`createGlobals: "${reason}".`);
return null; return null;

View File

@ -1620,9 +1620,9 @@ class PDFDocument {
} else { } else {
promise = catalog.getPageDict(pageIndex); promise = catalog.getPageDict(pageIndex);
} }
// eslint-disable-next-line arrow-body-style promise = promise.then(
promise = promise.then(([pageDict, ref]) => { ([pageDict, ref]) =>
return new Page({ new Page({
pdfManager: this.pdfManager, pdfManager: this.pdfManager,
xref: this.xref, xref: this.xref,
pageIndex, pageIndex,
@ -1636,8 +1636,8 @@ class PDFDocument {
systemFontCache: catalog.systemFontCache, systemFontCache: catalog.systemFontCache,
nonBlendModesSet: catalog.nonBlendModesSet, nonBlendModesSet: catalog.nonBlendModesSet,
xfaFactory, xfaFactory,
}); })
}); );
this._pagePromises.set(pageIndex, promise); this._pagePromises.set(pageIndex, promise);
return promise; return promise;

View File

@ -1231,15 +1231,13 @@ class PartialEvaluator {
fallbackFontDict = null, fallbackFontDict = null,
cssFontInfo = null cssFontInfo = null
) { ) {
// eslint-disable-next-line arrow-body-style const errorFont = async () =>
const errorFont = async () => { new TranslatedFont({
return new TranslatedFont({
loadedName: "g_font_error", loadedName: "g_font_error",
font: new ErrorFont(`Font "${fontName}" is not available.`), font: new ErrorFont(`Font "${fontName}" is not available.`),
dict: font, dict: font,
evaluatorOptions: this.options, evaluatorOptions: this.options,
}); });
};
let fontRef; let fontRef;
if (font) { if (font) {

View File

@ -106,9 +106,9 @@ async function inlineImages(node, silentErrors = false) {
} }
return response.blob(); return response.blob();
}) })
// eslint-disable-next-line arrow-body-style .then(
.then(blob => { blob =>
return new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const reader = new FileReader(); const reader = new FileReader();
reader.onload = () => { reader.onload = () => {
resolve(reader.result); resolve(reader.result);
@ -116,11 +116,11 @@ async function inlineImages(node, silentErrors = false) {
reader.onerror = reject; reader.onerror = reject;
reader.readAsDataURL(blob); reader.readAsDataURL(blob);
});
}) })
// eslint-disable-next-line arrow-body-style )
.then(dataUrl => { .then(
return new Promise((resolve, reject) => { dataUrl =>
new Promise((resolve, reject) => {
image.onload = resolve; image.onload = resolve;
image.onerror = evt => { image.onerror = evt => {
if (silentErrors) { if (silentErrors) {
@ -131,8 +131,8 @@ async function inlineImages(node, silentErrors = false) {
}; };
image.src = dataUrl; image.src = dataUrl;
});
}) })
)
.catch(reason => { .catch(reason => {
throw new Error(`Error inlining image (${url}): ${reason}`); throw new Error(`Error inlining image (${url}): ${reason}`);
}) })

View File

@ -4110,34 +4110,28 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
}) })
); );
// eslint-disable-next-line arrow-body-style const result1 = loadingTask1.promise.then(async pdfDoc => {
const result1 = loadingTask1.promise.then(pdfDoc => { const pdfPage = await pdfDoc.getPage(1);
// eslint-disable-next-line arrow-body-style const opList = await pdfPage.getOperatorList();
return pdfDoc.getPage(1).then(pdfPage => {
return pdfPage.getOperatorList().then(opList => {
expect(opList.fnArray.length).toBeGreaterThan(100); expect(opList.fnArray.length).toBeGreaterThan(100);
expect(opList.argsArray.length).toBeGreaterThan(100); expect(opList.argsArray.length).toBeGreaterThan(100);
expect(opList.lastChunk).toEqual(true); expect(opList.lastChunk).toEqual(true);
expect(opList.separateAnnots).toEqual(null); expect(opList.separateAnnots).toEqual(null);
return loadingTask1.destroy(); await loadingTask1.destroy();
});
});
}); });
// eslint-disable-next-line arrow-body-style const result2 = loadingTask2.promise.then(async pdfDoc => {
const result2 = loadingTask2.promise.then(pdfDoc => { const pdfPage = await pdfDoc.getPage(1);
// eslint-disable-next-line arrow-body-style const opList = await pdfPage.getOperatorList();
return pdfDoc.getPage(1).then(pdfPage => {
return pdfPage.getOperatorList().then(opList => {
expect(opList.fnArray.length).toEqual(0); expect(opList.fnArray.length).toEqual(0);
expect(opList.argsArray.length).toEqual(0); expect(opList.argsArray.length).toEqual(0);
expect(opList.lastChunk).toEqual(true); expect(opList.lastChunk).toEqual(true);
expect(opList.separateAnnots).toEqual(null); expect(opList.separateAnnots).toEqual(null);
return loadingTask2.destroy(); await loadingTask2.destroy();
});
});
}); });
await Promise.all([result1, result2]); await Promise.all([result1, result2]);